use of org.eclipse.winery.yaml.converter.yaml.support.extension.TImplementationArtifactDefinition 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;
}
Aggregations