Search in sources :

Example 1 with MultiMap

use of org.opencastproject.util.data.MultiMap in project opencast by opencast.

the class AbstractAclServiceRestEndpoint method getTransitionsFor.

@GET
@Path("/transitionsfor.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getTransitionsForAsJson", description = "Get the transitions for a list of episodes and/or series as json. At least one of the lists must not be empty.", returnDescription = "Get the transitions as json", restParameters = { @RestParameter(name = "episodeIds", isRequired = false, description = "A list of comma separated episode IDs", type = STRING), @RestParameter(name = "seriesIds", isRequired = false, description = "A list of comma separated series IDs", type = STRING), @RestParameter(name = "done", isRequired = false, description = "Indicates if already applied transitions should be included", type = BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The request was processed succesfully"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Parameter error"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during processing the request") })
public Response getTransitionsFor(@QueryParam("episodeIds") String episodeIds, @QueryParam("seriesIds") String seriesIds, @DefaultValue("false") @QueryParam("done") final boolean done) {
    final Monadics.ListMonadic<String> eIds = splitCommaSeparatedParam(option(episodeIds));
    final Monadics.ListMonadic<String> sIds = splitCommaSeparatedParam(option(seriesIds));
    if (eIds.value().isEmpty() && sIds.value().isEmpty()) {
        return badRequest();
    }
    final AclService aclService = aclService();
    try {
        // episodeId -> [transitions]
        final Map<String, List<EpisodeACLTransition>> eTs = eIds.foldl(MultiMap.<String, EpisodeACLTransition>multiHashMapWithArrayList(), new Function2.X<MultiMap<String, EpisodeACLTransition>, String, MultiMap<String, EpisodeACLTransition>>() {

            @Override
            public MultiMap<String, EpisodeACLTransition> xapply(MultiMap<String, EpisodeACLTransition> mmap, String id) throws Exception {
                // todo it is quite expensive to query each episode separately
                final TransitionQuery q = TransitionQuery.query().withId(id).withScope(AclScope.Episode).withDone(done);
                return mmap.putAll(id, aclService.getTransitions(q).getEpisodeTransistions());
            }
        }).value();
        // seriesId -> [transitions]
        final Map<String, List<SeriesACLTransition>> sTs = sIds.foldl(MultiMap.<String, SeriesACLTransition>multiHashMapWithArrayList(), new Function2.X<MultiMap<String, SeriesACLTransition>, String, MultiMap<String, SeriesACLTransition>>() {

            @Override
            public MultiMap<String, SeriesACLTransition> xapply(MultiMap<String, SeriesACLTransition> mmap, String id) throws Exception {
                // todo it is quite expensive to query each series separately
                final TransitionQuery q = TransitionQuery.query().withId(id).withScope(AclScope.Series).withDone(done);
                return mmap.putAll(id, aclService.getTransitions(q).getSeriesTransistions());
            }
        }).value();
        final Jsons.Obj episodesObj = buildEpisodesObj(eTs);
        final Jsons.Obj seriesObj = buildSeriesObj(sTs);
        return ok(obj(p("episodes", episodesObj), p("series", seriesObj)).toJson());
    } catch (Exception e) {
        logger.error("Error generating getTransitionsFor response", e);
        return serverError();
    }
}
Also used : Monadics(org.opencastproject.util.data.Monadics) Jsons(org.opencastproject.util.Jsons) SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) 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) MultiMap(org.opencastproject.util.data.MultiMap) 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) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

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 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 TransitionQuery (org.opencastproject.authorization.xacml.manager.api.TransitionQuery)1 JsonConv.fullAccessControlList (org.opencastproject.authorization.xacml.manager.endpoint.JsonConv.fullAccessControlList)1 AclTransitionDbDuplicatedException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException)1 AccessControlList (org.opencastproject.security.api.AccessControlList)1 SeriesException (org.opencastproject.series.api.SeriesException)1 Jsons (org.opencastproject.util.Jsons)1 NotFoundException (org.opencastproject.util.NotFoundException)1 Monadics (org.opencastproject.util.data.Monadics)1 MultiMap (org.opencastproject.util.data.MultiMap)1 RestQuery (org.opencastproject.util.doc.rest.RestQuery)1