-
Notifications
You must be signed in to change notification settings - Fork 4
JSON Raw data processing #143
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
b263024
Add unprocessed raw data endpoint
alexisszmundy ff82ef8
Add data processing
alexisszmundy e44151b
Add variable type storage
alexisszmundy c07fdea
Add exception management + fix after mongo tests
alexisszmundy 65517c9
Merge branch 'main' into devRawDataProcessing
alexisszmundy 265347c
refactors
alexisszmundy 7a57e42
Removed unused
alexisszmundy 80f2fdf
Store variablesmap in variabletype collection
alexisszmundy f5e3dbe
Merge branch 'main' into devRawDataProcessing
alicela 61ca83f
fix: remove unused
alicela 275fd5b
Merge branch 'main' into devRawDataProcessing
alexisszmundy 0cf7a1d
fix: cucumber definitions with vartype
alexisszmundy 6d19845
Merge branch 'devRawDataProcessing' of https://github.com/InseeFr/Gen…
alicela 70d916d
Fix for sonar
alicela f3fd06b
build: refactors
alexisszmundy 96881e0
feat: Disabled save Metadata when processing due to mapping problem
alexisszmundy 1651366
Merge branch 'main' into devRawDataProcessing
alexisszmundy 7257f87
fix: use VariableModel not CollectedVariable
alexisszmundy aeecb7c
fix: After merge fixes
alexisszmundy 7bb7385
Merge branch 'main' into devRawDataProcessing
alexisszmundy 23bf782
feat: input JSON raw data structure check and adaptations to lunatic …
alexisszmundy c5def6f
test: add raw data processing functional test
alexisszmundy 3bdac3e
feat: add data verification on raw data processing
alexisszmundy 2457ae9
Merge branch 'main' into devRawDataProcessing
alexisszmundy 9f59a18
refactor: added refactors from Init raw response controller
alexisszmundy b8e342d
Merge branch 'main' into devRawDataProcessing
alexisszmundy 70a2d69
fix: GroupUtils instead of LoopIdentifier
alexisszmundy aa25fed
fix: Mockito not creating mock
alexisszmundy 6a9c22b
chore: remove unused imports
alexisszmundy f9f5504
fix: error on parentId (group parent) name
loichenninger fd5dff3
fix: can't see endpoints in swagger
loichenninger bfca7b5
fix: empty values should be send too
loichenninger 64b5172
test: on fix empty values should be return too
loichenninger 1d76bb1
chore: renaming raw controller services
loichenninger 12e61f8
fix: remove code used for testing
loichenninger 4baf785
fix: change mapper to read raw data in db
loichenninger b095e4e
test: update to take into account the changes
loichenninger 216340c
refactor: RawData model change
loichenninger 6035763
build: WIP on process data corresponding tests are deactivated
loichenninger 2f4d79e
feat: forgot to add recordDate when saving the data
loichenninger 602e107
chore: response message with more details
loichenninger 7f8db99
chore: unnecessary code
loichenninger 6804728
fix: test for saving raw data
alicela File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/fr/insee/genesis/controller/dto/rawdata/LunaticJsonRawDataUnprocessedDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package fr.insee.genesis.controller.dto.rawdata; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| @Builder | ||
| @Data | ||
| public class LunaticJsonRawDataUnprocessedDto { | ||
| private String campaignId; | ||
| private String idUE; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import fr.insee.genesis.controller.dto.SurveyUnitDto; | ||
| import fr.insee.genesis.controller.dto.SurveyUnitId; | ||
| import fr.insee.genesis.controller.dto.SurveyUnitSimplified; | ||
| import fr.insee.genesis.controller.dto.rawdata.LunaticJsonRawDataUnprocessedDto; | ||
| import fr.insee.genesis.controller.sources.xml.LunaticXmlCampaign; | ||
| import fr.insee.genesis.controller.sources.xml.LunaticXmlDataParser; | ||
| import fr.insee.genesis.controller.sources.xml.LunaticXmlDataSequentialParser; | ||
|
|
@@ -22,6 +23,7 @@ | |
| import fr.insee.genesis.domain.ports.api.LunaticJsonRawDataApiPort; | ||
| import fr.insee.genesis.domain.ports.api.LunaticXmlRawDataApiPort; | ||
| import fr.insee.genesis.domain.ports.api.SurveyUnitApiPort; | ||
| import fr.insee.genesis.domain.ports.api.VariableTypeApiPort; | ||
| import fr.insee.genesis.domain.service.surveyunit.SurveyUnitQualityService; | ||
| import fr.insee.genesis.exceptions.GenesisError; | ||
| import fr.insee.genesis.exceptions.GenesisException; | ||
|
|
@@ -71,6 +73,7 @@ public class ResponseController { | |
| private final SurveyUnitQualityService surveyUnitQualityService; | ||
| private final LunaticXmlRawDataApiPort lunaticXmlRawDataApiPort; | ||
| private final LunaticJsonRawDataApiPort lunaticJsonRawDataApiPort; | ||
| private final VariableTypeApiPort variableTypeApiPort; | ||
| private final FileUtils fileUtils; | ||
| private final ControllerUtils controllerUtils; | ||
|
|
||
|
|
@@ -79,12 +82,14 @@ public ResponseController(SurveyUnitApiPort surveyUnitService, | |
| SurveyUnitQualityService surveyUnitQualityService, | ||
| LunaticXmlRawDataApiPort lunaticXmlRawDataApiPort, | ||
| LunaticJsonRawDataApiPort lunaticJsonRawDataApiPort, | ||
| VariableTypeApiPort variableTypeApiPort, | ||
| FileUtils fileUtils, | ||
| ControllerUtils controllerUtils) { | ||
| this.surveyUnitService = surveyUnitService; | ||
| this.surveyUnitQualityService = surveyUnitQualityService; | ||
| this.lunaticXmlRawDataApiPort = lunaticXmlRawDataApiPort; | ||
| this.lunaticJsonRawDataApiPort = lunaticJsonRawDataApiPort; | ||
| this.variableTypeApiPort = variableTypeApiPort; | ||
| this.fileUtils = fileUtils; | ||
| this.controllerUtils = controllerUtils; | ||
| } | ||
|
|
@@ -155,6 +160,7 @@ public ResponseEntity<Object> saveResponsesFromXmlCampaignFolder(@RequestParam(" | |
| return ResponseEntity.internalServerError().body(errors.getFirst().getMessage()); | ||
| } | ||
|
|
||
| //RAW DATA XML | ||
| @Operation(summary = "Save one file of raw responses to Genesis Database, passing its path as a parameter") | ||
| @PutMapping(path = "/lunatic-xml/raw/save-one") | ||
| public ResponseEntity<Object> saveRawResponsesFromXmlFile(@RequestParam("pathLunaticXml") String xmlFile, | ||
|
|
@@ -192,17 +198,19 @@ public ResponseEntity<Object> saveRawResponsesFromXmlCampaignFolder(@RequestPara | |
| return ResponseEntity.ok(getSuccessMessage(isAnyDataSaved)); | ||
| } | ||
|
|
||
| //JSON | ||
| //RAW DATA JSON | ||
| @Operation(summary = "Save lunatic json data to Genesis Database from the campaign root folder") | ||
| @PutMapping(path = "/lunatic-json/raw/save") | ||
| @PutMapping(path = "/lunatic-json/raw/save-one") | ||
| public ResponseEntity<Object> saveRawResponsesFromJsonBody( | ||
| @RequestParam("campaignName") String campaignName, | ||
| @RequestParam(value = "mode", required = false) Mode modeSpecified, | ||
| @RequestParam("idQuest") String idQuest, | ||
| @RequestParam("idUE") String idUE, | ||
| @RequestParam(value = "mode") Mode modeSpecified, | ||
| @RequestBody String dataJson | ||
| ) { | ||
| log.info("Try to import raw lunatic JSON data for campaign: {}", campaignName); | ||
| try { | ||
| lunaticJsonRawDataApiPort.saveData(campaignName, dataJson, modeSpecified); | ||
| lunaticJsonRawDataApiPort.saveData(campaignName, idQuest, idUE, dataJson, modeSpecified); | ||
| }catch (JsonProcessingException jpe){ | ||
| log.error(jpe.toString()); | ||
| return ResponseEntity.badRequest().body("Invalid JSON synthax"); | ||
|
|
@@ -211,6 +219,61 @@ public ResponseEntity<Object> saveRawResponsesFromJsonBody( | |
| return ResponseEntity.ok(SUCCESS_MESSAGE); | ||
| } | ||
|
|
||
| //GET unprocessed | ||
| @Operation(summary = "Get campaign id and idUE from all unprocessed raw json data") | ||
| @GetMapping(path = "/lunatic-json/raw/get/unprocessed") | ||
| public ResponseEntity<List<LunaticJsonRawDataUnprocessedDto>> getUnproccessedJsonRawData(){ | ||
| log.info("Try to get unprocessed raw JSON datas..."); | ||
| return ResponseEntity.ok(lunaticJsonRawDataApiPort.getUnprocessedDataIds()); | ||
| } | ||
|
|
||
| //PROCESS | ||
| @Operation(summary = "Process raw data of a campaign") | ||
| @PostMapping(path = "/lunatic-json/raw/process") | ||
| public ResponseEntity<Object> processJsonRawData( | ||
| @RequestParam("campaignName") String campaignName, | ||
| @RequestParam("questionnaireId") String questionnaireId, | ||
| @RequestBody List<String> idUEList | ||
| ){ | ||
| log.info("Try to get process raw JSON datas for campaign {} and {} idUEs", campaignName, idUEList.size()); | ||
alexisszmundy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| int dataCount = 0; | ||
| List<GenesisError> errors = new ArrayList<>(); | ||
|
|
||
| try { | ||
| List<Mode> modesList = controllerUtils.getModesList(campaignName, null); | ||
| for (Mode mode : modesList) { | ||
| //Load and save metadatas into database, throw exception if none | ||
| VariablesMap variablesMap = readMetadatas(campaignName, mode, errors, true); | ||
| if (variablesMap == null) { | ||
| throw new GenesisException(400, | ||
| "Error during metadata parsing for mode %s :%n%s" | ||
| .formatted(mode, errors.getLast().getMessage()) | ||
| ); | ||
| } | ||
|
|
||
| //Save converted data | ||
| List<SurveyUnitModel> surveyUnitModels = lunaticJsonRawDataApiPort.parseRawData( | ||
| campaignName, | ||
| mode, | ||
| idUEList, | ||
| variablesMap | ||
| ); | ||
| surveyUnitService.saveSurveyUnits(surveyUnitModels); | ||
|
|
||
| //Update process dates | ||
| lunaticJsonRawDataApiPort.updateProcessDates(surveyUnitModels); | ||
|
|
||
| //Save metadatas | ||
| variableTypeApiPort.saveMetadatas(campaignName, questionnaireId, mode, variablesMap); | ||
| dataCount += surveyUnitModels.size(); | ||
| } | ||
| return ResponseEntity.ok("%d document(s) processed".formatted(dataCount)); | ||
| }catch (GenesisException e){ //TODO replace with spring exception handler | ||
|
||
| return ResponseEntity.status(e.getStatus()).body(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| //SAVE ALL | ||
| @Operation(summary = "Save all files to Genesis Database (differential data folder only), regardless of the campaign") | ||
|
|
@@ -246,7 +309,6 @@ public ResponseEntity<Object> saveResponsesFromAllCampaignFolders(){ | |
| return ResponseEntity.status(209).body("Data saved with " + errors.size() + " errors"); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| //DELETE | ||
| @Operation(summary = "Delete all responses associated with a questionnaire") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/fr/insee/genesis/domain/model/variabletype/VariableTypeModel.java
alexisszmundy marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package fr.insee.genesis.domain.model.variabletype; | ||
|
|
||
| import fr.insee.bpm.metadata.model.VariableType; | ||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Data | ||
| @Builder | ||
| public class VariableTypeModel { | ||
| private String campaignId; | ||
| private String questionnaireId; | ||
| private Mode mode; | ||
| private Map<String, VariableType> variables; | ||
| } |
17 changes: 16 additions & 1 deletion
17
src/main/java/fr/insee/genesis/domain/ports/api/LunaticJsonRawDataApiPort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,23 @@ | ||
| package fr.insee.genesis.domain.ports.api; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import fr.insee.bpm.metadata.model.VariablesMap; | ||
| import fr.insee.genesis.controller.dto.rawdata.LunaticJsonRawDataUnprocessedDto; | ||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import fr.insee.genesis.domain.model.surveyunit.SurveyUnitModel; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface LunaticJsonRawDataApiPort { | ||
| void saveData(String campaignName, String dataJson, Mode mode) throws JsonProcessingException; | ||
| void saveData(String campaignName, String idQuest, String idUE, String dataJson, Mode mode) throws JsonProcessingException; | ||
| List<LunaticJsonRawDataUnprocessedDto> getUnprocessedDataIds(); | ||
|
|
||
| List<SurveyUnitModel> parseRawData( | ||
| String campaignName, | ||
| Mode mode, | ||
| List<String> idUEList, | ||
| VariablesMap variablesMap | ||
| ); | ||
|
|
||
| void updateProcessDates(List<SurveyUnitModel> surveyUnitModels); | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/fr/insee/genesis/domain/ports/api/VariableTypeApiPort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package fr.insee.genesis.domain.ports.api; | ||
|
|
||
| import fr.insee.bpm.metadata.model.VariablesMap; | ||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
|
|
||
| public interface VariableTypeApiPort { | ||
| void saveMetadatas(String campaignId, String questionnaireId, Mode mode, VariablesMap variablesMap); | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/fr/insee/genesis/domain/ports/spi/LunaticJsonPersistancePort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| package fr.insee.genesis.domain.ports.spi; | ||
|
|
||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import fr.insee.genesis.domain.model.surveyunit.rawdata.LunaticJsonDataModel; | ||
| import fr.insee.genesis.infrastructure.document.rawdata.LunaticJsonDataDocument; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| public interface LunaticJsonPersistancePort { | ||
| void save(LunaticJsonDataModel lunaticJsonDataModel); | ||
| List<LunaticJsonDataModel> getAllUnprocessedData(); | ||
|
|
||
| List<LunaticJsonDataDocument> findRawData(String campaignName, Mode mode, List<String> idUEList); | ||
|
|
||
| void updateProcessDates(String campaignId, Set<String> idUEs); | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/fr/insee/genesis/domain/ports/spi/VariableTypePersistancePort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package fr.insee.genesis.domain.ports.spi; | ||
|
|
||
| import fr.insee.genesis.domain.model.surveyunit.Mode; | ||
| import fr.insee.genesis.domain.model.variabletype.VariableTypeModel; | ||
| import fr.insee.genesis.infrastructure.document.variabletype.VariableTypeDocument; | ||
| import org.springframework.cache.annotation.Cacheable; | ||
|
|
||
| public interface VariableTypePersistancePort { | ||
| void save(VariableTypeModel variableTypeModel); | ||
| @Cacheable("variableTypes") | ||
| VariableTypeDocument find(String campaignId, String questionnaireId, Mode mode); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.