Search in sources :

Example 1 with TNodeTypeImplementation

use of org.eclipse.winery.model.tosca.TNodeTypeImplementation in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeImplementationId id) {
    // We have to use a HashSet to ensure that no duplicate ids are added
    // There may be multiple DAs/IAs referencing the same type
    Collection<DefinitionsChildId> ids = new HashSet<>();
    final TNodeTypeImplementation element = this.getElement(id);
    // DAs
    TDeploymentArtifacts deploymentArtifacts = element.getDeploymentArtifacts();
    if (deploymentArtifacts != null) {
        for (TDeploymentArtifact da : deploymentArtifacts.getDeploymentArtifact()) {
            QName qname;
            if ((qname = da.getArtifactRef()) != null) {
                ids.add(new ArtifactTemplateId(qname));
            }
            ids.add(new ArtifactTypeId(da.getArtifactType()));
        }
    }
    // IAs
    return this.getReferencedTOSCAComponentImplementationArtifactIds(ids, element.getImplementationArtifacts(), id);
}
Also used : TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) HashSet(java.util.HashSet)

Example 2 with TNodeTypeImplementation

use of org.eclipse.winery.model.tosca.TNodeTypeImplementation in project winery by eclipse.

the class EnhancementUtils method createFeatureNodeType.

/**
 * This method merges the Basic-NodeType of the given nodeTemplate with the selected Feature-NodeTypes and generates
 * respective implementations.
 *
 * @param nodeTemplate The NodeTemplate that is updated with the selected features.
 * @param featureTypes The list of selected features as generated by {@link #getAvailableFeaturesForTopology(TTopologyTemplate,
 *                     List}.
 * @return The mapping of the generated merged NodeType and the QName of the NodeType it replaces.
 */
public static TNodeType createFeatureNodeType(TNodeTemplate nodeTemplate, Map<QName, String> featureTypes) {
    IRepository repository = RepositoryFactory.getRepository();
    Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class);
    Map<QName, TNodeTypeImplementation> nodeTypeImplementations = repository.getQNameToElementMapping(NodeTypeImplementationId.class);
    StringBuilder featureNames = new StringBuilder();
    featureTypes.values().forEach(featureName -> {
        if (!featureNames.toString().isEmpty()) {
            featureNames.append("-");
        }
        featureNames.append(featureName.replaceAll("\\s", "_"));
    });
    // merge type
    String namespace = generateNewGeneratedNamespace(nodeTemplate.getType());
    TNodeType featureEnrichedNodeType = nodeTypes.get(nodeTemplate.getType());
    featureEnrichedNodeType.setTargetNamespace(namespace);
    featureEnrichedNodeType.setName(nodeTemplate.getType().getLocalPart() + "-" + nodeTemplate.getId() + "-" + featureNames + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1");
    // prepare Properties
    if (Objects.isNull(featureEnrichedNodeType.getWinerysPropertiesDefinition())) {
        WinerysPropertiesDefinition props = new WinerysPropertiesDefinition();
        props.setPropertyDefinitions(new ArrayList<>());
        ModelUtilities.replaceWinerysPropertiesDefinition(featureEnrichedNodeType, props);
    }
    List<PropertyDefinitionKV> baseProperties = featureEnrichedNodeType.getWinerysPropertiesDefinition().getPropertyDefinitions();
    // prepare Interfaces
    if (Objects.isNull(featureEnrichedNodeType.getInterfaces())) {
        featureEnrichedNodeType.setInterfaces(new ArrayList<>());
    }
    List<TInterface> baseInterfaces = featureEnrichedNodeType.getInterfaces();
    // merge impl accordingly
    TNodeTypeImplementation generatedImplementation = new TNodeTypeImplementation.Builder(featureEnrichedNodeType.getName() + "_Impl" + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1", featureEnrichedNodeType.getQName()).build();
    // ensure that the lists are initialized
    generatedImplementation.setImplementationArtifacts(new ArrayList<>());
    generatedImplementation.setDeploymentArtifacts(new ArrayList<>());
    Collection<NodeTypeImplementationId> baseTypeImplementations = repository.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, nodeTemplate.getType());
    if (baseTypeImplementations.size() > 0) {
        for (NodeTypeImplementationId id : baseTypeImplementations) {
            if (Objects.isNull(generatedImplementation.getTargetNamespace())) {
                generatedImplementation.setTargetNamespace(generateNewGeneratedNamespace(id.getQName()));
            }
            addAllDAsAndIAsToImplementation(generatedImplementation, nodeTypeImplementations.get(id.getQName()));
        }
    } else {
        // This should never be the case. However, we implement it as a valid fallback.
        generatedImplementation.setTargetNamespace(namespace.replace("nodetypes", "nodetypeimplementations"));
    }
    featureTypes.keySet().forEach(featureTypeQName -> {
        TNodeType nodeType = nodeTypes.get(featureTypeQName);
        // merge Properties
        if (Objects.nonNull(nodeType.getWinerysPropertiesDefinition())) {
            List<PropertyDefinitionKV> kvList = nodeType.getWinerysPropertiesDefinition().getPropertyDefinitions();
            if (Objects.nonNull(kvList) && !kvList.isEmpty()) {
                for (PropertyDefinitionKV kv : kvList) {
                    boolean listContainsProperty = baseProperties.stream().anyMatch(property -> property.getKey().equals(kv.getKey()));
                    if (!listContainsProperty) {
                        baseProperties.add(kv);
                    }
                }
            }
        }
        // merge Interfaces
        if (Objects.nonNull(nodeType.getInterfaces()) && !nodeType.getInterfaces().isEmpty()) {
            baseInterfaces.addAll(nodeType.getInterfaces());
        }
        // merge implementations
        repository.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, featureTypeQName).forEach(id -> addAllDAsAndIAsToImplementation(generatedImplementation, nodeTypeImplementations.get(id.getQName())));
    });
    // remove them from the type to ensure a compliant XML.
    if (Objects.nonNull(featureEnrichedNodeType.getWinerysPropertiesDefinition()) && Objects.nonNull(featureEnrichedNodeType.getWinerysPropertiesDefinition().getPropertyDefinitions()) && featureEnrichedNodeType.getWinerysPropertiesDefinition().getPropertyDefinitions().isEmpty()) {
        ModelUtilities.removeWinerysPropertiesDefinition(featureEnrichedNodeType);
    }
    try {
        repository.setElement(new NodeTypeId(featureEnrichedNodeType.getQName()), featureEnrichedNodeType);
        repository.setElement(new NodeTypeImplementationId(generatedImplementation.getQName()), generatedImplementation);
    } catch (IOException e) {
        logger.error("Error while saving generated definitions.", e);
    }
    return featureEnrichedNodeType;
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) TInterface(org.eclipse.winery.model.tosca.TInterface) QName(javax.xml.namespace.QName) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) IOException(java.io.IOException) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) TNodeType(org.eclipse.winery.model.tosca.TNodeType) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 3 with TNodeTypeImplementation

use of org.eclipse.winery.model.tosca.TNodeTypeImplementation in project winery by eclipse.

the class EdmmConverter method createOperations.

private void createOperations(TEntityType type, EntityId nodeTypeEntityId, EntityGraph entityGraph) {
    if (type instanceof TNodeType && Objects.nonNull(((TNodeType) type).getInterfaces())) {
        List<TInterface> interfaces = ((TNodeType) type).getInterfaces();
        interfaces.forEach(anInterface -> {
            anInterface.getOperations().forEach(operation -> {
                EntityId operationsEntityId = nodeTypeEntityId.extend(DefaultKeys.OPERATIONS);
                entityGraph.addEntity(new MappingEntity(operationsEntityId, entityGraph));
                TNodeTypeImplementation implementation = nodeTypeImplementations.values().stream().filter(impl -> impl.getNodeType().equals(type.getQName())).findFirst().orElse(null);
                String path = getImplementationForOperation(implementation, anInterface.getName(), operation.getName());
                EntityId operationId = operationsEntityId.extend(operation.getName());
                createPathReferenceEntity(entityGraph, path, operationId);
            });
        });
    }
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) TInterface(org.eclipse.winery.model.tosca.TInterface) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) MappingEntity(io.github.edmm.core.parser.MappingEntity) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 4 with TNodeTypeImplementation

use of org.eclipse.winery.model.tosca.TNodeTypeImplementation 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;
}
Also used : OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TestRefinementModelId(org.eclipse.winery.model.ids.extensions.TestRefinementModelId) TImport(org.eclipse.winery.model.tosca.TImport) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TDataType(org.eclipse.winery.model.tosca.TDataType) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) XSDImportId(org.eclipse.winery.model.ids.definitions.imports.XSDImportId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) TInterfaceType(org.eclipse.winery.model.tosca.TInterfaceType) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 5 with TNodeTypeImplementation

use of org.eclipse.winery.model.tosca.TNodeTypeImplementation in project winery by eclipse.

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeImplementationId id) {
    // We have to use a HashSet to ensure that no duplicate ids are added
    // There may be multiple DAs/IAs referencing the same type
    Collection<DefinitionsChildId> ids = new HashSet<>();
    final TNodeTypeImplementation element = this.getElement(id);
    // DAs
    List<TDeploymentArtifact> deploymentArtifacts = element.getDeploymentArtifacts();
    if (deploymentArtifacts != null) {
        for (TDeploymentArtifact da : deploymentArtifacts) {
            QName qname;
            if ((qname = da.getArtifactRef()) != null) {
                ids.add(new ArtifactTemplateId(qname));
            }
            ids.add(new ArtifactTypeId(da.getArtifactType()));
        }
    }
    // IAs
    return this.getReferencedTOSCAComponentImplementationArtifactIds(ids, element.getImplementationArtifacts(), id);
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) HashSet(java.util.HashSet)

Aggregations

TNodeTypeImplementation (org.eclipse.winery.model.tosca.TNodeTypeImplementation)12 QName (javax.xml.namespace.QName)9 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)7 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)6 TNodeType (org.eclipse.winery.model.tosca.TNodeType)5 HashSet (java.util.HashSet)4 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)4 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)4 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)4 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)4 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)4 IRepository (org.eclipse.winery.repository.backend.IRepository)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)3 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 List (java.util.List)2 Objects (java.util.Objects)2