Search in sources :

Example 6 with NodeTypeImplementationId

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

the class BackendUtils method getArtifactTemplatesOfReferencedDeploymentArtifacts.

public static Collection<QName> getArtifactTemplatesOfReferencedDeploymentArtifacts(TNodeTemplate nodeTemplate) {
    List<QName> l = new ArrayList<>();
    // DAs may be assigned directly to a node template
    Collection<QName> allReferencedArtifactTemplates = BackendUtils.getAllReferencedArtifactTemplates(nodeTemplate.getDeploymentArtifacts());
    l.addAll(allReferencedArtifactTemplates);
    // DAs may be assigned via node type implementations
    QName nodeTypeQName = nodeTemplate.getType();
    Collection<NodeTypeImplementationId> allNodeTypeImplementations = RepositoryFactory.getRepository().getAllElementsReferencingGivenType(NodeTypeImplementationId.class, nodeTypeQName);
    for (NodeTypeImplementationId nodeTypeImplementationId : allNodeTypeImplementations) {
        TDeploymentArtifacts deploymentArtifacts = RepositoryFactory.getRepository().getElement(nodeTypeImplementationId).getDeploymentArtifacts();
        allReferencedArtifactTemplates = BackendUtils.getAllReferencedArtifactTemplates(deploymentArtifacts);
        l.addAll(allReferencedArtifactTemplates);
    }
    return l;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList)

Example 7 with NodeTypeImplementationId

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

the class IGenericRepository method getReferenceCount.

default int getReferenceCount(ArtifactTemplateId id) {
    // We do not use a database, therefore, we have to go through all possibilities pointing to the artifact template
    // DAs and IAs point to an artifact template
    // DAs are contained in Node Type Implementations and Node Templates
    // IAs are contained in Node Type Implementations and Relationship Type Implementations
    int count = 0;
    Collection<TDeploymentArtifact> allDAs = new HashSet<>();
    Collection<TImplementationArtifact> allIAs = new HashSet<>();
    // handle Node Type Implementation, which contains DAs and IAs
    SortedSet<NodeTypeImplementationId> nodeTypeImplementations = this.getAllDefinitionsChildIds(NodeTypeImplementationId.class);
    for (NodeTypeImplementationId ntiId : nodeTypeImplementations) {
        final TNodeTypeImplementation nodeTypeImplementation = this.getElement(ntiId);
        TDeploymentArtifacts deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
        if (deploymentArtifacts != null) {
            allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
        }
        TImplementationArtifacts implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
        if (implementationArtifacts != null) {
            allIAs.addAll(implementationArtifacts.getImplementationArtifact());
        }
    }
    // check all Relationshiptype Implementations for IAs
    SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
    for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
        TImplementationArtifacts implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
        if (implementationArtifacts != null) {
            allIAs.addAll(implementationArtifacts.getImplementationArtifact());
        }
    }
    // check all node templates for DAs
    SortedSet<ServiceTemplateId> serviceTemplates = this.getAllDefinitionsChildIds(ServiceTemplateId.class);
    for (ServiceTemplateId sid : serviceTemplates) {
        TTopologyTemplate topologyTemplate = this.getElement(sid).getTopologyTemplate();
        if (topologyTemplate != null) {
            List<TEntityTemplate> nodeTemplateOrRelationshipTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate();
            for (TEntityTemplate template : nodeTemplateOrRelationshipTemplate) {
                if (template instanceof TNodeTemplate) {
                    TNodeTemplate nodeTemplate = (TNodeTemplate) template;
                    TDeploymentArtifacts deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
                    if (deploymentArtifacts != null) {
                        allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
                    }
                }
            }
        }
    }
    // now we have all DAs and IAs
    QName ourQName = id.getQName();
    // check DAs for artifact templates
    for (TDeploymentArtifact da : allDAs) {
        QName artifactRef = da.getArtifactRef();
        if (ourQName.equals(artifactRef)) {
            count++;
        }
    }
    // check IAs for artifact templates
    for (TImplementationArtifact ia : allIAs) {
        QName artifactRef = ia.getArtifactRef();
        if (ourQName.equals(artifactRef)) {
            count++;
        }
    }
    return count;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) QName(javax.xml.namespace.QName) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) RelationshipTypeImplementationId(org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) TImplementationArtifacts(org.eclipse.winery.model.tosca.TImplementationArtifacts) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet)

Example 8 with NodeTypeImplementationId

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

the class ImplementationsOfOneNodeTypeResource method getImplementationsTableData.

/**
 * required by implementations.jsp
 *
 * @return for each node type implementation implementing the associated
 * node type
 */
@Override
public String getImplementationsTableData() {
    String res;
    JsonFactory jsonFactory = new JsonFactory();
    StringWriter tableDataSW = new StringWriter();
    try {
        JsonGenerator jGenerator = jsonFactory.createGenerator(tableDataSW);
        jGenerator.writeStartArray();
        Collection<NodeTypeImplementationId> allNodeTypeImplementations = RepositoryFactory.getRepository().getAllElementsReferencingGivenType(NodeTypeImplementationId.class, this.getTypeId().getQName());
        for (NodeTypeImplementationId ntiID : allNodeTypeImplementations) {
            jGenerator.writeStartArray();
            jGenerator.writeString(ntiID.getNamespace().getDecoded());
            jGenerator.writeString(ntiID.getXmlId().getDecoded());
            jGenerator.writeEndArray();
        }
        jGenerator.writeEndArray();
        jGenerator.close();
        tableDataSW.close();
        res = tableDataSW.toString();
    } catch (Exception e) {
        ImplementationsOfOneNodeTypeResource.LOGGER.error(e.getMessage(), e);
        res = "[]";
    }
    return res;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId) StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Aggregations

NodeTypeImplementationId (org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId)8 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)3 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)2 RelationshipTypeImplementationId (org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId)2 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)2 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)2 TDeploymentArtifacts (org.eclipse.winery.model.tosca.TDeploymentArtifacts)2 TImplementationArtifacts (org.eclipse.winery.model.tosca.TImplementationArtifacts)2 TNodeType (org.eclipse.winery.model.tosca.TNodeType)2 TNodeTypeImplementation (org.eclipse.winery.model.tosca.TNodeTypeImplementation)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)1 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)1 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)1 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)1 PolicyTemplateId (org.eclipse.winery.common.ids.definitions.PolicyTemplateId)1