From d351d19d5d8927e84d7860a3b08dc84f0292a209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20S=C3=A9nave?= <59770457+nsenave@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:08:23 +0200 Subject: [PATCH] feat: component position property (#259) --- .../lunatic/model/flat/ComponentPosition.java | 34 +++++++++++++++++++ .../lunatic/model/flat/ComponentType.java | 3 ++ .../AccordionSerializationTest.java | 3 ++ 3 files changed, 40 insertions(+) create mode 100644 src/main/java/fr/insee/lunatic/model/flat/ComponentPosition.java diff --git a/src/main/java/fr/insee/lunatic/model/flat/ComponentPosition.java b/src/main/java/fr/insee/lunatic/model/flat/ComponentPosition.java new file mode 100644 index 0000000..819d5f3 --- /dev/null +++ b/src/main/java/fr/insee/lunatic/model/flat/ComponentPosition.java @@ -0,0 +1,34 @@ +package fr.insee.lunatic.model.flat; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Enum to define where a component should be displayed in a page. + */ +public enum ComponentPosition { + + /** Equivalent to a null value. This value is there to indicate explicitly that the position option is at default + * (a null value is implicit). */ + DEFAULT("default"), + + /** The component should be displayed on the bottom of the page. */ + BOTTOM("bottom"); + + @JsonValue + private final String value; + + @JsonCreator + ComponentPosition(String value) { + this.value = value; + } + + public static ComponentPosition fromValue(String value) { + for (ComponentPosition position : ComponentPosition.values()) { + if (value.equals(position.value)) + return position; + } + throw new IllegalArgumentException(value); + } + +} diff --git a/src/main/java/fr/insee/lunatic/model/flat/ComponentType.java b/src/main/java/fr/insee/lunatic/model/flat/ComponentType.java index e780458..f7c1217 100644 --- a/src/main/java/fr/insee/lunatic/model/flat/ComponentType.java +++ b/src/main/java/fr/insee/lunatic/model/flat/ComponentType.java @@ -113,6 +113,9 @@ public abstract class ComponentType { protected Boolean mandatory; protected String page; + /** {@link ComponentPosition} */ + protected ComponentPosition position; + /** This property should be moved in the Suggester component. * Yet having this property defined here makes Eno suggester specific treatment easier. * To be moved in the Suggester class when the suggester specific treatment is removed in Eno. */ diff --git a/src/test/java/fr/insee/lunatic/conversion/AccordionSerializationTest.java b/src/test/java/fr/insee/lunatic/conversion/AccordionSerializationTest.java index 2d2ce84..dd3a7f5 100644 --- a/src/test/java/fr/insee/lunatic/conversion/AccordionSerializationTest.java +++ b/src/test/java/fr/insee/lunatic/conversion/AccordionSerializationTest.java @@ -20,6 +20,7 @@ class AccordionSerializationTest { "components": [ { "componentType": "Accordion", + "position": "bottom", "items": [ { "label": { @@ -51,6 +52,7 @@ void serializeAccordion() throws SerializationException, JSONException { // Questionnaire questionnaire = new Questionnaire(); Accordion accordion = new Accordion(); + accordion.setPosition(ComponentPosition.BOTTOM); Accordion.Item item1 = new Accordion.Item(); item1.setLabel(new LabelType()); item1.getLabel().setValue("\"Why this question?\""); @@ -82,6 +84,7 @@ void deserializeAccordion() throws SerializationException { // Accordion accordion = assertInstanceOf(Accordion.class, questionnaire.getComponents().getFirst()); assertEquals(ComponentTypeEnum.ACCORDION, accordion.getComponentType()); + assertEquals(ComponentPosition.BOTTOM, accordion.getPosition()); //... }