use of org.opentosca.toscana.core.transformation.artifacts.TargetArtifact in project TOSCAna by StuPro-TOSCAna.
the class TransformationController method getTransformationArtifact.
/**
* Returns the URL to download the target Artifact (Wrapped in json)<p>
* <p>
* Accessed with http call <code>GET /csars/{csar}/transformations/{platform}/artifacts</code>
* <table summary="">
* <tr>
* <td>HTTP-Code</td>
* <td>Mime-Type</td>
* <td>Description (Returned if)</td>
* </tr>
* <tr>
* <td>200</td>
* <td>application/hal+json</td>
* <td>Returns a Json object containing the download url for the artifact</td>
* </tr>
* <tr>
* <td>400</td>
* <td>application/json</td>
* <td>Returned if the transformation is not in a valid state (has to be in DONE or ERROR) to set inputs</td>
* </tr>
* <tr>
* <td>404</td>
* <td>application/json</td>
* <td>Returns a error message if the csar is not found or if the csar does not have a transformation for the given
* name (see returned error message for details)</td>
* </tr>
* </table>
*/
@RequestMapping(path = "/{platform}/artifact", method = RequestMethod.GET, produces = "application/octet-stream")
@ApiOperation(value = "Download the target artifact archive", tags = { "transformations" }, notes = "Once the transformation is done (in the state DONE) or it has encountered a error (state ERROR). " + "It is possible to download a archive (ZIP format) of all the files generated while the transformation was " + "running.")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully"), @ApiResponse(code = 400, message = "There is nothing to download yet because the execution of the transformation has not yet started " + "or is not finished (With or without errors)", response = RestErrorResponse.class), @ApiResponse(code = 404, message = "There is no CSAR for the given identifier or the CSAR does not have " + "a Transformation for the specified platform.", response = RestErrorResponse.class) })
public ResponseEntity<Void> getTransformationArtifact(@ApiParam(value = "The unique identifier for the CSAR", required = true, example = "test") @PathVariable(name = "csarId") String csarName, @ApiParam(value = "The identifier for the platform", required = true, example = "kubernetes") @PathVariable(name = "platform") String platform, HttpServletResponse response) throws IOException {
Csar csar = csarService.getCsar(csarName).orElseThrow(CsarNotFoundException::new);
Transformation transformation = csar.getTransformation(platform).orElseThrow(TransformationNotFoundException::new);
TargetArtifact artifact = transformation.getTargetArtifact().orElseThrow(() -> new IllegalTransformationStateException(format("Artifact for csar '{}' and platform '{}' not found", csarName, platform)));
response.setHeader("Content-Disposition", "attachment; filename=\"" + artifact.name + "\"");
response.setHeader("Content-Type", "application/octet-stream");
response.setHeader("Content-Length", artifact.getFileSize() + "");
InputStream in = artifact.readAccess();
OutputStream out = response.getOutputStream();
IOUtils.copy(in, out);
in.close();
out.close();
return ResponseEntity.ok().build();
}
Aggregations