use of org.eclipse.winery.repository.yaml.export.YamlExporter in project winery by eclipse.
the class RestUtils method getYamlCSARofSelectedResource.
public static Response getYamlCSARofSelectedResource(final AbstractComponentInstanceResource resource) {
LocalDateTime start = LocalDateTime.now();
final YamlExporter exporter = new YamlExporter(RepositoryFactory.getRepository());
Map<String, Object> exportConfiguration = new HashMap<>();
StreamingOutput so = output -> {
try {
exporter.writeCsar(resource.getId(), output, exportConfiguration);
LOGGER.debug("CSAR export lasted {}", Duration.between(LocalDateTime.now(), start).toString());
} catch (Exception e) {
LOGGER.error("Error while exporting CSAR", e);
throw new WebApplicationException(e);
}
};
String contentDisposition = String.format("attachment;filename=\"%s%s\"", resource.getXmlId().getEncoded(), Constants.SUFFIX_CSAR);
return Response.ok().header("Content-Disposition", contentDisposition).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
use of org.eclipse.winery.repository.yaml.export.YamlExporter in project winery by eclipse.
the class AbstractComponentInstanceResource method exportToFilesystem.
@POST
@Path("exportToFilesystem")
public Response exportToFilesystem() {
if (RepositoryUtils.isYamlRepository(requestRepository)) {
LocalDateTime start = LocalDateTime.now();
YamlExporter exporter = new YamlExporter(RepositoryFactory.getRepository());
Map<String, Object> exportConfiguration = new HashMap<>();
String filename = getXmlId().getEncoded() + Constants.SUFFIX_CSAR;
File file = new File(Environments.getInstance().getRepositoryConfig().getCsarOutputPath(), filename);
try (FileOutputStream fos = new FileOutputStream(file, false)) {
exporter.writeCsar(getId(), fos, exportConfiguration);
LOGGER.debug("CSAR export to filesystem lasted {}", Duration.between(LocalDateTime.now(), start).toString());
} catch (Exception e) {
LOGGER.error("Error exporting CSAR to filesystem", e);
return Response.serverError().build();
}
} else {
throw new UnsupportedOperationException();
}
return Response.noContent().build();
}
Aggregations