Skip to content

Commit 358a3af

Browse files
committed
feat: new endpoint to list collection instrument ids containing unprocessed data
1 parent e8c3e86 commit 358a3af

File tree

8 files changed

+39
-3
lines changed

8 files changed

+39
-3
lines changed

src/main/java/fr/insee/genesis/controller/rest/responses/RawResponseController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ public ResponseEntity<String> processRawResponses(
215215
return ResponseEntity.status(e.getStatus()).body(e.getMessage());
216216
}
217217
}
218+
@Operation(summary = "Get the list of collection instruments containing unprocessed interrogations")
219+
@GetMapping(path = "/raw-responses/unprocessed/collection-intrument-ids")
220+
@PreAuthorize("hasRole('SCHEDULER')")
221+
public ResponseEntity<List<String>> getUnprocessedCollectionInstrument(){
222+
log.info("Try to get collection instruments containing unprocessed interrogations...");
223+
return ResponseEntity.ok(rawResponseApiPort.getUnprocessedCollectionInstrumentIds());
224+
}
218225

219226
//GET unprocessed
220227
@Operation(summary = "Get campaign id and interrogationId from all unprocessed raw json data")

src/main/java/fr/insee/genesis/domain/ports/api/RawResponseApiPort.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ public interface RawResponseApiPort {
1515
List<RawResponse> getRawResponses(String collectionInstrumentId, Mode mode, List<String> interrogationIdList);
1616
DataProcessResult processRawResponses(String collectionInstrumentId, List<String> interrogationIdList, List<GenesisError> errors) throws GenesisException;
1717
List<SurveyUnitModel> convertRawResponse(List<RawResponse> rawResponses, VariablesMap variablesMap);
18+
List<String> getUnprocessedCollectionInstrumentIds();
1819
void updateProcessDates(List<SurveyUnitModel> surveyUnitModels);
1920
}

src/main/java/fr/insee/genesis/domain/ports/spi/RawResponsePersistencePort.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public interface RawResponsePersistencePort {
1010

1111
List<RawResponse> findRawResponses(String collectionInstrumentId, Mode mode, List<String> interrogationIdList);
1212
void updateProcessDates(String collectionInstrumentId, Set<String> interrogationIds);
13+
List<String> getUnprocessedCollectionIds();
1314
}

src/main/java/fr/insee/genesis/domain/service/rawdata/RawResponseService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public DataProcessResult processRawResponses(String collectionInstrumentId, List
127127
batchNumber++;
128128
}
129129
}
130-
return new DataProcessResult(dataCount, formattedDataCount);
130+
return new DataProcessResult(dataCount, formattedDataCount, List.of());
131131
}
132132

133133
@Override
@@ -182,6 +182,11 @@ public List<SurveyUnitModel> convertRawResponse(List<RawResponse> rawResponses,
182182
//return List.of();
183183
}
184184

185+
@Override
186+
public List<String> getUnprocessedCollectionInstrumentIds() {
187+
return rawResponsePersistencePort.getUnprocessedCollectionIds();
188+
}
189+
185190
@Override
186191
public void updateProcessDates(List<SurveyUnitModel> surveyUnitModels) {
187192
Set<String> collectionInstrumentIds = new HashSet<>();

src/main/java/fr/insee/genesis/infrastructure/adapter/RawResponseMongoAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ public void updateProcessDates(String collectionInstrumentId, Set<String> interr
4646
, Constants.MONGODB_RAW_RESPONSES_COLLECTION_NAME
4747
);
4848
}
49+
50+
@Override
51+
public List<String> getUnprocessedCollectionIds() {
52+
return repository.findDistinctCollectionInstrumentIdByProcessDateIsNull();
53+
}
4954
}

src/main/java/fr/insee/genesis/infrastructure/repository/RawResponseRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.insee.genesis.infrastructure.repository;
22

33
import fr.insee.genesis.infrastructure.document.rawdata.RawResponseDocument;
4+
import org.springframework.data.mongodb.repository.Aggregation;
45
import org.springframework.data.mongodb.repository.MongoRepository;
56
import org.springframework.data.mongodb.repository.Query;
67
import org.springframework.stereotype.Repository;
@@ -12,4 +13,10 @@ public interface RawResponseRepository extends MongoRepository<RawResponseDocume
1213

1314
@Query(value = "{ 'collectionInstrumentId' : ?0, 'mode' : ?1, 'interrogationId': {$in: ?2} }")
1415
List<RawResponseDocument> findByCollectionInstrumentIdAndModeAndInterrogationIdList(String questionnaireId, String mode, List<String> interrogationIdList);
16+
@Aggregation(pipeline = {
17+
"{ $match: { processDate: null } }",
18+
"{ $group: { _id: '$collectionInstrumentId' } }",
19+
"{ $project: { _id: 0, collectionInstrumentId: '$_id' } }"
20+
})
21+
List<String> findDistinctCollectionInstrumentIdByProcessDateIsNull();
1522
}

src/test/java/cucumber/functional_tests/RawDataDefinitions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ public List<SurveyUnitModel> convertRawResponse(List<RawResponse> rawResponses,
120120
return List.of();
121121
}
122122

123+
@Override
124+
public List<String> getUnprocessedCollectionInstrumentIds() {
125+
return List.of();
126+
}
127+
123128
@Override
124129
public void updateProcessDates(List<SurveyUnitModel> surveyUnitModels) {
125130
// Do nothing - stub for test

src/test/java/fr/insee/genesis/controller/rest/responses/RawResponseControllerTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public List<SurveyUnitModel> convertRawResponse(List<RawResponse> rawResponses,
9393
return List.of();
9494
}
9595

96+
@Override
97+
public List<String> getUnprocessedCollectionInstrumentIds() {
98+
return List.of();
99+
}
100+
96101
@Override
97102
public void updateProcessDates(List<SurveyUnitModel> surveyUnitModels) {
98103

@@ -277,10 +282,10 @@ void processJsonRawDataV2Test(){
277282
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub()).isNotNull().isNotEmpty().hasSize(1);
278283
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst()).isNotNull();
279284
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getCampaignId()).isEqualTo(questionnaireId);
280-
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getQuestionnaireId()).isNotNull().isEqualTo(questionnaireId);
285+
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getCollectionInstrumentId()).isNotNull().isEqualTo(questionnaireId);
281286
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getMode()).isNotNull().isEqualTo(Mode.WEB);
282287
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getInterrogationId()).isEqualTo(interrogationId);
283-
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getIdUE()).isEqualTo(idUE);
288+
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getUsualSurveyUnitId()).isEqualTo(idUE);
284289
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getFileDate()).isNotNull();
285290
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getRecordDate()).isNotNull();
286291
Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub().getFirst().getCollectedVariables()).isNotNull().isNotEmpty().hasSize(1);

0 commit comments

Comments
 (0)