Search in sources :

Example 1 with TransitionResultImpl

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();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ArrayList(java.util.ArrayList) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) NoResultException(javax.persistence.NoResultException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) NotFoundException(org.opencastproject.util.NotFoundException) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate) TransitionResultImpl(org.opencastproject.authorization.xacml.manager.impl.TransitionResultImpl) EntityManager(javax.persistence.EntityManager) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException)

Example 2 with TransitionResultImpl

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();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ArrayList(java.util.ArrayList) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) NoResultException(javax.persistence.NoResultException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) NotFoundException(org.opencastproject.util.NotFoundException) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate) TransitionResultImpl(org.opencastproject.authorization.xacml.manager.impl.TransitionResultImpl) EntityManager(javax.persistence.EntityManager) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException)

Aggregations

ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 EntityManager (javax.persistence.EntityManager)2 NoResultException (javax.persistence.NoResultException)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 AclServiceNoReferenceException (org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException)2 AclTransitionDbDuplicatedException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException)2 AclTransitionDbException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException)2 TransitionResultImpl (org.opencastproject.authorization.xacml.manager.impl.TransitionResultImpl)2 NotFoundException (org.opencastproject.util.NotFoundException)2