Search in sources :

Example 6 with AclTransitionDbDuplicatedException

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

the class OsgiJpaAclTransitionDbTest method testStoreAndGetEpisodeACL.

@Test
public void testStoreAndGetEpisodeACL() throws Exception {
    final Date now = new Date();
    // a fallback to series transition should be saveable
    db.storeEpisodeAclTransition(ORG, "uuid", now, none(0L), Option.<ConfiguredWorkflowRef>none());
    // a transition referencing a non existing ACL should not be saveable
    try {
        db.storeEpisodeAclTransition(ORG, "uuid", new Date(), some(1L), 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 EpisodeACLTransition t3 = db.storeEpisodeAclTransition(ORG, "uuid-2", now, some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
    assertEquals("uuid-2", t3.getEpisodeId());
    assertEquals(now, t3.getApplicationDate());
    assertTrue(t3.getAccessControlList().isSome());
    assertEquals(macl.getName(), t3.getAccessControlList().get().getName());
    // a transition with the same properties should not be saveable
    try {
        db.storeEpisodeAclTransition(ORG, "uuid", now, some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
        fail("Duplicated episode ACL must not be stored");
    } catch (AclTransitionDbDuplicatedException ignore) {
    }
    List<EpisodeACLTransition> ts = db.getEpisodeAclTransitions(ORG, "uuid");
    assertEquals(1, ts.size());
    assertEquals("uuid", ts.get(0).getEpisodeId());
    assertTrue(ts.get(0).isDelete());
    assertTrue(!ts.get(0).isDone());
}
Also used : ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) Date(java.util.Date) Test(org.junit.Test)

Example 7 with AclTransitionDbDuplicatedException

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

the class AbstractAclServiceRestEndpoint method addEpisodeTransition.

@POST
@Path("/episode/{episodeId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "addepisodetransition", description = "Add an episode transition", returnDescription = "Add an episode transition", pathParameters = { @RestParameter(name = "episodeId", isRequired = true, description = "The episode id", type = STRING) }, restParameters = { @RestParameter(name = "applicationDate", isRequired = true, description = "The date to applicate", type = STRING), @RestParameter(name = "managedAclId", isRequired = false, 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) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The episode transition has successfully been added"), @RestResponse(responseCode = SC_CONFLICT, description = "The episode transition with the applicationDate already exists"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during adding an episode transition") })
public String addEpisodeTransition(@PathParam("episodeId") String episodeId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") Long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) {
    try {
        final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
        final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
        final EpisodeACLTransition transition = aclService().addEpisodeTransition(episodeId, option(managedAclId), at, workflow);
        return JsonConv.full(transition).toJson();
    } catch (AclTransitionDbDuplicatedException e) {
        logger.info("Error adding episode transition: transition with date {} already exists", applicationDate);
        throw new WebApplicationException(Status.CONFLICT);
    } catch (AclServiceException e) {
        logger.warn("Error adding episode 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) WebApplicationException(javax.ws.rs.WebApplicationException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) 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 8 with AclTransitionDbDuplicatedException

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

the class OsgiJpaAclTransitionDb method storeEpisodeAclTransition.

@Override
public EpisodeACLTransition storeEpisodeAclTransition(Organization org, String episodeId, Date applicationDate, Option<Long> managedAclId, Option<ConfiguredWorkflowRef> workflow) throws AclTransitionDbException {
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        EpisodeAclTransitionEntity entity = new EpisodeAclTransitionEntity().update(episodeId, org.getId(), applicationDate, getManagedAcl(em, managedAclId, org), workflow);
        em.persist(entity);
        tx.commit();
        return entity;
    } catch (AclTransitionDbException e) {
        throw e;
    } catch (Exception e) {
        if (tx != null && tx.isActive())
            tx.rollback();
        boolean isConstraintViolation = Util.isConstraintViolationException(e);
        if (isConstraintViolation)
            throw new AclTransitionDbDuplicatedException();
        else {
            logger.error("Could not store 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) 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)

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