Search in sources :

Example 1 with TImplementationArtifactDefinition

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;
}
Also used : java.util(java.util) SchemaVisitor(org.eclipse.winery.yaml.converter.yaml.visitors.SchemaVisitor) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) TMapRequirementAssignment(org.eclipse.winery.model.tosca.yaml.support.TMapRequirementAssignment) ReferenceVisitor(org.eclipse.winery.yaml.converter.yaml.visitors.ReferenceVisitor) LoggerFactory(org.slf4j.LoggerFactory) Reader(org.eclipse.winery.yaml.common.reader.yaml.Reader) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) Nullable(org.eclipse.jdt.annotation.Nullable) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) Namespaces(org.eclipse.winery.yaml.common.Namespaces) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Defaults(org.eclipse.winery.yaml.common.Defaults) TypeConverter(org.eclipse.winery.yaml.converter.yaml.support.TypeConverter) Path(java.nio.file.Path) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) org.eclipse.winery.model.tosca.yaml(org.eclipse.winery.model.tosca.yaml) TCapabilityDefinition(org.eclipse.winery.model.tosca.TCapabilityDefinition) TEntityType(org.eclipse.winery.model.tosca.TEntityType) Logger(org.slf4j.Logger) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Util(org.eclipse.winery.common.Util) Collectors(java.util.stream.Collectors) File(java.io.File) TImplementationArtifactDefinition(org.eclipse.winery.yaml.converter.yaml.support.extension.TImplementationArtifactDefinition) Stream(java.util.stream.Stream) org.eclipse.winery.model.tosca(org.eclipse.winery.model.tosca) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) Metadata(org.eclipse.winery.model.tosca.yaml.support.Metadata) WriterUtils(org.eclipse.winery.yaml.common.writer.WriterUtils) QName(javax.xml.namespace.QName) NonNull(org.eclipse.jdt.annotation.NonNull) Converter(org.eclipse.winery.yaml.converter.Converter) AssignmentBuilder(org.eclipse.winery.yaml.converter.yaml.support.AssignmentBuilder) QName(javax.xml.namespace.QName) AssignmentBuilder(org.eclipse.winery.yaml.converter.yaml.support.AssignmentBuilder) TImplementationArtifactDefinition(org.eclipse.winery.yaml.converter.yaml.support.extension.TImplementationArtifactDefinition)

Aggregations

File (java.io.File)1 Path (java.nio.file.Path)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 QName (javax.xml.namespace.QName)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Util (org.eclipse.winery.common.Util)1 org.eclipse.winery.model.tosca (org.eclipse.winery.model.tosca)1 TArtifactType (org.eclipse.winery.model.tosca.TArtifactType)1 TCapabilityDefinition (org.eclipse.winery.model.tosca.TCapabilityDefinition)1 TCapabilityType (org.eclipse.winery.model.tosca.TCapabilityType)1 TEntityType (org.eclipse.winery.model.tosca.TEntityType)1 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)1 TNodeType (org.eclipse.winery.model.tosca.TNodeType)1 TPolicyType (org.eclipse.winery.model.tosca.TPolicyType)1 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)1 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)1 TRequirementDefinition (org.eclipse.winery.model.tosca.TRequirementDefinition)1