Search in sources :

Example 51 with NodeTypeId

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

the class ThreatModelingUtilsWithGitBackendRepositoryTest method checkFindFirstAbstractTypeThatInheritsFromSVNF.

@Test
public void checkFindFirstAbstractTypeThatInheritsFromSVNF() throws Exception {
    this.setRevisionTo("origin/plain");
    String namespace = "http://example.com";
    QName base = new QName(namespace, "base");
    QName childA = new QName(namespace, "childA");
    QName childB = new QName(namespace, "childB");
    QName notDerivedOrAbstract = new QName(namespace, "notDerivedOrAbstract");
    TNodeType baseType = new TNodeType.Builder("base").setDerivedFrom(QName.valueOf(ThreatModelingConstants.SVNF_NODE_TYPE)).setAbstract(true).build();
    TNodeType childAType = new TNodeType.Builder("childA").setDerivedFrom(base).build();
    TNodeType childBType = new TNodeType.Builder("childB").setDerivedFrom(childA).build();
    TNodeType notDerivedOrAbstractType = new TNodeType.Builder("notDerivedOrAbstract").build();
    repository.setElement(new NodeTypeId(base), baseType);
    repository.setElement(new NodeTypeId(childA), childAType);
    repository.setElement(new NodeTypeId(childB), childBType);
    repository.setElement(new NodeTypeId(notDerivedOrAbstract), notDerivedOrAbstractType);
    ThreatModelingUtils tmu = new ThreatModelingUtils(repository);
    assertEquals(base, tmu.findFirstAbstractType(base));
    assertEquals(base, tmu.findFirstAbstractType(childA));
    assertEquals(base, tmu.findFirstAbstractType(childB));
    assertThrows(Exception.class, () -> tmu.findFirstAbstractType(notDerivedOrAbstract));
}
Also used : QName(javax.xml.namespace.QName) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Test(org.junit.jupiter.api.Test)

Example 52 with NodeTypeId

use of org.eclipse.winery.model.ids.definitions.NodeTypeId 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 53 with NodeTypeId

use of org.eclipse.winery.model.ids.definitions.NodeTypeId 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 54 with NodeTypeId

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

the class ToCanonical method getCapabilityDefinitionOfCapabilityName.

/**
 * Gets a Capability Definition corresponding to the passed capName such that it is the lowest in the type ancestry
 * of the corresponding nodeType. If no such Capability Definition is found, it returns null.
 */
private TCapabilityDefinition getCapabilityDefinitionOfCapabilityName(String capName, QName nodeType) {
    List<HasInheritance> ancestry = InheritanceUtils.getInheritanceHierarchy(new NodeTypeId(nodeType), context);
    List<TCapabilityDefinition> currentCapDefs;
    for (HasInheritance currentNT : ancestry) {
        assert currentNT instanceof TNodeType;
        if (((TNodeType) currentNT).getCapabilityDefinitions() != null) {
            currentCapDefs = ((TNodeType) currentNT).getCapabilityDefinitions();
            for (TCapabilityDefinition currentDef : currentCapDefs) {
                if (currentDef.getName().equals(capName)) {
                    return currentDef;
                }
            }
        }
    }
    return null;
}
Also used : HasInheritance(org.eclipse.winery.model.tosca.HasInheritance) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TCapabilityDefinition(org.eclipse.winery.model.tosca.TCapabilityDefinition) YTCapabilityDefinition(org.eclipse.winery.model.tosca.yaml.YTCapabilityDefinition) YTNodeType(org.eclipse.winery.model.tosca.yaml.YTNodeType) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 55 with NodeTypeId

use of org.eclipse.winery.model.ids.definitions.NodeTypeId 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

NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)67 TNodeType (org.eclipse.winery.model.tosca.TNodeType)36 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 Test (org.junit.jupiter.api.Test)27 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)23 QName (javax.xml.namespace.QName)21 IRepository (org.eclipse.winery.repository.backend.IRepository)20 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)15 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)15 WineryVersion (org.eclipse.winery.common.version.WineryVersion)14 Response (javax.ws.rs.core.Response)13 IOException (java.io.IOException)12 LinkedHashMap (java.util.LinkedHashMap)12 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)11 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)11 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)10 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)10 ArrayList (java.util.ArrayList)9 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)9 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)9