Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>fr.insee.pogues</groupId>
<artifactId>pogues-model</artifactId>
<version>1.15.1</version>
<version>1.15.2</version>
<packaging>jar</packaging>

<name>Pogues Model</name>
Expand Down
13 changes: 12 additions & 1 deletion src/main/resources/xsd/Questionnaire.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
<xs:element name="sourceVariableReferences" type="SourceVariableReferences" minOccurs="0">
<xs:annotation>
<xs:documentation>References of variables used by pairwise
questions to define the indivisuals.</xs:documentation>
questions to define the individuals.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="codeFilters" type="CodeFilter" minOccurs="0" maxOccurs="unbounded">
Expand Down Expand Up @@ -360,6 +360,17 @@
</xs:annotation>
<xs:sequence>
<xs:element name="CodeListReference" type="xs:token" minOccurs="0"/>
<xs:element name="VariableReference" type="xs:token" minOccurs="0">
<xs:annotation>
<xs:documentation>
Property defined on variables associated with a choice question, whose choices are
dynamically defined by the responses of another question.
The value of the 'VariableRerference' property is the identifier of the variable defining
these dynamic choices.
Therefore, it must only be used when the 'choiceType' in the associated question is 'VARIABLE'.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="Datatype" type="DatatypeType">
<xs:annotation>
<xs:documentation>Variable representation type to characterize the variable (numeric,
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/fr/insee/pogues/test/JSONDeserializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,34 @@ void testVariableResponsesFullConfiguration() throws JAXBException {
question.getResponse().getFirst().getVariableReference()
);
}

@Test
void testDeserializeVariableReferenceInExternalVariable() throws JAXBException {

String json = """
{
"Variables": {
"Variable": [
{
"id": "ext1",
"type": "ExternalVariableType",
"VariableReference": "id-variable-ref",
"Name": "NUMERO_MENAGE",
"Label": "Numéro du ménage"
}
]
}
}
""";

JSONDeserializer deserializer = new JSONDeserializer();
Questionnaire questionnaire = deserializer.deserializeString(json);

ExternalVariableType variable =
(ExternalVariableType) questionnaire.getVariables()
.getVariable().getFirst();

assertNotNull(variable);
assertEquals("id-variable-ref", variable.getVariableReference());
}
}
36 changes: 36 additions & 0 deletions src/test/java/fr/insee/pogues/test/JSONSerializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -714,4 +714,40 @@ void testSerializeVariableResponsesFullConfiguration() throws Exception {

JSONAssert.assertEquals(expectedJson, json, JSONCompareMode.STRICT);
}

@Test
void testSerializeVariableReferenceInExternalVariable() throws Exception {

ExternalVariableType variable = new ExternalVariableType();
variable.setId("ext1");
variable.setName("NUMERO_MENAGE");
variable.setLabel("Numéro du ménage");
variable.setVariableReference("id-variable-ref");

Questionnaire questionnaire = new Questionnaire();
questionnaire.setVariables(new Questionnaire.Variables());

questionnaire.getVariables().getVariable().add(variable);

JSONSerializer serializer = new JSONSerializer(true);
String json = serializer.serialize(questionnaire);

String expectedJson = """
{
"Variables": {
"Variable": [
{
"id": "ext1",
"type": "ExternalVariableType",
"VariableReference": "id-variable-ref",
"Name": "NUMERO_MENAGE",
"Label": "Numéro du ménage"
}
]
}
}
""";

JSONAssert.assertEquals(expectedJson, json, JSONCompareMode.STRICT);
}
}