use of org.eclipse.winery.yaml.converter.Converter in project winery by eclipse.
the class YAMLParserResource method importYAML.
@POST
@ApiOperation(value = "Imports the given zipped YAML files")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public Response importYAML(@FormDataParam("file") InputStream uploadInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("overwrite") @ApiParam(value = "true/false both not used") Boolean overwrite, @Context UriInfo uriInfo) {
LOGGER.debug("File {}", fileDetail);
Converter converter = new Converter();
try {
converter.convertY2X(uploadInputStream);
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(StringEscapeUtils.escapeHtml(e.getMessage().trim())).type("text/plain").build();
}
return Response.noContent().build();
}
use of org.eclipse.winery.yaml.converter.Converter in project winery by eclipse.
the class Showcase method zipTypeTest.
@Test
public void zipTypeTest() throws Exception {
String name = "Showcase";
String path = this.path + File.separator + name + ".csar";
// Read DriverInjectionTest and import the csar into the repository
InputStream fis = new FileInputStream(path);
IRepository repository = RepositoryFactory.getRepository(Utils.getTmpDir(Paths.get("repository")));
CsarImporter csarImporter = new CsarImporter();
csarImporter.readCSAR(fis, true, true);
// Read the csar again and convert it to yaml the resulting yaml service templates
// are written to a temporary dir and converted to a input stream of a zip file
Converter converter = new Converter(repository);
fis = new FileInputStream(path);
InputStream zip = converter.convertX2Y(fis);
// Write the zip file to the output path and rename it
File zipFile = new File(outPath + File.separator + name + ".csar");
if (!zipFile.getParentFile().exists()) {
zipFile.getParentFile().mkdirs();
}
Files.copy(zip, zipFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
// clean temporary repository
Utils.deleteTmpDir(Paths.get("repository"));
Assert.assertTrue(zipFile.exists());
}
use of org.eclipse.winery.yaml.converter.Converter in project winery by eclipse.
the class Showcases method zipTypeTest.
@Test
public void zipTypeTest() throws Exception {
String name = "Showcase.csar";
InputStream inputStream = new FileInputStream(path + File.separator + name);
Converter converter = new Converter();
converter.convertY2X(inputStream);
TServiceTemplate serviceTemplate = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(new Namespace(Namespaces.DEFAULT_NS, false), new XmlId("Showcase", false)));
Assert.assertNotNull(serviceTemplate);
}
use of org.eclipse.winery.yaml.converter.Converter in project winery by eclipse.
the class Y2XConverter method convert.
/**
* Converts TOSCA YAML TImportDefinitions and returns list of TOSCA XML TImports
*/
private TImport convert(TImportDefinition node, String name) {
Reader reader = Reader.getReader();
String namespace = node.getNamespaceUri() == null ? this.namespace : node.getNamespaceUri();
try {
org.eclipse.winery.model.tosca.yaml.TServiceTemplate serviceTemplate = reader.readImportDefinition(node, path, namespace);
Converter converter = new Converter(this.repository);
Definitions definitions = converter.convertY2X(serviceTemplate, getFileNameFromFile(node.getFile()), namespace, path, outPath);
WriterUtils.saveDefinitions(definitions, outPath, namespace, name);
TImport.Builder builder = new TImport.Builder(Namespaces.XML_NS);
builder.setLocation(WriterUtils.getDefinitionsLocation(namespace, name));
builder.setNamespace(namespace);
return builder.build();
} catch (MultiException e) {
e.printStackTrace();
}
return null;
}
use of org.eclipse.winery.yaml.converter.Converter in project winery by eclipse.
the class RestUtils method getYamlCSARofSelectedResource.
public static Response getYamlCSARofSelectedResource(final AbstractComponentInstanceResource resource) {
final Converter converter = new Converter();
StreamingOutput so = output -> {
try {
InputStream is = converter.convertX2Y(resource.getId());
byte[] buffer = new byte[1024];
int bytesRead;
// read from is to buffer
while ((bytesRead = is.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
is.close();
// flush OutputStream to write any buffered data to file
output.flush();
output.close();
} catch (Exception e) {
throw new WebApplicationException(e);
}
};
StringBuilder sb = new StringBuilder();
sb.append("attachment;filename=\"");
sb.append(resource.getXmlId().getEncoded());
sb.append(org.eclipse.winery.repository.Constants.SUFFIX_CSAR);
sb.append("\"");
return Response.ok().header("Content-Disposition", sb.toString()).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
Aggregations