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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations