Search in sources :

Example 1 with TRelationshipType

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

the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.

public static Definitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
    final Definitions definitions = createWrapperDefinitions(id);
    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 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 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 : ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TImport(org.eclipse.winery.model.tosca.TImport) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) NodeTypeImplementationId(org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId) XSDImportId(org.eclipse.winery.common.ids.definitions.imports.XSDImportId) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) Definitions(org.eclipse.winery.model.tosca.Definitions) RelationshipTypeImplementationId(org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 2 with TRelationshipType

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

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RelationshipTypeId id) {
    Collection<DefinitionsChildId> ids = new ArrayList<>();
    // add all implementations
    Collection<RelationshipTypeImplementationId> allTypeImplementations = this.getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, id.getQName());
    for (RelationshipTypeImplementationId ntiId : allTypeImplementations) {
        ids.add(ntiId);
    }
    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);
        }
    }
    return ids;
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) ArrayList(java.util.ArrayList) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId) RelationshipTypeImplementationId(org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId)

Example 3 with TRelationshipType

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

the class InterfacesResource method onPost.

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response onPost(List<TInterface> interfaceApiData) {
    if (!interfaceApiData.isEmpty()) {
        for (TInterface tInt : interfaceApiData) {
            if (!tInt.getOperation().isEmpty()) {
                for (TOperation tOp : tInt.getOperation()) {
                    if (tOp.getInputParameters() == null || tOp.getInputParameters().getInputParameter().isEmpty()) {
                        tOp.setInputParameters(null);
                    }
                    if (tOp.getOutputParameters() == null || tOp.getOutputParameters().getOutputParameter().isEmpty()) {
                        tOp.setOutputParameters(null);
                    }
                }
            } else {
                return Response.status(Response.Status.BAD_REQUEST).entity("No operation provided!").build();
            }
        }
    } else {
        return Response.status(Response.Status.BAD_REQUEST).entity("No interface provided!").build();
    }
    if (this.res instanceof RelationshipTypeResource) {
        TRelationshipType relationshipType = (TRelationshipType) this.res.getElement();
        switch(this.interfaceType) {
            case "source":
                TRelationshipType.SourceInterfaces sourceInterfaces = new TRelationshipType.SourceInterfaces();
                sourceInterfaces.getInterface().clear();
                sourceInterfaces.getInterface().addAll(interfaceApiData);
                relationshipType.setSourceInterfaces(sourceInterfaces);
                break;
            default:
                // it will be target
                TRelationshipType.TargetInterfaces targetInterfaces = new TRelationshipType.TargetInterfaces();
                targetInterfaces.getInterface().clear();
                targetInterfaces.getInterface().addAll(interfaceApiData);
                relationshipType.setTargetInterfaces(targetInterfaces);
                break;
        }
    } else if (this.res instanceof NodeTypeResource) {
        TNodeType nodeType = (TNodeType) this.res.getElement();
        TNodeType.Interfaces interfaces = new TNodeType.Interfaces();
        interfaces.getInterface().clear();
        interfaces.getInterface().addAll(interfaceApiData);
        nodeType.setInterfaces(interfaces);
    } else {
        throw new IllegalStateException("Interfaces are not supported for this element type!");
    }
    return RestUtils.persist(this.res);
}
Also used : TInterface(org.eclipse.winery.model.tosca.TInterface) RelationshipTypeResource(org.eclipse.winery.repository.rest.resources.entitytypes.relationshiptypes.RelationshipTypeResource) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TOperation(org.eclipse.winery.model.tosca.TOperation) NodeTypeResource(org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypeResource)

Example 4 with TRelationshipType

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

the class NodeTemplateConnector method findRelationshipType.

/**
 * Searches a compatible {@link TRelationshipType} to connect two {@link TNodeTemplate}s.
 *
 * @param source        the source {@link TNodeTemplate}
 * @param target        the target {@link TNodeTemplate}
 * @param toscaAnalyzer the {@link TOSCAAnalyzer} object to access the data model
 * @param requirement   the {@link TRequirement} of the source {@link TNodeTemplate}
 * @return a list of suitable {@link TRelationshipType}s
 */
public static List<TRelationshipType> findRelationshipType(TNodeTemplate source, TNodeTemplate target, TOSCAAnalyzer toscaAnalyzer, TRequirement requirement) {
    List<TRelationshipType> suitableRelationshipTypes = new ArrayList<TRelationshipType>();
    List<TRelationshipType> allRelationshipTypes = toscaAnalyzer.getRelationshipTypes();
    // in case the connection to a placeholder is searched, no requirement exists
    if (requirement != null) {
        List<TCapability> capabilities = target.getCapabilities().getCapability();
        // check if a RelationshipType can connect a requirement of the source NodeTemplate to a capability of the target NodeTemplate
        for (TRelationshipType relationshipType : allRelationshipTypes) {
            if (relationshipType.getValidSource() != null && relationshipType.getValidTarget() != null) {
                for (TCapability capability : capabilities) {
                    if ((relationshipType.getValidSource().getTypeRef().equals(requirement.getType()) && relationshipType.getValidTarget().getTypeRef().equals(capability.getType()))) {
                        suitableRelationshipTypes.add(relationshipType);
                    }
                }
            }
        }
    }
    // to extend the selection check if a RelationshipType can connect the type of the source NodeTemplate to the type of the target NodeTemplate
    for (TRelationshipType rt : allRelationshipTypes) {
        if (rt.getValidSource() != null && rt.getValidTarget() != null) {
            if ((rt.getValidSource().getTypeRef().equals(source.getType()) && rt.getValidTarget().getTypeRef().equals(target.getType()))) {
                suitableRelationshipTypes.add(rt);
            }
        }
    }
    // in case no suitable relationship type could be found, search for generic types without the optional ValidSource / ValidTarget elements.
    if (suitableRelationshipTypes.isEmpty()) {
        for (TRelationshipType rt : allRelationshipTypes) {
            if (rt.getValidSource() == null && rt.getValidTarget() == null) {
                suitableRelationshipTypes.add(rt);
            }
        }
    }
    return suitableRelationshipTypes;
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) ArrayList(java.util.ArrayList) TCapability(org.eclipse.winery.model.tosca.TCapability)

Example 5 with TRelationshipType

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

the class TOSCAModelHelper method createTRelationshipType.

public static TRelationshipType createTRelationshipType(String id, String namespace) {
    TRelationshipType relationshipType = new TRelationshipType();
    relationshipType.setName(id);
    relationshipType.setId(id);
    relationshipType.setTargetNamespace(namespace);
    return relationshipType;
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType)

Aggregations

TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)6 ArrayList (java.util.ArrayList)3 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)3 TNodeType (org.eclipse.winery.model.tosca.TNodeType)3 QName (javax.xml.namespace.QName)2 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)2 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)2 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)2 RelationshipTypeImplementationId (org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId)2 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 HashMap (java.util.HashMap)1 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)1 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)1 NodeTypeImplementationId (org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId)1 PolicyTemplateId (org.eclipse.winery.common.ids.definitions.PolicyTemplateId)1 PolicyTypeId (org.eclipse.winery.common.ids.definitions.PolicyTypeId)1 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)1 XSDImportId (org.eclipse.winery.common.ids.definitions.imports.XSDImportId)1 TOSCAModelHelper.createNodeTypeId (org.eclipse.winery.compliance.TOSCAModelHelper.createNodeTypeId)1