Search in sources :

Example 1 with TRequirementRef

use of org.eclipse.winery.model.tosca.TRequirementRef 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 2 with TRequirementRef

use of org.eclipse.winery.model.tosca.TRequirementRef 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)

Aggregations

TRequirement (org.eclipse.winery.model.tosca.TRequirement)2 TRequirementRef (org.eclipse.winery.model.tosca.TRequirementRef)2 ServiceTemplateResource (org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource)2