Skip to content

Commit

Permalink
feat(api): multi-model option in xforms and fo standard endpoints (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave authored Jan 15, 2024
1 parent 3e68d0d commit 2ec1dec
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tasks.withType(JavaCompile).configureEach {

allprojects {
group = 'fr.insee.eno'
version = '3.15.3'
version = '3.15.4'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,17 +77,21 @@ public Mono<ResponseEntity<String>> 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<Void> generateXforms(
@RequestPart(value="in") Mono<FilePart> in,
@RequestPart(value="metadata", required = false) Mono<FilePart> metadata,
@RequestPart(value="specificTreatment", required=false) Mono<FilePart> 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))
Expand All @@ -104,7 +109,8 @@ public Mono<Void> 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<Void> generateFO(
Expand All @@ -114,7 +120,10 @@ public Mono<Void> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,11 @@ public ResponseEntity<Object> exception(MetadataFileException exception) {
return new ResponseEntity<>("Metadata file error: "+exception.getMessage(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(value = MultiModelException.class)
public ResponseEntity<Object> exception(MultiModelException exception) {
return new ResponseEntity<>("Multi-model option error: "+exception.getMessage(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(value = EnoGenerationException.class)
public ResponseEntity<Object> exception(EnoGenerationException exception) {
return new ResponseEntity<>("EnoGeneration error : "+exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package fr.insee.eno.ws.exception;

public class MultiModelException extends Exception {

public MultiModelException(String message) {
super(message);
}

}

0 comments on commit 2ec1dec

Please sign in to comment.