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();
}
}
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));
}
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();
}
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)));
}
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)));
}
Aggregations