From a30a3c83594aa8d5e9ebe40a48ea47a8bfa6736a Mon Sep 17 00:00:00 2001 From: QDIBYS Date: Tue, 12 Nov 2024 10:56:01 +0100 Subject: [PATCH] Update MainService.java --- .../kraftwerk/api/services/MainService.java | 76 +++++++------------ 1 file changed, 26 insertions(+), 50 deletions(-) diff --git a/kraftwerk-api/src/main/java/fr/insee/kraftwerk/api/services/MainService.java b/kraftwerk-api/src/main/java/fr/insee/kraftwerk/api/services/MainService.java index 2904037a..4859cab4 100644 --- a/kraftwerk-api/src/main/java/fr/insee/kraftwerk/api/services/MainService.java +++ b/kraftwerk-api/src/main/java/fr/insee/kraftwerk/api/services/MainService.java @@ -60,19 +60,7 @@ public ResponseEntity mainService( ) { boolean fileByFile = false; boolean withDDI = true; - FileUtilsInterface fileUtilsInterface = getFileUtilsInterface(); - - MainProcessing mp = new MainProcessing(inDirectoryParam, fileByFile,withAllReportingData,withDDI, defaultDirectory, limitSize, fileUtilsInterface); - try { - mp.runMain(); - } catch (KraftwerkException e) { - return ResponseEntity.status(e.getStatus()).body(e.getMessage()); - } - - /* Step 4.3- 4.4 : Archive */ - if (Boolean.TRUE.equals(archiveAtEnd)) archive(inDirectoryParam,fileUtilsInterface); - - return ResponseEntity.ok(inDirectoryParam); + return runWithoutGenesis(inDirectoryParam, archiveAtEnd, fileByFile, withAllReportingData, withDDI); } @PutMapping(value = "/main/file-by-file") @@ -84,18 +72,7 @@ public ResponseEntity mainFileByFile( boolean fileByFile = true; boolean withAllReportingData = false; boolean withDDI = true; - FileUtilsInterface fileUtilsInterface = getFileUtilsInterface(); - - MainProcessing mp = new MainProcessing(inDirectoryParam, fileByFile,withAllReportingData,withDDI, defaultDirectory, limitSize, fileUtilsInterface); - try { - mp.runMain(); - } catch (KraftwerkException e) { - return ResponseEntity.status(e.getStatus()).body(e.getMessage()); - } - /* Step 4.3- 4.4 : Archive */ - if (Boolean.TRUE.equals(archiveAtEnd)) archive(inDirectoryParam, fileUtilsInterface); - - return ResponseEntity.ok(inDirectoryParam); + return runWithoutGenesis(inDirectoryParam, archiveAtEnd, fileByFile, withAllReportingData, withDDI); } @PutMapping(value = "/main/lunatic-only") @@ -107,36 +84,15 @@ public ResponseEntity mainLunaticOnly( boolean withDDI = false; boolean fileByFile = false; boolean withAllReportingData = false; - FileUtilsInterface fileUtilsInterface = getFileUtilsInterface(); - - MainProcessing mp = new MainProcessing(inDirectoryParam, fileByFile,withAllReportingData,withDDI, defaultDirectory, limitSize, fileUtilsInterface); - try { - mp.runMain(); - } catch (KraftwerkException e) { - return ResponseEntity.status(e.getStatus()).body(e.getMessage()); - } - /* Step 4.3- 4.4 : Archive */ - if (Boolean.TRUE.equals(archiveAtEnd)) archive(inDirectoryParam, fileUtilsInterface); - - return ResponseEntity.ok(inDirectoryParam); + return runWithoutGenesis(inDirectoryParam, archiveAtEnd, fileByFile, withAllReportingData, withDDI); } @PutMapping(value = "/main/genesis") @Operation(operationId = "mainGenesis", summary = "${summary.mainGenesis}", description = "${description.mainGenesis}") public ResponseEntity mainGenesis( @Parameter(description = "${param.idCampaign}", required = true, example = INDIRECTORY_EXAMPLE) @RequestBody String idCampaign) { - FileUtilsInterface fileUtilsInterface = getFileUtilsInterface(); - - MainProcessingGenesis mpGenesis = new MainProcessingGenesis(configProperties, fileUtilsInterface); - - try { - mpGenesis.runMain(idCampaign); - } catch (KraftwerkException e) { - return ResponseEntity.status(e.getStatus()).body(e.getMessage()); - } catch (IOException e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()); - } - return ResponseEntity.ok(idCampaign); + boolean withDDI = true; + return runWithGenesis(idCampaign, withDDI); } @@ -145,6 +101,27 @@ public ResponseEntity mainGenesis( public ResponseEntity mainGenesisLunaticOnly( @Parameter(description = "${param.idCampaign}", required = true, example = INDIRECTORY_EXAMPLE) @RequestBody String idCampaign) { boolean withDDI = false; + return runWithGenesis(idCampaign, withDDI); + } + + @NotNull + private ResponseEntity runWithoutGenesis(String inDirectoryParam, boolean archiveAtEnd, boolean fileByFile, boolean withAllReportingData, boolean withDDI) { + FileUtilsInterface fileUtilsInterface = getFileUtilsInterface(); + + MainProcessing mp = new MainProcessing(inDirectoryParam, fileByFile, withAllReportingData, withDDI, defaultDirectory, limitSize, fileUtilsInterface); + try { + mp.runMain(); + } catch (KraftwerkException e) { + return ResponseEntity.status(e.getStatus()).body(e.getMessage()); + } + /* Step 4.3- 4.4 : Archive */ + if (Boolean.TRUE.equals(archiveAtEnd)) archive(inDirectoryParam, fileUtilsInterface); + + return ResponseEntity.ok(inDirectoryParam); + } + + @NotNull + private ResponseEntity runWithGenesis(String idCampaign, boolean withDDI) { FileUtilsInterface fileUtilsInterface = getFileUtilsInterface(); MainProcessingGenesis mpGenesis = new MainProcessingGenesis(configProperties, fileUtilsInterface, withDDI); @@ -168,5 +145,4 @@ public ResponseEntity mainGenesisLunaticOnly( } return fileUtilsInterface; } - } \ No newline at end of file