Skip to content

Commit

Permalink
feat(suggester): option responses
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave committed Sep 18, 2024
1 parent 4159e29 commit a89b564
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>lunatic-model</artifactId>
<packaging>jar</packaging>

<version>3.14.0</version>
<version>3.15.0</version>
<name>Lunatic Model</name>
<description>Classes and converters for the Lunatic model</description>
<url>https://inseefr.github.io/Lunatic-Model/</url>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/fr/insee/lunatic/model/flat/Suggester.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
* Suggester component.
*/
@Getter
@Setter
public class Suggester extends ComponentType implements ComponentSimpleResponseType {

/* Name of the code list used for auto-completion. */
//private String storeName;
public Suggester() {
this.componentType = ComponentTypeEnum.SUGGESTER;
}

public record OptionResponse(String name, String attribute) {}

/** Collected response of the suggester component. */
@JsonProperty(required = true)
protected ResponseType response;

protected List<OptionResponse> optionResponses = new ArrayList<>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ class SuggesterSerializationTest {
"storeName": "FOO_CODE_LIST",
"response": {
"name": "FOO"
}
},
"optionResponses": [
{
"name": "FOO_LABEL",
"attribute": "label"
},
{
"name": "FOO_PRICE",
"attribute": "price"
}
]
}
]
}""";
Expand All @@ -42,6 +52,8 @@ void serializeSuggesterComponent() throws SerializationException, JSONException
suggester.setStoreName("FOO_CODE_LIST");
suggester.setResponse(new ResponseType());
suggester.getResponse().setName("FOO");
suggester.getOptionResponses().add(new Suggester.OptionResponse("FOO_LABEL", "label"));
suggester.getOptionResponses().add(new Suggester.OptionResponse("FOO_PRICE", "price"));
//
Questionnaire questionnaire = new Questionnaire();
questionnaire.setId("questionnaire-id");
Expand All @@ -67,6 +79,11 @@ void deserializeSuggesterComponent() throws SerializationException {
assertEquals(ComponentTypeEnum.SUGGESTER, suggester.getComponentType());
assertEquals("FOO_CODE_LIST", suggester.getStoreName());
assertEquals("FOO", suggester.getResponse().getName());
assertEquals(2, suggester.getOptionResponses().size());
assertEquals("FOO_LABEL", suggester.getOptionResponses().get(0).name());
assertEquals("FOO_PRICE", suggester.getOptionResponses().get(1).name());
assertEquals("label", suggester.getOptionResponses().get(0).attribute());
assertEquals("price", suggester.getOptionResponses().get(1).attribute());
}

}

0 comments on commit a89b564

Please sign in to comment.