Search in sources :

Example 1 with NodeTypeResource

use of org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypeResource in project winery by eclipse.

the class ImplementationArtifactsResource method getInterfacesOfAssociatedType.

/**
 * Method to get all interfaces associated to a nodetype or relationshiptype
 *
 * @return a list of TInterface
 */
@Path("interfaces/")
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<?> getInterfacesOfAssociatedType() {
    // TODO refactor this that IRepository offers this helper method
    boolean isNodeTypeImplementation = this.res instanceof NodeTypeImplementationResource;
    QName type = RestUtils.getType(this.res);
    List<Object> interfaces = new ArrayList<>();
    if (isNodeTypeImplementation) {
        NodeTypeResource typeResource = (NodeTypeResource) new NodeTypesResource().getComponentInstaceResource(type);
        interfaces.addAll(typeResource.getInterfaces().onGet("true"));
    } else {
        RelationshipTypeResource typeResource = (RelationshipTypeResource) new RelationshipTypesResource().getComponentInstaceResource(type);
        interfaces.addAll(typeResource.getSourceInterfaces().onGet("true"));
        interfaces.addAll(typeResource.getTargetInterfaces().onGet("true"));
    }
    return interfaces;
}
Also used : RelationshipTypeResource(org.eclipse.winery.repository.rest.resources.entitytypes.relationshiptypes.RelationshipTypeResource) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) NodeTypeImplementationResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationResource) NodeTypeResource(org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypeResource) RelationshipTypesResource(org.eclipse.winery.repository.rest.resources.entitytypes.relationshiptypes.RelationshipTypesResource) NodeTypesResource(org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypesResource) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with NodeTypeResource

use of org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypeResource 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)

Aggregations

NodeTypeResource (org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypeResource)2 RelationshipTypeResource (org.eclipse.winery.repository.rest.resources.entitytypes.relationshiptypes.RelationshipTypeResource)2 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 QName (javax.xml.namespace.QName)1 TInterface (org.eclipse.winery.model.tosca.TInterface)1 TNodeType (org.eclipse.winery.model.tosca.TNodeType)1 TOperation (org.eclipse.winery.model.tosca.TOperation)1 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)1 NodeTypeImplementationResource (org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationResource)1 NodeTypesResource (org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypesResource)1 RelationshipTypesResource (org.eclipse.winery.repository.rest.resources.entitytypes.relationshiptypes.RelationshipTypesResource)1