use of org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource 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(ToscaExportUtil.ExportProperties.REPOSITORY_URI.toString(), uri);
try {
exporter.exportTOSCA(RepositoryFactory.getRepository(), resource.getId(), output, conf);
} 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).build();
*/
return Response.ok().type(MediaType.APPLICATION_XML).entity(so).build();
}
use of org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource in project winery by eclipse.
the class RestUtils method getCSARofSelectedResource.
public static Response getCSARofSelectedResource(final AbstractComponentInstanceResource resource) {
final CsarExporter exporter = new CsarExporter();
StreamingOutput so = output -> {
try {
exporter.writeCsar(RepositoryFactory.getRepository(), resource.getId(), output);
} 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();
}
use of org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource in project winery by eclipse.
the class ServiceTemplatesResource method getCreateFromArtifactData.
@GET
@Path("createfromartifact")
@Produces(MediaType.APPLICATION_JSON)
public CreateFromArtifactApiData getCreateFromArtifactData() {
Set<QName> artifactTypes = new HashSet<QName>();
Set<QName> infrastructureNodeTypes = new HashSet<QName>();
Collection<AbstractComponentInstanceResource> templates = this.getAll();
for (AbstractComponentInstanceResource resource : templates) {
if (resource instanceof ServiceTemplateResource) {
ServiceTemplateResource stRes = (ServiceTemplateResource) resource;
if (stRes.getServiceTemplate().getTags() != null) {
int check = 0;
QName artifactType = null;
for (TTag tag : stRes.getServiceTemplate().getTags().getTag()) {
switch(tag.getName()) {
case "xaasPackageNode":
check++;
break;
case "xaasPackageArtifactType":
check++;
artifactType = QName.valueOf(tag.getValue());
break;
case "xaasPackageDeploymentArtifact":
check++;
break;
case "xaasPackageInfrastructure":
// optional tag, hence no check++
infrastructureNodeTypes.add(QName.valueOf(tag.getValue()));
default:
break;
}
}
if (check == 3) {
artifactTypes.add(artifactType);
}
}
}
}
return new CreateFromArtifactApiData(artifactTypes, infrastructureNodeTypes);
}
use of org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource in project winery by eclipse.
the class ServiceTemplatesResource method getXaaSPackageTemplates.
private Collection<ServiceTemplateId> getXaaSPackageTemplates() {
Collection<AbstractComponentInstanceResource> templates = this.getAll();
Collection<ServiceTemplateId> xaasPackages = new ArrayList<ServiceTemplateId>();
for (AbstractComponentInstanceResource resource : templates) {
if (resource instanceof ServiceTemplateResource) {
ServiceTemplateResource stRes = (ServiceTemplateResource) resource;
TTags tags = stRes.getServiceTemplate().getTags();
if (tags == null) {
continue;
}
int check = 0;
for (TTag tag : tags.getTag()) {
switch(tag.getName()) {
case "xaasPackageNode":
case "xaasPackageArtifactType":
case "xaasPackageDeploymentArtifact":
check++;
break;
default:
break;
}
}
if (check == 3) {
xaasPackages.add((ServiceTemplateId) stRes.getId());
}
}
}
return xaasPackages;
}
use of org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource 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