Search in sources :

Example 1 with AclTransitionDbDuplicatedException

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

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

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

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

the class AbstractAclServiceRestEndpoint method addSeriesTransition.

@POST
@Path("/series/{seriesId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "addseriestransition", description = "Add a series transition", returnDescription = "Add a series transition", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series id", type = STRING) }, restParameters = { @RestParameter(name = "applicationDate", isRequired = true, description = "The date to applicate", type = STRING), @RestParameter(name = "managedAclId", isRequired = true, description = "The managed access control list id", type = INTEGER), @RestParameter(name = "workflowDefinitionId", isRequired = false, description = "The workflow definition identifier", type = STRING), @RestParameter(name = "workflowParams", isRequired = false, description = "The workflow parameters as JSON", type = STRING), @RestParameter(name = "override", isRequired = false, description = "If to override the episode ACL's", type = STRING, defaultValue = "false") }, reponses = { @RestResponse(responseCode = SC_OK, description = "The series transition has successfully been added"), @RestResponse(responseCode = SC_CONFLICT, description = "The series transition with the applicationDate already exists"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The given managed acl id could not be found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during adding a series transition") })
public String addSeriesTransition(@PathParam("seriesId") String seriesId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams, @FormParam("override") boolean override) {
    try {
        final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
        final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
        SeriesACLTransition seriesTransition = aclService().addSeriesTransition(seriesId, managedAclId, at, override, workflow);
        return JsonConv.full(seriesTransition).toJson();
    } catch (AclServiceNoReferenceException e) {
        logger.info("Managed acl with id '{}' coudl not be found", managedAclId);
        throw new WebApplicationException(Status.BAD_REQUEST);
    } catch (AclTransitionDbDuplicatedException e) {
        logger.info("Error adding series transition: transition with date {} already exists", applicationDate);
        throw new WebApplicationException(Status.CONFLICT);
    } catch (AclServiceException e) {
        logger.warn("Error adding series transition:", e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (Exception e) {
        logger.warn("Unable to parse the application date");
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) WebApplicationException(javax.ws.rs.WebApplicationException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) Date(java.util.Date) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 5 with AclTransitionDbDuplicatedException

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

AclTransitionDbDuplicatedException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException)8 AclServiceNoReferenceException (org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException)6 AclTransitionDbException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException)6 NotFoundException (org.opencastproject.util.NotFoundException)6 Date (java.util.Date)4 EntityManager (javax.persistence.EntityManager)4 EntityTransaction (javax.persistence.EntityTransaction)4 NoResultException (javax.persistence.NoResultException)4 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Test (org.junit.Test)2 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)2 EpisodeACLTransition (org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition)2 ManagedAcl (org.opencastproject.authorization.xacml.manager.api.ManagedAcl)2 SeriesACLTransition (org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition)2 SeriesException (org.opencastproject.series.api.SeriesException)2 RestQuery (org.opencastproject.util.doc.rest.RestQuery)2 ConfiguredWorkflowRef (org.opencastproject.workflow.api.ConfiguredWorkflowRef)2