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));
}
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();
}
}
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;
}
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;
}
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);
}
Aggregations