Search in sources :

Example 26 with SeriesException

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);
    }
}
Also used : SeriesException(org.opencastproject.series.api.SeriesException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SeriesException(org.opencastproject.series.api.SeriesException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 27 with SeriesException

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");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) SeriesException(org.opencastproject.series.api.SeriesException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) 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 28 with SeriesException

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");
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) SeriesException(org.opencastproject.series.api.SeriesException)

Example 29 with SeriesException

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");
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) SeriesException(org.opencastproject.series.api.SeriesException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) 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 30 with SeriesException

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);
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) SeriesException(org.opencastproject.series.api.SeriesException)

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