@@ -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 }
0 commit comments