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();
}
}
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();
}
}
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;
}
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;
}
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();
}
}
Aggregations