use of org.eclipse.winery.model.tosca.TArtifactType in project winery by eclipse.
the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.
public static TDefinitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
final TDefinitions definitions = createWrapperDefinitions(id, repository);
HasIdInIdOrNameField element;
if (id instanceof RelationshipTypeImplementationId) {
element = new TRelationshipTypeImplementation();
} else if (id instanceof NodeTypeImplementationId) {
element = new TNodeTypeImplementation();
} else if (id instanceof RequirementTypeId) {
element = new TRequirementType();
} else if (id instanceof NodeTypeId) {
element = new TNodeType();
} else if (id instanceof RelationshipTypeId) {
element = new TRelationshipType();
} else if (id instanceof CapabilityTypeId) {
element = new TCapabilityType();
} else if (id instanceof DataTypeId) {
element = new TDataType();
} else if (id instanceof ArtifactTypeId) {
element = new TArtifactType();
} else if (id instanceof PolicyTypeId) {
element = new TPolicyType();
} else if (id instanceof PolicyTemplateId) {
element = new TPolicyTemplate();
} else if (id instanceof ServiceTemplateId) {
element = new TServiceTemplate();
} else if (id instanceof ArtifactTemplateId) {
element = new TArtifactTemplate();
} else if (id instanceof ComplianceRuleId) {
element = new OTComplianceRule(new OTComplianceRule.Builder(id.getXmlId().getDecoded()));
} else if (id instanceof PatternRefinementModelId) {
element = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder());
} else if (id instanceof TopologyFragmentRefinementModelId) {
element = new OTTopologyFragmentRefinementModel(new OTPatternRefinementModel.Builder());
} else if (id instanceof TestRefinementModelId) {
element = new OTTestRefinementModel(new OTTestRefinementModel.Builder());
} else if (id instanceof InterfaceTypeId) {
element = new TInterfaceType();
} else if (id instanceof XSDImportId) {
// TImport has no id; thus directly generating it without setting an id
TImport tImport = new TImport();
definitions.setElement(tImport);
return definitions;
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
copyIdToFields(element, id);
definitions.setElement((TExtensibleElements) element);
return definitions;
}
use of org.eclipse.winery.model.tosca.TArtifactType in project winery by eclipse.
the class DASpecification method getConcreteDA.
private static TDeploymentArtifact getConcreteDA(TDeploymentArtifact abstractDeploymentArtifact, List<TDeploymentArtifact> candidates) {
for (TDeploymentArtifact candidate : candidates) {
List<TArtifactType> artifactTypeHierarchy = getArtifactTypeHierarchy(getArtifactTypeOfDA(candidate));
TArtifactType abstractArtifactType = getArtifactTypeOfDA(abstractDeploymentArtifact);
for (TArtifactType containedArtifacts : artifactTypeHierarchy) {
// Can not be realized with streams because a check if the abstract Type is contained in the hierarchy doesn't work
if (containedArtifacts.getTargetNamespace().equals(abstractArtifactType.getTargetNamespace()) && containedArtifacts.getName() != null && containedArtifacts.getName().equals(abstractArtifactType.getName())) {
return candidate;
}
}
}
return null;
}
use of org.eclipse.winery.model.tosca.TArtifactType in project winery by eclipse.
the class Y2XConverter method refactorImplementationArtifacts.
private Map<String, TArtifactDefinition> refactorImplementationArtifacts(Map<String, TArtifactDefinition> map, org.eclipse.winery.model.tosca.yaml.TNodeType node) {
Map<String, TArtifactDefinition> implementationArtifacts = new LinkedHashMap<>(map.entrySet().stream().filter(entry -> Objects.nonNull(entry.getValue()) && !referenceVisitor.getTypes(entry.getValue().getType(), "TArtifactType").getNames().contains(Defaults.DEPLOYMENT_ARTIFACTS)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
// Convert Interface.Operations Artifacts to ArtifactDefinition
for (Map.Entry<String, TInterfaceDefinition> entry : node.getInterfaces().entrySet()) {
entry.getValue().getOperations().entrySet().stream().filter(operation -> operation.getValue() != null && operation.getValue().getImplementation() != null).forEach(operation -> {
String interfaceName = entry.getKey();
String operationName = operation.getKey();
TImplementation implementation = operation.getValue().getImplementation();
List<QName> list = implementation.getDependencies();
if (implementation.getPrimary() != null) {
list.add(implementation.getPrimary());
}
for (QName artifactQName : list) {
String artifactName = artifactQName.getLocalPart();
if (implementationArtifacts.containsKey(artifactName)) {
TImplementationArtifactDefinition.Builder iABuilder = new TImplementationArtifactDefinition.Builder(implementationArtifacts.get(artifactName));
TArtifactDefinition old = implementationArtifacts.get(artifactName);
// Check if implementation artifact is already defined for other interfaces
if (!(old instanceof TImplementationArtifactDefinition) || ((TImplementationArtifactDefinition) old).getInterfaceName() == null || ((TImplementationArtifactDefinition) old).getInterfaceName().equals(interfaceName)) {
iABuilder.setInterfaceName(interfaceName);
// Check if ArtifactDefinition is used in more than one operation implementation
if (old instanceof TImplementationArtifactDefinition && ((TImplementationArtifactDefinition) old).getInterfaceName().equals(interfaceName) && !(((TImplementationArtifactDefinition) old).getOperationName().equals(operationName))) {
iABuilder.setOperationName(null);
} else {
iABuilder.setOperationName(operationName);
}
} else {
// if interface is not ImplementationArtifactDefinition
// or interface not set
// or interface already defined
iABuilder.setInterfaceName(null);
}
iABuilder.setOperationName(operationName);
implementationArtifacts.put(artifactName, iABuilder.build());
}
}
});
}
return implementationArtifacts;
}
use of org.eclipse.winery.model.tosca.TArtifactType in project winery by eclipse.
the class DASpecificationTest method getArtifactTypeOfDA.
@Test
public void getArtifactTypeOfDA() throws Exception {
setRevisionTo("af529e513388dc9358a8f700757d8dc59aba3a55");
ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
assertNotNull(topologyTemplate);
TNodeTemplate nodeTemplateWithAbstractDA = topologyTemplate.getNodeTemplate("shetland_pony");
assertNotNull(nodeTemplateWithAbstractDA);
assertNotNull(nodeTemplateWithAbstractDA.getDeploymentArtifacts());
TDeploymentArtifact deploymentArtifact = nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0);
QName artifactTypeQName = deploymentArtifact.getArtifactType();
ArtifactTypeId artifactTypeId = new ArtifactTypeId(artifactTypeQName);
TArtifactType artifactType = this.repository.getElement(artifactTypeId);
assertEquals(artifactType.getTargetNamespace(), DASpecification.getArtifactTypeOfDA(nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0)).getTargetNamespace());
assertEquals(artifactType.getName(), DASpecification.getArtifactTypeOfDA(nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0)).getName());
}
use of org.eclipse.winery.model.tosca.TArtifactType in project winery by eclipse.
the class DASpecificationTest method getArtifactTypeHierarchy.
@Test
public void getArtifactTypeHierarchy() throws Exception {
setRevisionTo("af529e513388dc9358a8f700757d8dc59aba3a55");
ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
assertNotNull(topologyTemplate);
TNodeTemplate nodeTemplate = topologyTemplate.getNodeTemplate("westernequipment");
assertNotNull(nodeTemplate);
assertNotNull(nodeTemplate.getDeploymentArtifacts());
List<TArtifactType> artifactTypes = DASpecification.getArtifactTypeHierarchy(DASpecification.getArtifactTypeOfDA(nodeTemplate.getDeploymentArtifacts().get(0)));
List<String> artifactTypeNames = new ArrayList<>();
artifactTypes.forEach(at -> artifactTypeNames.add(at.getName()));
assertEquals(2, artifactTypes.size());
assertTrue(artifactTypeNames.contains("WesternEquipment_Pony"));
assertTrue(artifactTypeNames.contains("PonyEquipment"));
}
Aggregations