use of net.codestory.http.errors.NotFoundException in project datashare by ICIJ.
the class BatchSearchResource method copySearch.
/**
* Create a new batch search based on a previous one given its id, and enqueue it for running
*
* it returns 404 if the source BatchSearch object is not found in the repository.
*
* @param sourceBatchId: the id of BatchSearch to copy
* @param context : the context of request (containing body)
* @return 200 or 404
*
* Example:
* $(curl localhost:8080/api/batch/search/copy/b7bee2d8-5ede-4c56-8b69-987629742146 -H 'Content-Type: application/json' -d "{\"name\": \"my new batch\", \"description\":\"desc\"}"
*/
@Post("/search/copy/:sourcebatchid")
public String copySearch(String sourceBatchId, Context context) throws Exception {
BatchSearch sourceBatchSearch = batchSearchRepository.get((User) context.currentUser(), sourceBatchId);
if (sourceBatchSearch == null) {
throw new NotFoundException();
}
BatchSearch copy = new BatchSearch(sourceBatchSearch, context.extract(HashMap.class));
boolean isSaved = batchSearchRepository.save(copy);
if (isSaved)
batchSearchQueue.put(copy.uuid);
return copy.uuid;
}
Aggregations