11package fr .insee .genesis .controller .rest ;
22
3- import fr .insee .genesis .Constants ;
43import fr .insee .genesis .controller .dto .KraftwerkExecutionScheduleInput ;
5- import fr .insee .genesis .controller .dto .ScheduleDto ;
64import fr .insee .genesis .controller .dto .ScheduleRequestDto ;
75import fr .insee .genesis .controller .dto .rawdata .ScheduleResponseDto ;
8- import fr .insee .genesis .domain .model .context .schedule .ServiceToCall ;
96import fr .insee .genesis .domain .model .context .schedule .TrustParameters ;
107import fr .insee .genesis .domain .ports .api .DataProcessingContextApiPort ;
118import fr .insee .genesis .exceptions .GenesisException ;
1714import lombok .extern .slf4j .Slf4j ;
1815import org .springframework .http .HttpStatusCode ;
1916import org .springframework .http .ResponseEntity ;
20- import org .springframework .scheduling .support .CronExpression ;
2117import org .springframework .security .access .prepost .PreAuthorize ;
2218import org .springframework .stereotype .Controller ;
2319import org .springframework .web .bind .annotation .DeleteMapping ;
@@ -38,23 +34,6 @@ public class DataProcessingContextController {
3834 private DataProcessingContextApiPort dataProcessingContextApiPort ;
3935 private final FileUtils fileUtils ;
4036
41- @ Deprecated (forRemoval = true )
42- @ Operation (summary = "Create or update a data processing context" )
43- @ PutMapping (path = "/context/review" )
44- @ PreAuthorize ("hasAnyRole('USER_PLATINE', 'USER_BACK_OFFICE', 'SCHEDULER')" )
45- public ResponseEntity <Object > saveContext (
46- @ Parameter (description = "Identifier of the partition" , required = true ) @ RequestParam ("partitionId" ) String partitionId ,
47- @ Parameter (description = "Allow reviewing" ) @ RequestParam (value = "withReview" , defaultValue = "false" ) Boolean withReview
48- ){
49- try {
50- withReview = withReview != null && withReview ; //False if null
51- dataProcessingContextApiPort .saveContext (partitionId , withReview );
52- }catch (GenesisException e ){
53- return new ResponseEntity <>(e .getMessage (), HttpStatusCode .valueOf (e .getStatus ()));
54- }
55- return ResponseEntity .ok ().build ();
56- }
57-
5837 @ Operation (summary = "Create or update a data processing context" )
5938 @ PutMapping (path = "/contexts/{collectionInstrumentId}/review" )
6039 @ PreAuthorize ("hasAnyRole('USER_PLATINE', 'USER_BACK_OFFICE', 'SCHEDULER')" )
@@ -86,21 +65,6 @@ public ResponseEntity<Object> getReviewIndicatorByCollectionInstrumentId(
8665 }
8766 }
8867
89- @ Deprecated (forRemoval = true )
90- @ Operation (summary = "Returns partition review indicator" )
91- @ GetMapping (path = "/context/review" )
92- @ PreAuthorize ("hasAnyRole('USER_BACK_OFFICE','SCHEDULER','USER_PLATINE')" )
93- public ResponseEntity <Object > getReviewIndicator (
94- @ Parameter (description = "Identifier of the partition" , required = true ) @ RequestParam ("partitionId" ) String partitionId
95- ){
96- try {
97- boolean withReview = dataProcessingContextApiPort .getReviewByPartitionId (partitionId );
98- return ResponseEntity .ok (withReview );
99- }catch (GenesisException e ){
100- return new ResponseEntity <>(e .getMessage (), HttpStatusCode .valueOf (e .getStatus ()));
101- }
102- }
103-
10468 @ Operation (summary = "Create a Kraftwerk execution schedule V2" )
10569 @ PostMapping (path = "/contexts/schedules/v2" )
10670 @ PreAuthorize ("hasRole('USER_KRAFTWERK')" )
@@ -141,98 +105,6 @@ public ResponseEntity<Object> createScheduleV2(
141105 }
142106 }
143107
144- @ Deprecated (forRemoval = true )
145- @ Operation (summary = "Schedule a Kraftwerk execution" )
146- @ PutMapping (path = "/context/schedules" )
147- @ PreAuthorize ("hasRole('USER_KRAFTWERK')" )
148- public ResponseEntity <Object > saveSchedule (
149- @ Parameter (description = "Partition identifier to call Kraftwerk on" ) @ RequestParam ("partitionId" ) String partitionId ,
150- @ Parameter (description = "Kraftwerk endpoint" ) @ RequestParam (value = "serviceTocall" , defaultValue = Constants .KRAFTWERK_MAIN_ENDPOINT ) ServiceToCall serviceToCall ,
151- @ Parameter (description = "Frequency in Spring cron format (6 inputs, go to https://crontab.cronhub.io/ for generator) \n Example : 0 0 6 * * *" ) @ RequestParam ("frequency" ) String frequency ,
152- @ Parameter (description = "Schedule effective date and time" , example = "2024-01-01T12:00:00" ) @ RequestParam ("scheduleBeginDate" ) LocalDateTime scheduleBeginDate ,
153- @ Parameter (description = "Schedule end date and time" , example = "2024-01-01T12:00:00" ) @ RequestParam ("scheduleEndDate" ) LocalDateTime scheduleEndDate ,
154- @ Parameter (description = "Encrypt after process ? Ignore next parameters if false" ) @ RequestParam (value =
155- "useEncryption" ,
156- defaultValue = "false" ) boolean useEncryption ,
157- @ Parameter (description = "(Encryption) vault path" ) @ RequestParam (value = "encryptionVaultPath" , defaultValue = "" ) String encryptionVaultPath ,
158- @ Parameter (description = "(Encryption) output folder" ) @ RequestParam (value = "encryptionOutputFolder" ,
159- defaultValue = "" ) String encryptionOutputFolder ,
160- @ Parameter (description = "(Encryption) Use signature system" ) @ RequestParam (value = "useSignature" , defaultValue = "false" ) boolean useSignature
161- ) {
162- try {
163- //Check frequency
164- if (!CronExpression .isValidExpression (frequency )) {
165- log .warn ("Returned error for wrong frequency : {}" , frequency );
166- throw new GenesisException (400 , "Wrong frequency syntax" );
167- }
168-
169- TrustParameters trustParameters = null ;
170- if (useEncryption ) {
171- trustParameters = new TrustParameters (
172- fileUtils .getKraftwerkOutFolder (partitionId ),
173- encryptionOutputFolder ,
174- encryptionVaultPath ,
175- useSignature
176- );
177- }
178- dataProcessingContextApiPort .saveKraftwerkExecutionSchedule (
179- partitionId ,
180- serviceToCall == null ? ServiceToCall .MAIN : serviceToCall ,
181- frequency ,
182- scheduleBeginDate , scheduleEndDate , trustParameters
183- );
184- }catch (GenesisException e ){
185- return new ResponseEntity <>(e .getMessage (), HttpStatusCode .valueOf (e .getStatus ()));
186- }
187- return ResponseEntity .ok ().build ();
188- }
189-
190- // Should be refactored to make it restfull
191- @ Operation (summary = "Schedule a Kraftwerk execution using the collection instrument" )
192- @ PutMapping (path = "/contexts/schedules" )
193- @ PreAuthorize ("hasRole('USER_KRAFTWERK')" )
194- public ResponseEntity <Object > saveScheduleWithCollectionInstrumentId (
195- @ Parameter (description = "Collection instrument to call Kraftwerk on" ) @ RequestParam ("collectionInstrumentId" ) String collectionInstrumentId ,
196- @ Parameter (description = "Kraftwerk endpoint" ) @ RequestParam (value = "serviceTocall" , defaultValue = Constants .KRAFTWERK_MAIN_ENDPOINT ) ServiceToCall serviceToCall ,
197- @ Parameter (description = "Frequency in Spring cron format (6 inputs, go to https://crontab.cronhub.io/ for generator) \n Example : 0 0 6 * * *" ) @ RequestParam ("frequency" ) String frequency ,
198- @ Parameter (description = "Schedule effective date and time" , example = "2024-01-01T12:00:00" ) @ RequestParam ("scheduleBeginDate" ) LocalDateTime scheduleBeginDate ,
199- @ Parameter (description = "Schedule end date and time" , example = "2024-01-01T12:00:00" ) @ RequestParam ("scheduleEndDate" ) LocalDateTime scheduleEndDate ,
200- @ Parameter (description = "Encrypt after process ? Ignore next parameters if false" ) @ RequestParam (value =
201- "useEncryption" ,
202- defaultValue = "false" ) boolean useEncryption ,
203- @ Parameter (description = "(Encryption) vault path" ) @ RequestParam (value = "encryptionVaultPath" , defaultValue = "" ) String encryptionVaultPath ,
204- @ Parameter (description = "(Encryption) output folder" ) @ RequestParam (value = "encryptionOutputFolder" ,
205- defaultValue = "" ) String encryptionOutputFolder ,
206- @ Parameter (description = "(Encryption) Use signature system" ) @ RequestParam (value = "useSignature" , defaultValue = "false" ) boolean useSignature
207- ) {
208- try {
209- //Check frequency
210- if (!CronExpression .isValidExpression (frequency )) {
211- log .warn ("Returned error for wrong frequency : {}" , frequency );
212- throw new GenesisException (400 , "Wrong frequency syntax" );
213- }
214-
215- TrustParameters trustParameters = null ;
216- if (useEncryption ) {
217- trustParameters = new TrustParameters (
218- fileUtils .getKraftwerkOutFolder (collectionInstrumentId ),
219- encryptionOutputFolder ,
220- encryptionVaultPath ,
221- useSignature
222- );
223- }
224- dataProcessingContextApiPort .saveKraftwerkExecutionScheduleByCollectionInstrumentId (
225- collectionInstrumentId ,
226- serviceToCall == null ? ServiceToCall .MAIN : serviceToCall ,
227- frequency ,
228- scheduleBeginDate , scheduleEndDate , trustParameters
229- );
230- }catch (GenesisException e ){
231- return new ResponseEntity <>(e .getMessage (), HttpStatusCode .valueOf (e .getStatus ()));
232- }
233- return ResponseEntity .ok ().build ();
234- }
235-
236108 @ Operation (summary = "Update a Kraftwerk execution schedule V2" )
237109 @ PutMapping (path = "/contexts/{collectionInstrumentId}/schedules/v2/{scheduleUuid}" )
238110 @ PreAuthorize ("hasRole('USER_KRAFTWERK')" )
@@ -278,32 +150,6 @@ public ResponseEntity<Object> updateScheduleV2(
278150 return ResponseEntity .ok ().build ();
279151 }
280152
281- @ Deprecated (forRemoval = true )
282- @ Operation (summary = "Fetch all schedules" )
283- @ GetMapping (path = "/context/schedules" )
284- @ PreAuthorize ("hasAnyRole('SCHEDULER','READER')" )
285- public ResponseEntity <Object > getAllSchedules () {
286- log .debug ("Got GET all schedules request" );
287-
288- List <ScheduleDto > surveyScheduleDocumentModels = dataProcessingContextApiPort .getAllSchedules ();
289-
290- log .info ("Returning {} schedule documents..." , surveyScheduleDocumentModels .size ());
291- return ResponseEntity .ok (surveyScheduleDocumentModels );
292- }
293-
294- //It is just a change of path in the url
295- @ Operation (summary = "Fetch all schedules" )
296- @ GetMapping (path = "/contexts/schedules" )
297- @ PreAuthorize ("hasAnyRole('SCHEDULER','READER')" )
298- public ResponseEntity <Object > getAllSchedulesV2 () {
299- log .debug ("Got GET all schedules request" );
300-
301- List <ScheduleDto > surveyScheduleDocumentModels = dataProcessingContextApiPort .getAllSchedules ();
302-
303- log .info ("Returning {} schedule documents..." , surveyScheduleDocumentModels .size ());
304- return ResponseEntity .ok (surveyScheduleDocumentModels );
305- }
306-
307153 @ Operation (summary = "Fetch all schedules V2" )
308154 @ GetMapping (path = "/contexts/schedules/v2" )
309155 @ PreAuthorize ("hasAnyRole('SCHEDULER','READER')" )
@@ -328,55 +174,6 @@ public ResponseEntity<Object> getSchedulesV2ByCollectionInstrumentId(
328174 return ResponseEntity .ok (schedules );
329175 }
330176
331- @ Deprecated (forRemoval = true )
332- @ Operation (summary = "Set last execution date of a partition with new date or nothing" )
333- @ PostMapping (path = "/context/schedules/lastExecutionDate" )
334- @ PreAuthorize ("hasRole('SCHEDULER')" )
335- public ResponseEntity <Object > setSurveyLastExecution (
336- @ Parameter (description = "Survey name to call Kraftwerk on" ) @ RequestBody String partitionId ,
337- @ Parameter (description = "Date to save as last execution date" , example = "2024-01-01T12:00:00" ) @ RequestParam ("newDate" ) LocalDateTime newDate
338- ) {
339- try {
340- dataProcessingContextApiPort .updateLastExecutionDate (partitionId , newDate );
341- log .info ("{} last execution updated at {} !" , partitionId , newDate );
342- }catch (GenesisException e ){
343- return new ResponseEntity <>(e .getMessage (), HttpStatusCode .valueOf (e .getStatus ()));
344- }
345- return ResponseEntity .ok ().build ();
346- }
347-
348- @ Operation (summary = "Update the date of the last extraction of data corresponding to a collection instrument" )
349- @ PutMapping (path = "/contexts/{collectionInstrumentId}/lastExecutionDate" )
350- @ PreAuthorize ("hasRole('SCHEDULER')" )
351- public ResponseEntity <Object > setSurveyLastExecutionByCollectionInstrumentId (
352- @ PathVariable ("collectionInstrumentId" ) @ RequestBody String collectionInstrumentId ,
353- @ Parameter (description = "Date to save as last execution date" , example = "2024-01-01T12:00:00" ) @ RequestParam ("newDate" ) LocalDateTime newDate
354- ) {
355- try {
356- dataProcessingContextApiPort .updateLastExecutionDateByCollectionInstrumentId (collectionInstrumentId , newDate );
357- log .info ("{} last execution updated at {} !" , collectionInstrumentId , newDate );
358- }catch (GenesisException e ){
359- return new ResponseEntity <>(e .getMessage (), HttpStatusCode .valueOf (e .getStatus ()));
360- }
361- return ResponseEntity .ok ().build ();
362- }
363-
364- @ Deprecated (forRemoval = true )
365- @ Operation (summary = "Delete the Kraftwerk execution schedules of a partition" )
366- @ DeleteMapping (path = "/context/schedules" )
367- @ PreAuthorize ("hasRole('USER_KRAFTWERK')" )
368- public ResponseEntity <Object > deleteSchedules (
369- @ Parameter (description = "Survey name of the schedule(s) to delete" ) @ RequestParam ("partitionId" ) String partitionId
370- ){
371- try {
372- dataProcessingContextApiPort .deleteSchedules (partitionId );
373- }catch (GenesisException e ){
374- return new ResponseEntity <>(e .getMessage (), HttpStatusCode .valueOf (e .getStatus ()));
375- }
376- log .info ("Schedule deleted for survey {}" , partitionId );
377- return ResponseEntity .ok ().build ();
378- }
379-
380177 @ Operation (summary = "Delete the Kraftwerk execution schedules of a collection instrument id" )
381178 @ DeleteMapping (path = "/context/{collectionInstrumentId}/schedules" )
382179 @ PreAuthorize ("hasRole('USER_KRAFTWERK')" )
0 commit comments