Skip to content

Commit f642ce5

Browse files
committed
modify after CR
1 parent 6cb8990 commit f642ce5

7 files changed

Lines changed: 191 additions & 192 deletions

File tree

src/main/java/fr/insee/genesis/controller/rest/DataProcessingContextController.java

Lines changed: 65 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ public class DataProcessingContextController {
4040
@PutMapping(path = "/context/review")
4141
@PreAuthorize("hasAnyRole('USER_PLATINE', 'USER_BACK_OFFICE', 'SCHEDULER')")
4242
public ResponseEntity<Object> saveContext(
43-
@Parameter(description = "Identifier of the partition", required = true) @RequestParam("partitionId") String partitionId,
44-
@Parameter(description = "Allow reviewing") @RequestParam(value = "withReview", defaultValue = "false") Boolean withReview
45-
){
46-
try {
47-
withReview = withReview != null && withReview; //False if null
48-
dataProcessingContextApiPort.saveContext(partitionId, withReview);
49-
}catch (GenesisException e){
50-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
51-
}
43+
@Parameter(description = "Identifier of the partition", required = true)
44+
@RequestParam("partitionId") String partitionId,
45+
@Parameter(description = "Allow reviewing")
46+
@RequestParam(value = "withReview", defaultValue = "false") Boolean withReview
47+
) throws GenesisException {
48+
withReview = withReview != null && withReview;
49+
dataProcessingContextApiPort.saveContext(partitionId, withReview);
5250
return ResponseEntity.ok().build();
5351
}
5452

@@ -57,14 +55,11 @@ public ResponseEntity<Object> saveContext(
5755
@PreAuthorize("hasAnyRole('USER_PLATINE', 'USER_BACK_OFFICE', 'SCHEDULER')")
5856
public ResponseEntity<Object> saveContextWithCollectionInstrumentId(
5957
@PathVariable("collectionInstrumentId") String collectionInstrumentId,
60-
@Parameter(description = "Allow reviewing") @RequestParam(value = "withReview", defaultValue = "false") Boolean withReview
61-
){
62-
try {
63-
withReview = withReview != null && withReview; //False if null
64-
dataProcessingContextApiPort.saveContextByCollectionInstrumentId(collectionInstrumentId, withReview);
65-
}catch (GenesisException e){
66-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
67-
}
58+
@Parameter(description = "Allow reviewing")
59+
@RequestParam(value = "withReview", defaultValue = "false") Boolean withReview
60+
) throws GenesisException {
61+
withReview = withReview != null && withReview;
62+
dataProcessingContextApiPort.saveContextByCollectionInstrumentId(collectionInstrumentId, withReview);
6863
return ResponseEntity.ok().build();
6964
}
7065

@@ -74,28 +69,21 @@ public ResponseEntity<Object> saveContextWithCollectionInstrumentId(
7469
@PreAuthorize("hasAnyRole('USER_BACK_OFFICE','SCHEDULER','USER_PLATINE')")
7570
public ResponseEntity<Object> getReviewIndicatorByCollectionInstrumentId(
7671
@PathVariable("collectionInstrumentId") String collectionInstrumentId
77-
){
78-
try {
79-
boolean withReview = dataProcessingContextApiPort.getReviewByCollectionInstrumentId(collectionInstrumentId);
80-
return ResponseEntity.ok(withReview);
81-
}catch (GenesisException e){
82-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
83-
}
72+
) throws GenesisException {
73+
boolean withReview = dataProcessingContextApiPort.getReviewByCollectionInstrumentId(collectionInstrumentId);
74+
return ResponseEntity.ok(withReview);
8475
}
8576

8677
@Deprecated(forRemoval = true)
8778
@Operation(summary = "Returns partition review indicator")
8879
@GetMapping(path = "/context/review")
8980
@PreAuthorize("hasAnyRole('USER_BACK_OFFICE','SCHEDULER','USER_PLATINE')")
9081
public ResponseEntity<Object> getReviewIndicator(
91-
@Parameter(description = "Identifier of the partition", required = true) @RequestParam("partitionId") String partitionId
92-
){
93-
try {
94-
boolean withReview = dataProcessingContextApiPort.getReviewByPartitionId(partitionId);
95-
return ResponseEntity.ok(withReview);
96-
}catch (GenesisException e){
97-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
98-
}
82+
@Parameter(description = "Identifier of the partition", required = true)
83+
@RequestParam("partitionId") String partitionId
84+
) throws GenesisException {
85+
boolean withReview = dataProcessingContextApiPort.getReviewByPartitionId(partitionId);
86+
return ResponseEntity.ok(withReview);
9987
}
10088

10189
@Deprecated(forRemoval = true)
@@ -115,32 +103,33 @@ public ResponseEntity<Object> saveSchedule(
115103
@Parameter(description = "(Encryption) output folder") @RequestParam(value = "encryptionOutputFolder",
116104
defaultValue = "") String encryptionOutputFolder,
117105
@Parameter(description = "(Encryption) Use signature system") @RequestParam(value = "useSignature", defaultValue = "false") boolean useSignature
118-
) {
119-
try {
120-
//Check frequency
121-
if(!CronExpression.isValidExpression(frequency)) {
122-
log.warn("Returned error for wrong frequency : {}", frequency);
123-
throw new GenesisException(HttpStatus.BAD_REQUEST, "Wrong frequency syntax");
124-
}
106+
) throws GenesisException {
125107

126-
TrustParameters trustParameters = null;
127-
if(useEncryption) {
128-
trustParameters = new TrustParameters(
129-
fileUtils.getKraftwerkOutFolder(partitionId),
130-
encryptionOutputFolder,
131-
encryptionVaultPath,
132-
useSignature
133-
);
134-
}
135-
dataProcessingContextApiPort.saveKraftwerkExecutionSchedule(
136-
partitionId,
137-
serviceToCall == null ? ServiceToCall.MAIN : serviceToCall,
138-
frequency,
139-
scheduleBeginDate, scheduleEndDate, trustParameters
108+
//Check frequency
109+
if (!CronExpression.isValidExpression(frequency)) {
110+
log.warn("Returned error for wrong frequency : {}", frequency);
111+
throw new GenesisException(HttpStatus.BAD_REQUEST, "Wrong frequency syntax");
112+
}
113+
114+
TrustParameters trustParameters = null;
115+
if (useEncryption) {
116+
trustParameters = new TrustParameters(
117+
fileUtils.getKraftwerkOutFolder(partitionId),
118+
encryptionOutputFolder,
119+
encryptionVaultPath,
120+
useSignature
140121
);
141-
}catch (GenesisException e){
142-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
143122
}
123+
124+
dataProcessingContextApiPort.saveKraftwerkExecutionSchedule(
125+
partitionId,
126+
serviceToCall == null ? ServiceToCall.MAIN : serviceToCall,
127+
frequency,
128+
scheduleBeginDate,
129+
scheduleEndDate,
130+
trustParameters
131+
);
132+
144133
return ResponseEntity.ok().build();
145134
}
146135

@@ -161,8 +150,7 @@ public ResponseEntity<Object> saveScheduleWithCollectionInstrumentId(
161150
@Parameter(description = "(Encryption) output folder") @RequestParam(value = "encryptionOutputFolder",
162151
defaultValue = "") String encryptionOutputFolder,
163152
@Parameter(description = "(Encryption) Use signature system") @RequestParam(value = "useSignature", defaultValue = "false") boolean useSignature
164-
) {
165-
try {
153+
) throws GenesisException{
166154
//Check frequency
167155
if(!CronExpression.isValidExpression(frequency)) {
168156
log.warn("Returned error for wrong frequency : {}", frequency);
@@ -184,9 +172,7 @@ public ResponseEntity<Object> saveScheduleWithCollectionInstrumentId(
184172
frequency,
185173
scheduleBeginDate, scheduleEndDate, trustParameters
186174
);
187-
}catch (GenesisException e){
188-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
189-
}
175+
190176
return ResponseEntity.ok().build();
191177
}
192178

@@ -224,13 +210,11 @@ public ResponseEntity<Object> getAllSchedulesV2() {
224210
public ResponseEntity<Object> setSurveyLastExecution(
225211
@Parameter(description = "Survey name to call Kraftwerk on") @RequestBody String partitionId,
226212
@Parameter(description = "Date to save as last execution date", example = "2024-01-01T12:00:00") @RequestParam("newDate") LocalDateTime newDate
227-
) {
228-
try {
229-
dataProcessingContextApiPort.updateLastExecutionDate(partitionId, newDate);
230-
log.info("{} last execution updated at {} !", partitionId, newDate);
231-
}catch (GenesisException e){
232-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
233-
}
213+
) throws GenesisException{
214+
215+
dataProcessingContextApiPort.updateLastExecutionDate(partitionId, newDate);
216+
log.info("{} last execution updated at {} !", partitionId, newDate);
217+
234218
return ResponseEntity.ok().build();
235219
}
236220

@@ -240,13 +224,11 @@ public ResponseEntity<Object> setSurveyLastExecution(
240224
public ResponseEntity<Object> setSurveyLastExecutionByCollectionInstrumentId(
241225
@PathVariable("collectionInstrumentId") @RequestBody String collectionInstrumentId,
242226
@Parameter(description = "Date to save as last execution date", example = "2024-01-01T12:00:00") @RequestParam("newDate") LocalDateTime newDate
243-
) {
244-
try {
245-
dataProcessingContextApiPort.updateLastExecutionDateByCollectionInstrumentId(collectionInstrumentId, newDate);
246-
log.info("{} last execution updated at {} !", collectionInstrumentId, newDate);
247-
}catch (GenesisException e){
248-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
249-
}
227+
) throws GenesisException{
228+
229+
dataProcessingContextApiPort.updateLastExecutionDateByCollectionInstrumentId(collectionInstrumentId, newDate);
230+
log.info("{} last execution updated at {} !", collectionInstrumentId, newDate);
231+
250232
return ResponseEntity.ok().build();
251233
}
252234

@@ -256,12 +238,9 @@ public ResponseEntity<Object> setSurveyLastExecutionByCollectionInstrumentId(
256238
@PreAuthorize("hasRole('USER_KRAFTWERK')")
257239
public ResponseEntity<Object> deleteSchedules(
258240
@Parameter(description = "Survey name of the schedule(s) to delete") @RequestParam("partitionId") String partitionId
259-
){
260-
try {
261-
dataProcessingContextApiPort.deleteSchedules(partitionId);
262-
}catch (GenesisException e){
263-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
264-
}
241+
) throws GenesisException{
242+
243+
dataProcessingContextApiPort.deleteSchedules(partitionId);
265244
log.info("Schedule deleted for survey {}", partitionId);
266245
return ResponseEntity.ok().build();
267246
}
@@ -271,25 +250,19 @@ public ResponseEntity<Object> deleteSchedules(
271250
@PreAuthorize("hasRole('USER_KRAFTWERK')")
272251
public ResponseEntity<Object> deleteSchedulesByCollectionInstrumentId(
273252
@PathVariable("collectionInstrumentId") String collectionInstrumentId
274-
){
275-
try {
276-
dataProcessingContextApiPort.deleteSchedulesByCollectionInstrumentId(collectionInstrumentId);
277-
}catch (GenesisException e){
278-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
279-
}
253+
) throws GenesisException{
254+
255+
dataProcessingContextApiPort.deleteSchedulesByCollectionInstrumentId(collectionInstrumentId);
280256
log.info("Schedule deleted for survey {}", collectionInstrumentId);
281257
return ResponseEntity.ok().build();
282258
}
283259

284260
@Operation(summary = "Delete expired schedules")
285261
@DeleteMapping(path = "/context/schedules/expired-schedules")
286262
@PreAuthorize("hasRole('SCHEDULER')")
287-
public ResponseEntity<Object> deleteExpiredSchedules(){
288-
try{
289-
dataProcessingContextApiPort.deleteExpiredSchedules(fileUtils.getLogFolder());
290-
} catch (GenesisException e){
291-
return new ResponseEntity<>(e.getMessage(), e.getStatus());
292-
}
263+
public ResponseEntity<Object> deleteExpiredSchedules() throws GenesisException{
264+
265+
dataProcessingContextApiPort.deleteExpiredSchedules(fileUtils.getLogFolder());
293266
log.info("Expired schedules deleted");
294267
return ResponseEntity.ok().build();
295268
}

src/main/java/fr/insee/genesis/controller/rest/QuestionnaireMetadataController.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@ public class QuestionnaireMetadataController {
2525
public ResponseEntity<Object> getMetadata(
2626
@RequestParam("questionnaireId") String questionnaireId,
2727
@RequestParam("mode") Mode mode
28-
){
29-
try {
28+
) throws QuestionnaireNotFoundException{
29+
3030
return ResponseEntity.ok().body(questionnaireMetadataApiPort.find(questionnaireId, mode));
31-
} catch (QuestionnaireNotFoundException e) {
32-
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
33-
}
3431
}
3532

3633
@Operation(summary = "Save questionnaire metadata into database")

src/main/java/fr/insee/genesis/controller/rest/UtilsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ResponseEntity<Object> saveResponsesFromXmlFile(@RequestParam("inputFolde
4747
XMLSplitter.split(inputFolder, filename, outputFolder, "SurveyUnit", nbSU);
4848
return ResponseEntity.ok("File split");
4949
}
50-
//TODO
50+
5151
@Operation(summary = "Record volumetrics of each campaign in a folder")
5252
@PutMapping(path = "/volumetrics/save-all-campaigns")
5353
@PreAuthorize("hasRole('SCHEDULER')")

src/main/java/fr/insee/genesis/infrastructure/utils/FileUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,14 @@ public void ensureContextualFolderExists(String questionnaireId, Mode mode) thro
263263
String contextualFolderPath =
264264
getDataFolder(questionnaireId, mode.getFolder(), null) + Constants.CONTEXTUAL_FOLDER;
265265

266-
if (!isFolderPresent(contextualFolderPath)) {
267-
Files.createDirectories(Path.of(contextualFolderPath));
268-
log.debug("contextual folder created : {}", contextualFolderPath);
269-
} else {
266+
if (isFolderPresent(contextualFolderPath)) {
270267
log.debug("contextual folder already exists : {}", contextualFolderPath);
268+
return;
271269
}
272270

271+
Files.createDirectories(Path.of(contextualFolderPath));
272+
log.debug("contextual folder created : {}", contextualFolderPath);
273+
273274
} catch (IOException e) {
274275
throw new GenesisException(
275276
HttpStatus.INTERNAL_SERVER_ERROR,

src/test/java/cucumber/functional_tests/DataProcessingContextDefinitions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ public void add_context_with_expired_schedule(String partitionId, int expectedSc
108108
}
109109

110110
@When("We save data processing context for partition {string}")
111-
public void save_context(String partitionId){
111+
public void save_context(String partitionId) throws GenesisException {
112112
response = dataProcessingContextController.saveContext(partitionId, null);
113113
}
114114

115115
@When("We save data processing context for partition {string} and review indicator to {string}")
116-
public void save_context_with_review_indicator(String partitionId, String withReviewString) {
116+
public void save_context_with_review_indicator(String partitionId, String withReviewString) throws GenesisException {
117117
response = dataProcessingContextController.saveContext(partitionId, Boolean.parseBoolean(withReviewString));
118118
}
119119

@@ -122,7 +122,7 @@ public void save_kraftwerk_schedule(String partitionId,
122122
String frequency,
123123
String serviceToCallString,
124124
String startDateString,
125-
String endDateString) {
125+
String endDateString) throws GenesisException {
126126
ServiceToCall serviceToCall = ServiceToCall.valueOf(serviceToCallString);
127127
LocalDateTime startDate = LocalDateTime.parse(startDateString);
128128
LocalDateTime endDate = LocalDateTime.parse(endDateString);
@@ -139,7 +139,7 @@ public void save_kraftwerk_schedule(String partitionId,
139139
}
140140

141141
@When("We delete the schedules of {string}")
142-
public void delete_schedules(String partitionId){
142+
public void delete_schedules(String partitionId) throws GenesisException {
143143
response = dataProcessingContextController.deleteSchedules(partitionId);
144144
}
145145

0 commit comments

Comments
 (0)