Search in sources :

Example 11 with RelationshipTypeId

use of org.eclipse.winery.model.ids.definitions.RelationshipTypeId in project winery by eclipse.

the class VersionSupport method getDefinitionInTheGivenVersion.

public static DefinitionsChildId getDefinitionInTheGivenVersion(DefinitionsChildId childId, WineryVersion otherVersion) {
    if (childId.getVersion().compareTo(otherVersion) == 0) {
        return childId;
    }
    String localPart = childId.getNameWithoutVersion() + (otherVersion.toString().length() > 0 ? WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + otherVersion.toString() : "");
    QName qName = new QName(childId.getNamespace().getDecoded(), localPart);
    if (childId instanceof RelationshipTypeImplementationId) {
        return new RelationshipTypeImplementationId(qName);
    } else if (childId instanceof NodeTypeImplementationId) {
        return new NodeTypeImplementationId(qName);
    } else if (childId instanceof RequirementTypeId) {
        return new RequirementTypeId(qName);
    } else if (childId instanceof NodeTypeId) {
        return new NodeTypeId(qName);
    } else if (childId instanceof RelationshipTypeId) {
        return new RelationshipTypeId(qName);
    } else if (childId instanceof CapabilityTypeId) {
        return new CapabilityTypeId(qName);
    } else if (childId instanceof ArtifactTypeId) {
        return new ArtifactTypeId(qName);
    } else if (childId instanceof PolicyTypeId) {
        return new PolicyTypeId(qName);
    } else if (childId instanceof PolicyTemplateId) {
        return new PolicyTemplateId(qName);
    } else if (childId instanceof ServiceTemplateId) {
        return new ServiceTemplateId(qName);
    } else if (childId instanceof ArtifactTemplateId) {
        return new ArtifactTemplateId(qName);
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId)

Example 12 with RelationshipTypeId

use of org.eclipse.winery.model.ids.definitions.RelationshipTypeId in project winery by eclipse.

the class YamlRepository method getRequestedDefinition.

/**
 * Parses only requested Definition from converted yaml service template
 *
 * @param id          Definitions Child id
 * @param definitions converted definitions
 * @return requested definitions
 */
private TDefinitions getRequestedDefinition(DefinitionsChildId id, TDefinitions definitions) {
    if (id instanceof ArtifactTemplateId) {
        String artifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
        List<TArtifactTemplate> artifactTemplates = definitions.getArtifactTemplates();
        List<TArtifactTemplate> requestedArtifactTemplates = new ArrayList<>();
        for (TArtifactTemplate artifactTemplate : artifactTemplates) {
            if (artifactTemplate.getId().equalsIgnoreCase(artifactName)) {
                requestedArtifactTemplates.add(artifactTemplate);
                TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
                requestedDefinitions.addArtifactTemplates(requestedArtifactTemplates);
                return requestedDefinitions.build();
            }
        }
        // we did not find the artifact template id (this should not happen!)
        LOGGER.error("requested artifact template id (" + id.toReadableString() + ") cannot be extracted from definitions object!");
        return definitions;
    } else {
        TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
        if (id instanceof NodeTypeId) {
            requestedDefinitions.addNodeTypes(definitions.getNodeTypes());
        } else if (id instanceof RelationshipTypeId) {
            requestedDefinitions.addRelationshipTypes(definitions.getRelationshipTypes());
        } else if (id instanceof NodeTypeImplementationId) {
            requestedDefinitions.addNodeTypeImplementations(definitions.getNodeTypeImplementations());
        } else if (id instanceof RelationshipTypeImplementationId) {
            requestedDefinitions.addRelationshipTypeImplementations(definitions.getRelationshipTypeImplementations());
        } else if (id instanceof ArtifactTypeId) {
            requestedDefinitions.addArtifactTypes(definitions.getArtifactTypes());
        } else if (id instanceof CapabilityTypeId) {
            requestedDefinitions.addCapabilityTypes(definitions.getCapabilityTypes());
        } else if (id instanceof DataTypeId) {
            requestedDefinitions.addDataTypes(definitions.getDataTypes());
        } else if (id instanceof RequirementTypeId) {
            requestedDefinitions.addRequirementTypes(definitions.getRequirementTypes());
        } else if (id instanceof PolicyTypeId) {
            requestedDefinitions.addPolicyTypes(definitions.getPolicyTypes());
        } else if (id instanceof InterfaceTypeId) {
            requestedDefinitions.addInterfaceTypes(definitions.getInterfaceTypes());
        } else {
            // we do not need to filter anything
            return definitions;
        }
        return requestedDefinitions.build();
    }
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ArrayList(java.util.ArrayList) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions)

Example 13 with RelationshipTypeId

use of org.eclipse.winery.model.ids.definitions.RelationshipTypeId in project winery by eclipse.

the class YamlRepository method convertGenericId.

/**
 * Converts Generic id of non existing XML Definitions in compatible YAML Definition
 *
 * @param id GenericId
 * @return converted Generic Id
 */
private GenericId convertGenericId(GenericId id) {
    if (id instanceof NodeTypeImplementationId) {
        return new NodeTypeId(((NodeTypeImplementationId) id).getQName());
    } else if (id instanceof RelationshipTypeImplementationId) {
        return new RelationshipTypeId(((RelationshipTypeImplementationId) id).getQName());
    } else if (id instanceof ArtifactTemplateId) {
        QName qName = ((ArtifactTemplateId) id).getQName();
        Matcher nameMatcher = namePattern.matcher(qName.getLocalPart());
        if (nameMatcher.matches()) {
            String typeName = nameMatcher.group(2);
            if (nameMatcher.group(3).equalsIgnoreCase("nodetypes")) {
                return new NodeTypeId(new QName(qName.getNamespaceURI(), typeName));
            } else {
                return new RelationshipTypeId(new QName(qName.getNamespaceURI(), typeName));
            }
        } else {
            return new NodeTypeId(new QName(qName.getNamespaceURI(), "Cache"));
        }
    }
    return null;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) Matcher(java.util.regex.Matcher) QName(javax.xml.namespace.QName) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)

Example 14 with RelationshipTypeId

use of org.eclipse.winery.model.ids.definitions.RelationshipTypeId in project winery by eclipse.

the class Splitting method getBasisRelationshipType.

public TRelationshipType getBasisRelationshipType(QName relationshipTypeQName) {
    RelationshipTypeId parentRelationshipTypeId = new RelationshipTypeId(relationshipTypeQName);
    TRelationshipType parentRelationshipType = RepositoryFactory.getRepository().getElement(parentRelationshipTypeId);
    TRelationshipType basisRelationshipType = parentRelationshipType;
    while (parentRelationshipType != null) {
        basisRelationshipType = parentRelationshipType;
        if (parentRelationshipType.getDerivedFrom() != null) {
            relationshipTypeQName = parentRelationshipType.getDerivedFrom().getTypeRef();
            parentRelationshipTypeId = new RelationshipTypeId(relationshipTypeQName);
            parentRelationshipType = RepositoryFactory.getRepository().getElement(parentRelationshipTypeId);
        } else {
            parentRelationshipType = null;
        }
    }
    return basisRelationshipType;
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId)

Example 15 with RelationshipTypeId

use of org.eclipse.winery.model.ids.definitions.RelationshipTypeId in project winery by eclipse.

the class ComplianceRuleCheckerTests method setup.

@BeforeEach
public void setup() throws IOException {
    HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
    ToscaModelPropertiesBuilder bldr = new ToscaModelPropertiesBuilder(TEST_TARGET_NAMESPACE, "MyProperties");
    bldr.addProperty("key1", "value1");
    bldr.addProperty("key2", "value2");
    // create NodeTypes A B
    String idNodeTypeA = "idA";
    TNodeType nodeTypeA = createTNodeType(idNodeTypeA, TEST_TARGET_NAMESPACE);
    String idNodeTypeB = "idB";
    TNodeType nodeTypeB = createTNodeType(idNodeTypeB, TEST_TARGET_NAMESPACE);
    String idNodeTypeC = "idC";
    TNodeType nodeTypeC = createTNodeType(idNodeTypeC, TEST_TARGET_NAMESPACE);
    NodeTypeId idA = createNodeTypeId(idNodeTypeA);
    NodeTypeId idB = createNodeTypeId(idNodeTypeB);
    NodeTypeId idC = createNodeTypeId(idNodeTypeC);
    allEntities.put(idA, nodeTypeA);
    allEntities.put(idB, nodeTypeB);
    allEntities.put(idC, nodeTypeC);
    // createRelationshipTypes
    String relTypeIdAString = "adRelA";
    RelationshipTypeId relTypeIdA = new RelationshipTypeId(new QName(TEST_TARGET_NAMESPACE, relTypeIdAString));
    TRelationshipType relTypeA = createTRelationshipType(relTypeIdAString, TEST_TARGET_NAMESPACE);
    allEntities.put(relTypeIdA, relTypeA);
    // createNodeTemplates
    TNodeTemplate nodeTemplate1 = createTNodeTemplate("01");
    nodeTemplate1.setType(idA.getQName());
    TNodeTemplate nodeTemplate2 = createTNodeTemplate("02");
    nodeTemplate2.setType(idB.getQName());
    TNodeTemplate nodeTemplate3 = createTNodeTemplate("03");
    nodeTemplate3.setType(idA.getQName());
    nodeTemplate3.setProperties(bldr.build());
    TNodeTemplate nodeTemplate4 = createTNodeTemplate("04");
    nodeTemplate4.setType(idB.getQName());
    TNodeTemplate nodeTemplate5 = createTNodeTemplate("05");
    nodeTemplate5.setType(idA.getQName());
    TNodeTemplate nodeTemplate6 = createTNodeTemplate("06");
    nodeTemplate6.setType(idB.getQName());
    TNodeTemplate nodeTemplate7 = createTNodeTemplate("07");
    nodeTemplate7.setType(idA.getQName());
    nodeTemplate7.setProperties(bldr.build());
    TNodeTemplate nodeTemplate8 = createTNodeTemplate("08");
    nodeTemplate8.setType(idB.getQName());
    TNodeTemplate nodeTemplate9 = createTNodeTemplate("CompletelyUnrelated");
    nodeTemplate9.setType(idC.getQName());
    // create RelationshipTemplates
    TRelationshipTemplate relTemplate1 = createTRelationshipTemplate("1");
    relTemplate1.setSourceNodeTemplate(nodeTemplate1);
    relTemplate1.setTargetNodeTemplate(nodeTemplate2);
    relTemplate1.setType(relTypeIdA.getQName());
    TRelationshipTemplate relTemplate2 = createTRelationshipTemplate("2");
    relTemplate2.setSourceNodeTemplate(nodeTemplate3);
    relTemplate2.setTargetNodeTemplate(nodeTemplate4);
    relTemplate2.setType(relTypeIdA.getQName());
    TRelationshipTemplate relTemplate3 = createTRelationshipTemplate("3");
    relTemplate3.setSourceNodeTemplate(nodeTemplate5);
    relTemplate3.setTargetNodeTemplate(nodeTemplate6);
    relTemplate3.setType(relTypeIdA.getQName());
    TRelationshipTemplate relTemplate4 = createTRelationshipTemplate("4");
    relTemplate4.setSourceNodeTemplate(nodeTemplate7);
    relTemplate4.setTargetNodeTemplate(nodeTemplate8);
    relTemplate4.setType(relTypeIdA.getQName());
    // create TopologyTemplates
    List<TNodeTemplate> nodeTemplates = new ArrayList<>();
    List<TRelationshipTemplate> relationshipTemplates = new ArrayList<>();
    // create identifier
    nodeTemplates.add(nodeTemplate1);
    nodeTemplates.add(nodeTemplate2);
    relationshipTemplates.add(relTemplate1);
    identifier = createTTopologyTemplate(nodeTemplates, relationshipTemplates);
    identifier.setNodeTemplates(nodeTemplates);
    identifier.setRelationshipTemplates(relationshipTemplates);
    nodeTemplates.clear();
    relationshipTemplates.clear();
    // create required structure
    nodeTemplates.add(nodeTemplate3);
    nodeTemplates.add(nodeTemplate4);
    relationshipTemplates.add(relTemplate2);
    requiredStructure = createTTopologyTemplate(nodeTemplates, relationshipTemplates);
    requiredStructure.setNodeTemplates(nodeTemplates);
    requiredStructure.setRelationshipTemplates(relationshipTemplates);
    nodeTemplates.clear();
    relationshipTemplates.clear();
    // create topologyToSearchIn
    nodeTemplates.add(nodeTemplate5);
    nodeTemplates.add(nodeTemplate6);
    nodeTemplates.add(nodeTemplate7);
    nodeTemplates.add(nodeTemplate8);
    relationshipTemplates.add(relTemplate3);
    relationshipTemplates.add(relTemplate4);
    topologyTemplateToSearchIn = createTTopologyTemplate(nodeTemplates, relationshipTemplates);
    topologyTemplateToSearchIn.setNodeTemplates(nodeTemplates);
    topologyTemplateToSearchIn.setRelationshipTemplates(relationshipTemplates);
    nodeTemplates.clear();
    relationshipTemplates.clear();
    // create unrelated topology
    nodeTemplates.add(nodeTemplate9);
    unrelatedTopology = createTTopologyTemplate(nodeTemplates, relationshipTemplates);
    unrelatedTopology.setNodeTemplates(nodeTemplates);
    unrelatedTopology.setRelationshipTemplates(relationshipTemplates);
    nodeTemplates.clear();
    relationshipTemplates.clear();
    persist(allEntities);
}
Also used : RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) ToscaModelHelper.createTNodeType(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeType) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) ToscaModelHelper.createTRelationshipType(org.eclipse.winery.compliance.ToscaModelHelper.createTRelationshipType) ToscaModelHelper.createTRelationshipTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTRelationshipTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ToscaModelHelper.createNodeTypeId(org.eclipse.winery.compliance.ToscaModelHelper.createNodeTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ToscaModelHelper.createTNodeTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeTemplate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)18 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)12 QName (javax.xml.namespace.QName)9 TNodeType (org.eclipse.winery.model.tosca.TNodeType)9 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)9 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)7 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)7 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)7 ArrayList (java.util.ArrayList)6 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)6 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)6 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)6 RequirementTypeId (org.eclipse.winery.model.ids.definitions.RequirementTypeId)6 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)6 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)5 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)5 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)5 HashSet (java.util.HashSet)4