Search in sources :

Example 31 with ServiceTemplateId

use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class RestUtils method cloneServiceTemplate.

public static ServiceTemplateId cloneServiceTemplate(ServiceTemplateId serviceTemplate, String newName, String artifactName) throws JAXBException, IllegalArgumentException, IOException {
    ServiceTemplateId newServiceTemplateId = new ServiceTemplateId(serviceTemplate.getNamespace().getDecoded(), newName, false);
    RepositoryFileReference fileRef = new RepositoryFileReference(newServiceTemplateId, "ServiceTemplate.tosca");
    Definitions defs = new ServiceTemplateResource(serviceTemplate).getDefinitions();
    defs.setId(newName + "Definitions");
    defs.setName(newName + "Definitions generated from Artifact " + artifactName);
    TServiceTemplate oldSTModel = null;
    for (TExtensibleElements el : defs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation()) {
        if (el instanceof TServiceTemplate) {
            oldSTModel = (TServiceTemplate) el;
        }
    }
    oldSTModel.setId(newName);
    oldSTModel.setName(newName + " generated from Artifact " + artifactName);
    // remove xaaspackager tags
    Collection<TTag> toRemove = new ArrayList<TTag>();
    for (TTag tag : oldSTModel.getTags().getTag()) {
        switch(tag.getName()) {
            case "xaasPackageNode":
            case "xaasPackageArtifactType":
            case "xaasPackageDeploymentArtifact":
                toRemove.add(tag);
                break;
            default:
                break;
        }
    }
    oldSTModel.getTags().getTag().removeAll(toRemove);
    JAXBContext context = JAXBContext.newInstance(Definitions.class);
    Marshaller m = context.createMarshaller();
    StringWriter sw = new StringWriter();
    m.marshal(defs, sw);
    String xmlString = sw.toString();
    RepositoryFactory.getRepository().putContentToFile(fileRef, xmlString, MediaTypes.MEDIATYPE_TOSCA_DEFINITIONS);
    return newServiceTemplateId;
}
Also used : Marshaller(javax.xml.bind.Marshaller) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) JAXBContext(javax.xml.bind.JAXBContext) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) StringWriter(java.io.StringWriter)

Example 32 with ServiceTemplateId

use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class APIResource method getAllArtifactTemplatesOfContainedImplementationArtifacts.

/**
 * Implementation similar to
 * getAllArtifactTemplatesOfContainedDeploymentArtifacts. Only difference is
 * "getArtifactTemplatesOfReferencedImplementationArtifacts" instead of
 * "getArtifactTemplatesOfReferencedDeploymentArtifacts".
 */
@GET
@Path("getallartifacttemplatesofcontainedimplementationartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedImplementationArtifacts(@QueryParam("servicetemplate") String serviceTemplateQNameString, @QueryParam("nodetemplateid") String nodeTemplateId) {
    if (StringUtils.isEmpty(serviceTemplateQNameString)) {
        return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter").build();
    }
    QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);
    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
    if (!RepositoryFactory.getRepository().exists(serviceTemplateId)) {
        return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
    }
    ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);
    Collection<QName> artifactTemplates = new ArrayList<>();
    List<TNodeTemplate> allNestedNodeTemplates = BackendUtils.getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
    for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
        if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
            Collection<QName> ats = BackendUtils.getArtifactTemplatesOfReferencedImplementationArtifacts(nodeTemplate);
            artifactTemplates.addAll(ats);
        }
    }
    // convert QName list to select2 data
    Select2DataWithOptGroups res = new Select2DataWithOptGroups();
    for (QName qName : artifactTemplates) {
        res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
    }
    return Response.ok().entity(res.asSortedSet()).build();
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) Select2DataWithOptGroups(org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 33 with ServiceTemplateId

use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class APIResource method getAllArtifactTemplatesOfContainedDeploymentArtifacts.

@GET
@Path("getallartifacttemplatesofcontaineddeploymentartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedDeploymentArtifacts(@QueryParam("servicetemplate") String serviceTemplateQNameString, @QueryParam("nodetemplateid") String nodeTemplateId) {
    if (StringUtils.isEmpty(serviceTemplateQNameString)) {
        return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter").build();
    }
    QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);
    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
    if (!RepositoryFactory.getRepository().exists(serviceTemplateId)) {
        return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
    }
    ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);
    Collection<QName> artifactTemplates = new ArrayList<>();
    List<TNodeTemplate> allNestedNodeTemplates = BackendUtils.getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
    for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
        if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
            Collection<QName> ats = BackendUtils.getArtifactTemplatesOfReferencedDeploymentArtifacts(nodeTemplate);
            artifactTemplates.addAll(ats);
        }
    }
    // convert QName list to select2 data
    Select2DataWithOptGroups res = new Select2DataWithOptGroups();
    for (QName qName : artifactTemplates) {
        res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
    }
    return Response.ok().entity(res.asSortedSet()).build();
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) Select2DataWithOptGroups(org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 34 with ServiceTemplateId

use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class AbstractComponentsResource method onPost.

/**
 * Creates a new component instance in the given namespace
 *
 * @param namespace plain namespace
 * @param name      the name; used as id
 */
protected ResourceCreationResult onPost(String namespace, String name) {
    ResourceCreationResult res;
    if (StringUtils.isEmpty(namespace) || StringUtils.isEmpty(name)) {
        res = new ResourceCreationResult(Status.BAD_REQUEST);
    } else {
        String id = RestUtils.createXMLidAsString(name);
        DefinitionsChildId tcId;
        try {
            tcId = this.getDefinitionsChildId(namespace, id, false);
            res = this.createComponentInstance(tcId);
            // in case the resource additionally supports a name attribute, we set the original name
            if (res.getStatus().equals(Status.CREATED)) {
                if ((tcId instanceof ServiceTemplateId) || (tcId instanceof ArtifactTemplateId) || (tcId instanceof PolicyTemplateId)) {
                    // these three types have an additional name (instead of a pure id)
                    // we store the name
                    IHasName resource = (IHasName) AbstractComponentsResource.getComponentInstaceResource(tcId);
                    resource.setName(name);
                }
            }
        } catch (Exception e) {
            AbstractComponentsResource.LOGGER.debug("Could not create id instance", e);
            res = new ResourceCreationResult(Status.INTERNAL_SERVER_ERROR);
        }
    }
    return res;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) NotFoundException(com.sun.jersey.api.NotFoundException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)34 QName (javax.xml.namespace.QName)12 Test (org.junit.Test)12 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)5 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)5 POST (javax.ws.rs.POST)4 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)4 NonNull (org.eclipse.jdt.annotation.NonNull)3 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)3 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)3 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)3 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)3 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)3 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)3