use of org.opencastproject.series.impl.SeriesServiceDatabaseException in project opencast by opencast.
the class SeriesServiceDatabaseImpl method updateOptOutStatus.
/**
* Updates a series' opt out status.
*
* @param seriesId
* The id of the series to update the opt out status of.
* @param optOut
* Whether to opt out this series or not.
*/
@Override
public void updateOptOutStatus(String seriesId, boolean optOut) 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 + " does not exist");
entity.setOptOut(optOut);
em.merge(entity);
tx.commit();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
if (tx.isActive()) {
tx.rollback();
}
logger.error("Could not update series opted out status: {}", e.getMessage());
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 getSeriesProperty.
/**
* {@inheritDoc}
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#getSeriesProperty(java.lang.String, java.lang.String)
*/
@Override
public String getSeriesProperty(String seriesId, String propertyName) 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");
}
if (entity.getProperties() == null || StringUtils.isBlank(entity.getProperties().get(propertyName))) {
throw new NotFoundException("No series property for series with id=" + seriesId + " and property name " + propertyName);
}
return entity.getProperties().get(propertyName);
} 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 storeSeriesElement.
@Override
public boolean storeSeriesElement(String seriesId, String type, byte[] data) throws SeriesServiceDatabaseException {
EntityManager em = null;
EntityTransaction tx = null;
final boolean success;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
SeriesEntity series = getSeriesEntity(seriesId, em);
if (series == null) {
success = false;
} else {
series.addElement(type, data);
em.merge(series);
tx.commit();
success = true;
}
} 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 storeSeries.
/*
* (non-Javadoc)
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#storeSeries(org.opencastproject.metadata.dublincore.
* DublinCoreCatalog)
*/
@Override
public DublinCoreCatalog storeSeries(DublinCoreCatalog dc) throws SeriesServiceDatabaseException, UnauthorizedException {
if (dc == null) {
throw new SeriesServiceDatabaseException("Invalid value for Dublin core catalog: null");
}
String seriesId = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
String seriesXML;
try {
seriesXML = serializeDublinCore(dc);
} catch (Exception e1) {
logger.error("Could not serialize Dublin Core: {}", e1);
throw new SeriesServiceDatabaseException(e1);
}
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
DublinCoreCatalog newSeries = null;
try {
tx.begin();
SeriesEntity entity = getSeriesEntity(seriesId, em);
if (entity == null) {
// no series stored, create new entity
entity = new SeriesEntity();
entity.setOrganization(securityService.getOrganization().getId());
entity.setSeriesId(seriesId);
entity.setSeries(seriesXML);
em.persist(entity);
newSeries = dc;
} else {
// Ensure this user is allowed to update 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);
}
}
entity.setSeries(seriesXML);
em.merge(entity);
}
tx.commit();
return newSeries;
} 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 storeSeriesAccessControl.
/*
* (non-Javadoc)
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#storeSeriesAccessControl(java.lang.String,
* org.opencastproject.security.api.AccessControlList)
*/
@Override
public boolean storeSeriesAccessControl(String seriesId, AccessControlList accessControl) throws NotFoundException, SeriesServiceDatabaseException {
if (accessControl == null) {
logger.error("Access control parameter is <null> for series '{}'", seriesId);
throw new IllegalArgumentException("Argument for updating ACL for series " + seriesId + " is null");
}
String serializedAC;
try {
serializedAC = AccessControlParser.toXml(accessControl);
} catch (Exception e) {
logger.error("Could not serialize access control parameter: {}", e.getMessage());
throw new SeriesServiceDatabaseException(e);
}
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
boolean updated = false;
try {
tx.begin();
SeriesEntity entity = getSeriesEntity(seriesId, em);
if (entity == null) {
throw new NotFoundException("Series with ID " + seriesId + " does not exist.");
}
if (entity.getAccessControl() != null) {
// Ensure this user is allowed to update 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 ACLs on series " + seriesId);
}
}
updated = true;
}
entity.setAccessControl(serializedAC);
em.merge(entity);
tx.commit();
return updated;
} 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();
}
}
Aggregations