@Context LinkBuilders linkProcessor,
@Context UriInfo uriInfo) {
// if content was not sent => there is no meaning for the defect, throw
// exception.
DefectBean defect = asset.getDefect();
if (defect == null) {
throw new WebApplicationException(
new RuntimeException(
"The content of the defect is missing"),
Response.Status.BAD_REQUEST);
}
DataStore store = DataStore.getInstance();
if (defect.getId() != null) {
// undelete operation
if (!store.isDefectDeleted(defect.getId())) {
// the defect was already undeleted!
// it's a conflict!
return Response.status(Status.CONFLICT).build();
}
// this is undelete operation, there is no need to populate new id
} else {
// this is a new defect so generate an id
defect.setId(store.getDefectUniqueId());
}
// validate that the user didn't send deleted=true by mistake
defect.setDeleted(false);
// add defect legacy bean to the memory store
store.putDefect(defect.getId(), defect);
URI location = uriInfo.getAbsolutePathBuilder().segment(defect.getId()).build();
return Response.created(location).entity(asset).build();
}