Skip to content

Commit 6558884

Browse files
authored
feat: pairwise source variables (#321)
1 parent 5d033de commit 6558884

4 files changed

Lines changed: 70 additions & 9 deletions

File tree

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>fr.insee.lunatic</groupId>
77
<artifactId>lunatic-model</artifactId>
88
<packaging>jar</packaging>
9-
<version>5.11.0</version>
9+
<version>5.12.0</version>
1010
<name>Lunatic Model</name>
1111
<description>Classes and converters for the Lunatic model</description>
1212
<url>https://inseefr.github.io/Lunatic-Model/</url>
@@ -117,8 +117,8 @@
117117
<artifactId>maven-compiler-plugin</artifactId>
118118
<version>3.14.0</version>
119119
<configuration>
120-
<source>17</source>
121-
<target>17</target>
120+
<source>21</source>
121+
<target>21</target>
122122
</configuration>
123123
</plugin>
124124
</plugins>

src/main/java/fr/insee/lunatic/model/flat/PairwiseLinks.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,37 @@
2121
"bindingDependencies",
2222
"xAxisIterations",
2323
"yAxisIterations",
24+
"sourceVariables",
2425
"components",
2526
"symLinks"
2627
})
2728
@Getter
2829
@Setter
29-
public class PairwiseLinks
30-
extends ComponentType
31-
implements ComponentNestingType
32-
{
30+
public class PairwiseLinks extends ComponentType implements ComponentNestingType {
31+
32+
/**
33+
* Variables associated with the pairwise links component.
34+
*/
35+
@Getter
36+
@Setter
37+
public static class SourceVariables {
38+
/** Name variable name. */
39+
private String name;
40+
/** Gender variable name. */
41+
private String gender;
42+
/** Age variable name. */
43+
private String age;
44+
}
3345

3446
@JsonProperty("xAxisIterations")
3547
protected LabelType xAxisIterations;
3648

3749
@JsonProperty("yAxisIterations")
3850
protected LabelType yAxisIterations;
51+
52+
/** {@link SourceVariables} */
53+
private SourceVariables sourceVariables;
54+
3955
protected List<ComponentType> components;
4056
protected SymLinksType symLinks;
4157

src/test/java/fr/insee/lunatic/conversion/CleaningSerializationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ class CleaningSerializationTest {
4545
]
4646
}
4747
}
48-
}
49-
""";
48+
}""";
5049

5150
@Test
5251
void serializeCleaning() throws SerializationException, JSONException {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package fr.insee.lunatic.conversion;
2+
3+
import fr.insee.lunatic.exception.SerializationException;
4+
import fr.insee.lunatic.model.flat.PairwiseLinks;
5+
import fr.insee.lunatic.model.flat.Questionnaire;
6+
import org.json.JSONException;
7+
import org.junit.jupiter.api.Test;
8+
import org.skyscreamer.jsonassert.JSONAssert;
9+
import org.skyscreamer.jsonassert.JSONCompareMode;
10+
11+
class PairwiseLinksSerializationTest {
12+
13+
@Test
14+
void serializePairwiseLinks() throws SerializationException, JSONException {
15+
//
16+
Questionnaire questionnaire = new Questionnaire();
17+
PairwiseLinks pairwiseLinks = new PairwiseLinks();
18+
pairwiseLinks.setId("foo-id");
19+
PairwiseLinks.SourceVariables sourceVariables = new PairwiseLinks.SourceVariables();
20+
sourceVariables.setName("FIRST_NAME_VAR");
21+
sourceVariables.setGender("GENDER_VAR");
22+
pairwiseLinks.setSourceVariables(sourceVariables);
23+
questionnaire.getComponents().add(pairwiseLinks);
24+
//
25+
String result = new JsonSerializer().serialize(questionnaire);
26+
//
27+
String expected = """
28+
{
29+
"componentType": "Questionnaire",
30+
"components": [
31+
{
32+
"id": "foo-id",
33+
"componentType": "PairwiseLinks",
34+
"sourceVariables": {
35+
"name": "FIRST_NAME_VAR",
36+
"gender": "GENDER_VAR"
37+
},
38+
"components": []
39+
}
40+
]
41+
}
42+
""";
43+
JSONAssert.assertEquals(expected, result, JSONCompareMode.STRICT);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)