use of org.opencastproject.util.Jsons.Prop in project opencast by opencast.
the class SchedulerRestService method getTechnicalMetadataJSON.
/**
* Gets a XML with the media package for the specified event.
*
* @param eventId
* The unique ID of the event.
* @return media package XML for the event
*/
@GET
@Produces(MediaType.TEXT_XML)
@Path("{id:.+}/technical.json")
@RestQuery(name = "gettechnicalmetadatajson", description = "Retrieves the technical metadata for specified event", returnDescription = "technical metadata as JSON", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "ID of event for which the technical metadata will be retrieved", type = Type.STRING) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "technical metadata of event is in the body of response"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "Event with specified ID does not exist"), @RestResponse(responseCode = HttpServletResponse.SC_UNAUTHORIZED, description = "You do not have permission to remove the event. Maybe you need to authenticate.") })
public Response getTechnicalMetadataJSON(@PathParam("id") String eventId) throws UnauthorizedException {
try {
TechnicalMetadata metadata = service.getTechnicalMetadata(eventId);
Val state = v("");
Val lastHeard = v("");
if (metadata.getRecording().isSome()) {
state = v(metadata.getRecording().get().getState());
lastHeard = v(DateTimeSupport.toUTC(metadata.getRecording().get().getLastCheckinTime()));
}
Arr presenters = arr(mlist(metadata.getPresenters()).map(Jsons.stringVal));
List<Prop> wfProperties = new ArrayList<>();
for (Entry<String, String> entry : metadata.getWorkflowProperties().entrySet()) {
wfProperties.add(p(entry.getKey(), entry.getValue()));
}
List<Prop> agentConfig = new ArrayList<>();
for (Entry<String, String> entry : metadata.getCaptureAgentConfiguration().entrySet()) {
agentConfig.add(p(entry.getKey(), entry.getValue()));
}
return RestUtil.R.ok(obj(p("id", metadata.getEventId()), p("location", metadata.getAgentId()), p("start", DateTimeSupport.toUTC(metadata.getStartDate().getTime())), p("end", DateTimeSupport.toUTC(metadata.getEndDate().getTime())), p("optOut", metadata.isOptOut()), p("presenters", presenters), p("wfProperties", obj(wfProperties.toArray(new Prop[wfProperties.size()]))), p("agentConfig", obj(agentConfig.toArray(new Prop[agentConfig.size()]))), p("state", state), p("lastHeardFrom", lastHeard)));
} catch (NotFoundException e) {
logger.info("Event with id '{}' does not exist.", eventId);
return Response.status(Status.NOT_FOUND).build();
} catch (SchedulerException e) {
logger.error("Unable to retrieve event with id '{}': {}", eventId, getMessage(e));
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations