1111import fr .insee .genesis .controller .dto .SurveyUnitInputDto ;
1212import fr .insee .genesis .controller .dto .SurveyUnitQualityToolDto ;
1313import fr .insee .genesis .controller .dto .SurveyUnitSimplified ;
14- import fr .insee .genesis .controller .services .MetadataService ;
1514import fr .insee .genesis .controller .rest .CommonApiResponse ;
15+ import fr .insee .genesis .controller .services .MetadataService ;
1616import fr .insee .genesis .controller .sources .xml .LunaticXmlCampaign ;
1717import fr .insee .genesis .controller .sources .xml .LunaticXmlDataParser ;
1818import fr .insee .genesis .controller .sources .xml .LunaticXmlDataSequentialParser ;
5757import java .nio .file .Paths ;
5858import java .time .LocalDateTime ;
5959import java .util .ArrayList ;
60- import java .util .HashSet ;
6160import java .util .List ;
6261import java .util .Set ;
6362import java .util .stream .Stream ;
@@ -79,7 +78,6 @@ public class ResponseController implements CommonApiResponse {
7978 private final AuthUtils authUtils ;
8079 private final MetadataService metadataService ;
8180
82-
8381 public ResponseController (SurveyUnitApiPort surveyUnitService ,
8482 SurveyUnitQualityService surveyUnitQualityService ,
8583 FileUtils fileUtils ,
@@ -107,7 +105,7 @@ public ResponseEntity<Object> saveResponsesFromXmlFile(@RequestParam("pathLunati
107105 VariablesMap variablesMap ;
108106 if (withDDI ) {
109107 //Parse DDI
110- log .info (String . format ( "Try to read DDI file : %s " , metadataFilePath ) );
108+ log .info ("Try to read DDI file : {} " , metadataFilePath );
111109 try {
112110 variablesMap =
113111 DDIReader .getMetadataFromDDI (Path .of (metadataFilePath ).toFile ().toURI ().toURL ().toString (),
@@ -117,12 +115,12 @@ public ResponseEntity<Object> saveResponsesFromXmlFile(@RequestParam("pathLunati
117115 }
118116 }else {
119117 //Parse Lunatic
120- log .info (String . format ( "Try to read lunatic file : %s " , metadataFilePath ) );
118+ log .info ("Try to read lunatic file : {} " , metadataFilePath );
121119
122120 variablesMap = LunaticReader .getMetadataFromLunatic (new FileInputStream (metadataFilePath )).getVariables ();
123121 }
124122
125- log .info (String . format ( "Try to read Xml file : %s " , xmlFile ) );
123+ log .info ("Try to read Xml file : {} " , xmlFile );
126124 Path filepath = Paths .get (xmlFile );
127125
128126 if (getFileSizeInMB (filepath ) <= Constants .MAX_FILE_SIZE_UNTIL_SEQUENTIAL ) {
@@ -331,7 +329,7 @@ public ResponseEntity<Object> saveEditedVariables(
331329 //Try to look for DDI first, if no DDI found looks for lunatic components
332330 List <GenesisError > errors = new ArrayList <>();
333331 //We need to retrieve campaignId
334- HashSet <String > campaignIds = findCampaignId (surveyUnitInputDto );
332+ Set <String > campaignIds = surveyUnitService . findCampaignIdsFrom (surveyUnitInputDto );
335333 if (campaignIds .size () != 1 ){
336334 return ResponseEntity .status (500 ).body ("Impossible to assign one campaignId to that response" );
337335 }
@@ -384,14 +382,7 @@ public ResponseEntity<Object> saveEditedVariables(
384382 return ResponseEntity .ok (SUCCESS_MESSAGE );
385383 }
386384
387- private HashSet <String > findCampaignId (SurveyUnitInputDto surveyUnitInputDto ) {
388- List <SurveyUnitModel > responses = surveyUnitService .findByIdsInterrogationAndQuestionnaire (surveyUnitInputDto .getInterrogationId (), surveyUnitInputDto .getQuestionnaireId ());
389- HashSet <String > campaignIds = new HashSet <>();
390- for (SurveyUnitModel response : responses ){
391- campaignIds .add (response .getCampaignId ());
392- }
393- return campaignIds ;
394- }
385+
395386
396387 //Utilities
397388 /**
0 commit comments