Search in sources :

Example 6 with BulkOperationResult

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();
}
Also used : JSONArray(org.json.simple.JSONArray) NotFoundException(org.opencastproject.util.NotFoundException) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) BulkOperationResult(org.opencastproject.rest.BulkOperationResult) WebApplicationException(javax.ws.rs.WebApplicationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SeriesException(org.opencastproject.series.api.SeriesException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

BulkOperationResult (org.opencastproject.rest.BulkOperationResult)6 NotFoundException (org.opencastproject.util.NotFoundException)5 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 JSONParser (org.json.simple.parser.JSONParser)4 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)3 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)3 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)3 SeriesException (org.opencastproject.series.api.SeriesException)3 JObject (com.entwinemedia.fn.data.json.JObject)2 ParseException (java.text.ParseException)2 HttpResponse (org.apache.http.HttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1