Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
java-version: '25'

- name: install model filiere
run: mvn install:install-file -Dfile="$(pwd)/libs/modelefiliere-2.1.0.jar" -DgroupId=fr.insee -DartifactId=modelefiliere -Dversion=2.1.0 -Dpackaging=jar -DgeneratePom=true
run: mvn install:install-file -Dfile="$(pwd)/libs/modelefiliere-2.2.2-springboot4.jar" -DgroupId=fr.insee -DartifactId=modelefiliere -Dversion=2.2.2-springboot4 -Dpackaging=jar -DgeneratePom=true

- name: Clone BPM
uses: actions/checkout@v6
Expand Down Expand Up @@ -182,4 +182,4 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }}
default_branch: ${{ github.ref }}
tags: ${{ needs.check-version.outputs.release-tag }}
workdir: .
workdir: .
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
java-version: "25"

- name: install model filiere
run: mvn install:install-file -Dfile="$(pwd)/libs/modelefiliere-2.1.0.jar" -DgroupId=fr.insee -DartifactId=modelefiliere -Dversion=2.1.0 -Dpackaging=jar -DgeneratePom=true
run: mvn install:install-file -Dfile="$(pwd)/libs/modelefiliere-2.2.2-springboot4.jar" -DgroupId=fr.insee -DartifactId=modelefiliere -Dversion=2.2.2-springboot4 -Dpackaging=jar -DgeneratePom=true

- name: Clone BPM
uses: actions/checkout@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
cache: maven

- name: install model filiere
run: mvn install:install-file -Dfile="$(pwd)/libs/modelefiliere-2.1.0.jar" -DgroupId=fr.insee -DartifactId=modelefiliere -Dversion=2.1.0 -Dpackaging=jar -DgeneratePom=true
run: mvn install:install-file -Dfile="$(pwd)/libs/modelefiliere-2.2.2-springboot4.jar" -DgroupId=fr.insee -DartifactId=modelefiliere -Dversion=2.2.2-springboot4 -Dpackaging=jar -DgeneratePom=true

- name: Clone BPM
uses: actions/checkout@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scheduled-version-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:

- name: install model filiere
run: |
mvn install:install-file -Dfile="$(pwd)/genesis/libs/modelefiliere-2.1.0.jar" -DgroupId=fr.insee -DartifactId=modelefiliere -Dversion=2.1.0 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile="$(pwd)/genesis/libs/modelefiliere-2.2.2-springboot4.jar" -DgroupId=fr.insee -DartifactId=modelefiliere -Dversion=2.2.2-springboot4 -Dpackaging=jar -DgeneratePom=true

- name: Clone BPM
uses: actions/checkout@master
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ src/bin/

# Package Files #
*.jar
!libs/*.jar
*.war
*.nar
*.ear
Expand Down
Binary file removed libs/modelefiliere-2.1.0.jar
Binary file not shown.
Binary file added libs/modelefiliere-2.2.2-springboot4.jar
Binary file not shown.
21 changes: 14 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.14</version>
<version>4.0.6</version>
</parent>

<properties>
Expand All @@ -20,12 +20,10 @@
<!-- (!!!) Dependency versions temporary overwritten for security reasons -->
<tomcat.version>11.0.21</tomcat.version>
<commons-lang3.version>3.20.0</commons-lang3.version>
<junit-jupiter.version>5.13.4</junit-jupiter.version>
<jackson-bom.version>2.21.1</jackson-bom.version>

<!-- Dependency versions not managed by Spring -->
<bpm.version>1.1.4</bpm.version>
<springdoc.version>2.8.17</springdoc.version>
<springdoc.version>3.0.3</springdoc.version>
<mapstruct.version>1.6.3</mapstruct.version>
<pitest.version>1.23.1</pitest.version>
<pitest.junit.version>1.2.3</pitest.junit.version>
Expand Down Expand Up @@ -75,10 +73,19 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- AssertJ -->
<!-- https://www.baeldung.com/introduction-to-assertj -->
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
Expand Down Expand Up @@ -106,7 +113,7 @@
<dependency>
<groupId>fr.insee</groupId>
<artifactId>modelefiliere</artifactId>
<version>2.1.0</version>
<version>2.2.2-springboot4</version>
</dependency>
<!-- XML libraries -->
<!-- XML-XSLT with Saxon -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package fr.insee.genesis.controller.dto;

import fr.insee.genesis.domain.model.surveyunit.Mode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class SurveyUnitInputDto {
private String questionnaireId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.insee.genesis.controller.rest;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.JacksonException;
import fr.insee.genesis.domain.model.lunaticmodel.LunaticModelModel;
import fr.insee.genesis.domain.ports.api.LunaticModelApiPort;
import fr.insee.genesis.exceptions.GenesisException;
Expand All @@ -15,6 +14,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import tools.jackson.databind.json.JsonMapper;

import java.util.Map;

Expand Down Expand Up @@ -45,10 +45,12 @@ public ResponseEntity<String> saveRawResponsesFromJsonBody(
@PreAuthorize("hasRole('READER')")
public ResponseEntity<String> getLunaticModelFromQuestionnaireId(
@RequestParam("questionnaireId") String questionnaireId
) throws JsonProcessingException, GenesisException {
) throws JacksonException, GenesisException {

LunaticModelModel lunaticModelModel = lunaticModelApiPort.get(questionnaireId);
ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();
JsonMapper objectMapper = JsonMapper.builder()
.findAndAddModules()
.build();
return ResponseEntity.ok(objectMapper.writeValueAsString(lunaticModelModel.lunaticModel()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private static void setValues(LunaticXmlCollectedData varData, Node value, List<
varData.setPrevious(valueTypes);
break;
default:
throw new GenesisException(HttpStatus.DESTINATION_LOCKED, "Tag not recognized: " + valueElement.getTagName());
throw new GenesisException(HttpStatus.LOCKED, "Tag not recognized: " + valueElement.getTagName());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package fr.insee.genesis.controller.utils;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import tools.jackson.databind.node.StringNode;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.node.ArrayNode;
import tools.jackson.databind.node.ObjectNode;
public class ExtendedJsonNormalizer {

public static final String $_DATE = "$date";
Expand All @@ -23,18 +23,20 @@ public static JsonNode normalize(JsonNode node) {
ObjectNode obj = (ObjectNode) node;

if (obj.size() == 1) {
if (obj.has($_DATE) && obj.get($_DATE).isTextual()) {
return TextNode.valueOf(obj.get($_DATE).asText());
if (obj.has($_DATE) && obj.get($_DATE).isString()) {
return StringNode.valueOf(obj.get($_DATE).asString());
}
// if (obj.has("$oid") && obj.get("$oid").isTextual()) {
// return TextNode.valueOf(obj.get("$oid").asText());
// }
}

ObjectNode copy = obj.objectNode();
obj.fields().forEachRemaining(e ->

obj.properties().forEach(e ->
copy.set(e.getKey(), normalize(e.getValue()))
);

return copy;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.insee.genesis.domain.service.context;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import tools.jackson.databind.json.JsonMapper;
import fr.insee.genesis.Constants;
import fr.insee.genesis.controller.dto.KraftwerkExecutionScheduleInput;
import fr.insee.genesis.controller.dto.rawdata.ScheduleResponseDto;
Expand Down Expand Up @@ -275,8 +274,9 @@ public void deleteExpiredSchedules(String logFolder) throws GenesisException {
String scheduleName = context.getCollectionInstrumentId();
Path jsonLogPath = Path.of(logFolder, Constants.SCHEDULE_ARCHIVE_FOLDER_NAME,
scheduleName + ".json");
ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();
objectMapper.registerModule(new JavaTimeModule());
JsonMapper objectMapper = JsonMapper.builder()
.findAndAddModules()
.build();
String jsonToWrite = objectMapper.writeValueAsString(deletedKraftwerkExecutionSchedules);
if(Files.exists(jsonLogPath)){
//Remove last ] and append survey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fr.insee.genesis.domain.service.contextualvariable.external;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import fr.insee.genesis.exceptions.JsonParsingException;
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonParser;
import tools.jackson.core.json.JsonFactory;
import tools.jackson.core.JsonToken;
import fr.insee.genesis.domain.model.contextualvariable.ContextualExternalVariableModel;
import fr.insee.genesis.domain.ports.api.ContextualExternalVariableApiPort;
import fr.insee.genesis.domain.ports.spi.ContextualExternalVariablePersistancePort;
Expand Down Expand Up @@ -74,7 +75,7 @@ public boolean readContextualExternalFile(String collectionInstrumentId, String
contextualExternalVariablePersistancePort.deleteBackup(collectionInstrumentId);
return true;
}
}catch (JsonParseException jpe){
}catch (JacksonException jpe){
contextualExternalVariablePersistancePort.restoreBackup(collectionInstrumentId);
throw new GenesisException(HttpStatus.BAD_REQUEST, "JSON Parsing exception : %s".formatted(jpe.toString()));
}catch (IOException ioe){
Expand All @@ -90,7 +91,7 @@ public ContextualExternalVariableModel findByCollectionInstrumentIdAndInterrogat

private static boolean goToContextualExternalToken(JsonParser jsonParser) throws IOException {
while (jsonParser.nextToken() != null) {
if (jsonParser.currentToken() == JsonToken.FIELD_NAME
if (jsonParser.currentToken() == JsonToken.PROPERTY_NAME
&& "editedExternal".equals(jsonParser.currentName())) {
return true;
}
Expand Down Expand Up @@ -127,15 +128,15 @@ private ContextualExternalVariableModel readNextContextualExternal(JsonParser js
String collectionInstrumentId
) throws IOException {
if(jsonParser.currentToken() != JsonToken.START_OBJECT){
throw new JsonParseException("Expected { on line %d, got token %s".formatted(jsonParser.currentLocation().getLineNr(), jsonParser.currentToken()));
throw new JsonParsingException("Expected { on line %d, got token %s".formatted(jsonParser.currentLocation().getLineNr(), jsonParser.currentToken()));
}
ContextualExternalVariableModel contextualExternalVariableModel = ContextualExternalVariableModel.builder()
.collectionInstrumentId(collectionInstrumentId)
.variables(new HashMap<>())
.build();
jsonParser.nextToken();
while (!jsonParser.currentToken().equals(JsonToken.END_OBJECT)){
if(jsonParser.currentToken().equals(JsonToken.FIELD_NAME) && jsonParser.currentName().equals("interrogationId")){
if(jsonParser.currentToken().equals(JsonToken.PROPERTY_NAME) && jsonParser.currentName().equals("interrogationId")){
jsonParser.nextToken();
contextualExternalVariableModel.setInterrogationId(jsonParser.getText());
jsonParser.nextToken();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fr.insee.genesis.domain.service.contextualvariable.previous;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import tools.jackson.core.JacksonException;
import tools.jackson.core.json.JsonFactory;
import fr.insee.genesis.exceptions.JsonParsingException;
import tools.jackson.core.JsonParser;
import tools.jackson.core.JsonToken;
import fr.insee.genesis.domain.model.contextualvariable.ContextualPreviousVariableModel;
import fr.insee.genesis.domain.ports.api.ContextualPreviousVariableApiPort;
import fr.insee.genesis.domain.ports.spi.ContextualPreviousVariablePersistancePort;
Expand Down Expand Up @@ -41,7 +42,7 @@ public boolean readContextualPreviousFile(String collectionInstrumentId,
try(FileInputStream inputStream = new FileInputStream(filePath)){
checkSourceStateLength(sourceState);

JsonFactory jsonFactory = new JsonFactory();
JsonFactory jsonFactory = JsonFactory.builder().build();
try (JsonParser jsonParser = jsonFactory.createParser(inputStream)) {
if (!goToEditedPreviousToken(jsonParser)) {
log.warn("No EditedPrevious part found in file {}", filePath);
Expand Down Expand Up @@ -79,7 +80,7 @@ public boolean readContextualPreviousFile(String collectionInstrumentId,
contextualPreviousVariablePersistancePort.deleteBackup(collectionInstrumentId);
return true;
}
}catch (JsonParseException jpe){
}catch (JacksonException jpe){
contextualPreviousVariablePersistancePort.restoreBackup(collectionInstrumentId);
throw new GenesisException(HttpStatus.BAD_REQUEST, "JSON Parsing exception : %s".formatted(jpe.toString()));
}catch (IOException _){
Expand Down Expand Up @@ -116,8 +117,8 @@ private static void checkSourceStateLength(String sourceState) throws GenesisExc

private boolean goToEditedPreviousToken(JsonParser jsonParser) throws IOException {
while (jsonParser.nextToken() != null) {
if (jsonParser.currentToken() == JsonToken.FIELD_NAME
&& "editedPrevious".equals(jsonParser.getCurrentName())) {
if (jsonParser.currentToken() == JsonToken.PROPERTY_NAME
&& "editedPrevious".equals(jsonParser.currentName())) {
return true;
}
}
Expand All @@ -129,7 +130,7 @@ private ContextualPreviousVariableModel readNextContextualPrevious(JsonParser js
String sourceState
) throws IOException {
if(jsonParser.currentToken() != JsonToken.START_OBJECT){
throw new JsonParseException("Expected { on line %d, got token %s".formatted(jsonParser.currentLocation().getLineNr(), jsonParser.currentToken()));
throw new JsonParsingException("Expected { on line %d, got token %s".formatted(jsonParser.currentLocation().getLineNr(), jsonParser.currentToken()));
}
ContextualPreviousVariableModel contextualPreviousVariableModel = ContextualPreviousVariableModel.builder()
.collectionInstrumentId(collectionInstrumentId)
Expand All @@ -138,7 +139,7 @@ private ContextualPreviousVariableModel readNextContextualPrevious(JsonParser js
.build();
jsonParser.nextToken();
while (!jsonParser.currentToken().equals(JsonToken.END_OBJECT)){
if(jsonParser.currentToken().equals(JsonToken.FIELD_NAME) && jsonParser.currentName().equals("interrogationId")){
if(jsonParser.currentToken().equals(JsonToken.PROPERTY_NAME) && jsonParser.currentName().equals("interrogationId")){
jsonParser.nextToken();
contextualPreviousVariableModel.setInterrogationId(jsonParser.getText());
jsonParser.nextToken();
Expand Down Expand Up @@ -174,7 +175,7 @@ private Object readValue(JsonParser jsonParser) throws IOException{
case START_ARRAY -> {
return readArray(jsonParser);
}
case null, default -> throw new JsonParseException("Unexpected token %s on line %d".formatted(
case null, default -> throw new JsonParsingException("Unexpected token %s on line %d".formatted(
jsonParser.currentToken(), jsonParser.currentLocation().getLineNr())
);
}
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/fr/insee/genesis/domain/utils/JsonUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package fr.insee.genesis.domain.utils;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.JsonParser;
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonToken;
import lombok.experimental.UtilityClass;
import tools.jackson.databind.json.JsonMapper;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -14,9 +13,11 @@

@UtilityClass
public class JsonUtils {
private static final ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();
JsonMapper objectMapper = JsonMapper.builder()
.findAndAddModules()
.build();

public static Map<String, Object> jsonToMap(String json) throws JsonProcessingException {
public static Map<String, Object> jsonToMap(String json) throws JacksonException {
return objectMapper.readValue(json, Map.class);
}

Expand Down Expand Up @@ -54,7 +55,7 @@ public static Object readValue(JsonParser jsonParser) throws IOException {
case START_ARRAY -> {
return readArray(jsonParser);
}
case null, default -> throw new JsonParseException("Unexpected token %s on line %d".formatted(
case null, default -> throw new IOException("Unexpected token %s on line %d".formatted(
jsonParser.currentToken(), jsonParser.currentLocation().getLineNr())
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package fr.insee.genesis.exceptions;

import java.io.IOException;

public class JsonParsingException extends IOException {
public JsonParsingException(String message) {
super(message);
}
}
Loading
Loading