-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: roundabout component * refactor: reorder some component properties * chore: release version 3.12.0
- Loading branch information
Showing
9 changed files
with
218 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package fr.insee.lunatic.model.flat; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Roundabout component. Its behavior is similar to a loop, but with refinements. | ||
* The core idea is to display a menu (the "roundabout") for the iterations. | ||
*/ | ||
@Getter | ||
@Setter | ||
public class Roundabout extends ComponentType implements ComponentNestingType { | ||
|
||
/** | ||
* Object that holds the configuration of roundabout's items. | ||
*/ | ||
@Getter | ||
@Setter | ||
public static class Item { | ||
|
||
/** Label of the items collected in the roundabout. */ | ||
@JsonProperty(required = true) | ||
private LabelType label; | ||
|
||
/** Optional description of the items collected in the roundabout. */ | ||
private LabelType description; | ||
|
||
/** Expression that determines if a roundabout's item has to receive answers or not. */ | ||
private LabelType disabled; | ||
} | ||
|
||
public Roundabout() { | ||
super(); | ||
this.componentType = ComponentTypeEnum.ROUNDABOUT; | ||
this.components = new ArrayList<>(); | ||
} | ||
|
||
/** Expression that defines the number of items in the roundabout. */ | ||
private LabelType iterations; | ||
|
||
/** Boolean option to lock or not an item answers when it gets the 'completed' status. */ | ||
private Boolean locked; | ||
|
||
/** Name of the variable that stores the current progress in each roundabout's item. */ | ||
private String progressVariable; | ||
|
||
/** {@link Item} */ | ||
private Item item; | ||
|
||
/** Roundabout components (sequences and response components). */ | ||
private List<ComponentType> components; | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/test/java/fr/insee/lunatic/conversion/RoundaboutSerializationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package fr.insee.lunatic.conversion; | ||
|
||
import fr.insee.lunatic.exception.SerializationException; | ||
import fr.insee.lunatic.model.flat.*; | ||
import fr.insee.lunatic.utils.TestUtils; | ||
import org.json.JSONException; | ||
import org.junit.jupiter.api.Test; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
import org.skyscreamer.jsonassert.JSONCompareMode; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
|
||
import static fr.insee.lunatic.utils.TestUtils.createLabel; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
|
||
class RoundaboutSerializationTest { | ||
|
||
@Test | ||
void serializeRoundabout() throws SerializationException, IOException, JSONException { | ||
// | ||
Questionnaire questionnaire = new Questionnaire(); | ||
questionnaire.setId("questionnaire-id"); | ||
// | ||
Roundabout roundabout = new Roundabout(); | ||
roundabout.setId("roundabout-id"); | ||
roundabout.setPage("1"); | ||
roundabout.setConditionFilter(new ConditionFilterType()); | ||
roundabout.getConditionFilter().setValue("true"); | ||
roundabout.getConditionFilter().setType(LabelTypeEnum.VTL); | ||
roundabout.setLabel(createLabel("\"Roundabout label.\"", LabelTypeEnum.VTL)); | ||
roundabout.setIterations(createLabel("NUMBER_VAR", LabelTypeEnum.VTL)); | ||
roundabout.setLocked(true); | ||
roundabout.setProgressVariable("PROGRESS"); | ||
Roundabout.Item roundaboutItem = new Roundabout.Item(); | ||
roundaboutItem.setLabel(createLabel("FIRST_NAME", LabelTypeEnum.VTL)); | ||
roundaboutItem.setDescription(createLabel( | ||
"if AGE > 18 then \"Questions for \" || FIRST_NAME else FIRST_NAME || \" is not concerned\"", | ||
LabelTypeEnum.VTL)); | ||
roundaboutItem.setDisabled(createLabel("AGE < 18", LabelTypeEnum.VTL)); | ||
roundabout.setItem(roundaboutItem); | ||
Input input = new Input(); | ||
input.setId("input-id"); | ||
roundabout.getComponents().add(input); | ||
// | ||
questionnaire.getComponents().add(roundabout); | ||
|
||
// | ||
String result = new JsonSerializer().serialize(questionnaire); | ||
|
||
// | ||
String expectedJson = TestUtils.readResourceFile("roundabout.json"); | ||
JSONAssert.assertEquals(result, expectedJson, JSONCompareMode.STRICT); | ||
} | ||
|
||
@Test | ||
void deserializeRoundabout() throws IOException, SerializationException { | ||
// | ||
String jsonInput = TestUtils.readResourceFile("roundabout.json"); | ||
|
||
// | ||
Questionnaire questionnaire = new JsonDeserializer().deserialize( | ||
new ByteArrayInputStream(jsonInput.getBytes())); | ||
|
||
// | ||
Roundabout roundabout = assertInstanceOf(Roundabout.class, questionnaire.getComponents().getFirst()); | ||
assertEquals(1, roundabout.getComponents().size()); | ||
assertEquals(ComponentTypeEnum.INPUT, roundabout.getComponents().getFirst().getComponentType()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"id": "questionnaire-id", | ||
"componentType": "Questionnaire", | ||
"components": [ | ||
{ | ||
"id": "roundabout-id", | ||
"componentType": "Roundabout", | ||
"page": "1", | ||
"conditionFilter": { | ||
"value": "true", | ||
"type": "VTL" | ||
}, | ||
"label": { | ||
"value": "\"Roundabout label.\"", | ||
"type": "VTL" | ||
}, | ||
"iterations": { | ||
"value": "NUMBER_VAR", | ||
"type": "VTL" | ||
}, | ||
"locked": true, | ||
"progressVariable": "PROGRESS", | ||
"item": { | ||
"label": { | ||
"value": "FIRST_NAME", | ||
"type": "VTL" | ||
}, | ||
"description": { | ||
"value": "if AGE > 18 then \"Questions for \" || FIRST_NAME else FIRST_NAME || \" is not concerned\"", | ||
"type": "VTL" | ||
}, | ||
"disabled": { | ||
"value": "AGE < 18", | ||
"type": "VTL" | ||
} | ||
}, | ||
"components": [ | ||
{ | ||
"id": "input-id", | ||
"componentType": "Input" | ||
} | ||
] | ||
} | ||
] | ||
} |