Search in sources :

Example 16 with SeriesException

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

the class SeriesRestService method putSeriesElement.

@PUT
@Path("{seriesId}/elements/{elementType}")
@RestQuery(name = "updateSeriesElement", description = "Updates an existing series element", returnDescription = "An empty response", pathParameters = { @RestParameter(name = "seriesId", description = "The series identifier", type = STRING, isRequired = true), @RestParameter(name = "elementType", description = "The element type", type = STRING, isRequired = true) }, reponses = { @RestResponse(responseCode = SC_NO_CONTENT, description = "Series element updated"), @RestResponse(responseCode = SC_CREATED, description = "Series element created"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error while processing the request") })
public Response putSeriesElement(@Context HttpServletRequest request, @PathParam("seriesId") String seriesId, @PathParam("elementType") String elementType) {
    InputStream is = null;
    try {
        is = request.getInputStream();
        final byte[] data = IOUtils.toByteArray(is);
        if (seriesService.getSeriesElementData(seriesId, elementType).isSome()) {
            if (seriesService.updateSeriesElement(seriesId, elementType, data)) {
                return R.noContent();
            } else {
                return R.serverError();
            }
        } else {
            if (seriesService.addSeriesElement(seriesId, elementType, data)) {
                return R.created(URI.create(UrlSupport.concat(serverUrl, serviceUrl, seriesId, "elements", elementType)));
            } else {
                return R.serverError();
            }
        }
    } catch (IOException e) {
        logger.error("Error while trying to read from request: {}", ExceptionUtils.getStackTrace(e));
        return R.serverError();
    } catch (SeriesException e) {
        logger.warn("Error while adding element to series '{}': {}", seriesId, ExceptionUtils.getStackTrace(e));
        return R.serverError();
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) SeriesException(org.opencastproject.series.api.SeriesException) Path(javax.ws.rs.Path) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 17 with SeriesException

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

the class SeriesServiceImpl method updateSeriesProperty.

@Override
public void updateSeriesProperty(String seriesID, String propertyName, String propertyValue) throws SeriesException, NotFoundException, UnauthorizedException {
    try {
        persistence.updateSeriesProperty(seriesID, propertyName, propertyValue);
        messageSender.sendObjectMessage(SeriesItem.SERIES_QUEUE, MessageSender.DestinationType.Queue, SeriesItem.updateProperty(seriesID, propertyName, propertyValue));
    } catch (SeriesServiceDatabaseException e) {
        logger.error("Failed to get series property for series with series id '{}' and property name '{}' and value '{}': {}", seriesID, propertyName, propertyValue, ExceptionUtils.getStackTrace(e));
        throw new SeriesException(e);
    }
}
Also used : SeriesException(org.opencastproject.series.api.SeriesException)

Example 18 with SeriesException

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

the class SeriesServiceImpl method updateOptOutStatus.

@Override
public void updateOptOutStatus(String seriesId, boolean optOut) throws NotFoundException, SeriesException {
    try {
        persistence.updateOptOutStatus(seriesId, optOut);
        index.updateOptOutStatus(seriesId, optOut);
        messageSender.sendObjectMessage(SeriesItem.SERIES_QUEUE, MessageSender.DestinationType.Queue, SeriesItem.updateOptOut(seriesId, optOut));
    } catch (SeriesServiceDatabaseException e) {
        logger.error("Failed to update opt out status of series with id '{}': {}", seriesId, ExceptionUtils.getStackTrace(e));
        throw new SeriesException(e);
    }
}
Also used : SeriesException(org.opencastproject.series.api.SeriesException)

Example 19 with SeriesException

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

the class SeriesServiceImpl method deleteSeries.

/*
   * (non-Javadoc)
   *
   * @see org.opencastproject.series.api.SeriesService#deleteSeries(java.lang.String)
   */
@Override
public void deleteSeries(final String seriesID) throws SeriesException, NotFoundException {
    try {
        persistence.deleteSeries(seriesID);
        messageSender.sendObjectMessage(SeriesItem.SERIES_QUEUE, MessageSender.DestinationType.Queue, SeriesItem.delete(seriesID));
    } catch (SeriesServiceDatabaseException e1) {
        logger.error("Could not delete series with id {} from persistence storage", seriesID);
        throw new SeriesException(e1);
    }
    try {
        index.delete(seriesID);
    } catch (SeriesServiceDatabaseException e) {
        logger.error("Unable to delete series with id {}: {}", seriesID, e.getMessage());
        throw new SeriesException(e);
    }
}
Also used : SeriesException(org.opencastproject.series.api.SeriesException)

Example 20 with SeriesException

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

the class ThemesEndpoint method deleteThemeOnSeries.

/**
 * Deletes all related series theme entries
 *
 * @param themeId
 *          the theme id
 */
private void deleteThemeOnSeries(long themeId) throws UnauthorizedException {
    SeriesSearchQuery query = new SeriesSearchQuery(securityService.getOrganization().getId(), securityService.getUser()).withTheme(themeId);
    SearchResult<Series> results = null;
    try {
        results = searchIndex.getByQuery(query);
    } catch (SearchIndexException e) {
        logger.error("The admin UI Search Index was not able to get the series with theme '{}': {}", themeId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    }
    for (SearchResultItem<Series> item : results.getItems()) {
        String seriesId = item.getSource().getIdentifier();
        try {
            seriesService.deleteSeriesProperty(seriesId, SeriesEndpoint.THEME_KEY);
        } catch (NotFoundException e) {
            logger.warn("Theme {} already deleted on series {}", themeId, seriesId);
        } catch (SeriesException e) {
            logger.error("Unable to remove theme from series {}: {}", seriesId, ExceptionUtils.getStackTrace(e));
            throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
        }
    }
}
Also used : Series(org.opencastproject.index.service.impl.index.series.Series) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) WebApplicationException(javax.ws.rs.WebApplicationException) SeriesSearchQuery(org.opencastproject.index.service.impl.index.series.SeriesSearchQuery) NotFoundException(org.opencastproject.util.NotFoundException) 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