Search in sources :

Example 1 with AclTransitionDbException

use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.

the class OsgiJpaAclTransitionDb method updateEpisodeAclTransition.

@Override
public EpisodeACLTransition updateEpisodeAclTransition(Organization org, long transitionId, Date applicationDate, Option<Long> managedAclId, Option<ConfiguredWorkflowRef> workflow) 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.update(entity.getEpisodeId(), org.getId(), applicationDate, getManagedAcl(em, managedAclId, org), workflow);
        em.merge(entity);
        tx.commit();
        return entity;
    } catch (NotFoundException e) {
        throw e;
    } catch (AclTransitionDbException e) {
        throw e;
    } catch (Exception e) {
        if (tx != null && tx.isActive())
            tx.rollback();
        boolean isContraintViolation = Util.isConstraintViolationException(e);
        if (isContraintViolation)
            throw new AclTransitionDbDuplicatedException();
        else {
            logger.error("Could not update the scheduled episode ACL: {}", e.getMessage());
            throw new AclTransitionDbException(e);
        }
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) NotFoundException(org.opencastproject.util.NotFoundException) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) 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)

Example 2 with AclTransitionDbException

use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.

the class OsgiJpaAclTransitionDb method storeSeriesAclTransition.

@Override
public SeriesACLTransition storeSeriesAclTransition(Organization org, String seriesId, Date applicationDate, long managedAclId, boolean override, Option<ConfiguredWorkflowRef> workflow) throws AclTransitionDbException {
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        SeriesAclTransitionEntity entity = new SeriesAclTransitionEntity().update(seriesId, org.getId(), applicationDate, getManagedAcl(em, some(managedAclId), org).get(), workflow, override);
        em.persist(entity);
        tx.commit();
        return entity;
    } catch (AclTransitionDbException e) {
        throw e;
    } catch (Exception e) {
        if (tx != null && tx.isActive())
            tx.rollback();
        boolean isContraintViolation = Util.isConstraintViolationException(e);
        if (isContraintViolation)
            throw new AclTransitionDbDuplicatedException();
        else {
            logger.error("Could not store the scheduled series ACL: {}", e.getMessage());
            throw new AclTransitionDbException(e);
        }
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) 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)

Example 3 with AclTransitionDbException

use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.

the class OsgiJpaAclTransitionDb method updateSeriesAclTransition.

@Override
public SeriesACLTransition updateSeriesAclTransition(Organization org, long transitionId, Date applicationDate, long managedAclId, boolean override, Option<ConfiguredWorkflowRef> workflow) throws AclTransitionDbException, NotFoundException {
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        SeriesAclTransitionEntity entity = getSeriesEntity(transitionId, org.getId(), em);
        if (entity == null)
            throw new NotFoundException("Series transition " + transitionId + " not found!");
        entity.update(entity.getSeriesId(), org.getId(), applicationDate, getManagedAcl(em, some(managedAclId), org).get(), workflow, override);
        em.merge(entity);
        tx.commit();
        return entity;
    } catch (NotFoundException e) {
        throw e;
    } catch (AclTransitionDbException e) {
        throw e;
    } catch (Exception e) {
        if (tx != null && tx.isActive())
            tx.rollback();
        boolean isContraintViolation = Util.isConstraintViolationException(e);
        if (isContraintViolation)
            throw new AclTransitionDbDuplicatedException();
        else {
            logger.error("Could not update the scheduled series ACL: {}", e.getMessage());
            throw new AclTransitionDbException(e);
        }
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) NotFoundException(org.opencastproject.util.NotFoundException) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) 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)

Example 4 with AclTransitionDbException

use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException 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 5 with AclTransitionDbException

use of org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException in project opencast by opencast.

the class OsgiJpaAclTransitionDbTest method testStoreAndGetSeriesACL.

@Test
public void testStoreAndGetSeriesACL() throws Exception {
    final Date now = new Date();
    // a transition referencing a non existing ACL should not be saveable
    try {
        db.storeSeriesAclTransition(ORG, "uuid", new Date(), 1L, true, Option.<ConfiguredWorkflowRef>none());
        fail("No ACL with ID 1");
    } catch (AclTransitionDbException ignore) {
    }
    // a transition referencing an existing ACL should be saveable
    final ManagedAcl macl = createAcl();
    final SeriesACLTransition t3 = db.storeSeriesAclTransition(ORG, "uuid", now, macl.getId(), false, Option.<ConfiguredWorkflowRef>none());
    assertEquals("uuid", t3.getSeriesId());
    assertEquals(now, t3.getApplicationDate());
    assertEquals(macl.getName(), t3.getAccessControlList().getName());
    // a transition with the same properties should not be saveable
    try {
        db.storeSeriesAclTransition(ORG, "uuid", now, macl.getId(), true, Option.<ConfiguredWorkflowRef>none());
        fail("Duplicated episode ACL must not be stored");
    } catch (AclTransitionDbDuplicatedException ignore) {
    }
    List<SeriesACLTransition> ts = db.getSeriesAclTransitions(ORG, "uuid");
    assertEquals(1, ts.size());
    assertEquals("uuid", ts.get(0).getSeriesId());
    assertTrue(!ts.get(0).isOverride());
    assertTrue(!ts.get(0).isDone());
}
Also used : SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) Date(java.util.Date) Test(org.junit.Test)

Aggregations

AclTransitionDbException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException)12 AclTransitionDbDuplicatedException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException)10 NotFoundException (org.opencastproject.util.NotFoundException)10 EntityManager (javax.persistence.EntityManager)8 NoResultException (javax.persistence.NoResultException)8 AclServiceNoReferenceException (org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException)8 Date (java.util.Date)6 EntityTransaction (javax.persistence.EntityTransaction)6 Test (org.junit.Test)4 ManagedAcl (org.opencastproject.authorization.xacml.manager.api.ManagedAcl)4 ArrayList (java.util.ArrayList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 EpisodeACLTransition (org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition)2 SeriesACLTransition (org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition)2 TransitionResultImpl (org.opencastproject.authorization.xacml.manager.impl.TransitionResultImpl)2