Search in sources :

Example 91 with RestQuery

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

the class CaptureAgentStateRestService method getRecordingState.

@GET
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Path("recordings/{id}.{type:xml|json|}")
@RestQuery(name = "getRecordingState", description = "Return the state of a given recording", pathParameters = { @RestParameter(description = "The ID of a given recording", isRequired = true, name = "id", type = Type.STRING), @RestParameter(description = "The Documenttype", isRequired = true, name = "type", type = Type.STRING) }, restParameters = {}, reponses = { @RestResponse(description = "Returns the state of the recording with the correct id", responseCode = SC_OK), @RestResponse(description = "The recording with the specified ID does not exist", responseCode = SC_NOT_FOUND) }, returnDescription = "")
public Response getRecordingState(@PathParam("id") String id, @PathParam("type") String type) throws NotFoundException {
    try {
        Recording rec = schedulerService.getRecordingState(id);
        logger.debug("Submitting state for recording {}", id);
        if ("json".equals(type)) {
            return Response.ok(new RecordingStateUpdate(rec)).type(MediaType.APPLICATION_JSON).build();
        } else {
            return Response.ok(new RecordingStateUpdate(rec)).type(MediaType.TEXT_XML).build();
        }
    } catch (SchedulerException e) {
        logger.debug("Unable to get recording state of {}: {}", id, ExceptionUtils.getStackTrace(e));
        return Response.serverError().build();
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) Recording(org.opencastproject.scheduler.api.Recording) RecordingStateUpdate(org.opencastproject.capture.admin.impl.RecordingStateUpdate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 92 with RestQuery

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

the class BaseEndpoint method getUserInfo.

@GET
@Path("info/me")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "getuserinfo", description = "Returns information on the logged in user.", returnDescription = "", reponses = { @RestResponse(description = "The user information is returned.", responseCode = HttpServletResponse.SC_OK) })
public Response getUserInfo() {
    final User user = securityService.getUser();
    JValue json = obj(f("email", v(user.getEmail(), Jsons.BLANK)), f("name", v(user.getName())), f("provider", v(user.getProvider())), f("userrole", v(getUserIdRole(user.getUsername()))), f("username", v(user.getUsername())));
    return RestUtil.R.ok(MediaType.APPLICATION_JSON_TYPE, serializer.toJson(json));
}
Also used : User(org.opencastproject.security.api.User) JValue(com.entwinemedia.fn.data.json.JValue) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 93 with RestQuery

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

the class BaseEndpoint method recreateIndex.

@POST
@Path("recreateIndex")
@RestQuery(name = "recreateIndex", description = "Repopulates the External Index directly from the Services", returnDescription = "OK if repopulation has started", reponses = { @RestResponse(description = "OK if repopulation has started", responseCode = HttpServletResponse.SC_OK) })
public Response recreateIndex() {
    final SecurityContext securityContext = new SecurityContext(securityService, securityService.getOrganization(), securityService.getUser());
    executor.execute(new Runnable() {

        @Override
        public void run() {
            securityContext.runInContext(new Effect0() {

                @Override
                protected void run() {
                    try {
                        logger.info("Starting to repopulate the external index");
                        externalIndex.recreateIndex();
                        logger.info("Finished repopulating the external index");
                    } catch (InterruptedException e) {
                        logger.error("Repopulating the external index was interrupted {}", getStackTrace(e));
                    } catch (CancellationException e) {
                        logger.trace("Listening for external index messages has been cancelled.");
                    } catch (ExecutionException e) {
                        logger.error("Repopulating the external index failed to execute because {}", getStackTrace(e));
                    } catch (Throwable t) {
                        logger.error("Repopulating the external index failed because {}", getStackTrace(t));
                    }
                }
            });
        }
    });
    return R.ok();
}
Also used : CancellationException(java.util.concurrent.CancellationException) Effect0(org.opencastproject.util.data.Effect0) SecurityContext(org.opencastproject.security.util.SecurityContext) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 94 with RestQuery

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

the class BaseEndpoint method getUserRoles.

@GET
@Path("info/me/roles")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "getuserroles", description = "Returns current user's roles.", returnDescription = "", reponses = { @RestResponse(description = "The set of roles is returned.", responseCode = HttpServletResponse.SC_OK) })
public Response getUserRoles() {
    final User user = securityService.getUser();
    List<JValue> roles = new ArrayList<>();
    for (final Role role : user.getRoles()) {
        roles.add(v(role.getName()));
    }
    return RestUtil.R.ok(MediaType.APPLICATION_JSON_TYPE, serializer.toJson(arr(roles)));
}
Also used : UserIdRoleProvider.getUserIdRole(org.opencastproject.userdirectory.UserIdRoleProvider.getUserIdRole) Role(org.opencastproject.security.api.Role) User(org.opencastproject.security.api.User) JValue(com.entwinemedia.fn.data.json.JValue) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 95 with RestQuery

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

the class BaseEndpoint method getOrganizationProperties.

@GET
@Path("info/organization/properties")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "getorganizationproperties", description = "Returns the current organization's properties.", returnDescription = "", reponses = { @RestResponse(description = "The organization properties are returned.", responseCode = HttpServletResponse.SC_OK) })
public Response getOrganizationProperties() {
    final Organization org = securityService.getOrganization();
    List<Field> props = new ArrayList<>();
    for (Entry<String, String> prop : org.getProperties().entrySet()) {
        props.add(f(prop.getKey(), v(prop.getValue(), Jsons.BLANK)));
    }
    return RestUtil.R.ok(MediaType.APPLICATION_JSON_TYPE, serializer.toJson(obj(props)));
}
Also used : Field(com.entwinemedia.fn.data.json.Field) Organization(org.opencastproject.security.api.Organization) ArrayList(java.util.ArrayList) JString(com.entwinemedia.fn.data.json.JString) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) 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