Search in sources :

Example 36 with SeriesException

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

the class SeriesServiceImpl method updateSeries.

@Override
public DublinCoreCatalog updateSeries(DublinCoreCatalog dc) throws SeriesException, UnauthorizedException {
    try {
        for (DublinCoreCatalog dublinCore : isNew(notNull(dc, "dc"))) {
            final String id = dublinCore.getFirst(DublinCore.PROPERTY_IDENTIFIER);
            if (!dublinCore.hasValue(DublinCore.PROPERTY_CREATED)) {
                DublinCoreValue date = EncodingSchemeUtils.encodeDate(new Date(), Precision.Minute);
                dublinCore.set(DublinCore.PROPERTY_CREATED, date);
                logger.debug("Setting series creation date to '{}'", date.getValue());
            }
            if (dublinCore.hasValue(DublinCore.PROPERTY_TITLE)) {
                if (dublinCore.getFirst(DublinCore.PROPERTY_TITLE).length() > 255) {
                    dublinCore.set(DublinCore.PROPERTY_TITLE, dublinCore.getFirst(DublinCore.PROPERTY_TITLE).substring(0, 255));
                    logger.warn("Title was longer than 255 characters. Cutting excess off.");
                }
            }
            logger.debug("Updating series {}", id);
            index.updateIndex(dublinCore);
            try {
                final AccessControlList acl = persistence.getAccessControlList(id);
                if (acl != null) {
                    index.updateSecurityPolicy(id, acl);
                }
            } catch (NotFoundException ignore) {
            // Ignore not found since this is the first indexing
            }
            try {
                index.updateOptOutStatus(id, persistence.isOptOut(id));
            } catch (NotFoundException ignore) {
            // Ignore not found since this is the first indexing
            }
            // Make sure store to persistence comes after index, return value can be null
            DublinCoreCatalog updated = persistence.storeSeries(dublinCore);
            messageSender.sendObjectMessage(SeriesItem.SERIES_QUEUE, MessageSender.DestinationType.Queue, SeriesItem.updateCatalog(dublinCore));
            return (updated == null) ? null : dublinCore;
        }
        return dc;
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) NotFoundException(org.opencastproject.util.NotFoundException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Date(java.util.Date) ServiceException(org.osgi.framework.ServiceException) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) FunctionException(org.opencastproject.util.data.FunctionException)

Example 37 with SeriesException

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

the class SeriesServiceImpl method deleteSeriesProperty.

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

Example 38 with SeriesException

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

the class SeriesServiceImpl method updateAccessControl.

// todo method signature does not fit the three different possible return values
@Override
public boolean updateAccessControl(final String seriesId, final AccessControlList accessControl) throws NotFoundException, SeriesException {
    if (StringUtils.isEmpty(seriesId)) {
        throw new IllegalArgumentException("Series ID parameter must not be null or empty.");
    }
    if (accessControl == null) {
        throw new IllegalArgumentException("ACL parameter must not be null");
    }
    if (needsUpdate(seriesId, accessControl)) {
        logger.debug("Updating ACL of series {}", seriesId);
        boolean updated;
        // not found is thrown if it doesn't exist
        try {
            index.updateSecurityPolicy(seriesId, accessControl);
        } catch (SeriesServiceDatabaseException e) {
            logger.error("Could not update series {} with access control rules: {}", seriesId, e.getMessage());
            throw new SeriesException(e);
        }
        try {
            updated = persistence.storeSeriesAccessControl(seriesId, accessControl);
            messageSender.sendObjectMessage(SeriesItem.SERIES_QUEUE, MessageSender.DestinationType.Queue, SeriesItem.updateAcl(seriesId, accessControl));
        } catch (SeriesServiceDatabaseException e) {
            logger.error("Could not update series {} with access control rules: {}", seriesId, e.getMessage());
            throw new SeriesException(e);
        }
        return updated;
    } else {
        // todo not the right return code
        return true;
    }
}
Also used : SeriesException(org.opencastproject.series.api.SeriesException)

Example 39 with SeriesException

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

the class SolrIndexManager method createSeriesInputDocument.

/**
 * Creates a solr input document for the series metadata of the media package.
 *
 * @param seriesId
 *          the id of the series
 * @param acl
 *          the access control list for this mediapackage
 * @return an input document ready to be posted to solr or null
 */
private SolrInputDocument createSeriesInputDocument(String seriesId, AccessControlList acl) throws IOException, UnauthorizedException {
    if (seriesId == null)
        return null;
    DublinCoreCatalog dc = null;
    try {
        dc = seriesService.getSeries(seriesId);
    } catch (SeriesException e) {
        logger.debug("No series dublincore found for series id " + seriesId);
        return null;
    } catch (NotFoundException e) {
        logger.debug("No series dublincore found for series id " + seriesId);
        return null;
    }
    SolrInputDocument doc = new SolrInputDocument();
    // Populate document with existing data
    try {
        StringBuffer query = new StringBuffer("q=");
        query = query.append(Schema.ID).append(":").append(SolrUtils.clean(seriesId));
        SolrParams params = SolrRequestParsers.parseQueryString(query.toString());
        QueryResponse solrResponse = solrServer.query(params);
        if (solrResponse.getResults().size() > 0) {
            SolrDocument existingSolrDocument = solrResponse.getResults().get(0);
            for (String fieldName : existingSolrDocument.getFieldNames()) {
                doc.addField(fieldName, existingSolrDocument.getFieldValue(fieldName));
            }
        }
    } catch (Exception e) {
        logger.error("Error trying to load series " + seriesId, e);
    }
    // Fill document
    Schema.setId(doc, seriesId);
    // OC specific fields
    Schema.setOrganization(doc, securityService.getOrganization().getId());
    Schema.setOcMediatype(doc, SearchResultItemType.Series.toString());
    Schema.setOcModified(doc, new Date());
    // DC fields
    addSeriesMetadata(doc, dc);
    // Authorization
    setAuthorization(doc, securityService, acl);
    return doc;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) NotFoundException(org.opencastproject.util.NotFoundException) SolrParams(org.apache.solr.common.params.SolrParams) SeriesException(org.opencastproject.series.api.SeriesException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SeriesException(org.opencastproject.series.api.SeriesException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SearchServiceDatabaseException(org.opencastproject.search.impl.persistence.SearchServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) Date(java.util.Date)

Example 40 with SeriesException

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

the class CalendarGenerator method getSeriesDublinCoreAsString.

/**
 * Returns series DC associated with this event or null if {@link SeriesService} is not available or does not contain
 * entry for series with specified ID.
 *
 * @param seriesID
 *          {@link DublinCoreCatalog} to be retrieved
 * @return DC serialized to string or null
 * @throws UnauthorizedException
 *           if the current user is not allowed to view this series
 * @throws NotFoundException
 *           if the series cannot be found
 */
private String getSeriesDublinCoreAsString(String seriesID) throws UnauthorizedException, NotFoundException {
    if (StringUtils.isBlank(seriesID))
        return null;
    if (seriesService == null) {
        logger.warn("No SeriesService available");
        return null;
    }
    DublinCoreCatalog seriesDC = series.get(seriesID);
    if (seriesDC == null) {
        try {
            seriesDC = seriesService.getSeries(seriesID);
            series.put(seriesID, seriesDC);
        } catch (SeriesException e) {
            logger.error("Error loading DublinCoreCatalog for series '{}': {}", seriesID, ExceptionUtils.getStackTrace(e));
            return null;
        }
    }
    try {
        return seriesDC.toXmlString();
    } catch (IOException e) {
        logger.error("Error serializing DublinCoreCatalog of series '{}': {}", seriesID, ExceptionUtils.getStackTrace(e));
        return null;
    }
}
Also used : SeriesException(org.opencastproject.series.api.SeriesException) IOException(java.io.IOException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

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