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());
}
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);
}
}
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();
}
}
Aggregations