use of org.eclipse.winery.repository.export.ToscaExportUtil in project winery by eclipse.
the class RestUtils method getDefinitionsOfSelectedResource.
/**
* Returns the plain XML for the selected resource
*/
public static Response getDefinitionsOfSelectedResource(final AbstractComponentInstanceResource resource, final URI uri) {
final ToscaExportUtil exporter = new ToscaExportUtil();
StreamingOutput so = output -> {
Map<String, Object> conf = new HashMap<>();
conf.put(CsarExportConfiguration.REPOSITORY_URI.toString(), uri);
try {
exporter.writeTOSCA(RepositoryFactory.getRepository(), resource.getId(), conf, output);
} catch (Exception e) {
throw new WebApplicationException(e);
}
output.close();
};
/*
* this code is for offering a download action // Browser offers save as
* // .tosca is more or less needed for debugging, only a CSAR makes
* sense. // Therefore, we want to have the xml opened in the browser.
* StringBuilder sb = new StringBuilder();
* sb.append("attachment;filename=\"");
* sb.append(resource.getXmlId().getEncoded()); sb.append(" - ");
* sb.append(resource.getNamespace().getEncoded()); sb.append(".xml");
* sb.append("\""); return Response.ok().header("Content-Disposition",
* sb
* .toString()).type(MediaType.APPLICATION_XML_TYPE).entity(so).buildProvenanceSmartContract();
*/
return Response.ok().type(MediaType.APPLICATION_XML).entity(so).build();
}
use of org.eclipse.winery.repository.export.ToscaExportUtil in project winery by eclipse.
the class BackendUtils method getDefinitionsHavingCorrectImports.
public static Definitions getDefinitionsHavingCorrectImports(IRepository repository, DefinitionsChildId id) throws Exception {
// idea: get the XML, parse it, return it
// the conversion to JSON is made by Jersey automatically
// TODO: future work: force TOSCAExportUtil to return TDefinitions directly
// Have to use TOScAExportUtil to have the imports correctly set
ToscaExportUtil exporter = new ToscaExportUtil();
// we include everything related
Map<String, Object> conf = new HashMap<>();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
exporter.exportTOSCA(repository, id, bos, conf);
String xmlRepresentation = bos.toString(StandardCharsets.UTF_8.toString());
Unmarshaller u = JAXBSupport.createUnmarshaller();
return ((Definitions) u.unmarshal(new StringReader(xmlRepresentation)));
}
Aggregations