Search in sources :

Example 1 with TransformationManager

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();
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) TransformationManager(org.eclipse.winery.edmm.TransformationManager) File(java.io.File) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

EntityGraph (io.github.edmm.core.parser.EntityGraph)1 File (java.io.File)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 TransformationManager (org.eclipse.winery.edmm.TransformationManager)1