Search in sources :

Example 1 with Select2DataWithOptGroups

use of org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups 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 2 with Select2DataWithOptGroups

use of org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups 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 3 with Select2DataWithOptGroups

use of org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups in project winery by eclipse.

the class EntityTypeResource method getListOfAllInstances.

/**
 * Used by children to implement getListOfAllInstances()
 */
protected SortedSet<Select2OptGroup> getListOfAllInstances(Class<? extends DefinitionsChildId> clazz) throws RepositoryCorruptException {
    Select2DataWithOptGroups data = new Select2DataWithOptGroups();
    Collection<? extends DefinitionsChildId> instanceIds = RepositoryFactory.getRepository().getAllElementsReferencingGivenType(clazz, this.id.getQName());
    for (DefinitionsChildId instanceId : instanceIds) {
        String groupText = instanceId.getNamespace().getDecoded();
        String text = BackendUtils.getName(instanceId);
        data.add(groupText, instanceId.getQName().toString(), text);
    }
    return data.asSortedSet();
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) Select2DataWithOptGroups(org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups)

Aggregations

Select2DataWithOptGroups (org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups)3 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 QName (javax.xml.namespace.QName)2 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)2 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)2 ServiceTemplateResource (org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource)2 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)1