use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.
the class SeriesServiceDatabaseImpl method deleteSeries.
/*
* (non-Javadoc)
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#deleteSeries(java.lang.String)
*/
@Override
public void deleteSeries(String seriesId) throws SeriesServiceDatabaseException, NotFoundException {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
SeriesEntity entity = getSeriesEntity(seriesId, em);
if (entity == null) {
throw new NotFoundException("Series with ID " + seriesId + " does not exist");
}
// Ensure this user is allowed to delete this series
String accessControlXml = entity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.WRITE.toString())) {
throw new UnauthorizedException(currentUser + " is not authorized to update series " + seriesId);
}
}
em.remove(entity);
tx.commit();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not delete 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 deleteSeriesElement.
@Override
public boolean deleteSeriesElement(String seriesId, String type) throws SeriesServiceDatabaseException {
final boolean success;
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
SeriesEntity series = getSeriesEntity(seriesId, em);
if (series == null) {
success = false;
} else {
if (series.getElements().containsKey(type)) {
series.removeElement(type);
em.merge(series);
tx.commit();
success = true;
} else {
success = false;
}
}
} catch (Exception e) {
if (tx.isActive()) {
tx.rollback();
}
throw new SeriesServiceDatabaseException(e);
} finally {
if (em != null)
em.close();
}
return success;
}
use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.
the class SeriesServiceDatabaseImpl method getAllSeries.
/*
* (non-Javadoc)
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#getAllSeries()
*/
@SuppressWarnings("unchecked")
@Override
public List<SeriesEntity> getAllSeries() throws SeriesServiceDatabaseException {
EntityManager em = emf.createEntityManager();
Query query = em.createNamedQuery("Series.findAll");
try {
return query.getResultList();
} catch (Exception e) {
logger.error("Could not retrieve all series: {}", e.getMessage());
throw new SeriesServiceDatabaseException(e);
} finally {
em.close();
}
}
use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.
the class SeriesServiceDatabaseImpl method getSeries.
/**
* {@inheritDoc}
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#getSeries(java.lang.String)
*/
@Override
public DublinCoreCatalog getSeries(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");
}
// Ensure this user is allowed to read this series
String accessControlXml = entity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
// There are several reasons a user may need to load a series: to read content, to edit it, or add content
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.READ.toString()) && !AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.CONTRIBUTE.toString()) && !AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.WRITE.toString())) {
throw new UnauthorizedException(currentUser + " is not authorized to see series " + seriesId);
}
}
return dcService.load(IOUtils.toInputStream(entity.getDublinCoreXML(), "UTF-8"));
} 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 deleteSeriesProperty.
/*
* (non-Javadoc)
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#deleteSeriesProperty(java.lang.String)
*/
@Override
public void deleteSeriesProperty(String seriesId, String propertyName) throws SeriesServiceDatabaseException, NotFoundException {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
SeriesEntity entity = getSeriesEntity(seriesId, em);
if (entity == null) {
throw new NotFoundException("Series with ID " + seriesId + " does not exist");
}
Map<String, String> properties = entity.getProperties();
String propertyValue = properties.get(propertyName);
if (propertyValue == null) {
throw new NotFoundException("Series with ID " + seriesId + " doesn't have a property with name '" + propertyName + "'");
}
if (!userHasWriteAccess(entity)) {
throw new UnauthorizedException(securityService.getUser() + " is not authorized to delete series " + seriesId + " property " + propertyName);
}
properties.remove(propertyName);
entity.setProperties(properties);
em.merge(entity);
tx.commit();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not delete series: {}", e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new SeriesServiceDatabaseException(e);
} finally {
em.close();
}
}
Aggregations