use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class RestDocsAnnotationTest method testRestQueryDocs.
@Test
public void testRestQueryDocs() {
Method testMethod;
try {
testMethod = TestServletSample.class.getMethod("methodA");
if (testMethod != null) {
RestQuery annotation = (RestQuery) testMethod.getAnnotation(RestQuery.class);
Assert.assertEquals("Starts a capture using the default devices as appropriate.", annotation.description());
Assert.assertEquals("A list of capture agent things", annotation.returnDescription());
Assert.assertTrue(annotation.pathParameters().length == 1);
Assert.assertEquals("location", annotation.pathParameters()[0].name());
Assert.assertEquals("The room of the capture agent", annotation.pathParameters()[0].description());
Assert.assertFalse(annotation.pathParameters()[0].isRequired());
Assert.assertTrue(annotation.restParameters().length == 1);
Assert.assertEquals("id", annotation.restParameters()[0].name());
Assert.assertEquals("The ID of the capture to start", annotation.restParameters()[0].description());
Assert.assertTrue(annotation.restParameters()[0].isRequired());
Assert.assertTrue(annotation.reponses().length == 2);
Assert.assertEquals(200, annotation.reponses()[0].responseCode());
Assert.assertEquals("When the capture started correctly", annotation.reponses()[0].description());
Assert.assertEquals(400, annotation.reponses()[1].responseCode());
Assert.assertEquals("When there are no media devices", annotation.reponses()[1].description());
}
} catch (SecurityException e) {
Assert.fail();
} catch (NoSuchMethodException e) {
Assert.fail();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class IBMWatsonTranscriptionRestService method reportStatus.
/**
* { "id": "{job_id}", "event": "{recognitions_status}", "user_token": "{user_token}" } If the event is
* recognitions.completed_with_results, the object includes a results field that provides the results of the
* recognition request. The client should respond to the callback notification with status code 200.
*/
@POST
@Path("results")
@Produces(MediaType.TEXT_PLAIN)
@RestQuery(name = "results", description = "Called by the speech-to-text service to report status.", returnDescription = "", reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Got notification!") })
public Response reportStatus(String body) {
logger.trace("Body is: " + body);
JSONObject jsonObj = null;
try {
JSONParser parser = new JSONParser();
jsonObj = (JSONObject) parser.parse(body);
// jsonObj = (JSONObject) parser.parse(request.getReader());
String mpId = (String) jsonObj.get("user_token");
String event = (String) jsonObj.get("event");
logger.info("Transcription notification for mp {} is {}", mpId, event);
if (IBMWatsonTranscriptionService.JobEvent.COMPLETED_WITH_RESULTS.equals(event))
service.transcriptionDone(mpId, jsonObj);
else if (IBMWatsonTranscriptionService.JobEvent.FAILED.equals(event))
service.transcriptionError(mpId, jsonObj);
// return Response.ok().build();
return Response.ok().type(MediaType.APPLICATION_JSON).build();
} catch (ParseException e) {
logger.warn("{} occurred. Notification results could not be parsed: {}", e.getClass(), jsonObj == null ? jsonObj : jsonObj.toJSONString());
return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
} catch (Exception e) {
logger.warn(e.getMessage());
return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class CaptureAgentStateRestService method getKnownAgents.
@GET
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Path("agents.{type:xml|json}")
@RestQuery(name = "getKnownAgents", description = "Return all of the known capture agents on the system", pathParameters = { @RestParameter(description = "The Document type", isRequired = true, name = "type", type = Type.STRING) }, restParameters = {}, reponses = { @RestResponse(description = "An XML representation of the agent capabilities", responseCode = SC_OK) }, returnDescription = "")
public Response getKnownAgents(@PathParam("type") String type) {
if (service == null)
return Response.serverError().status(Response.Status.SERVICE_UNAVAILABLE).build();
logger.debug("Returning list of known agents...");
LinkedList<AgentStateUpdate> update = new LinkedList<AgentStateUpdate>();
Map<String, Agent> data = service.getKnownAgents();
logger.debug("Agents: {}", data);
// Run through and build a map of updates (rather than states)
for (Entry<String, Agent> e : data.entrySet()) {
update.add(new AgentStateUpdate(e.getValue()));
}
if ("json".equals(type)) {
return Response.ok(new AgentStateUpdateList(update)).type(MediaType.APPLICATION_JSON).build();
} else {
return Response.ok(new AgentStateUpdateList(update)).type(MediaType.TEXT_XML).build();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class CaptureAgentStateRestService method setConfiguration.
@POST
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Path("agents/{name}/configuration")
@RestQuery(name = "setAgentStateConfiguration", description = "Set the configuration of a given capture agent, registering it if it does not exist", pathParameters = { @RestParameter(description = "Name of the capture agent", isRequired = true, name = "name", type = Type.STRING) }, restParameters = { @RestParameter(description = "An XML or JSON representation of the capabilities. XML as specified in " + "http://java.sun.com/dtd/properties.dtd (friendly names as keys, device locations as corresponding values)", type = Type.TEXT, isRequired = true, name = "configuration") }, reponses = { @RestResponse(description = "An XML or JSON representation of the agent configuration", responseCode = SC_OK), @RestResponse(description = "The configuration format is incorrect OR the agent name is blank or null", responseCode = SC_BAD_REQUEST) }, returnDescription = "")
public Response setConfiguration(@PathParam("name") String agentName, @FormParam("configuration") String configuration) {
if (service == null)
return Response.serverError().status(Response.Status.SERVICE_UNAVAILABLE).build();
if (StringUtils.isBlank(configuration)) {
logger.debug("The configuration data cannot be blank");
return Response.serverError().status(Response.Status.BAD_REQUEST).build();
}
Properties caps;
if (StringUtils.startsWith(configuration, "{")) {
// JSON
Gson gson = new Gson();
try {
caps = gson.fromJson(configuration, Properties.class);
if (!service.setAgentConfiguration(agentName, caps)) {
logger.debug("'{}''s configuration has not been updated because nothing has been changed", agentName);
}
return Response.ok(gson.toJson(caps)).type(MediaType.APPLICATION_JSON).build();
} catch (JsonSyntaxException e) {
logger.debug("Exception when deserializing capabilities: {}", e.getMessage());
return Response.status(javax.ws.rs.core.Response.Status.BAD_REQUEST).build();
}
} else {
// XML
caps = new Properties();
ByteArrayInputStream bais = null;
try {
bais = new ByteArrayInputStream(configuration.getBytes());
caps.loadFromXML(bais);
if (!service.setAgentConfiguration(agentName, caps)) {
logger.debug("'{}''s configuration has not been updated because nothing has been changed", agentName);
}
// Prepares the value to return
PropertiesResponse r = new PropertiesResponse(caps);
logger.debug("{}'s configuration updated", agentName);
return Response.ok(r).type(MediaType.TEXT_XML).build();
} catch (IOException e) {
logger.debug("Unexpected I/O Exception when unmarshalling the capabilities: {}", e.getMessage());
return Response.status(javax.ws.rs.core.Response.Status.BAD_REQUEST).build();
} finally {
IOUtils.closeQuietly(bais);
}
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class CaptureAgentStateRestService method getAllRecordings.
@GET
@Produces(MediaType.TEXT_XML)
@Path("recordings")
@RestQuery(name = "getAllRecordings", description = "Return all registered recordings and their state", pathParameters = {}, restParameters = {}, reponses = { @RestResponse(description = "Returns all known recordings.", responseCode = SC_OK) }, returnDescription = "")
public List<RecordingStateUpdate> getAllRecordings() {
try {
LinkedList<RecordingStateUpdate> update = new LinkedList<RecordingStateUpdate>();
Map<String, Recording> data = schedulerService.getKnownRecordings();
// Run through and build a map of updates (rather than states)
for (Entry<String, Recording> e : data.entrySet()) {
update.add(new RecordingStateUpdate(e.getValue()));
}
return update;
} catch (SchedulerException e) {
logger.debug("Unable to get all recordings: {}", ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations