Skip to content

Commit

Permalink
Add endpoint genesis lunatic-only
Browse files Browse the repository at this point in the history
  • Loading branch information
alicela committed Oct 29, 2024
1 parent c56af14 commit 7798ac0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class MainProcessingGenesis {
private final FileUtilsInterface fileUtilsInterface;
private Statement database;

private final boolean withDDI;

private KraftwerkExecutionContext kraftwerkExecutionContext;

/* SPECIFIC VARIABLES */
Expand All @@ -59,23 +61,30 @@ public class MainProcessingGenesis {

private final GenesisClient client;

public MainProcessingGenesis(ConfigProperties config, FileUtilsInterface fileUtilsInterface, boolean withDDI) {
this.client = new GenesisClient(new RestTemplateBuilder(), config);
this.fileUtilsInterface = fileUtilsInterface;
this.withDDI = withDDI;
}

public MainProcessingGenesis(ConfigProperties config, FileUtilsInterface fileUtilsInterface) {
this.client = new GenesisClient(new RestTemplateBuilder(), config);
this.fileUtilsInterface = fileUtilsInterface;
this.withDDI = true;
}

public void init(String idCampaign) throws KraftwerkException {
kraftwerkExecutionContext = new KraftwerkExecutionContext();
log.info("Kraftwerk main service started for campaign: {}", idCampaign);
log.info("Kraftwerk main service started for campaign: {} {}", idCampaign, withDDI ? "withDDI": "without DDI");
this.controlInputSequenceGenesis = new ControlInputSequenceGenesis(client.getConfigProperties().getDefaultDirectory(), fileUtilsInterface);
inDirectory = controlInputSequenceGenesis.getInDirectory(idCampaign);
//First we check the modes present in database for the given questionnaire
//We build userInputs for the given questionnaire
userInputs = new UserInputsGenesis(controlInputSequenceGenesis.isHasConfigFile(), inDirectory, client.getModes(idCampaign), fileUtilsInterface);
if (!userInputs.getModes().isEmpty()) {
try {
metadataModels = MetadataUtilsGenesis.getMetadata(userInputs.getModeInputsMap(), fileUtilsInterface);
} catch (MetadataParserException e) {
metadataModels = withDDI ? MetadataUtilsGenesis.getMetadata(userInputs.getModeInputsMap(), fileUtilsInterface): MetadataUtilsGenesis.getMetadataFromLunatic(userInputs.getModeInputsMap(), fileUtilsInterface);
} catch (MetadataParserException e) {
throw new KraftwerkException(500, e.getMessage());
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.insee.kraftwerk.api.services;


import fr.insee.bpm.exceptions.MetadataParserException;
import fr.insee.kraftwerk.api.configuration.ConfigProperties;
import fr.insee.kraftwerk.api.configuration.MinioConfig;
import fr.insee.kraftwerk.api.process.MainProcessing;
Expand All @@ -15,6 +14,7 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -60,12 +60,7 @@ public ResponseEntity<String> mainService(
) {
boolean fileByFile = false;
boolean withDDI = true;
FileUtilsInterface fileUtilsInterface;
if(Boolean.TRUE.equals(useMinio)){
fileUtilsInterface = new MinioImpl(minioClient, minioConfig.getBucketName());
}else{
fileUtilsInterface = new FileSystemImpl(defaultDirectory);
}
FileUtilsInterface fileUtilsInterface = getFileUtilsInterface();

MainProcessing mp = new MainProcessing(inDirectoryParam, fileByFile,withAllReportingData,withDDI, defaultDirectory, limitSize, fileUtilsInterface);
try {
Expand All @@ -89,12 +84,7 @@ public ResponseEntity<String> mainFileByFile(
boolean fileByFile = true;
boolean withAllReportingData = false;
boolean withDDI = true;
FileUtilsInterface fileUtilsInterface;
if(Boolean.TRUE.equals(useMinio)){
fileUtilsInterface = new MinioImpl(minioClient, minioConfig.getBucketName());
}else{
fileUtilsInterface = new FileSystemImpl(defaultDirectory);
}
FileUtilsInterface fileUtilsInterface = getFileUtilsInterface();

MainProcessing mp = new MainProcessing(inDirectoryParam, fileByFile,withAllReportingData,withDDI, defaultDirectory, limitSize, fileUtilsInterface);
try {
Expand All @@ -117,12 +107,7 @@ public ResponseEntity<String> mainLunaticOnly(
boolean withDDI = false;
boolean fileByFile = false;
boolean withAllReportingData = false;
FileUtilsInterface fileUtilsInterface;
if(Boolean.TRUE.equals(useMinio)){
fileUtilsInterface = new MinioImpl(minioClient, minioConfig.getBucketName());
}else{
fileUtilsInterface = new FileSystemImpl(defaultDirectory);
}
FileUtilsInterface fileUtilsInterface = getFileUtilsInterface();

MainProcessing mp = new MainProcessing(inDirectoryParam, fileByFile,withAllReportingData,withDDI, defaultDirectory, limitSize, fileUtilsInterface);
try {
Expand All @@ -140,12 +125,7 @@ public ResponseEntity<String> mainLunaticOnly(
@Operation(operationId = "mainGenesis", summary = "${summary.mainGenesis}", description = "${description.mainGenesis}")
public ResponseEntity<String> mainGenesis(
@Parameter(description = "${param.idCampaign}", required = true, example = INDIRECTORY_EXAMPLE) @RequestBody String idCampaign) {
FileUtilsInterface fileUtilsInterface;
if(Boolean.TRUE.equals(useMinio)){
fileUtilsInterface = new MinioImpl(minioClient, minioConfig.getBucketName());
}else{
fileUtilsInterface = new FileSystemImpl(defaultDirectory);
}
FileUtilsInterface fileUtilsInterface = getFileUtilsInterface();

MainProcessingGenesis mpGenesis = new MainProcessingGenesis(configProperties, fileUtilsInterface);

Expand All @@ -160,4 +140,33 @@ public ResponseEntity<String> mainGenesis(
}


@PutMapping(value = "/main/genesis/lunatic-only")
@Operation(operationId = "mainGenesisLunaticOnly", summary = "${summary.mainGenesis}", description = "${description.mainGenesis}")
public ResponseEntity<String> mainGenesisLunaticOnly(
@Parameter(description = "${param.idCampaign}", required = true, example = INDIRECTORY_EXAMPLE) @RequestBody String idCampaign) {
boolean withDDI = false;
FileUtilsInterface fileUtilsInterface = getFileUtilsInterface();

MainProcessingGenesis mpGenesis = new MainProcessingGenesis(configProperties, fileUtilsInterface, withDDI);

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);
}

private @NotNull FileUtilsInterface getFileUtilsInterface() {
FileUtilsInterface fileUtilsInterface;
if(Boolean.TRUE.equals(useMinio)){
fileUtilsInterface = new MinioImpl(minioClient, minioConfig.getBucketName());
}else{
fileUtilsInterface = new FileSystemImpl(defaultDirectory);
}
return fileUtilsInterface;
}

}

0 comments on commit 7798ac0

Please sign in to comment.