Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: suggester complex type #100

Merged
merged 23 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
44b8c0d
add complexType Suggester + reenter SequenceType into Questionnaire
BulotF Jul 10, 2023
133f70e
replace id with key in SuggesterMultipleResponsesType
BulotF Jul 11, 2023
478f7a4
test: update after removing `SequenceType`
nsenave Aug 17, 2023
67b31e0
refactor: update after removal of `SequenceType`
nsenave Aug 17, 2023
c09fbc0
Merge branch 'dev-suggester' of https://github.com/InseeFr/Lunatic-Mo…
nsenave Aug 17, 2023
c1020f2
test(suggester): add conversion tests
nsenave Nov 13, 2023
c69e7b0
build: bump eclipse dependencies from 2.6.0 to 2.7.13
nsenave Nov 13, 2023
dc3be5a
chore: new feature version
nsenave Nov 13, 2023
0203a31
Merge branch 'master' into dev-suggester
nsenave Nov 13, 2023
10592c3
add complexType Suggester + reenter SequenceType into Questionnaire
BulotF Jul 10, 2023
e195f68
replace id with key in SuggesterMultipleResponsesType
BulotF Jul 11, 2023
757fde6
refactor: update after removal of `SequenceType`
nsenave Aug 17, 2023
4147d90
test(suggester): add conversion tests
nsenave Nov 13, 2023
3bf0f8c
build: bump eclipse dependencies from 2.6.0 to 2.7.13
nsenave Nov 13, 2023
8200abb
chore: new feature version
nsenave Nov 13, 2023
566c52a
set suggester version to integer
BulotF Dec 7, 2023
91abeb1
fix : xs:integer instead of integer
BulotF Dec 7, 2023
78df112
Merge branch 'dev-suggester' of https://github.com/InseeFr/Lunatic-Mo…
nsenave Dec 8, 2023
89970be
Merge branch 'master' into dev-suggester
nsenave Dec 8, 2023
f5114fc
enrich suggester configuration
BulotF Dec 11, 2023
449969b
chore: bump version after patch
nsenave Dec 12, 2023
8dee8c6
chore: bump version to 2.5+ to avoid conflicts with previous tags
nsenave Dec 12, 2023
4dffe34
chore: release version 2.5.0
nsenave Dec 12, 2023
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
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.insee.lunatic</groupId>
<artifactId>lunatic-model</artifactId>
<version>2.4.0-SNAPSHOT</version>

<packaging>jar</packaging>

<version>2.3.5</version>
<name>Lunatic Model</name>
<description>Classes and converters for the Lunatic model</description>
<url>https://inseefr.github.io/Lunatic-Model/</url>
Expand Down Expand Up @@ -65,6 +66,11 @@
<artifactId>eclipselink</artifactId>
<version>2.7.13</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.4</version>
</dependency>

<!-- JSON-P -->
<dependency>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/fr/insee/lunatic/conversion/XMLSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.slf4j.LoggerFactory;

import fr.insee.lunatic.model.flat.Questionnaire;
import fr.insee.lunatic.model.flat.SequenceType;
import fr.insee.lunatic.model.flat.ComponentType;

public class XMLSerializer {

Expand All @@ -37,19 +37,19 @@ public String serialize(Questionnaire questionnaire) throws JAXBException, Unsup

}

public String serialize(SequenceType sequence) throws JAXBException, UnsupportedEncodingException {
public String serialize(ComponentType component) throws JAXBException, UnsupportedEncodingException {

if (sequence == null) return "";
if (component == null) return "";

logger.debug("Serializing sequence " + sequence.getId());
logger.debug("Serializing component " + component.getId());

JAXBContext context = JAXBContext.newInstance(SequenceType.class);
JAXBContext context = JAXBContext.newInstance(ComponentType.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshal(sequence, baos);
marshaller.marshal(component, baos);

return baos.toString("UTF-8");
}
Expand Down
50 changes: 33 additions & 17 deletions src/main/resources/xsd/LunaticModel.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
<xs:element name="Questionnaire">
<xs:complexType>
<xs:complexContent>
<xs:extension base="SequenceType">
<xs:extension base="ComponentType">
<xs:sequence>
<xs:element name="components" type="ComponentType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="suggesters" type="SuggesterType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="variables" type="IVariableType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="cleaning" type="CleaningType" minOccurs="0" maxOccurs="1"/>
<xs:element name="missingBlock" type="MissingType" minOccurs="0" maxOccurs="1"/>
<xs:element name="resizing" type="ResizingType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="final" type="xs:boolean"/>
<xs:attribute name="modele" type="xs:string" use="optional"/>
<xs:attribute name="enoCoreVersion" type="xs:string" use="optional"/>
Expand All @@ -23,21 +31,6 @@
</xs:complexType>
</xs:element>

<xs:complexType name="SequenceType">
<xs:complexContent>
<xs:extension base="ComponentType">
<xs:sequence>
<xs:element name="components" type="ComponentType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="suggesters" type="SuggesterType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="variables" type="IVariableType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="cleaning" type="CleaningType" minOccurs="0" maxOccurs="1"/>
<xs:element name="missingBlock" type="MissingType" minOccurs="0" maxOccurs="1"/>
<xs:element name="resizing" type="ResizingType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="Sequence">
<xs:complexContent>
<xs:extension base="ComponentType">
Expand Down Expand Up @@ -184,6 +177,7 @@
<xs:enumeration value="Dropdown"/>
<xs:enumeration value="Textarea"/>
<xs:enumeration value="FilterDescription"/>
<xs:enumeration value="Suggester"/>
</xs:restriction>
</xs:simpleType>

Expand All @@ -201,7 +195,7 @@
<xs:element name="order" type="SuggesterOrder" minOccurs="0"/>
<xs:element name="queryParser" type="SuggesterQueryParser"/>
<xs:element name="url" type="xs:string" minOccurs="0"/>
<xs:element name="version" type="xs:string"/>
<xs:element name="version" type="xs:integer"/>
</xs:sequence>
</xs:complexType>

Expand Down Expand Up @@ -442,6 +436,28 @@
</xs:complexContent>
</xs:complexType>

<xs:complexType name="Suggester">
<xs:complexContent>
<xs:extension base="ComponentType">
<xs:sequence>
<xs:element name="storeName" type="xs:string"/>
<xs:element name="options" type="Options" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice>
<xs:element name="response" type="ResponseType"/>
<xs:element name="responses" type="SuggesterMultipleResponsesType" maxOccurs="unbounded"/>
</xs:choice>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="SuggesterMultipleResponsesType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
<xs:element name="response" type="ResponseType"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="CheckboxGroup">
<xs:complexContent>
<xs:extension base="ComponentType">
Expand Down
55 changes: 33 additions & 22 deletions src/main/resources/xsd/LunaticModelFlat.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
<xs:element name="Questionnaire">
<xs:complexType>
<xs:complexContent>
<xs:extension base="SequenceType">
<xs:extension base="ComponentType">
<xs:sequence>
<xs:element name="components" type="ComponentType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="suggesters" type="SuggesterType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="variables" type="IVariableType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="cleaning" type="CleaningType" minOccurs="0" maxOccurs="1"/>
<xs:element name="missingBlock" type="MissingType" minOccurs="0" maxOccurs="1"/>
<xs:element name="resizing" type="ResizingType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="final" type="xs:boolean"/>
<xs:attribute name="modele" type="xs:string" use="optional"/>
<xs:attribute name="enoCoreVersion" type="xs:string" use="optional"/>
Expand All @@ -23,21 +31,6 @@
</xs:complexType>
</xs:element>

<xs:complexType name="SequenceType">
<xs:complexContent>
<xs:extension base="ComponentType">
<xs:sequence>
<xs:element name="components" type="ComponentType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="suggesters" type="SuggesterType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="variables" type="IVariableType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="cleaning" type="CleaningType" minOccurs="0" maxOccurs="1"/>
<xs:element name="missingBlock" type="MissingType" minOccurs="0" maxOccurs="1"/>
<xs:element name="resizing" type="ResizingType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="Sequence">
<xs:complexContent>
<xs:extension base="ComponentType"/>
Expand Down Expand Up @@ -96,14 +89,10 @@
<xs:element name="declarations" type="DeclarationType" minOccurs="0" maxOccurs="unbounded"/>
<!-- Warning : To validate the name -->
<xs:element name="conditionFilter" type="ConditionFilterType" minOccurs="0"/>

<xs:element name="controls" type="ControlType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="hierarchy" type="hierarchy" minOccurs="0"/>
<xs:element name="missingResponse" type="ResponseType" minOccurs="0"/>

<xs:element name="storeName" type="xs:string" minOccurs="0"/>

<xs:element name="bindingDependencies" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="bindingDependencies" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="componentType" type="ComponentTypeEnum"/>
Expand Down Expand Up @@ -195,7 +184,7 @@
<xs:element name="order" type="SuggesterOrder" minOccurs="0"/>
<xs:element name="queryParser" type="SuggesterQueryParser"/>
<xs:element name="url" type="xs:string" minOccurs="0"/>
<xs:element name="version" type="xs:string"/>
<xs:element name="version" type="xs:integer"/>
</xs:sequence>
</xs:complexType>

Expand Down Expand Up @@ -436,6 +425,28 @@
</xs:complexContent>
</xs:complexType>

<xs:complexType name="Suggester">
<xs:complexContent>
<xs:extension base="ComponentType">
<xs:sequence>
<xs:element name="storeName" type="xs:string"/>
<xs:element name="options" type="Options" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice>
<xs:element name="response" type="ResponseType"/>
<xs:element name="responses" type="SuggesterMultipleResponsesType" maxOccurs="unbounded"/>
</xs:choice>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="SuggesterMultipleResponsesType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
<xs:element name="response" type="ResponseType"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="CheckboxGroup">
<xs:complexContent>
<xs:extension base="ComponentType">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.insee.lunatic.conversion;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;

class XMLLunaticFlatToJSONLunaticFlatTranslatorTest {

@Test
void convertQuestionnaireWithSuggester_nonNullOutput() throws Exception {
// Given (using a xml hierarchical as input and supposing that xml h et xml flat translator works fine)
XMLLunaticToXMLLunaticFlatTranslator xmlToXmlFlatTranslator = new XMLLunaticToXMLLunaticFlatTranslator();
String xmlFlat = xmlToXmlFlatTranslator.generate(this.getClass().getClassLoader().getResourceAsStream(
"conversion/questionnaire-suggester-xml-h.xml"));

// When
XMLLunaticFlatToJSONLunaticFlatTranslator xmlFlatToJsonFlatTranslator = new XMLLunaticFlatToJSONLunaticFlatTranslator();
xmlFlatToJsonFlatTranslator.translate(xmlFlat);

// Then
assertNotNull(xmlFlat);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fr.insee.lunatic.conversion;

import org.junit.jupiter.api.Test;

import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertNotNull;

class XMLLunaticToJSONLunaticTranslatorTest {

@Test
void convertQuestionnaireWithSuggester_nonNullOutput() throws Exception {
// Given
URL resource = this.getClass().getClassLoader().getResource("conversion/questionnaire-suggester-xml-h.xml");
assert resource != null;
// When
XMLLunaticToJSONLunaticTranslator xmlToJsonFlatTranslator = new XMLLunaticToJSONLunaticTranslator();
String result = xmlToJsonFlatTranslator.translate(Files.readString(Path.of(resource.toURI())));
// Then
assertNotNull(result);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fr.insee.lunatic.conversion;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;

class XMLLunaticToXMLLunaticFlatTranslatorTest {

@Test
void convertQuestionnaireWithSuggester_nonNullOutput() throws Exception {
// Given + When
XMLLunaticToXMLLunaticFlatTranslator xmlToXmlFlatTranslator = new XMLLunaticToXMLLunaticFlatTranslator();
String result = xmlToXmlFlatTranslator.generate(this.getClass().getClassLoader().getResourceAsStream(
"conversion/questionnaire-suggester-xml-h.xml"));
// Then
assertNotNull(result);
}

}
Loading
Loading