use of org.eclipse.winery.model.tosca.TPropertyMapping in project winery by eclipse.
the class PropertyMappingsResource method onPost.
@ApiOperation(value = "Creates or updates a property mapping with the given fields")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public // @formatter:off
Response onPost(PropertyMapping apiPropertyMapping) {
// @formatter:on
if (StringUtils.isEmpty(apiPropertyMapping.serviceTemplatePropertyRef)) {
return Response.status(Status.BAD_REQUEST).entity("serviceTemplatePropertyRef must not be empty").build();
}
if (StringUtils.isEmpty(apiPropertyMapping.targetObjectRef)) {
return Response.status(Status.BAD_REQUEST).entity("targetObjectRef must not be empty").build();
}
if (StringUtils.isEmpty(apiPropertyMapping.targetPropertyRef)) {
return Response.status(Status.BAD_REQUEST).entity("targetPropertyRef must not be empty").build();
}
TEntityTemplate template = ModelUtilities.findNodeTemplateOrRequirementOfNodeTemplateOrCapabilityOfNodeTemplateOrRelationshipTemplate(this.res.getServiceTemplate().getTopologyTemplate(), apiPropertyMapping.targetObjectRef);
if (template == null) {
return Response.status(Status.BAD_REQUEST).entity("targetObjectRef " + apiPropertyMapping.targetObjectRef + " could not be resolved.").build();
}
// replace propertyMapping if it exists
for (TPropertyMapping propertyMapping : this.propertyMappings.getPropertyMapping()) {
if (propertyMapping.getServiceTemplatePropertyRef().equals(apiPropertyMapping.serviceTemplatePropertyRef)) {
// we found a property with the same mapping
// just update it ...
this.updatePropertyMapping(propertyMapping, apiPropertyMapping.serviceTemplatePropertyRef, template, apiPropertyMapping.targetPropertyRef);
// ... and finish processing
return RestUtils.persist(this.res);
}
}
// the property mapping didn't exist,
// we create a new one
TPropertyMapping newPropertyMapping = new TPropertyMapping();
this.updatePropertyMapping(newPropertyMapping, apiPropertyMapping.serviceTemplatePropertyRef, template, apiPropertyMapping.targetPropertyRef);
this.propertyMappings.getPropertyMapping().add(newPropertyMapping);
return RestUtils.persist(this.res);
}
use of org.eclipse.winery.model.tosca.TPropertyMapping in project winery by eclipse.
the class PropertyMappingsResource method onDelete.
@Path("{serviceTemplatePropertyRef}")
@DELETE
public Response onDelete(@PathParam("serviceTemplatePropertyRef") String serviceTemplatePropertyRef) {
serviceTemplatePropertyRef = Util.URLdecode(serviceTemplatePropertyRef);
Iterator<TPropertyMapping> iterator = this.propertyMappings.getPropertyMapping().iterator();
while (iterator.hasNext()) {
TPropertyMapping propertyMapping = iterator.next();
if (propertyMapping.getServiceTemplatePropertyRef().equals(serviceTemplatePropertyRef)) {
iterator.remove();
return RestUtils.persist(this.res);
}
}
// otherwise "iterator.remove()" has called and the resource persisted
return Response.status(Status.NOT_FOUND).build();
}
Aggregations