use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.
the class OsgiJpaAclTransitionDb method getSeriesResult.
/**
* Search series transitions with the given transition query and return it in a transition result
*
* @param query
* the transition query
* @return the series transition result
* @throws AclTransitionDbException
* if exception occurs during reading/storing from the persistence layer
*/
private TransitionResult getSeriesResult(TransitionQuery query, String orgId) throws AclTransitionDbException {
for (long transitionId : query.getTransitionId()) {
EntityManager em = null;
try {
em = emf.createEntityManager();
return new TransitionResultImpl(Collections.<EpisodeACLTransition>nil(), Misc.<SeriesACLTransition>widen(option(getSeriesEntity(transitionId, orgId, em)).list()));
} catch (Exception e) {
logger.warn("Error parsing episode ACL:", e);
throw new AclTransitionDbException(e);
} finally {
if (em != null)
em.close();
}
}
EntityManager em = null;
try {
em = emf.createEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SeriesAclTransitionEntity> q = cb.createQuery(SeriesAclTransitionEntity.class);
Root<SeriesAclTransitionEntity> c = q.from(SeriesAclTransitionEntity.class);
q.select(c);
// create predicates joined in an "and" expression
final List<Predicate> predicates = new ArrayList<Predicate>();
predicates.add(cb.equal(c.get("organizationId"), orgId));
for (String p : query.getId()) predicates.add(cb.equal(c.get("seriesId"), p));
for (Boolean p : query.getDone()) {
if (p)
predicates.add(cb.isTrue(c.get("done").as(Boolean.class)));
else
predicates.add(cb.isFalse(c.get("done").as(Boolean.class)));
}
for (Long p : query.getAclId()) predicates.add(cb.equal(c.get("managedAcl").get("id").as(Long.class), p));
for (Date p : query.getAfter()) predicates.add(cb.greaterThanOrEqualTo(c.get("applicationDate").as(Date.class), p));
for (Date p : query.getBefore()) predicates.add(cb.lessThanOrEqualTo(c.get("applicationDate").as(Date.class), p));
q.where(cb.and(toArray(predicates)));
q.orderBy(cb.asc(c.get("applicationDate")));
TypedQuery<SeriesAclTransitionEntity> typedQuery = em.createQuery(q);
return new TransitionResultImpl(Collections.<EpisodeACLTransition>nil(), Misc.<SeriesACLTransition>widen(typedQuery.getResultList()));
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.
the class OsgiJpaAclTransitionDb method markEpisodeTransitionAsCompleted.
@Override
public EpisodeACLTransition markEpisodeTransitionAsCompleted(Organization org, long transitionId) throws AclTransitionDbException, NotFoundException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
EpisodeAclTransitionEntity entity = getEpisodeEntity(transitionId, org.getId(), em);
if (entity == null)
throw new NotFoundException("Episode transition " + transitionId + " not found!");
entity.setDone(true);
em.merge(entity);
tx.commit();
return entity;
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not update the scheduled episode ACL: {}", e.getMessage());
if (tx != null && tx.isActive())
tx.rollback();
throw new AclTransitionDbException(e);
} finally {
if (em != null)
em.close();
}
}
Aggregations