use of org.opencastproject.authorization.xacml.manager.impl.TransitionResultImpl in project opencast by opencast.
the class OsgiJpaAclTransitionDb method getEpisodeResult.
/**
* Search episode transitions with the given transition query and return it in a transition result
*
* @param query
* the transition query
* @return the episode transition result
* @throws AclTransitionDbException
* if exception occurs during reading/storing from the persistence layer
*/
private TransitionResult getEpisodeResult(TransitionQuery query, String orgId) throws AclTransitionDbException {
for (long transitionId : query.getTransitionId()) {
EntityManager em = null;
try {
em = emf.createEntityManager();
return new TransitionResultImpl(Misc.<EpisodeACLTransition>widen(option(getEpisodeEntity(transitionId, orgId, em)).list()), Collections.<SeriesACLTransition>nil());
} 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<EpisodeAclTransitionEntity> q = cb.createQuery(EpisodeAclTransitionEntity.class);
Root<EpisodeAclTransitionEntity> c = q.from(EpisodeAclTransitionEntity.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("episodeId"), 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<EpisodeAclTransitionEntity> typedQuery = em.createQuery(q);
return new TransitionResultImpl(Misc.<EpisodeACLTransition>widen(typedQuery.getResultList()), Collections.<SeriesACLTransition>nil());
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.authorization.xacml.manager.impl.TransitionResultImpl 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();
}
}
Aggregations