Search in sources :

Example 1 with AbstractComponentInstanceResource

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();
}
Also used : XLogger(org.slf4j.ext.XLogger) MimeTypes(org.eclipse.winery.common.constants.MimeTypes) ToscaElementId(org.eclipse.winery.common.ids.elements.ToscaElementId) XLoggerFactory(org.slf4j.ext.XLoggerFactory) FileTime(java.nio.file.attribute.FileTime) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) NamespaceAndDefinedLocalNamesForAngular(org.eclipse.winery.repository.rest.datatypes.NamespaceAndDefinedLocalNamesForAngular) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) ResourceCreationResult(org.eclipse.winery.repository.rest.resources._support.ResourceCreationResult) Constants(org.eclipse.winery.repository.Constants) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) IPersistable(org.eclipse.winery.repository.rest.resources._support.IPersistable) URI(java.net.URI) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) GenericId(org.eclipse.winery.common.ids.GenericId) ContentDisposition(com.sun.jersey.core.header.ContentDisposition) Util(org.eclipse.winery.common.Util) JAXBException(javax.xml.bind.JAXBException) Collectors(java.util.stream.Collectors) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) TopologyGraphElementEntityTypeResource(org.eclipse.winery.repository.rest.resources.entitytypes.TopologyGraphElementEntityTypeResource) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) NamespaceAndDefinedLocalNames(org.eclipse.winery.repository.backend.xsd.NamespaceAndDefinedLocalNames) org.eclipse.winery.model.tosca(org.eclipse.winery.model.tosca) AccessControlException(java.security.AccessControlException) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) WebApplicationException(javax.ws.rs.WebApplicationException) Namespace(org.eclipse.winery.common.ids.Namespace) QName(javax.xml.namespace.QName) Converter(org.eclipse.winery.yaml.converter.Converter) java.util(java.util) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) ClientResponse(com.sun.jersey.api.client.ClientResponse) Marshaller(javax.xml.bind.Marshaller) XmlId(org.eclipse.winery.common.ids.XmlId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Application(org.eclipse.winery.model.selfservice.Application) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) WebResource(com.sun.jersey.api.client.WebResource) Environment(org.eclipse.winery.repository.configuration.Environment) Status(javax.ws.rs.core.Response.Status) JAXBContext(javax.xml.bind.JAXBContext) CsarExporter(org.eclipse.winery.repository.export.CsarExporter) ToscaExportUtil(org.eclipse.winery.repository.export.ToscaExportUtil) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) AbstractComponentInstanceResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource) StringWriter(java.io.StringWriter) IOException(java.io.IOException) javax.ws.rs.core(javax.ws.rs.core) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) Family(javax.ws.rs.core.Response.Status.Family) Client(com.sun.jersey.api.client.Client) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) AbstractComponentsResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentsResource) InputStream(java.io.InputStream) WebApplicationException(javax.ws.rs.WebApplicationException) ToscaExportUtil(org.eclipse.winery.repository.export.ToscaExportUtil) JAXBException(javax.xml.bind.JAXBException) AccessControlException(java.security.AccessControlException) WebApplicationException(javax.ws.rs.WebApplicationException) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) IOException(java.io.IOException)

Example 2 with AbstractComponentInstanceResource

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();
}
Also used : XLogger(org.slf4j.ext.XLogger) MimeTypes(org.eclipse.winery.common.constants.MimeTypes) ToscaElementId(org.eclipse.winery.common.ids.elements.ToscaElementId) XLoggerFactory(org.slf4j.ext.XLoggerFactory) FileTime(java.nio.file.attribute.FileTime) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) NamespaceAndDefinedLocalNamesForAngular(org.eclipse.winery.repository.rest.datatypes.NamespaceAndDefinedLocalNamesForAngular) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) ResourceCreationResult(org.eclipse.winery.repository.rest.resources._support.ResourceCreationResult) Constants(org.eclipse.winery.repository.Constants) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) IPersistable(org.eclipse.winery.repository.rest.resources._support.IPersistable) URI(java.net.URI) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) GenericId(org.eclipse.winery.common.ids.GenericId) ContentDisposition(com.sun.jersey.core.header.ContentDisposition) Util(org.eclipse.winery.common.Util) JAXBException(javax.xml.bind.JAXBException) Collectors(java.util.stream.Collectors) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) TopologyGraphElementEntityTypeResource(org.eclipse.winery.repository.rest.resources.entitytypes.TopologyGraphElementEntityTypeResource) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) NamespaceAndDefinedLocalNames(org.eclipse.winery.repository.backend.xsd.NamespaceAndDefinedLocalNames) org.eclipse.winery.model.tosca(org.eclipse.winery.model.tosca) AccessControlException(java.security.AccessControlException) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) WebApplicationException(javax.ws.rs.WebApplicationException) Namespace(org.eclipse.winery.common.ids.Namespace) QName(javax.xml.namespace.QName) Converter(org.eclipse.winery.yaml.converter.Converter) java.util(java.util) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) ClientResponse(com.sun.jersey.api.client.ClientResponse) Marshaller(javax.xml.bind.Marshaller) XmlId(org.eclipse.winery.common.ids.XmlId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Application(org.eclipse.winery.model.selfservice.Application) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) WebResource(com.sun.jersey.api.client.WebResource) Environment(org.eclipse.winery.repository.configuration.Environment) Status(javax.ws.rs.core.Response.Status) JAXBContext(javax.xml.bind.JAXBContext) CsarExporter(org.eclipse.winery.repository.export.CsarExporter) ToscaExportUtil(org.eclipse.winery.repository.export.ToscaExportUtil) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) AbstractComponentInstanceResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource) StringWriter(java.io.StringWriter) IOException(java.io.IOException) javax.ws.rs.core(javax.ws.rs.core) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) Family(javax.ws.rs.core.Response.Status.Family) Client(com.sun.jersey.api.client.Client) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) AbstractComponentsResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentsResource) InputStream(java.io.InputStream) WebApplicationException(javax.ws.rs.WebApplicationException) CsarExporter(org.eclipse.winery.repository.export.CsarExporter) JAXBException(javax.xml.bind.JAXBException) AccessControlException(java.security.AccessControlException) WebApplicationException(javax.ws.rs.WebApplicationException) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) IOException(java.io.IOException)

Example 3 with AbstractComponentInstanceResource

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);
}
Also used : TTag(org.eclipse.winery.model.tosca.TTag) CreateFromArtifactApiData(org.eclipse.winery.repository.rest.resources._support.CreateFromArtifactApiData) QName(javax.xml.namespace.QName) AbstractComponentInstanceResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource)

Example 4 with AbstractComponentInstanceResource

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;
}
Also used : TTag(org.eclipse.winery.model.tosca.TTag) AbstractComponentInstanceResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource) TTags(org.eclipse.winery.model.tosca.TTags) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId)

Example 5 with AbstractComponentInstanceResource

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();
}
Also used : XLogger(org.slf4j.ext.XLogger) MimeTypes(org.eclipse.winery.common.constants.MimeTypes) ToscaElementId(org.eclipse.winery.common.ids.elements.ToscaElementId) XLoggerFactory(org.slf4j.ext.XLoggerFactory) FileTime(java.nio.file.attribute.FileTime) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) NamespaceAndDefinedLocalNamesForAngular(org.eclipse.winery.repository.rest.datatypes.NamespaceAndDefinedLocalNamesForAngular) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) ResourceCreationResult(org.eclipse.winery.repository.rest.resources._support.ResourceCreationResult) Constants(org.eclipse.winery.repository.Constants) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) IPersistable(org.eclipse.winery.repository.rest.resources._support.IPersistable) URI(java.net.URI) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) GenericId(org.eclipse.winery.common.ids.GenericId) ContentDisposition(com.sun.jersey.core.header.ContentDisposition) Util(org.eclipse.winery.common.Util) JAXBException(javax.xml.bind.JAXBException) Collectors(java.util.stream.Collectors) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) TopologyGraphElementEntityTypeResource(org.eclipse.winery.repository.rest.resources.entitytypes.TopologyGraphElementEntityTypeResource) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) NamespaceAndDefinedLocalNames(org.eclipse.winery.repository.backend.xsd.NamespaceAndDefinedLocalNames) org.eclipse.winery.model.tosca(org.eclipse.winery.model.tosca) AccessControlException(java.security.AccessControlException) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) WebApplicationException(javax.ws.rs.WebApplicationException) Namespace(org.eclipse.winery.common.ids.Namespace) QName(javax.xml.namespace.QName) Converter(org.eclipse.winery.yaml.converter.Converter) java.util(java.util) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) ClientResponse(com.sun.jersey.api.client.ClientResponse) Marshaller(javax.xml.bind.Marshaller) XmlId(org.eclipse.winery.common.ids.XmlId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Application(org.eclipse.winery.model.selfservice.Application) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) WebResource(com.sun.jersey.api.client.WebResource) Environment(org.eclipse.winery.repository.configuration.Environment) Status(javax.ws.rs.core.Response.Status) JAXBContext(javax.xml.bind.JAXBContext) CsarExporter(org.eclipse.winery.repository.export.CsarExporter) ToscaExportUtil(org.eclipse.winery.repository.export.ToscaExportUtil) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) AbstractComponentInstanceResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource) StringWriter(java.io.StringWriter) IOException(java.io.IOException) javax.ws.rs.core(javax.ws.rs.core) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) Family(javax.ws.rs.core.Response.Status.Family) Client(com.sun.jersey.api.client.Client) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) AbstractComponentsResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentsResource) InputStream(java.io.InputStream) WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) Converter(org.eclipse.winery.yaml.converter.Converter) JAXBException(javax.xml.bind.JAXBException) AccessControlException(java.security.AccessControlException) WebApplicationException(javax.ws.rs.WebApplicationException) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) IOException(java.io.IOException)

Aggregations

QName (javax.xml.namespace.QName)4 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)4 Client (com.sun.jersey.api.client.Client)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 WebResource (com.sun.jersey.api.client.WebResource)3 ContentDisposition (com.sun.jersey.core.header.ContentDisposition)3 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)3 FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 StringWriter (java.io.StringWriter)3 URI (java.net.URI)3 FileTime (java.nio.file.attribute.FileTime)3 AccessControlException (java.security.AccessControlException)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 javax.ws.rs.core (javax.ws.rs.core)3 Status (javax.ws.rs.core.Response.Status)3 Family (javax.ws.rs.core.Response.Status.Family)3