use of org.opencastproject.series.api.SeriesException in project opencast by opencast.
the class SeriesServiceSolrIndex method clear.
/**
* Clears the index of all series instances.
*/
public void clear() throws SeriesException {
try {
synchronized (solrServer) {
solrServer.deleteByQuery("*:*");
solrServer.commit();
}
} catch (Exception e) {
throw new SeriesException(e);
}
}
use of org.opencastproject.series.api.SeriesException in project opencast by opencast.
the class SeriesServiceRemoteImpl method updateSeries.
@Override
public DublinCoreCatalog updateSeries(DublinCoreCatalog dc) throws SeriesException, UnauthorizedException {
String seriesId = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
HttpPost post = new HttpPost("/");
try {
List<BasicNameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("series", dc.toXmlString()));
post.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new SeriesException("Unable to assemble a remote series request for updating series " + seriesId, e);
}
HttpResponse response = getResponse(post, SC_NO_CONTENT, SC_CREATED, SC_UNAUTHORIZED);
try {
if (response != null) {
int statusCode = response.getStatusLine().getStatusCode();
if (SC_NO_CONTENT == statusCode) {
logger.info("Successfully updated series {} in the series service", seriesId);
return null;
} else if (SC_UNAUTHORIZED == statusCode) {
throw new UnauthorizedException("Not authorized to update series " + seriesId);
} else if (SC_CREATED == statusCode) {
DublinCoreCatalog catalogImpl = DublinCores.read(response.getEntity().getContent());
logger.info("Successfully created series {} in the series service", seriesId);
return catalogImpl;
}
}
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SeriesException("Unable to update series " + seriesId + " using the remote series services: " + e);
} finally {
closeConnection(response);
}
throw new SeriesException("Unable to update series " + seriesId + " using the remote series services");
}
use of org.opencastproject.series.api.SeriesException in project opencast by opencast.
the class SeriesServiceRemoteImpl method deleteSeries.
@Override
public void deleteSeries(String seriesID) throws SeriesException, NotFoundException, UnauthorizedException {
HttpDelete del = new HttpDelete(seriesID);
HttpResponse response = getResponse(del, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
try {
if (response != null) {
int statusCode = response.getStatusLine().getStatusCode();
if (SC_NOT_FOUND == statusCode) {
throw new NotFoundException("Series not found: " + seriesID);
} else if (SC_UNAUTHORIZED == statusCode) {
throw new UnauthorizedException("Not authorized to delete series " + seriesID);
} else if (SC_OK == statusCode) {
logger.info("Successfully deleted {} from the remote series index", seriesID);
return;
}
}
} finally {
closeConnection(response);
}
throw new SeriesException("Unable to remove " + seriesID + " from a remote series index");
}
use of org.opencastproject.series.api.SeriesException in project opencast by opencast.
the class SeriesServiceRemoteImpl method getSeries.
@Override
public DublinCoreCatalog getSeries(String seriesID) throws SeriesException, NotFoundException, UnauthorizedException {
HttpGet get = new HttpGet(seriesID + ".xml");
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
throw new NotFoundException("Series " + seriesID + " not found in remote series index!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
throw new UnauthorizedException("Not authorized to get series " + seriesID);
} else {
DublinCoreCatalog dublinCoreCatalog = DublinCores.read(response.getEntity().getContent());
logger.debug("Successfully received series {} from the remote series index", seriesID);
return dublinCoreCatalog;
}
}
} catch (UnauthorizedException e) {
throw e;
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new SeriesException("Unable to parse series from remote series index: " + e);
} finally {
closeConnection(response);
}
throw new SeriesException("Unable to get series from remote series index");
}
use of org.opencastproject.series.api.SeriesException in project opencast by opencast.
the class SeriesServiceRemoteImpl method deleteSeriesElement.
@Override
public boolean deleteSeriesElement(String seriesID, String type) throws SeriesException {
if (isBlank(seriesID))
throw new IllegalArgumentException("Series ID must not be blank");
if (isBlank(type))
throw new IllegalArgumentException("Element type must not be blank");
HttpDelete del = new HttpDelete("/" + seriesID + "/elements/" + type);
HttpResponse response = getResponse(del, SC_NO_CONTENT, SC_NOT_FOUND, SC_INTERNAL_SERVER_ERROR);
try {
if (response == null) {
throw new SeriesException("Unable to remove " + seriesID + " from a remote series index");
} else {
final int statusCode = response.getStatusLine().getStatusCode();
switch(statusCode) {
case SC_NO_CONTENT:
return true;
case SC_NOT_FOUND:
return false;
case SC_INTERNAL_SERVER_ERROR:
throw new SeriesException(format("Error while deleting element of type '%s' from series '%s'", type, seriesID));
default:
throw new SeriesException(format("Unexpected status code", statusCode));
}
}
} finally {
closeConnection(response);
}
}
Aggregations