@Produces( {MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_XML})
public Response createDefect(DefectAsset asset, @Context UriInfo uriInfo) {
// if content was not sent => there is no meaning for the defect, throw
// exception.
DefectBean defect = asset.getDefect();
if (defect == null) {
logger.error("The content of the defect is missing");
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
// set unique Id in the new defect bean:
// - Id in the input data is ignored, actually there should be no Id
// there,
// - resource collection always decides about the unique Id of its own
// entries,
// - in our case we use a helper method to generate a unique Id
defect.setId(DataStore.getInstance().getDefectUniqueId());
// add defect legacy bean to the memory store
DataStore store = DataStore.getInstance();
store.putDefect(defect.getId(), defect);
// return status code 201 (created) with the created defect
URI location = uriInfo.getAbsolutePathBuilder().segment(defect.getId()).build();
return Response.status(Response.Status.CREATED).entity(asset).location(location)
.tag(new EntityTag(String.valueOf(defect.hashCode()))).build();
}