@POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response addNewElement(@FormParam("name") String name, @FormParam("ref") String reference) { // Implementation adapted from super addNewElement if (reference == null) { return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build(); } TCapabilityRef ref = new TCapabilityRef(); ref.setName(name); // may also be null // 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); }
@POST @Consumes(MediaType.APPLICATION_JSON) public Response addNewElementJSON(RequirementsOrCapabilityApiData reqOrCap) { // Implementation adapted from super addNewElement if (reqOrCap.ref == null) { return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build(); } TCapabilityRef ref = new TCapabilityRef(); ref.setName(reqOrCap.name); // may also be null // 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); }