use of org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition in project opencast by opencast.
the class OsgiJpaAclTransitionDbTest method testDone.
@Test
public void testDone() throws Exception {
EpisodeACLTransition t = db.storeEpisodeAclTransition(ORG, "episode-id", new Date(1347005303736L), none(0L), Option.<ConfiguredWorkflowRef>none());
assertEquals(1, db.getByQuery(ORG, TransitionQuery.query().withDone(false)).getEpisodeTransistions().size());
// ensure predicates are joined by "and"
assertEquals(0, db.getByQuery(ORG, TransitionQuery.query().after(new Date(1347005303736L)).withDone(true)).getEpisodeTransistions().size());
db.markEpisodeTransitionAsCompleted(ORG, t.getTransitionId());
assertEquals(0, db.getByQuery(ORG, TransitionQuery.query().withDone(false)).getEpisodeTransistions().size());
assertEquals(1, db.getByQuery(ORG, TransitionQuery.query().withDone(true)).getEpisodeTransistions().size());
}
use of org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition in project opencast by opencast.
the class OsgiJpaAclTransitionDbTest method testGetByQuery.
@Test
public void testGetByQuery() throws Exception {
final ManagedAcl macl = createAcl();
SeriesACLTransition st1 = db.storeSeriesAclTransition(ORG, "uuid-series", new Date(1347000000000L), macl.getId(), true, Option.<ConfiguredWorkflowRef>none());
SeriesACLTransition st2 = db.storeSeriesAclTransition(ORG, "uuid-series", new Date(1347000900000L), macl.getId(), false, Option.<ConfiguredWorkflowRef>none());
SeriesACLTransition st3 = db.storeSeriesAclTransition(ORG, "uuid-series2", new Date(1347000030000L), macl.getId(), false, option(workflow("full")));
SeriesACLTransition st4 = db.markSeriesTransitionAsCompleted(ORG, st3.getTransitionId());
EpisodeACLTransition et1 = db.storeEpisodeAclTransition(ORG, "uuid-episode", new Date(1347005303736L), Option.<Long>none(), Option.<ConfiguredWorkflowRef>none());
EpisodeACLTransition et2 = db.storeEpisodeAclTransition(ORG, "uuid-episode", new Date(1347005343736L), some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
EpisodeACLTransition et3 = db.storeEpisodeAclTransition(ORG, "uuid-episode2", new Date(1347005343736L), some(macl.getId()), option(workflow("full")));
EpisodeACLTransition et4 = db.markEpisodeTransitionAsCompleted(ORG, et3.getTransitionId());
// Test All
TransitionQuery query = TransitionQuery.query();
TransitionResult result = db.getByQuery(ORG, query);
assertEquals(3, result.getEpisodeTransistions().size());
assertEquals(3, result.getSeriesTransistions().size());
assertEquals(et1.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
assertEquals(et2.getTransitionId(), result.getEpisodeTransistions().get(1).getTransitionId());
assertEquals(et4.getTransitionId(), result.getEpisodeTransistions().get(2).getTransitionId());
assertEquals(st1.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
assertEquals(st4.getTransitionId(), result.getSeriesTransistions().get(1).getTransitionId());
assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(2).getTransitionId());
// Test Episode
query.withScope(AclScope.Episode);
result = db.getByQuery(ORG, query);
assertEquals(3, result.getEpisodeTransistions().size());
assertEquals(0, result.getSeriesTransistions().size());
assertEquals(et1.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
assertEquals(et2.getTransitionId(), result.getEpisodeTransistions().get(1).getTransitionId());
assertEquals(et3.getTransitionId(), result.getEpisodeTransistions().get(2).getTransitionId());
query.withScope(AclScope.Episode);
result = db.getByQuery(ORG2, query);
assertEquals(0, result.getEpisodeTransistions().size());
assertEquals(0, result.getSeriesTransistions().size());
// Test Series
query.withScope(AclScope.Series);
result = db.getByQuery(ORG, query);
assertEquals(0, result.getEpisodeTransistions().size());
assertEquals(3, result.getSeriesTransistions().size());
assertEquals(st1.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
assertEquals(st3.getTransitionId(), result.getSeriesTransistions().get(1).getTransitionId());
assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(2).getTransitionId());
// Test Date from
query = TransitionQuery.query().after(new Date(1347000040000L));
result = db.getByQuery(ORG, query);
assertEquals(3, result.getEpisodeTransistions().size());
assertEquals(1, result.getSeriesTransistions().size());
assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
// Test Date from, to
query.before(new Date(1347005313736L)).after(new Date(1347000040000L));
result = db.getByQuery(ORG, query);
assertEquals(1, result.getEpisodeTransistions().size());
assertEquals(1, result.getSeriesTransistions().size());
assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
assertEquals(et1.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
// Test id
query = TransitionQuery.query().withId("uuid-series");
result = db.getByQuery(ORG, query);
assertEquals(0, result.getEpisodeTransistions().size());
assertEquals(2, result.getSeriesTransistions().size());
assertEquals(st1.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(1).getTransitionId());
query = TransitionQuery.query().withId("uuid-series");
result = db.getByQuery(ORG2, query);
assertEquals(0, result.getEpisodeTransistions().size());
assertEquals(0, result.getSeriesTransistions().size());
// Test transitionId
result = db.getByQuery(ORG, TransitionQuery.query().withTransitionId(et2.getTransitionId()));
assertEquals(1, result.getEpisodeTransistions().size());
assertEquals(0, result.getSeriesTransistions().size());
assertEquals(et2.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
// Test is done
query = TransitionQuery.query().withDone(false);
result = db.getByQuery(ORG, query);
assertEquals(2, result.getEpisodeTransistions().size());
assertEquals(2, result.getSeriesTransistions().size());
assertEquals(et1.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
assertEquals(et2.getTransitionId(), result.getEpisodeTransistions().get(1).getTransitionId());
assertEquals(st1.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(1).getTransitionId());
query.withDone(true);
result = db.getByQuery(ORG, query);
assertEquals(1, result.getEpisodeTransistions().size());
assertEquals(1, result.getSeriesTransistions().size());
assertEquals(et3.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
assertEquals(st3.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
}
use of org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition in project opencast by opencast.
the class OsgiJpaAclTransitionDbTest method testUpdateEpisode.
@Test
public void testUpdateEpisode() throws Exception {
final ManagedAcl macl = createAcl();
EpisodeACLTransition t1 = db.storeEpisodeAclTransition(ORG, "uuid", new Date(), some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
EpisodeACLTransition u1 = db.updateEpisodeAclTransition(ORG, t1.getTransitionId(), t1.getApplicationDate(), none(0L), Option.some(workflow("full")));
assertEquals(t1.getTransitionId(), u1.getTransitionId());
assertEquals(t1.getEpisodeId(), u1.getEpisodeId());
assertEquals(t1.getOrganizationId(), u1.getOrganizationId());
assertTrue(u1.getAccessControlList().isNone());
assertNotSame(t1.isDelete(), u1.isDelete());
assertNotSame(t1.getWorkflow(), u1.getWorkflow());
try {
db.updateEpisodeAclTransition(ORG2, t1.getTransitionId(), t1.getApplicationDate(), some(macl.getId()), Option.some(workflow("full")));
fail("Updating from non-owner org should not be possible");
} catch (AclTransitionDbException ignore1) {
} catch (NotFoundException ignore2) {
}
}
use of org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition in project opencast by opencast.
the class OsgiJpaAclTransitionDbTest method testDeleteEpisode.
@Test
public void testDeleteEpisode() throws Exception {
final ManagedAcl macl = createAcl();
EpisodeACLTransition t1 = db.storeEpisodeAclTransition(ORG, "uuid", new Date(), some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
// try deletion from different org
try {
db.deleteEpisodeAclTransition(ORG2, t1.getTransitionId());
fail("Deleting from non-owner org should not be possible");
} catch (NotFoundException ignore) {
}
db.deleteEpisodeAclTransition(ORG, t1.getTransitionId());
try {
db.deleteEpisodeAclTransition(ORG, t1.getTransitionId());
fail("Deleting a non existing transition should throw an exception");
} catch (NotFoundException ignore) {
}
}
use of org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition 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);
}
}
Aggregations