Search in sources :

Example 1 with TExportedOperation

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

the class InterfacesResource method onPost.

/**
 * A special handling for TExportedInterface is required as this object uses IDREF, which must not be a string, but
 * the real object when persisting.
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response onPost(TExportedInterface[] exportedInterfacesList) {
    if (exportedInterfacesList == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity("a valid XML/JSON element has to be posted").build();
    }
    for (TExportedInterface exportedInterface : exportedInterfacesList) {
        for (TExportedOperation exportedOperation : exportedInterface.getOperation()) {
            if (exportedOperation.getNodeOperation() != null) {
                final String nodeRef = (String) exportedOperation.getNodeOperation().getNodeRef();
                final TNodeTemplate nodeTemplate = ((ServiceTemplateResource) res).getServiceTemplate().getTopologyTemplate().getNodeTemplates().stream().filter(node -> node.getId().contentEquals(nodeRef)).findFirst().get();
                exportedOperation.getNodeOperation().setNodeRef(nodeTemplate);
            } else if (exportedOperation.getRelationshipOperation() != null) {
                final String relationshipRef = (String) exportedOperation.getRelationshipOperation().getRelationshipRef();
                final TRelationshipTemplate relationshipTemplate = ((ServiceTemplateResource) res).getServiceTemplate().getTopologyTemplate().getRelationshipTemplates().stream().filter(relationship -> relationship.getId().contentEquals(relationshipRef)).findFirst().get();
                exportedOperation.getRelationshipOperation().setRelationshipRef(relationshipTemplate);
            } else if (exportedOperation.getPlan() != null) {
                final String planRef = (String) exportedOperation.getPlan().getPlanRef();
                final TPlan planTemplate = ((ServiceTemplateResource) res).getServiceTemplate().getPlans().stream().filter(relationship -> relationship.getId().contentEquals(planRef)).findFirst().get();
                exportedOperation.getPlan().setPlanRef(planTemplate);
            } else {
                return Response.status(Response.Status.BAD_REQUEST).entity("No linked operation provided").build();
            }
        }
    }
    this.list.clear();
    this.list.addAll(Arrays.asList(exportedInterfacesList));
    return RestUtils.persist(this.res);
}
Also used : Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) EntityWithIdCollectionResource(org.eclipse.winery.repository.rest.resources._support.collections.withid.EntityWithIdCollectionResource) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) TExportedInterface(org.eclipse.winery.model.tosca.TExportedInterface) Consumes(javax.ws.rs.Consumes) Response(javax.ws.rs.core.Response) TPlan(org.eclipse.winery.model.tosca.TPlan) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) IPersistable(org.eclipse.winery.repository.rest.resources._support.IPersistable) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) RestUtils(org.eclipse.winery.repository.rest.RestUtils) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TExportedOperation(org.eclipse.winery.model.tosca.TExportedOperation) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TExportedInterface(org.eclipse.winery.model.tosca.TExportedInterface) TPlan(org.eclipse.winery.model.tosca.TPlan) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TExportedOperation(org.eclipse.winery.model.tosca.TExportedOperation) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with TExportedOperation

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

the class ToCanonical method convert.

private TExportedOperation convert(XTExportedOperation xml) {
    TExportedOperation canonical = new TExportedOperation(xml.getName());
    if (xml.getNodeOperation() != null) {
        canonical.setNodeOperation(convert(xml.getNodeOperation()));
    }
    if (xml.getRelationshipOperation() != null) {
        canonical.setRelationshipOperation(convert(xml.getRelationshipOperation()));
    }
    if (xml.getPlan() != null) {
        TExportedOperation.Plan plan = new TExportedOperation.Plan();
        if (xml.getPlan().getPlanRef() instanceof String) {
            plan.setPlanRef(xml.getPlan().getPlanRef());
        } else {
            plan.setPlanRef(convert((XTPlan) xml.getPlan().getPlanRef()));
        }
        canonical.setPlan(plan);
    }
    return canonical;
}
Also used : XTPlan(org.eclipse.winery.model.tosca.xml.XTPlan) XTPlan(org.eclipse.winery.model.tosca.xml.XTPlan) TPlan(org.eclipse.winery.model.tosca.TPlan) XTExportedOperation(org.eclipse.winery.model.tosca.xml.XTExportedOperation) TExportedOperation(org.eclipse.winery.model.tosca.TExportedOperation)

Aggregations

TExportedOperation (org.eclipse.winery.model.tosca.TExportedOperation)2 TPlan (org.eclipse.winery.model.tosca.TPlan)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 TExportedInterface (org.eclipse.winery.model.tosca.TExportedInterface)1 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)1 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)1 XTExportedOperation (org.eclipse.winery.model.tosca.xml.XTExportedOperation)1 XTPlan (org.eclipse.winery.model.tosca.xml.XTPlan)1 RestUtils (org.eclipse.winery.repository.rest.RestUtils)1 IPersistable (org.eclipse.winery.repository.rest.resources._support.IPersistable)1 EntityWithIdCollectionResource (org.eclipse.winery.repository.rest.resources._support.collections.withid.EntityWithIdCollectionResource)1 ServiceTemplateResource (org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource)1