Search in sources :

Example 11 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceDatabaseImpl method getSeriesProperties.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.series.impl.SeriesServiceDatabase#getSeriesProperties(java.lang.String)
 */
@Override
public Map<String, String> getSeriesProperties(String seriesId) throws NotFoundException, SeriesServiceDatabaseException {
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        SeriesEntity entity = getSeriesEntity(seriesId, em);
        if (entity == null) {
            throw new NotFoundException("No series with id=" + seriesId + " exists");
        }
        if (!userHasReadAccess(entity)) {
            throw new UnauthorizedException(securityService.getUser() + " is not authorized to see series " + seriesId + " properties");
        }
        return entity.getProperties();
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not update series: {}", e.getMessage());
        if (tx.isActive()) {
            tx.rollback();
        }
        throw new SeriesServiceDatabaseException(e);
    } finally {
        em.close();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) AccessControlParsingException(org.opencastproject.security.api.AccessControlParsingException)

Example 12 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceDatabaseImpl method updateSeriesProperty.

@Override
public void updateSeriesProperty(String seriesId, String propertyName, String propertyValue) throws NotFoundException, SeriesServiceDatabaseException {
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        SeriesEntity entity = getSeriesEntity(seriesId, em);
        if (entity == null) {
            throw new NotFoundException("Series with ID " + seriesId + " doesn't exist");
        }
        if (!userHasWriteAccess(entity)) {
            throw new UnauthorizedException(securityService.getUser() + " is not authorized to update series " + seriesId + " property " + propertyName + " to " + propertyValue);
        }
        Map<String, String> properties = entity.getProperties();
        properties.put(propertyName, propertyValue);
        entity.setProperties(properties);
        em.merge(entity);
        tx.commit();
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        if (tx.isActive()) {
            tx.rollback();
        }
        logger.error("Couldn't update series {} with property: {}:{} because {}", seriesId, propertyName, propertyValue, ExceptionUtils.getStackTrace(e));
        throw new SeriesServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) NoResultException(javax.persistence.NoResultException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) AccessControlParsingException(org.opencastproject.security.api.AccessControlParsingException)

Example 13 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceDatabaseImpl method getSeriesElements.

@Override
public Opt<Map<String, byte[]>> getSeriesElements(String seriesId) throws SeriesServiceDatabaseException {
    final Opt<Map<String, byte[]>> elements;
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        SeriesEntity series = getSeriesEntity(seriesId, em);
        if (series == null) {
            elements = Opt.none();
        } else {
            elements = Opt.some(series.getElements());
        }
    } catch (Exception e) {
        throw new SeriesServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
    return elements;
}
Also used : EntityManager(javax.persistence.EntityManager) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) Map(java.util.Map) NoResultException(javax.persistence.NoResultException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) AccessControlParsingException(org.opencastproject.security.api.AccessControlParsingException)

Example 14 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceDatabaseImpl method getSeriesElement.

@Override
public Opt<byte[]> getSeriesElement(String seriesId, String type) throws SeriesServiceDatabaseException {
    final Opt<byte[]> data;
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        SeriesEntity series = getSeriesEntity(seriesId, em);
        if (series == null) {
            data = Opt.none();
        } else {
            Map<String, byte[]> elements = series.getElements();
            if (elements.containsKey(type))
                data = Opt.some(elements.get(type));
            else {
                data = Opt.none();
            }
        }
    } catch (Exception e) {
        throw new SeriesServiceDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
    return data;
}
Also used : EntityManager(javax.persistence.EntityManager) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NoResultException(javax.persistence.NoResultException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) AccessControlParsingException(org.opencastproject.security.api.AccessControlParsingException)

Example 15 with SeriesServiceDatabaseException

use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.

the class SeriesServiceDatabaseImpl method countSeries.

@Override
public int countSeries() throws SeriesServiceDatabaseException {
    EntityManager em = emf.createEntityManager();
    Query query = em.createNamedQuery("Series.getCount");
    try {
        Long total = (Long) query.getSingleResult();
        return total.intValue();
    } catch (Exception e) {
        logger.error("Could not find number of series.", e);
        throw new SeriesServiceDatabaseException(e);
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NoResultException(javax.persistence.NoResultException) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) AccessControlParsingException(org.opencastproject.security.api.AccessControlParsingException)

Aggregations

SeriesServiceDatabaseException (org.opencastproject.series.impl.SeriesServiceDatabaseException)24 IOException (java.io.IOException)23 NotFoundException (org.opencastproject.util.NotFoundException)23 EntityManager (javax.persistence.EntityManager)15 NoResultException (javax.persistence.NoResultException)15 AccessControlParsingException (org.opencastproject.security.api.AccessControlParsingException)15 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)15 EntityTransaction (javax.persistence.EntityTransaction)11 SolrServerException (org.apache.solr.client.solrj.SolrServerException)8 MalformedURLException (java.net.MalformedURLException)7 SeriesException (org.opencastproject.series.api.SeriesException)7 SolrDocument (org.apache.solr.common.SolrDocument)6 AccessControlList (org.opencastproject.security.api.AccessControlList)5 Organization (org.opencastproject.security.api.Organization)4 User (org.opencastproject.security.api.User)4 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)3 Query (javax.persistence.Query)2