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