Search in sources :

Example 1 with TRequirementType

use of org.eclipse.winery.model.tosca.TRequirementType 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 2 with TRequirementType

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

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RequirementTypeId id) {
    Collection<DefinitionsChildId> ids = new ArrayList<>(1);
    final TRequirementType element = this.getElement(id);
    QName requiredCapabilityType = element.getRequiredCapabilityType();
    if (requiredCapabilityType != null) {
        CapabilityTypeId capId = new CapabilityTypeId(requiredCapabilityType);
        ids.add(capId);
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType)

Example 3 with TRequirementType

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

the class Splitting method getRequiredCapabilityTypeQNameOfRequirement.

public QName getRequiredCapabilityTypeQNameOfRequirement(TRequirement requirement) {
    QName reqTypeQName = requirement.getType();
    RequirementTypeId reqTypeId = new RequirementTypeId(reqTypeQName);
    TRequirementType requirementType = RepositoryFactory.getRepository().getElement(reqTypeId);
    return requirementType.getRequiredCapabilityType();
}
Also used : QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType)

Example 4 with TRequirementType

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

the class Splitting method getMatchingRelationshipType.

/**
 */
private TRelationshipType getMatchingRelationshipType(TRequirement requirement, TCapability capability) {
    TRelationshipType matchingRelationshipType = null;
    SortedSet<RelationshipTypeId> relTypeIds = RepositoryFactory.getRepository().getAllDefinitionsChildIds(RelationshipTypeId.class);
    List<TRelationshipType> relationshipTypes = new ArrayList<>();
    for (RelationshipTypeId id : relTypeIds) {
        relationshipTypes.add(RepositoryFactory.getRepository().getElement(id));
    }
    Map<String, String> requirementProperties = ModelUtilities.getPropertiesKV(requirement);
    Map<String, String> capabilityProperties = ModelUtilities.getPropertiesKV(capability);
    /* If the property "requiredRelationshipType" is defined for the requirement and the capability this relationship type
           has to be taken - if the specified relationship type is not available, no relationship type is chosen */
    if (requirementProperties != null && capabilityProperties != null && requirementProperties.containsKey("requiredRelationshipType") && capabilityProperties.containsKey("requiredRelationshipType") && requirementProperties.get("requiredRelationshipType").equals(capabilityProperties.get("requiredRelationshipType")) && requirementProperties.get("requiredRelationshipType") != null) {
        // Assumption: We work on basic KV properties here
        QName referencedRelationshipType = QName.valueOf((String) requirementProperties.get("requiredRelationshipType"));
        RelationshipTypeId relTypeId = new RelationshipTypeId(referencedRelationshipType);
        if (relTypeIds.stream().anyMatch(rti -> rti.equals(relTypeId))) {
            return RepositoryFactory.getRepository().getElement(relTypeId);
        }
    } else {
        QName requirementTypeQName = requirement.getType();
        RequirementTypeId reqTypeId = new RequirementTypeId(requirement.getType());
        TRequirementType requirementType = RepositoryFactory.getRepository().getElement(reqTypeId);
        QName capabilityTypeQName = capability.getType();
        CapabilityTypeId capTypeId = new CapabilityTypeId(capability.getType());
        TCapabilityType capabilityType = RepositoryFactory.getRepository().getElement(capTypeId);
        List<TRelationshipType> availableMatchingRelationshipTypes = new ArrayList<>();
        availableMatchingRelationshipTypes.clear();
        while (requirementType != null && capabilityType != null) {
            // relationship type with valid source origin requirement type or empty and valid target origin capability type
            for (TRelationshipType rt : relationshipTypes) {
                if ((rt.getValidSource() == null || rt.getValidSource().getTypeRef().equals(requirementTypeQName)) && (rt.getValidTarget() != null && rt.getValidTarget().getTypeRef().equals(capabilityTypeQName))) {
                    availableMatchingRelationshipTypes.add(rt);
                }
            }
            if (!availableMatchingRelationshipTypes.isEmpty() && availableMatchingRelationshipTypes.size() == 1) {
                return availableMatchingRelationshipTypes.get(0);
            } else if (!availableMatchingRelationshipTypes.isEmpty() && availableMatchingRelationshipTypes.size() > 1) {
                return null;
            } else if (requirementType.getDerivedFrom() != null || capabilityType.getDerivedFrom() != null) {
                TCapabilityType derivedFromCapabilityType = null;
                TRequirementType derivedFromRequirementType = null;
                availableMatchingRelationshipTypes.clear();
                List<TRelationshipType> additionalMatchingRelationshipTypes = new ArrayList<>();
                if (capabilityType.getDerivedFrom() != null) {
                    QName derivedFromCapabilityTypeRef = capabilityType.getDerivedFrom().getTypeRef();
                    CapabilityTypeId derivedFromCapTypeId = new CapabilityTypeId(derivedFromCapabilityTypeRef);
                    derivedFromCapabilityType = RepositoryFactory.getRepository().getElement(derivedFromCapTypeId);
                    for (TRelationshipType rt : relationshipTypes) {
                        if ((rt.getValidSource() == null || rt.getValidSource().getTypeRef().equals(requirementTypeQName)) && (rt.getValidTarget() != null && rt.getValidTarget().getTypeRef().equals(derivedFromCapabilityTypeRef))) {
                            availableMatchingRelationshipTypes.add(rt);
                        }
                    }
                }
                if (requirementType.getDerivedFrom() != null) {
                    QName derivedFromRequirementTypeRef = requirementType.getDerivedFrom().getTypeRef();
                    RequirementTypeId derivedFromReqTypeId = new RequirementTypeId(derivedFromRequirementTypeRef);
                    derivedFromRequirementType = RepositoryFactory.getRepository().getElement(derivedFromReqTypeId);
                    for (TRelationshipType rt : relationshipTypes) {
                        if ((rt.getValidSource() != null && rt.getValidSource().getTypeRef().equals(derivedFromRequirementTypeRef)) && (rt.getValidTarget() != null && rt.getValidTarget().getTypeRef().equals(capabilityTypeQName))) {
                            additionalMatchingRelationshipTypes.add(rt);
                        }
                    }
                }
                availableMatchingRelationshipTypes.addAll(additionalMatchingRelationshipTypes);
                if (!availableMatchingRelationshipTypes.isEmpty() && availableMatchingRelationshipTypes.size() == 1) {
                    return availableMatchingRelationshipTypes.get(0);
                } else if (!availableMatchingRelationshipTypes.isEmpty() && availableMatchingRelationshipTypes.size() > 1) {
                    return null;
                }
                requirementType = derivedFromRequirementType;
                capabilityType = derivedFromCapabilityType;
            }
        }
        TCapabilityType basisCapabilityType = getBasisCapabilityType(capability.getType());
        for (TRelationshipType relationshipType : relationshipTypes) {
            if (basisCapabilityType != null && basisCapabilityType.getName().equalsIgnoreCase("container") && relationshipType.getName().equalsIgnoreCase("hostedon") && relationshipType.getValidSource() == null && (relationshipType.getValidTarget() == null || relationshipType.getValidTarget().getTypeRef().getLocalPart().equalsIgnoreCase("container"))) {
                return relationshipType;
            }
            if (basisCapabilityType != null && basisCapabilityType.getName().equalsIgnoreCase("endpoint") && relationshipType.getName().equalsIgnoreCase("connectsto") && relationshipType.getValidSource() == null && (relationshipType.getValidTarget() == null || relationshipType.getValidTarget().getTypeRef().getLocalPart().equalsIgnoreCase("endpoint"))) {
                return relationshipType;
            }
        }
    }
    return matchingRelationshipType;
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) ArrayList(java.util.ArrayList) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType)

Example 5 with TRequirementType

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

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RequirementTypeId id) {
    Collection<DefinitionsChildId> ids = new ArrayList<>(1);
    final TRequirementType element = this.getElement(id);
    QName requiredCapabilityType = element.getRequiredCapabilityType();
    if (requiredCapabilityType != null) {
        CapabilityTypeId capId = new CapabilityTypeId(requiredCapabilityType);
        ids.add(capId);
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType)

Aggregations

TRequirementType (org.eclipse.winery.model.tosca.TRequirementType)5 QName (javax.xml.namespace.QName)4 ArrayList (java.util.ArrayList)3 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)3 RequirementTypeId (org.eclipse.winery.model.ids.definitions.RequirementTypeId)3 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)2 TCapabilityType (org.eclipse.winery.model.tosca.TCapabilityType)2 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)2 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)1 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)1 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)1 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)1 DataTypeId (org.eclipse.winery.model.ids.definitions.DataTypeId)1 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)1 InterfaceTypeId (org.eclipse.winery.model.ids.definitions.InterfaceTypeId)1 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)1 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)1 PolicyTemplateId (org.eclipse.winery.model.ids.definitions.PolicyTemplateId)1 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)1 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)1