1515import io .swagger .v3 .oas .annotations .Operation ;
1616import io .swagger .v3 .oas .annotations .Parameter ;
1717import jakarta .validation .Valid ;
18+ import lombok .RequiredArgsConstructor ;
1819import lombok .extern .slf4j .Slf4j ;
1920import org .springframework .data .domain .Page ;
2021import org .springframework .data .domain .PageRequest ;
4344
4445@ Slf4j
4546@ Controller
47+ @ RequiredArgsConstructor
4648public class RawResponseController {
4749
4850 private static final String SUCCESS_MESSAGE = "Interrogation %s saved" ;
4951 private static final String INTERROGATION_ID = "interrogationId" ;
50- public static final String NB_DOCS_WITH_FORMATTED = "%d document(s) processed, including %d FORMATTED after data verification for collectionInstrumentId %s" ;
51- public static final String NB_DOCS = "%d document(s) processed for collectionInstrumentId %s" ;
52+
5253 private final LunaticJsonRawDataApiPort lunaticJsonRawDataApiPort ;
5354 private final RawResponseApiPort rawResponseApiPort ;
5455 private final RawResponseInputRepository rawRepository ;
5556
56-
57- public RawResponseController (LunaticJsonRawDataApiPort lunaticJsonRawDataApiPort , RawResponseApiPort rawResponseApiPort , RawResponseInputRepository rawRepository ) {
58- this .lunaticJsonRawDataApiPort = lunaticJsonRawDataApiPort ;
59- this .rawResponseApiPort = rawResponseApiPort ;
60- this .rawRepository = rawRepository ;
61- }
62-
6357 @ Operation (summary = "Save lunatic json data from one interrogation in Genesis Database" )
6458 @ PutMapping (path = "/responses/raw/lunatic-json/save" )
6559 @ PreAuthorize ("hasRole('COLLECT_PLATFORM')" )
@@ -118,11 +112,8 @@ public ResponseEntity<String> processRawResponses(
118112 log .info ("Try to process raw responses for collectionInstrumentId {} and {} interrogationIds" , collectionInstrumentId , interrogationIdList .size ());
119113 List <GenesisError > errors = new ArrayList <>();
120114 try {
121- DataProcessResult result = rawResponseApiPort .processRawResponses (collectionInstrumentId , interrogationIdList , errors );
122- return result .formattedDataCount () == 0 ?
123- ResponseEntity .ok (NB_DOCS .formatted (result .dataCount (), collectionInstrumentId ))
124- : ResponseEntity .ok (NB_DOCS_WITH_FORMATTED
125- .formatted (result .dataCount (), result .formattedDataCount (), collectionInstrumentId ));
115+ DataProcessResult result = rawResponseApiPort .processRawResponsesByInterrogationIds (collectionInstrumentId , interrogationIdList , errors );
116+ return ResponseEntity .ok (result .message (collectionInstrumentId ));
126117 } catch (GenesisException e ) {
127118 return ResponseEntity .status (e .getStatus ()).body (e .getMessage ());
128119 }
@@ -140,11 +131,8 @@ public ResponseEntity<String> processRawResponsesByCollectionInstrumentId(
140131 ) {
141132 log .info ("Try to process raw responses for collectionInstrumentId {}" , collectionInstrumentId );
142133 try {
143- DataProcessResult result = rawResponseApiPort .processRawResponses (collectionInstrumentId );
144- return result .formattedDataCount () == 0 ?
145- ResponseEntity .ok (NB_DOCS .formatted (result .dataCount (), collectionInstrumentId ))
146- : ResponseEntity .ok (NB_DOCS_WITH_FORMATTED
147- .formatted (result .dataCount (), result .formattedDataCount (), collectionInstrumentId ));
134+ DataProcessResult result = rawResponseApiPort .processRawResponsesByInterrogationIds (collectionInstrumentId );
135+ return ResponseEntity .ok (result .message (collectionInstrumentId ));
148136 } catch (GenesisException e ) {
149137 return ResponseEntity .status (e .getStatus ()).body (e .getMessage ());
150138 }
@@ -183,7 +171,7 @@ public ResponseEntity<LunaticJsonRawDataModel> getJsonRawData(
183171 @ RequestParam ("campaignName" ) String campaignName ,
184172 @ RequestParam (value = "mode" ) Mode modeSpecified
185173 ) {
186- List <LunaticJsonRawDataModel > data = lunaticJsonRawDataApiPort .getRawData (campaignName , modeSpecified , List .of (interrogationId ));
174+ List <LunaticJsonRawDataModel > data = lunaticJsonRawDataApiPort .getRawDataByQuestionnaireId (campaignName , modeSpecified , List .of (interrogationId ));
187175 return ResponseEntity .ok (data .getFirst ());
188176 }
189177
@@ -201,7 +189,7 @@ public ResponseEntity<String> processJsonRawData(
201189 List <GenesisError > errors = new ArrayList <>();
202190
203191 try {
204- DataProcessResult result = lunaticJsonRawDataApiPort .processRawData (campaignName , interrogationIdList , errors );
192+ DataProcessResult result = lunaticJsonRawDataApiPort .processRawDataByInterrogationIds (campaignName , interrogationIdList , errors );
205193 return result .formattedDataCount () == 0 ?
206194 ResponseEntity .ok ("%d document(s) processed" .formatted (result .dataCount ()))
207195 : ResponseEntity .ok ("%d document(s) processed, including %d FORMATTED after data verification"
0 commit comments