diff --git a/build.gradle b/build.gradle index e4bf242e1..bbf86de3d 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ tasks.withType(JavaCompile).configureEach { allprojects { group = 'fr.insee.eno' - version = '3.15.3' + version = '3.15.4' } subprojects { diff --git a/eno-ws/src/main/java/fr/insee/eno/ws/controller/GenerationStandardController.java b/eno-ws/src/main/java/fr/insee/eno/ws/controller/GenerationStandardController.java index 0b813022e..f8d6d3d3e 100644 --- a/eno-ws/src/main/java/fr/insee/eno/ws/controller/GenerationStandardController.java +++ b/eno-ws/src/main/java/fr/insee/eno/ws/controller/GenerationStandardController.java @@ -10,6 +10,7 @@ import fr.insee.eno.treatments.LunaticPostProcessing; import fr.insee.eno.ws.PassThrough; import fr.insee.eno.ws.controller.utils.ReactiveControllerUtils; +import fr.insee.eno.ws.exception.MultiModelException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; @@ -76,7 +77,8 @@ public Mono> generateLunatic( "Generation of a Xforms questionnaire (for business web surveys) from the given DDI with " + "standard parameters, in function of context. " + "An metadata `xml` file can be added and is required is the context is 'BUSINESS'. " + - "An optional specific treatment `xsl` file can be added.") + "An optional specific treatment `xsl` file can be added. " + + "If the multi-model option is set to true, the output questionnaire(s) are put in a zip file.") @PostMapping(value = "{context}/xforms", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public Mono generateXforms( @@ -84,9 +86,12 @@ public Mono generateXforms( @RequestPart(value="metadata", required = false) Mono metadata, @RequestPart(value="specificTreatment", required=false) Mono specificTreatment, @PathVariable Context context, + @RequestParam(value="multi-model", required=false, defaultValue="false") boolean multiModel, ServerHttpRequest request, ServerHttpResponse response) { if (Context.HOUSEHOLD.equals(context)) return Mono.error(new ContextException("Xforms format is not compatible with 'HOUSEHOLD' context.")); + if (Context.BUSINESS.equals(context) && (! multiModel)) + return Mono.error(new MultiModelException("Multi-model option must be 'true' in 'BUSINESS' context.")); metadata.hasElement() .flatMap(hasElementValue -> { if (Context.BUSINESS.equals(context) && Boolean.FALSE.equals(hasElementValue)) @@ -104,7 +109,8 @@ public Mono generateXforms( "parameters, in function of context. Custom values can be passed for format of columns and " + "capture mode. " + "An metadata `xml` file can be added and is required is the context is 'BUSINESS'. " + - "An optional specific treatment `xsl` file can be added." ) + "An optional specific treatment `xsl` file can be added. " + + "If the multi-model option is set to true, the output questionnaire(s) are put in a zip file." ) @PostMapping(value = "{context}/fo", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public Mono generateFO( @@ -114,7 +120,10 @@ public Mono generateFO( @RequestParam(value="Format-column", required=false) Integer nbColumn, @RequestParam(value="Capture", required=false) CaptureEnum capture, @PathVariable Context context, + @RequestParam(value="multi-model", required=false, defaultValue="false") boolean multiModel, ServerHttpRequest request, ServerHttpResponse response) { + if (Context.BUSINESS.equals(context) && (! multiModel)) + return Mono.error(new MultiModelException("Multi-model option must be 'true' in 'BUSINESS' context.")); metadata.hasElement() .flatMap(hasElementValue -> { if (Context.BUSINESS.equals(context) && Boolean.FALSE.equals(hasElementValue)) diff --git a/eno-ws/src/main/java/fr/insee/eno/ws/controller/exception/EnoExceptionController.java b/eno-ws/src/main/java/fr/insee/eno/ws/controller/exception/EnoExceptionController.java index d3917b92d..65219c10d 100644 --- a/eno-ws/src/main/java/fr/insee/eno/ws/controller/exception/EnoExceptionController.java +++ b/eno-ws/src/main/java/fr/insee/eno/ws/controller/exception/EnoExceptionController.java @@ -8,6 +8,7 @@ import fr.insee.eno.legacy.exception.EnoLegacyParametersException; import fr.insee.eno.treatments.exceptions.SpecificTreatmentsDeserializationException; import fr.insee.eno.treatments.exceptions.SpecificTreatmentsValidationException; +import fr.insee.eno.ws.exception.MultiModelException; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -44,6 +45,11 @@ public ResponseEntity exception(MetadataFileException exception) { return new ResponseEntity<>("Metadata file error: "+exception.getMessage(), HttpStatus.BAD_REQUEST); } + @ExceptionHandler(value = MultiModelException.class) + public ResponseEntity exception(MultiModelException exception) { + return new ResponseEntity<>("Multi-model option error: "+exception.getMessage(), HttpStatus.BAD_REQUEST); + } + @ExceptionHandler(value = EnoGenerationException.class) public ResponseEntity exception(EnoGenerationException exception) { return new ResponseEntity<>("EnoGeneration error : "+exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); diff --git a/eno-ws/src/main/java/fr/insee/eno/ws/exception/MultiModelException.java b/eno-ws/src/main/java/fr/insee/eno/ws/exception/MultiModelException.java new file mode 100644 index 000000000..df6cdb5c3 --- /dev/null +++ b/eno-ws/src/main/java/fr/insee/eno/ws/exception/MultiModelException.java @@ -0,0 +1,9 @@ +package fr.insee.eno.ws.exception; + +public class MultiModelException extends Exception { + + public MultiModelException(String message) { + super(message); + } + +}