Search in sources :

Example 1 with TransitionResult

use of org.opencastproject.authorization.xacml.manager.api.TransitionResult in project opencast by opencast.

the class AbstractAclServiceRestEndpoint method getTransitionsAsJson.

@GET
@Path("/transitions.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "gettransitionsasjson", description = "Get the transitions as json", returnDescription = "Get the transitions as json", restParameters = { @RestParameter(name = "after", isRequired = false, description = "All transitions with an application date after this one", type = STRING), @RestParameter(name = "before", isRequired = false, description = "All transitions with an application date before this one", type = STRING), @RestParameter(name = "scope", isRequired = false, description = "The transition scope", type = STRING), @RestParameter(name = "id", isRequired = false, description = "The series or episode identifier", type = STRING), @RestParameter(name = "transitionId", isRequired = false, description = "The transition identifier", type = STRING), @RestParameter(name = "managedAclId", isRequired = false, description = "The managed acl identifier", type = INTEGER), @RestParameter(name = "done", isRequired = false, description = "Indicates if already applied", type = BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The request was processed succesfully"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Error parsing the given scope"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during processing the request") })
public Response getTransitionsAsJson(@QueryParam("after") String afterStr, @QueryParam("before") String beforeStr, @QueryParam("scope") String scopeStr, @QueryParam("id") String id, @QueryParam("transitionId") Long transitionId, @QueryParam("managedAclId") Long managedAclId, @QueryParam("done") Boolean done) {
    try {
        final TransitionQuery query = TransitionQuery.query();
        if (StringUtils.isNotBlank(afterStr))
            query.after(new Date(DateTimeSupport.fromUTC(afterStr)));
        if (StringUtils.isNotBlank(beforeStr))
            query.before(new Date(DateTimeSupport.fromUTC(beforeStr)));
        if (StringUtils.isNotBlank(id))
            query.withId(id);
        if (StringUtils.isNotBlank(scopeStr)) {
            if ("episode".equalsIgnoreCase(scopeStr))
                query.withScope(AclScope.Episode);
            else if ("series".equalsIgnoreCase(scopeStr))
                query.withScope(AclScope.Series);
            else
                return badRequest();
        }
        if (transitionId != null)
            query.withTransitionId(transitionId);
        if (managedAclId != null)
            query.withAclId(managedAclId);
        if (done != null)
            query.withDone(done);
        final AclService aclService = aclService();
        // run query
        final TransitionResult r = aclService().getTransitions(query);
        // episodeId -> [transitions]
        final Map<String, List<EpisodeACLTransition>> episodeGroup = groupByEpisodeId(r.getEpisodeTransistions());
        // seriesId -> [transitions]
        final Map<String, List<SeriesACLTransition>> seriesGroup = groupBySeriesId(r.getSeriesTransistions());
        final Jsons.Obj episodesObj = buildEpisodesObj(episodeGroup);
        final Jsons.Obj seriesObj = buildSeriesObj(seriesGroup);
        // create final response
        return ok(obj(p("episodes", episodesObj), p("series", seriesObj)).toJson());
    } catch (Exception e) {
        logger.error("Error generating getTransitions response", e);
        return serverError();
    }
}
Also used : Jsons(org.opencastproject.util.Jsons) TransitionQuery(org.opencastproject.authorization.xacml.manager.api.TransitionQuery) JsonConv.fullAccessControlList(org.opencastproject.authorization.xacml.manager.endpoint.JsonConv.fullAccessControlList) List(java.util.List) AccessControlList(org.opencastproject.security.api.AccessControlList) AclService(org.opencastproject.authorization.xacml.manager.api.AclService) TransitionResult(org.opencastproject.authorization.xacml.manager.api.TransitionResult) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 2 with TransitionResult

use of org.opencastproject.authorization.xacml.manager.api.TransitionResult 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());
}
Also used : SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) TransitionQuery(org.opencastproject.authorization.xacml.manager.api.TransitionQuery) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) TransitionResult(org.opencastproject.authorization.xacml.manager.api.TransitionResult) Date(java.util.Date) Test(org.junit.Test)

Example 3 with TransitionResult

use of org.opencastproject.authorization.xacml.manager.api.TransitionResult in project opencast by opencast.

the class AclServiceImpl method deleteAcl.

@Override
public boolean deleteAcl(long id) throws AclServiceException, NotFoundException {
    final TransitionQuery query = TransitionQuery.query().withDone(false).withAclId(id);
    final TransitionResult result = persistence.getByQuery(organization, query);
    if (result.getEpisodeTransistions().size() > 0 || result.getSeriesTransistions().size() > 0)
        return false;
    Option<ManagedAcl> deletedAcl = getAcl(id);
    if (aclDb.deleteAcl(organization, id)) {
        if (deletedAcl.isSome()) {
            AclItem aclItem = AclItem.delete(deletedAcl.get().getName());
            messageSender.sendObjectMessage(AclItem.ACL_QUEUE, MessageSender.DestinationType.Queue, aclItem);
        }
        return true;
    }
    throw new NotFoundException("Managed acl with id " + id + " not found.");
}
Also used : AclItem(org.opencastproject.message.broker.api.acl.AclItem) TransitionQuery(org.opencastproject.authorization.xacml.manager.api.TransitionQuery) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) NotFoundException(org.opencastproject.util.NotFoundException) TransitionResult(org.opencastproject.authorization.xacml.manager.api.TransitionResult)

Aggregations

TransitionQuery (org.opencastproject.authorization.xacml.manager.api.TransitionQuery)3 TransitionResult (org.opencastproject.authorization.xacml.manager.api.TransitionResult)3 Date (java.util.Date)2 ManagedAcl (org.opencastproject.authorization.xacml.manager.api.ManagedAcl)2 NotFoundException (org.opencastproject.util.NotFoundException)2 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Test (org.junit.Test)1 AclService (org.opencastproject.authorization.xacml.manager.api.AclService)1 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)1 AclServiceNoReferenceException (org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException)1 EpisodeACLTransition (org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition)1 SeriesACLTransition (org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition)1 JsonConv.fullAccessControlList (org.opencastproject.authorization.xacml.manager.endpoint.JsonConv.fullAccessControlList)1 AclTransitionDbDuplicatedException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException)1 AclItem (org.opencastproject.message.broker.api.acl.AclItem)1 AccessControlList (org.opencastproject.security.api.AccessControlList)1