Search in sources :

Example 1 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.

the class AbstractAclServiceRestEndpoint method updateAcl.

@PUT
@Path("/acl/{aclId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "updateacl", description = "Update an ACL", returnDescription = "Update an ACL", pathParameters = { @RestParameter(name = "aclId", isRequired = true, description = "The ACL identifier", type = INTEGER) }, restParameters = { @RestParameter(name = "name", isRequired = true, description = "The ACL name", type = STRING), @RestParameter(name = "acl", isRequired = true, description = "The access control list", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has successfully been updated"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The ACL has not been found"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the ACL"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during updating the ACL") })
public String updateAcl(@PathParam("aclId") long aclId, @FormParam("name") String name, @FormParam("acl") String accessControlList) throws NotFoundException {
    final Organization org = getSecurityService().getOrganization();
    final AccessControlList acl = parseAcl.apply(accessControlList);
    final ManagedAclImpl managedAcl = new ManagedAclImpl(aclId, name, org.getId(), acl);
    if (!aclService().updateAcl(managedAcl)) {
        logger.info("No ACL with id '{}' could be found under organization '{}'", aclId, org.getId());
        throw new NotFoundException();
    }
    return JsonConv.full(managedAcl).toJson();
}
Also used : JsonConv.fullAccessControlList(org.opencastproject.authorization.xacml.manager.endpoint.JsonConv.fullAccessControlList) AccessControlList(org.opencastproject.security.api.AccessControlList) Organization(org.opencastproject.security.api.Organization) ManagedAclImpl(org.opencastproject.authorization.xacml.manager.impl.ManagedAclImpl) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 2 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.

the class AbstractAclServiceRestEndpoint method updateEpisodeTransition.

@PUT
@Path("/episode/{transitionId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "updateepisodetransition", description = "Update an existing episode transition", returnDescription = "Update an existing episode transition", pathParameters = { @RestParameter(name = "transitionId", isRequired = true, description = "The transition 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 updated"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during updating an episode transition") })
public String updateEpisodeTransition(@PathParam("transitionId") long transitionId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") Long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) throws NotFoundException {
    try {
        final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
        final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
        final EpisodeACLTransition t = aclService().updateEpisodeTransition(transitionId, option(managedAclId), at, workflow);
        return JsonConv.full(t).toJson();
    } catch (AclServiceException e) {
        logger.warn("Error updating episode transition:", e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (NotFoundException e) {
        throw e;
    } 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) NotFoundException(org.opencastproject.util.NotFoundException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) 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) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 3 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery 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 4 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.

the class AbstractAclServiceRestEndpoint method addSeriesTransition.

@POST
@Path("/series/{seriesId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "addseriestransition", description = "Add a series transition", returnDescription = "Add a series transition", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series id", type = STRING) }, restParameters = { @RestParameter(name = "applicationDate", isRequired = true, description = "The date to applicate", type = STRING), @RestParameter(name = "managedAclId", isRequired = true, 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), @RestParameter(name = "override", isRequired = false, description = "If to override the episode ACL's", type = STRING, defaultValue = "false") }, reponses = { @RestResponse(responseCode = SC_OK, description = "The series transition has successfully been added"), @RestResponse(responseCode = SC_CONFLICT, description = "The series transition with the applicationDate already exists"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The given managed acl id could not be found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during adding a series transition") })
public String addSeriesTransition(@PathParam("seriesId") String seriesId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams, @FormParam("override") boolean override) {
    try {
        final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
        final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
        SeriesACLTransition seriesTransition = aclService().addSeriesTransition(seriesId, managedAclId, at, override, workflow);
        return JsonConv.full(seriesTransition).toJson();
    } catch (AclServiceNoReferenceException e) {
        logger.info("Managed acl with id '{}' coudl not be found", managedAclId);
        throw new WebApplicationException(Status.BAD_REQUEST);
    } catch (AclTransitionDbDuplicatedException e) {
        logger.info("Error adding series transition: transition with date {} already exists", applicationDate);
        throw new WebApplicationException(Status.CONFLICT);
    } catch (AclServiceException e) {
        logger.warn("Error adding series 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) SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) WebApplicationException(javax.ws.rs.WebApplicationException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) 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 5 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.

the class AbstractAclServiceRestEndpoint method createAcl.

@POST
@Path("/acl")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "createacl", description = "Create an ACL", returnDescription = "Create an ACL", restParameters = { @RestParameter(name = "name", isRequired = true, description = "The ACL name", type = STRING), @RestParameter(name = "acl", isRequired = true, description = "The access control list", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has successfully been added"), @RestResponse(responseCode = SC_CONFLICT, description = "An ACL with the same name already exists"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the ACL"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during adding the ACL") })
public String createAcl(@FormParam("name") String name, @FormParam("acl") String accessControlList) {
    final AccessControlList acl = parseAcl.apply(accessControlList);
    final Option<ManagedAcl> managedAcl = aclService().createAcl(acl, name);
    if (managedAcl.isNone()) {
        logger.info("An ACL with the same name '{}' already exists", name);
        throw new WebApplicationException(Response.Status.CONFLICT);
    }
    return JsonConv.full(managedAcl.get()).toJson();
}
Also used : JsonConv.fullAccessControlList(org.opencastproject.authorization.xacml.manager.endpoint.JsonConv.fullAccessControlList) AccessControlList(org.opencastproject.security.api.AccessControlList) WebApplicationException(javax.ws.rs.WebApplicationException) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) JsonConv.digestManagedAcl(org.opencastproject.authorization.xacml.manager.endpoint.JsonConv.digestManagedAcl) Util.getManagedAcl(org.opencastproject.authorization.xacml.manager.impl.Util.getManagedAcl) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

RestQuery (org.opencastproject.util.doc.rest.RestQuery)228 Path (javax.ws.rs.Path)226 Produces (javax.ws.rs.Produces)172 GET (javax.ws.rs.GET)97 POST (javax.ws.rs.POST)89 WebApplicationException (javax.ws.rs.WebApplicationException)83 NotFoundException (org.opencastproject.util.NotFoundException)83 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)55 MediaPackage (org.opencastproject.mediapackage.MediaPackage)52 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)46 Event (org.opencastproject.index.service.impl.index.event.Event)34 ParseException (java.text.ParseException)33 JSONObject (org.json.simple.JSONObject)33 IOException (java.io.IOException)32 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)32 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)31 Job (org.opencastproject.job.api.Job)30 Date (java.util.Date)29 ArrayList (java.util.ArrayList)28 PUT (javax.ws.rs.PUT)28