Skip to content

Commit

Permalink
Rename services and extract volumetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
alicela committed Oct 23, 2024
1 parent 17b5a23 commit 796bd2c
Show file tree
Hide file tree
Showing 4 changed files with 446 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import fr.insee.genesis.domain.model.surveyunit.Variable;
import fr.insee.genesis.domain.ports.api.SurveyUnitApiPort;
import fr.insee.genesis.domain.service.surveyunit.SurveyUnitQualityService;
import fr.insee.genesis.domain.service.volumetry.VolumetryLogService;
import fr.insee.genesis.exceptions.GenesisError;
import fr.insee.genesis.exceptions.GenesisException;
import fr.insee.genesis.exceptions.NoDataError;
Expand Down Expand Up @@ -58,7 +57,7 @@
import java.util.Set;
import java.util.stream.Stream;

@RequestMapping(path = "/response" )
@RequestMapping(path = "/responses" )
@Controller
@Tag(name = "Response services for interrogations", description = "A **response** is considered the entire set of data associated with an interrogation (idUE x idQuestionnaire). \n\n These data may have different state (collected, edited, external, ...) ")
@Slf4j
Expand All @@ -68,22 +67,20 @@ public class ResponseController {
public static final String S_S = "%s/%s";
private final SurveyUnitApiPort surveyUnitService;
private final SurveyUnitQualityService surveyUnitQualityService;
private final VolumetryLogService volumetryLogService;
private final FileUtils fileUtils;
private final ControllerUtils controllerUtils;

@Autowired
public ResponseController(SurveyUnitApiPort surveyUnitService, SurveyUnitQualityService surveyUnitQualityService, VolumetryLogService volumetryLogService, FileUtils fileUtils, ControllerUtils controllerUtils) {
public ResponseController(SurveyUnitApiPort surveyUnitService, SurveyUnitQualityService surveyUnitQualityService, FileUtils fileUtils, ControllerUtils controllerUtils) {
this.surveyUnitService = surveyUnitService;
this.surveyUnitQualityService = surveyUnitQualityService;
this.volumetryLogService = volumetryLogService;
this.fileUtils = fileUtils;
this.controllerUtils = controllerUtils;
}

//SAVE
@Operation(summary = "Save one file of responses to Genesis Database, passing its path as a parameter")
@PutMapping(path = "/save/lunatic-xml/one-file")
@PutMapping(path = "/lunatic-xml/save-one")
public ResponseEntity<Object> saveResponsesFromXmlFile(@RequestParam("pathLunaticXml") String xmlFile,
@RequestParam(value = "pathSpecFile") String metadataFilePath,
@RequestParam(value = "mode") Mode modeSpecified,
Expand Down Expand Up @@ -118,7 +115,7 @@ public ResponseEntity<Object> saveResponsesFromXmlFile(@RequestParam("pathLunati
}

@Operation(summary = "Save multiple files to Genesis Database from the campaign root folder")
@PutMapping(path = "/save/lunatic-xml")
@PutMapping(path = "/lunatic-xml/save-folder")
public ResponseEntity<Object> saveResponsesFromXmlCampaignFolder(@RequestParam("campaignName") String campaignName,
@RequestParam(value = "mode", required = false) Mode modeSpecified,
@RequestParam(value = "withDDI", defaultValue = "true") boolean withDDI
Expand All @@ -140,7 +137,7 @@ public ResponseEntity<Object> saveResponsesFromXmlCampaignFolder(@RequestParam("

//SAVE ALL
@Operation(summary = "Save all files to Genesis Database (differential data folder only), regardless of the campaign")
@PutMapping(path = "/save/lunatic-xml/all-campaigns")
@PutMapping(path = "/lunatic-xml/save-all-campaigns")
public ResponseEntity<Object> saveResponsesFromAllCampaignFolders(){
List<GenesisError> errors = new ArrayList<>();
List<File> campaignFolders = fileUtils.listAllSpecsFolders();
Expand Down Expand Up @@ -170,17 +167,11 @@ public ResponseEntity<Object> saveResponsesFromAllCampaignFolders(){
}
}

@Operation(summary = "Record volumetrics of each campaign in a folder")
@PutMapping(path = "/save-volumetry/all-campaigns")
public ResponseEntity<Object> saveVolumetry() throws IOException {
volumetryLogService.writeVolumetries(surveyUnitService);
volumetryLogService.cleanOldFiles();
return ResponseEntity.ok("Volumetric saved");
}


//DELETE
@Operation(summary = "Delete all responses associated with a questionnaire")
@DeleteMapping(path = "/delete-responses/by-questionnaire")
@DeleteMapping(path = "/delete/by-questionnaire")
public ResponseEntity<Object> deleteAllResponsesByQuestionnaire(@RequestParam("idQuestionnaire") String idQuestionnaire) {
log.info("Try to delete all responses of questionnaire : {}", idQuestionnaire);
Long ndDocuments = surveyUnitService.deleteByIdQuestionnaire(idQuestionnaire);
Expand All @@ -199,7 +190,7 @@ public ResponseEntity<List<SurveyUnitModel>> findResponsesByUEAndQuestionnaire(@

@Operation(summary = "Retrieve responses for an interrogation, using IdUE and IdQuestionnaire from Genesis Database with the latest value for each available state of every variable")
@GetMapping(path = "/get-responses/by-ue-and-questionnaire/latest-states")
public ResponseEntity<SurveyUnitDto> findResponsesByUEAndQuestionnaireLastestStates(
public ResponseEntity<SurveyUnitDto> findResponsesByUEAndQuestionnaireLatestStates(
@RequestParam("idUE") String idUE,
@RequestParam("idQuestionnaire") String idQuestionnaire) {
SurveyUnitDto response = surveyUnitService.findLatestValuesByStateByIdAndByIdQuestionnaire(idUE, idQuestionnaire);
Expand Down Expand Up @@ -236,8 +227,8 @@ public ResponseEntity<List<SurveyUnitModel>> getLatestByUE(@RequestParam("idUE")
return ResponseEntity.ok(responses);
}

@Operation(summary = "Retrieve response latest state with IdUE and IdQuestionnaire in one object in the output")
@GetMapping(path = "/get-simplified-response/by-ue-and-questionnaire/latest")
@Operation(summary = "Retrieve responses for an interrogation, using IdUE and IdQuestionnaire from Genesis Database. It returns only the latest value of each variable regardless of the state. The result is in one object in the output")
@GetMapping(path = "/get-simplified-response/by-ue-questionnaire-and-mode/latest")
public ResponseEntity<SurveyUnitSimplified> getLatestByUEOneObject(@RequestParam("idUE") String idUE,
@RequestParam("idQuestionnaire") String idQuestionnaire,
@RequestParam("mode") Mode mode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
package fr.insee.genesis.controller.rest;

import fr.insee.genesis.domain.ports.api.SurveyUnitApiPort;
import fr.insee.genesis.domain.service.volumetry.VolumetryLogService;
import fr.insee.genesis.domain.utils.XMLSplitter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping(path = "/utils")
import java.io.IOException;

@RequestMapping(path = "/")
@Controller
@Slf4j
@Tag(name = "Technical services")
public class UtilsController {

private final VolumetryLogService volumetryLogService;
private final SurveyUnitApiPort surveyUnitService;


@Autowired
public UtilsController(SurveyUnitApiPort surveyUnitService,VolumetryLogService volumetryLogService) {
this.surveyUnitService = surveyUnitService;
this.volumetryLogService = volumetryLogService;

}



@Operation(summary = "Split a XML file into smaller ones")
@PutMapping(path = "/split/lunatic-xml")
@PutMapping(path = "/utils/split/lunatic-xml")
public ResponseEntity<Object> saveResponsesFromXmlFile(@RequestParam("inputFolder") String inputFolder,
@RequestParam("outputFolder") String outputFolder,
@RequestParam("filename") String filename,
@RequestParam("nbResponsesByFile") int nbSU)
throws Exception {
log.info("Split XML file : {} into {} SU by file", filename, nbSU);
XMLSplitter.split(inputFolder, filename, outputFolder, "SurveyUnit", nbSU);
return ResponseEntity.ok("Test");
return ResponseEntity.ok("File split");
}

@Operation(summary = "Record volumetrics of each campaign in a folder")
@PutMapping(path = "/volumetrics/save-all-campaigns")
public ResponseEntity<Object> saveVolumetry() throws IOException {
volumetryLogService.writeVolumetries(surveyUnitService);
volumetryLogService.cleanOldFiles();
return ResponseEntity.ok("Volumetric saved");
}
}
Loading

0 comments on commit 796bd2c

Please sign in to comment.