Search in sources :

Example 1 with ServiceTemplateResource

use of org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource in project winery by eclipse.

the class CapabilitiesResource method addNewElement.

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response addNewElement(@FormParam("name") String name, @FormParam("ref") String reference) {
    if (reference == null) {
        return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build();
    }
    TCapabilityRef ref = new TCapabilityRef();
    // may also be null
    ref.setName(name);
    // The XML model fordces us to put a reference to the object and not just the string
    ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
    TCapability resolved = ModelUtilities.resolveCapability(rs.getServiceTemplate(), reference);
    // In case nothing was found: report back to the user
    if (resolved == null) {
        return Response.status(Status.BAD_REQUEST).entity("Reference could not be resolved").build();
    }
    ref.setRef(resolved);
    // "this.alreadyContains(ref)" cannot be called as this leads to a mappable exception: The data does not contain an id where the given ref attribute may point to
    this.list.add(ref);
    return CollectionsHelper.persist(this.res, this, ref, true);
}
Also used : ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) TCapability(org.eclipse.winery.model.tosca.TCapability) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef)

Example 2 with ServiceTemplateResource

use of org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource in project winery by eclipse.

the class RequirementsResource method addNewElement.

/**
 * Adds an element using form-encoding
 * <p>
 * This is necessary as TRequirementRef contains an IDREF and the XML snippet itself does not contain the target id
 *
 * @param name      the optional name of the requirement
 * @param reference the reference to a requirement in the topology
 */
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response addNewElement(@FormParam("name") String name, @FormParam("ref") String reference) {
    if (reference == null) {
        return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build();
    }
    TRequirementRef ref = new TRequirementRef();
    // may also be null
    ref.setName(name);
    // The XML model forces us to put a reference to the object and not just the string
    ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
    TRequirement resolved = ModelUtilities.resolveRequirement(rs.getServiceTemplate(), reference);
    // In case nothing was found: report back to the user
    if (resolved == null) {
        return Response.status(Status.BAD_REQUEST).entity("Reference could not be resolved").build();
    }
    ref.setRef(resolved);
    // "this.alreadyContains(ref)" cannot be called as this leads to a mappable exception: The data does not contain an id where the given ref attribute may point to
    this.list.add(ref);
    return CollectionsHelper.persist(this.res, this, ref, true);
}
Also used : TRequirement(org.eclipse.winery.model.tosca.TRequirement) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) TRequirementRef(org.eclipse.winery.model.tosca.TRequirementRef)

Example 3 with ServiceTemplateResource

use of org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource in project winery by eclipse.

the class RequirementsResource method addNewElementJSON.

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addNewElementJSON(RequirementsOrCapabilityApiData reqOrCap) {
    if (reqOrCap.ref == null) {
        return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build();
    }
    TRequirementRef ref = new TRequirementRef();
    // may also be null
    ref.setName(reqOrCap.name);
    // The XML model forces us to put a reference to the object and not just the string
    ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
    TRequirement resolved = ModelUtilities.resolveRequirement(rs.getServiceTemplate(), reqOrCap.ref);
    // In case nothing was found: report back to the user
    if (resolved == null) {
        return Response.status(Status.BAD_REQUEST).entity("Reference could not be resolved").build();
    }
    ref.setRef(resolved);
    // "this.alreadyContains(ref)" cannot be called as this leads to a mappable exception: The data does not contain an id where the given ref attribute may point to
    this.list.add(ref);
    return CollectionsHelper.persist(this.res, this, ref, true);
}
Also used : TRequirement(org.eclipse.winery.model.tosca.TRequirement) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) TRequirementRef(org.eclipse.winery.model.tosca.TRequirementRef)

Example 4 with ServiceTemplateResource

use of org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource in project winery by eclipse.

the class CapabilitiesResource method addNewElementJSON.

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addNewElementJSON(RequirementsOrCapabilityApiData reqOrCap) {
    if (reqOrCap.ref == null) {
        return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build();
    }
    TCapabilityRef ref = new TCapabilityRef();
    // may also be null
    ref.setName(reqOrCap.name);
    // The XML model fordces us to put a reference to the object and not just the string
    ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
    TCapability resolved = ModelUtilities.resolveCapability(rs.getServiceTemplate(), reqOrCap.ref);
    // In case nothing was found: report back to the user
    if (resolved == null) {
        return Response.status(Status.BAD_REQUEST).entity("Reference could not be resolved").build();
    }
    ref.setRef(resolved);
    // "this.alreadyContains(ref)" cannot be called as this leads to a mappable exception: The data does not contain an id where the given ref attribute may point to
    this.list.add(ref);
    return CollectionsHelper.persist(this.res, this, ref, true);
}
Also used : ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) TCapability(org.eclipse.winery.model.tosca.TCapability) TCapabilityRef(org.eclipse.winery.model.tosca.TCapabilityRef)

Example 5 with ServiceTemplateResource

use of org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource in project winery by eclipse.

the class PlansResource method saveFile.

private Response saveFile(TPlan tPlan, InputStream uploadedInputStream, FormDataContentDisposition fileDetail, FormDataBodyPart body) {
    boolean bpmn4toscaMode = Namespaces.URI_BPMN4TOSCA_20.equals(tPlan.getPlanLanguage());
    if (uploadedInputStream != null || bpmn4toscaMode) {
        // Determine Id
        PlansId plansId = new PlansId((ServiceTemplateId) ((ServiceTemplateResource) this.res).getId());
        PlanId planId = new PlanId(plansId, new XmlId(tPlan.getId(), false));
        // Ensure overwriting
        if (RepositoryFactory.getRepository().exists(planId)) {
            try {
                RepositoryFactory.getRepository().forceDelete(planId);
                // Quick hack to remove the deleted plan from the plans element
                ((ServiceTemplateResource) this.res).synchronizeReferences();
            } catch (IOException e) {
                return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
            }
        }
        String fileName;
        if (bpmn4toscaMode) {
            fileName = tPlan.getId() + Constants.SUFFIX_BPMN4TOSCA;
            RepositoryFileReference ref = new RepositoryFileReference(planId, fileName);
            // Errors are ignored in the following call
            RestUtils.putContentToFile(ref, "{}", MediaTypes.MEDIATYPE_APPLICATION_JSON);
        } else {
            // We use the filename also as local file name. Alternatively, we could use the xml id
            // With URL encoding, this should not be an issue
            fileName = Util.URLencode(fileDetail.getFileName());
            // Really store it
            RepositoryFileReference ref = new RepositoryFileReference(planId, fileName);
            // Errors are ignored in the following call
            RestUtils.putContentToFile(ref, uploadedInputStream, body.getMediaType());
        }
        PlansResource.setPlanModelReference(tPlan, planId, fileName);
    }
    return RestUtils.persist(this.res);
}
Also used : RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) PlanId(org.eclipse.winery.common.ids.elements.PlanId) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) XmlId(org.eclipse.winery.common.ids.XmlId) IOException(java.io.IOException) PlansId(org.eclipse.winery.common.ids.elements.PlansId)

Aggregations

ServiceTemplateResource (org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource)8 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)3 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 QName (javax.xml.namespace.QName)2 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)2 TCapability (org.eclipse.winery.model.tosca.TCapability)2 TCapabilityRef (org.eclipse.winery.model.tosca.TCapabilityRef)2 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)2 TRequirement (org.eclipse.winery.model.tosca.TRequirement)2 TRequirementRef (org.eclipse.winery.model.tosca.TRequirementRef)2 Select2DataWithOptGroups (org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 XmlId (org.eclipse.winery.common.ids.XmlId)1 PlanId (org.eclipse.winery.common.ids.elements.PlanId)1