Search in sources :

Example 26 with TNodeTemplate

use of org.eclipse.winery.model.tosca.TNodeTemplate 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)

Aggregations

TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)26 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)11 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)10 ArrayList (java.util.ArrayList)9 QName (javax.xml.namespace.QName)9 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)8 Test (org.junit.Test)7 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)6 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)6 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)6 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)4 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)4 TOSCANode (org.eclipse.winery.compliance.model.TOSCANode)4 TDeploymentArtifacts (org.eclipse.winery.model.tosca.TDeploymentArtifacts)4 TRequirement (org.eclipse.winery.model.tosca.TRequirement)4 TOSCAModelHelper.createNodeTypeId (org.eclipse.winery.compliance.TOSCAModelHelper.createNodeTypeId)3 TOSCAModelHelper.createTNodeTemplate (org.eclipse.winery.compliance.TOSCAModelHelper.createTNodeTemplate)3