use of org.opencastproject.rest.BulkOperationResult in project opencast by opencast.
the class SeriesEndpoint method deleteMultipleSeries.
@POST
@Path("deleteSeries")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "deletemultipleseries", description = "Deletes a json list of series by their given ids e.g. [\"Series-1\", \"Series-2\"]", returnDescription = "A JSON object with arrays that show whether a series was deleted, was not found or there was an error deleting it.", reponses = { @RestResponse(description = "Series have been deleted", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "The list of ids could not be parsed into a json list.", responseCode = HttpServletResponse.SC_BAD_REQUEST) })
public Response deleteMultipleSeries(String seriesIdsContent) throws NotFoundException {
if (StringUtils.isBlank(seriesIdsContent)) {
return Response.status(Status.BAD_REQUEST).build();
}
JSONParser parser = new JSONParser();
JSONArray seriesIdsArray;
try {
seriesIdsArray = (JSONArray) parser.parse(seriesIdsContent);
} catch (org.json.simple.parser.ParseException e) {
logger.error("Unable to parse '{}' because: {}", seriesIdsContent, ExceptionUtils.getStackTrace(e));
return Response.status(Status.BAD_REQUEST).build();
} catch (ClassCastException e) {
logger.error("Unable to cast '{}' to a JSON array because: {}", seriesIdsContent, ExceptionUtils.getMessage(e));
return Response.status(Status.BAD_REQUEST).build();
}
BulkOperationResult result = new BulkOperationResult();
for (Object seriesId : seriesIdsArray) {
try {
indexService.removeSeries(seriesId.toString());
result.addOk(seriesId.toString());
} catch (NotFoundException e) {
result.addNotFound(seriesId.toString());
} catch (Exception e) {
logger.error("Unable to remove the series '{}': {}", seriesId.toString(), ExceptionUtils.getStackTrace(e));
result.addServerError(seriesId.toString());
}
}
return Response.ok(result.toJson()).build();
}
Aggregations