5353
5454import javax .xml .parsers .ParserConfigurationException ;
5555import javax .xml .stream .XMLStreamException ;
56- import java .io .*;
56+ import java .io .File ;
57+ import java .io .FileInputStream ;
58+ import java .io .FileNotFoundException ;
59+ import java .io .IOException ;
60+ import java .io .InputStream ;
5761import java .net .MalformedURLException ;
5862import java .nio .file .Files ;
5963import java .nio .file .Path ;
@@ -296,6 +300,7 @@ public ResponseEntity<SurveyUnitSimplified> getLatestByInterrogationOneObject(@R
296300 "For a given id, the endpoint returns a document by collection mode (if there is more than one)." )
297301 @ PostMapping (path = "/simplified/by-list-interrogation-and-collection-instrument/latest" )
298302 @ PreAuthorize ("hasRole('USER_KRAFTWERK')" )
303+ //TODO move logic and unit test to surveyUnitService (also extract some methods instead of multiple lambdas)
299304 public ResponseEntity <List <SurveyUnitSimplified >> getLatestForInterrogationListAndCollectionInstrument (
300305 @ RequestParam ("collectionInstrumentId" ) String collectionInstrumentId ,
301306 @ RequestBody List <InterrogationId > interrogationIds )
@@ -307,16 +312,20 @@ public ResponseEntity<List<SurveyUnitSimplified>> getLatestForInterrogationListA
307312 modes .forEach (mode -> {
308313 List <VariableModel > outputVariables = new ArrayList <>();
309314 List <VariableModel > outputExternalVariables = new ArrayList <>();
315+ List <String > usualSurveyUnitIds = new ArrayList <>();
310316 responses .stream ().filter (rep -> rep .getMode ().equals (mode )).forEach (response -> {
311317 outputVariables .addAll (response .getCollectedVariables ());
312318 outputExternalVariables .addAll (response .getExternalVariables ());
319+ if (response .getUsualSurveyUnitId () != null ){
320+ usualSurveyUnitIds .add (response .getUsualSurveyUnitId ());
321+ }
313322 });
314323 if (!outputVariables .isEmpty () || !outputExternalVariables .isEmpty ()) {
315324 results .add (SurveyUnitSimplified .builder ()
316325 .collectionInstrumentId (responses .getFirst ().getCollectionInstrumentId ())
317326 .campaignId (responses .getFirst ().getCampaignId ())
318- .interrogationId (responses . getFirst () .getInterrogationId ())
319- .usualSurveyUnitId (responses . getFirst (). getUsualSurveyUnitId () )
327+ .interrogationId (interrogationId .getInterrogationId ())
328+ .usualSurveyUnitId (! usualSurveyUnitIds . isEmpty () ? usualSurveyUnitIds . getFirst () : null )
320329 .mode (mode )
321330 .variablesUpdate (outputVariables )
322331 .externalVariables (outputExternalVariables )
0 commit comments