Skip to content

Commit

Permalink
fix: wrong zip name in xforms and fo outputs (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiVerriez authored Dec 11, 2024
1 parent f9e6e4d commit 1f1c9db
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>fr.insee</groupId>
<artifactId>eno-ws</artifactId>
<packaging>jar</packaging>
<version>2.6.0</version>
<version>2.6.1</version>
<name>Eno-Web-Service</name>

<!-- Spring Boot parent -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public ResponseEntity<StreamingResponseBody> generateXformsCustomParams(
}
log.info("END of Eno Xforms generation processing");

return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromEnoParameters(enoParameters, true));
return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromCampagneName(enoParameters));
}

@Operation(
Expand Down Expand Up @@ -196,7 +196,7 @@ public ResponseEntity<StreamingResponseBody> generateFOCustomParams(
enoOutput = multiModelService.generateQuestionnaire(enoInput, enoParameters, metadataIS, specificTreatmentIS, null);
}
log.info("END of Eno FO generation processing");
return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromEnoParameters(enoParameters, true));
return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromCampagneName(enoParameters));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ResponseEntity<StreamingResponseBody> generateDDIQuestionnaire(
StreamingResponseBody stream = out -> out.write(enoOutput.toByteArray());
enoOutput.close();

return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromEnoParameters(enoParameters, false));
return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromParameters(enoParameters, false));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public ResponseEntity<StreamingResponseBody> generateXforms(
enoOutput = generateQuestionnaireService.generateMultiModelQuestionnaires(
context, OutFormat.XFORMS, null, in, metadata, specificTreatment);

return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromEnoParameters(OutFormat.XFORMS, multiModel));
return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromParameters(OutFormat.XFORMS, multiModel));
}

@Operation(
Expand Down Expand Up @@ -206,7 +206,7 @@ public ResponseEntity<StreamingResponseBody> generateFO(


log.info("END of Eno FO questionnaire processing");
return ResponseUtils.generateResponseFromOutputStream(enoOutput,parameterService.getFileNameFromEnoParameters(enoParameters, multiModel));
return ResponseUtils.generateResponseFromOutputStream(enoOutput,parameterService.getFileNameFromParameters(enoParameters, multiModel));
}

@Operation(
Expand All @@ -227,7 +227,7 @@ public ResponseEntity<StreamingResponseBody> generateFODT(
ByteArrayOutputStream enoOutput = generateQuestionnaireService.generateQuestionnaireFile(
context, OutFormat.FODT, null, in, null, null);

return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromEnoParameters(OutFormat.FODT, false));
return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromParameters(OutFormat.FODT, false));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ResponseEntity<StreamingResponseBody> generate(
log.info("END of Eno 'in to out' processing");
}

return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromEnoParameters(enoParameters, multiModel));
return ResponseUtils.generateResponseFromOutputStream(enoOutput, parameterService.getFileNameFromParameters(enoParameters, multiModel));
}

}
36 changes: 23 additions & 13 deletions src/main/java/fr/insee/eno/ws/service/ParameterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,30 @@ public InputStream getDefaultParametersIS() {
return xmlParameters;
}

public String getFileNameFromEnoParameters(ENOParameters enoParameters, boolean multiModel){
return getFileNameFromEnoParameters(enoParameters.getPipeline().getOutFormat(), multiModel);
public String getFileNameFromCampagneName(ENOParameters enoParameters) {
if (enoParameters == null || enoParameters.getParameters() == null || enoParameters.getParameters().getCampagne() == null ||
enoParameters.getParameters().getCampagne().isEmpty()) {
throw new EnoParametersException("The 'campagne' tag is null or empty.");
}
return enoParameters.getParameters().getCampagne() + ".zip";
}

public String getFileNameFromEnoParameters(OutFormat outFormat, boolean multiModel){
if(multiModel) return "questionnaires.zip";
return switch (outFormat){
case FO -> "questionnaire.fo";
case FODT -> "questionnaire.fodt";
case DDI -> "ddi-questionnaire.xml";
case LUNATIC_XML -> "lunatic-questionnaire.xml";
case XFORMS -> "questionnaire.xhtml";
};
public String getFileNameFromParameters(ENOParameters enoParameters, boolean multiModel){
return getFileNameFromParameters(enoParameters.getPipeline().getOutFormat(), multiModel);
}


}
public String getFileNameFromParameters (OutFormat outFormat,boolean multiModel){
if (multiModel) return "questionnaires.zip";
return switch (outFormat) {
case FO -> "questionnaire.fo";
case FODT -> "questionnaire.fodt";
case DDI -> "ddi-questionnaire.xml";
case LUNATIC_XML -> "lunatic-questionnaire.xml";
case XFORMS -> "questionnaire.xhtml";
};
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.zip.ZipOutputStream;

@Service
@Slf4j
Expand Down Expand Up @@ -51,9 +52,9 @@ public ByteArrayOutputStream generateQuestionnaireFile(Context context, OutForma
}

public ByteArrayOutputStream generateMultiModelQuestionnaires(Context context, OutFormat outFormat, Mode mode,
MultipartFile in,
MultipartFile metadata,
MultipartFile specificTreatment) throws Exception {
MultipartFile in,
MultipartFile metadata,
MultipartFile specificTreatment) throws Exception {

ENOParameters enoParameters = parameterService.getDefaultCustomParameters(context, outFormat, mode);
ByteArrayOutputStream enoOutput;
Expand Down

0 comments on commit 1f1c9db

Please sign in to comment.