Search in sources :

Example 6 with CapabilityTypeId

use of org.eclipse.winery.model.ids.definitions.CapabilityTypeId 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 7 with CapabilityTypeId

use of org.eclipse.winery.model.ids.definitions.CapabilityTypeId in project winery by eclipse.

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RelationshipTypeId id) {
    // add all implementations
    Collection<DefinitionsChildId> ids = new ArrayList<>(this.getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, id.getQName()));
    final TRelationshipType relationshipType = this.getElement(id);
    TRelationshipType.ValidSource validSource = relationshipType.getValidSource();
    if (validSource != null) {
        QName typeRef = validSource.getTypeRef();
        // can be a node type or a requirement type
        // similar code as for valid target (difference: req/cap)
        NodeTypeId ntId = new NodeTypeId(typeRef);
        if (this.exists(ntId)) {
            ids.add(ntId);
        } else {
            RequirementTypeId rtId = new RequirementTypeId(typeRef);
            ids.add(rtId);
        }
    }
    TRelationshipType.ValidTarget validTarget = relationshipType.getValidTarget();
    if (validTarget != null) {
        QName typeRef = validTarget.getTypeRef();
        // can be a node type or a capability type
        // similar code as for valid target (difference: req/cap)
        NodeTypeId ntId = new NodeTypeId(typeRef);
        if (this.exists(ntId)) {
            ids.add(ntId);
        } else {
            CapabilityTypeId capId = new CapabilityTypeId(typeRef);
            ids.add(capId);
        }
    }
    List<QName> validTargetList = relationshipType.getValidTargetList();
    if (validTargetList != null) {
        for (QName typeRef : validTargetList) {
            CapabilityTypeId capId = new CapabilityTypeId(typeRef);
            if (this.exists(capId)) {
                ids.add(capId);
            }
        }
    }
    getReferencedDefinitionsOfProperties(ids, relationshipType.getProperties());
    return ids;
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) 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) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)

Example 8 with CapabilityTypeId

use of org.eclipse.winery.model.ids.definitions.CapabilityTypeId in project winery by eclipse.

the class RequiredCapabilityTypeResource method putRequiredCapabilityType.

@PUT
@Consumes(MediaType.TEXT_PLAIN)
public Response putRequiredCapabilityType(String type) {
    if (StringUtils.isEmpty(type)) {
        return Response.status(Status.BAD_REQUEST).entity("type must not be empty").build();
    }
    QName qname = QName.valueOf(type);
    CapabilityTypeId id = new CapabilityTypeId(qname);
    if (RepositoryFactory.getRepository().exists(id)) {
        // everything allright. Store new reference
        this.getRequirementType().setRequiredCapabilityType(qname);
        return RestUtils.persist(this.requirementTypeResource);
    } else {
        throw new NotFoundException("Given QName could not be resolved to an existing capability type");
    }
}
Also used : CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) NotFoundException(javax.ws.rs.NotFoundException) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 9 with CapabilityTypeId

use of org.eclipse.winery.model.ids.definitions.CapabilityTypeId in project winery by eclipse.

the class VersionSupport method getDefinitionInTheGivenVersion.

public static DefinitionsChildId getDefinitionInTheGivenVersion(DefinitionsChildId childId, WineryVersion otherVersion) {
    if (childId.getVersion().compareTo(otherVersion) == 0) {
        return childId;
    }
    String localPart = childId.getNameWithoutVersion() + (otherVersion.toString().length() > 0 ? WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + otherVersion.toString() : "");
    QName qName = new QName(childId.getNamespace().getDecoded(), localPart);
    if (childId instanceof RelationshipTypeImplementationId) {
        return new RelationshipTypeImplementationId(qName);
    } else if (childId instanceof NodeTypeImplementationId) {
        return new NodeTypeImplementationId(qName);
    } else if (childId instanceof RequirementTypeId) {
        return new RequirementTypeId(qName);
    } else if (childId instanceof NodeTypeId) {
        return new NodeTypeId(qName);
    } else if (childId instanceof RelationshipTypeId) {
        return new RelationshipTypeId(qName);
    } else if (childId instanceof CapabilityTypeId) {
        return new CapabilityTypeId(qName);
    } else if (childId instanceof ArtifactTypeId) {
        return new ArtifactTypeId(qName);
    } else if (childId instanceof PolicyTypeId) {
        return new PolicyTypeId(qName);
    } else if (childId instanceof PolicyTemplateId) {
        return new PolicyTemplateId(qName);
    } else if (childId instanceof ServiceTemplateId) {
        return new ServiceTemplateId(qName);
    } else if (childId instanceof ArtifactTemplateId) {
        return new ArtifactTemplateId(qName);
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId)

Example 10 with CapabilityTypeId

use of org.eclipse.winery.model.ids.definitions.CapabilityTypeId in project winery by eclipse.

the class YamlRepository method getRequestedDefinition.

/**
 * Parses only requested Definition from converted yaml service template
 *
 * @param id          Definitions Child id
 * @param definitions converted definitions
 * @return requested definitions
 */
private TDefinitions getRequestedDefinition(DefinitionsChildId id, TDefinitions definitions) {
    if (id instanceof ArtifactTemplateId) {
        String artifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
        List<TArtifactTemplate> artifactTemplates = definitions.getArtifactTemplates();
        List<TArtifactTemplate> requestedArtifactTemplates = new ArrayList<>();
        for (TArtifactTemplate artifactTemplate : artifactTemplates) {
            if (artifactTemplate.getId().equalsIgnoreCase(artifactName)) {
                requestedArtifactTemplates.add(artifactTemplate);
                TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
                requestedDefinitions.addArtifactTemplates(requestedArtifactTemplates);
                return requestedDefinitions.build();
            }
        }
        // we did not find the artifact template id (this should not happen!)
        LOGGER.error("requested artifact template id (" + id.toReadableString() + ") cannot be extracted from definitions object!");
        return definitions;
    } else {
        TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
        if (id instanceof NodeTypeId) {
            requestedDefinitions.addNodeTypes(definitions.getNodeTypes());
        } else if (id instanceof RelationshipTypeId) {
            requestedDefinitions.addRelationshipTypes(definitions.getRelationshipTypes());
        } else if (id instanceof NodeTypeImplementationId) {
            requestedDefinitions.addNodeTypeImplementations(definitions.getNodeTypeImplementations());
        } else if (id instanceof RelationshipTypeImplementationId) {
            requestedDefinitions.addRelationshipTypeImplementations(definitions.getRelationshipTypeImplementations());
        } else if (id instanceof ArtifactTypeId) {
            requestedDefinitions.addArtifactTypes(definitions.getArtifactTypes());
        } else if (id instanceof CapabilityTypeId) {
            requestedDefinitions.addCapabilityTypes(definitions.getCapabilityTypes());
        } else if (id instanceof DataTypeId) {
            requestedDefinitions.addDataTypes(definitions.getDataTypes());
        } else if (id instanceof RequirementTypeId) {
            requestedDefinitions.addRequirementTypes(definitions.getRequirementTypes());
        } else if (id instanceof PolicyTypeId) {
            requestedDefinitions.addPolicyTypes(definitions.getPolicyTypes());
        } else if (id instanceof InterfaceTypeId) {
            requestedDefinitions.addInterfaceTypes(definitions.getInterfaceTypes());
        } else {
            // we do not need to filter anything
            return definitions;
        }
        return requestedDefinitions.build();
    }
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ArrayList(java.util.ArrayList) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions)

Aggregations

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