Skip to content

Commit

Permalink
feat: component position property (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave committed Aug 12, 2024
1 parent 0303949 commit d351d19
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/fr/insee/lunatic/model/flat/ComponentPosition.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
3 changes: 3 additions & 0 deletions src/main/java/fr/insee/lunatic/model/flat/ComponentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AccordionSerializationTest {
"components": [
{
"componentType": "Accordion",
"position": "bottom",
"items": [
{
"label": {
Expand Down Expand Up @@ -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?\"");
Expand Down Expand Up @@ -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());
//...
}

Expand Down

0 comments on commit d351d19

Please sign in to comment.