use of org.eclipse.winery.edmm.TransformationManager in project winery by eclipse.
the class EdmmResource method transform.
@GET
@Path("transform")
@Produces(MimeTypes.MIMETYPE_ZIP)
public Response transform(@QueryParam(value = "target") String target) {
EntityGraph graph = RestUtils.getEdmmEntityGraph(this.element, false);
GraphNormalizer.normalize(graph);
String wineryRepository = Environments.getInstance().getRepositoryConfig().getRepositoryRoot();
String filename;
byte[] response;
try {
// the transform command applies the transformation towards the specific target deployment files
// and return a zip of them
TransformationManager transformationManager = new TransformationManager();
File zipFile = transformationManager.transform(graph, target, wineryRepository);
filename = zipFile.getName();
response = FileUtils.readFileToByteArray(zipFile);
} catch (Exception e) {
// we send back a Server Error
String message = String.format("<html><body>" + "<div> %s </div>" + "<div> Probably something is missing in the service template XML or something went wrong on the server </div>" + "</body></html>", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).type(MediaType.TEXT_HTML).entity(message).build();
}
return Response.ok().header("Content-Disposition", "attachment; filename=\"" + filename + "\"").type(MimeTypes.MIMETYPE_ZIP).entity(response).build();
}
Aggregations