Search in sources :

Example 11 with SeriesException

use of org.opencastproject.series.api.SeriesException in project opencast by opencast.

the class SeriesServiceRemoteImpl method updateSeriesElement.

@Override
public boolean updateSeriesElement(String seriesID, String type, byte[] data) throws SeriesException {
    HttpPut put = new HttpPut("/" + seriesID + "/elements/" + type);
    put.setEntity(new ByteArrayEntity(data, ContentType.DEFAULT_BINARY));
    HttpResponse response = getResponse(put, SC_NO_CONTENT, SC_INTERNAL_SERVER_ERROR);
    try {
        if (response == null) {
            throw new SeriesException(format("Error while updating element of type '%s' in series '%s'", type, seriesID));
        } else {
            final int statusCode = response.getStatusLine().getStatusCode();
            switch(statusCode) {
                case SC_NO_CONTENT:
                    return true;
                case SC_INTERNAL_SERVER_ERROR:
                    throw new SeriesException(format("Error while updating element of type '%s' in series '%s'", type, seriesID));
                default:
                    throw new SeriesException(format("Unexpected status code", statusCode));
            }
        }
    } finally {
        closeConnection(response);
    }
}
Also used : ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpResponse(org.apache.http.HttpResponse) SeriesException(org.opencastproject.series.api.SeriesException) HttpPut(org.apache.http.client.methods.HttpPut)

Example 12 with SeriesException

use of org.opencastproject.series.api.SeriesException in project opencast by opencast.

the class SeriesServiceRemoteImpl method getSeriesCount.

@Override
public int getSeriesCount() throws SeriesException {
    HttpGet get = new HttpGet("/count");
    HttpResponse response = getResponse(get);
    try {
        if (response != null) {
            int count = Integer.parseInt(IOUtils.toString(response.getEntity().getContent()));
            logger.info("Successfully get series dublin core catalog list from the remote series index");
            return count;
        }
    } catch (Exception e) {
        throw new SeriesException("Unable to count series from remote series index: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to count series from remote series index");
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) SeriesException(org.opencastproject.series.api.SeriesException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 13 with SeriesException

use of org.opencastproject.series.api.SeriesException in project opencast by opencast.

the class SeriesServiceRemoteImpl method getSeriesAccessControl.

@Override
public AccessControlList getSeriesAccessControl(String seriesID) throws NotFoundException, SeriesException {
    HttpGet get = new HttpGet(seriesID + "/acl.xml");
    HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND);
    try {
        if (response != null) {
            if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
                throw new NotFoundException("Series ACL " + seriesID + " not found on remote series index!");
            } else {
                AccessControlList acl = AccessControlParser.parseAcl(response.getEntity().getContent());
                logger.info("Successfully get series ACL {} from the remote series index", seriesID);
                return acl;
            }
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new SeriesException("Unable to parse series ACL form remote series index: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SeriesException("Unable to get series ACL from remote series index");
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) SeriesException(org.opencastproject.series.api.SeriesException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 14 with SeriesException

use of org.opencastproject.series.api.SeriesException in project opencast by opencast.

the class SeriesRestService method getAllSeriesIdTitle.

@GET
@Path("allSeriesIdTitle.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getAll", description = "Returns a list of identifier and title of all series", returnDescription = "Json list of identifier and title of all series", reponses = { @RestResponse(responseCode = SC_OK, description = "A list with series"), @RestResponse(responseCode = SC_FORBIDDEN, description = "A user is not allowed to list all series"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error while processing the request") })
public Response getAllSeriesIdTitle() {
    try {
        Map<String, String> allSeries = seriesService.getIdTitleMapOfAllSeries();
        JSONArray seriesJsonArr = new JSONArray();
        for (String seriesId : allSeries.keySet()) {
            JSONObject seriesJsonObj = new JSONObject();
            seriesJsonObj.put("identifier", seriesId);
            seriesJsonObj.put("title", allSeries.get(seriesId));
            seriesJsonArr.add(seriesJsonObj);
        }
        JSONObject resultJson = new JSONObject();
        resultJson.put("series", seriesJsonArr);
        return Response.ok(resultJson.toJSONString()).build();
    } catch (SeriesException ex) {
        return R.serverError();
    } catch (UnauthorizedException ex) {
        return R.forbidden();
    }
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) SeriesException(org.opencastproject.series.api.SeriesException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 15 with SeriesException

use of org.opencastproject.series.api.SeriesException in project opencast by opencast.

the class SeriesRestService method getSeriesElements.

@GET
@Path("{seriesId}/elements.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getSeriesElements", description = "Returns all the element types of a series", returnDescription = "Returns a JSON array with all the types of elements of the given series.", pathParameters = { @RestParameter(name = "seriesId", description = "The series identifier", type = STRING, isRequired = true) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Series found"), @RestResponse(responseCode = SC_NOT_FOUND, description = "Series not found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error while processing the request") })
public Response getSeriesElements(@PathParam("seriesId") String seriesId) {
    try {
        Opt<Map<String, byte[]>> optSeriesElements = seriesService.getSeriesElements(seriesId);
        if (optSeriesElements.isSome()) {
            Map<String, byte[]> seriesElements = optSeriesElements.get();
            JValue jsonArray = Jsons.arr(Stream.$(seriesElements.keySet()).map(Jsons.Functions.stringToJValue));
            return Response.ok(new SimpleSerializer().toJson(jsonArray)).build();
        } else {
            return R.notFound();
        }
    } catch (SeriesException e) {
        logger.warn("Error while retrieving elements for sieres '{}': {}", seriesId, ExceptionUtils.getStackTrace(e));
        return R.serverError();
    }
}
Also used : SimpleSerializer(com.entwinemedia.fn.data.json.SimpleSerializer) JValue(com.entwinemedia.fn.data.json.JValue) SeriesException(org.opencastproject.series.api.SeriesException) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

SeriesException (org.opencastproject.series.api.SeriesException)40 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)24 NotFoundException (org.opencastproject.util.NotFoundException)24 HttpResponse (org.apache.http.HttpResponse)19 WebApplicationException (javax.ws.rs.WebApplicationException)16 ParseException (java.text.ParseException)14 HttpGet (org.apache.http.client.methods.HttpGet)10 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)6 AccessControlList (org.opencastproject.security.api.AccessControlList)6 HashMap (java.util.HashMap)5 Path (javax.ws.rs.Path)5 RestQuery (org.opencastproject.util.doc.rest.RestQuery)5 InputStream (java.io.InputStream)4 Map (java.util.Map)4 HttpPost (org.apache.http.client.methods.HttpPost)4 JSONArray (org.codehaus.jettison.json.JSONArray)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 GET (javax.ws.rs.GET)3