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);
}
}
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");
}
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");
}
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();
}
}
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();
}
}
Aggregations