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.13.1</version>
<version>1.14.0</version>
<packaging>jar</packaging>

<name>Pogues Model</name>
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/xsd/Questionnaire.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<xs:include schemaLocation="articulation/Articulation.xsd"/>
<xs:include schemaLocation="multimode/Multimode.xsd"/>
<xs:include schemaLocation="pairwise/Pairwise.xsd"/>
<xs:include schemaLocation="TypesUtils.xsd"/>

<xs:annotation>
Expand Down Expand Up @@ -220,6 +221,12 @@
</xs:annotation>
</xs:element>
<xs:element name="Scope" type="xs:token" minOccurs="0"/>
<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>
</xs:annotation>
</xs:element>
<xs:element name="codeFilters" type="CodeFilter" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>codeFilters is list of CodeFilter, indicate in this question,
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/xsd/multimode/Multimode.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</xs:restriction>
</xs:simpleType>


<xs:complexType name="Rule">
<xs:sequence>
<xs:element name="name" type="MultimodeRuleNameEnum"/>
Expand Down
25 changes: 25 additions & 0 deletions src/main/resources/xsd/pairwise/Pairwise.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xs:include schemaLocation="../TypesUtils.xsd"/>

<xs:complexType name="SourceVariableReferences">
<xs:annotation>
<xs:documentation>A pairwise question is defined from source variables
which allow to know the individuals we are specifying the links of.
</xs:documentation>
<xs:documentation>The name source variable allow to ask the question
"what is he nature of the relationship between A and B?".
</xs:documentation>
<xs:documentation>The gender and age source variable allow to compute
additional information about the indivisuals (to display a recap or to
generate complex variables to create filters from).</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="name" type="xs:token"/>
<xs:element name="gender" type="xs:token" minOccurs="0"/>
<xs:element name="age" type="xs:token" minOccurs="0"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why age ?

I think is not usefull right now.
Are your preparing the future feature ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used by the recap component (which is merged in Pogues but hidden by a feature flag)...

</xs:sequence>
</xs:complexType>

</xs:schema>
31 changes: 31 additions & 0 deletions src/test/java/fr/insee/pogues/test/JSONDeserializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,35 @@ void testExternalVariableIsDeletedOnReset() throws JAXBException {
assertEquals("NUMERO_MENAGE", externalVariableType.getName());
assertTrue(externalVariableType.isDeletedOnReset());
}

@Test
void testPairwiseSourceVariableReferences() throws JAXBException {
// Given the JSON of a question with sourceVariableReferences
String json = """
{
"Child": [
{
"type": "QuestionType",
"sourceVariableReferences": {
"name": "var-name-id",
"gender": "var-gender-id",
"age": "var-age-id"
}
}
]
}
""";

// When it is deserialized
JSONDeserializer deserializer = new JSONDeserializer();
Questionnaire questionnaire = deserializer.deserializeString(json);

// Then the sourceVariableReferences are correctly deserialized
QuestionType pairwiseQuestion = (QuestionType) questionnaire.getChild().getFirst();

assertNotNull(pairwiseQuestion);
assertEquals("var-name-id", pairwiseQuestion.getSourceVariableReferences().getName());
assertEquals("var-gender-id", pairwiseQuestion.getSourceVariableReferences().getGender());
assertEquals("var-age-id", pairwiseQuestion.getSourceVariableReferences().getAge());
}
}
38 changes: 38 additions & 0 deletions src/test/java/fr/insee/pogues/test/JSONSerializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.insee.pogues.mock.*;
import fr.insee.pogues.model.*;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.core.util.Source;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
Expand Down Expand Up @@ -638,4 +639,41 @@ void serializeExternalVariableIsDeletedOnReset() throws JAXBException, Unsupport

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

@Test
void serializePairwiseSourceVariableReferences() throws JAXBException, UnsupportedEncodingException, JSONException {
// Given a questionnaire with a question with sourceVariableReferences
Questionnaire questionnaire = new Questionnaire();

QuestionType pairwiseQuestion = new QuestionType();
SourceVariableReferences sourceVariableReferences = new SourceVariableReferences();
sourceVariableReferences.setName("var-name-id");
sourceVariableReferences.setGender("var-gender-id");
sourceVariableReferences.setAge("var-age-id");
pairwiseQuestion.setSourceVariableReferences(sourceVariableReferences);

questionnaire.getChild().add(pairwiseQuestion);

// When it is serialized
JSONSerializer serializer = new JSONSerializer(true);
String result = serializer.serialize(questionnaire);

String expectedJson = """
{
"Child": [
{
"type": "QuestionType",
"sourceVariableReferences": {
"name": "var-name-id",
"gender": "var-gender-id",
"age": "var-age-id"
}
}
]
}
""";

// Then the sourceVariableReferences are correctly serialized
JSONAssert.assertEquals(expectedJson, result, JSONCompareMode.STRICT);
}
}