use of com.entwinemedia.fn.data.json.Field 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)));
}
use of com.entwinemedia.fn.data.json.Field in project opencast by opencast.
the class EventsEndpoint method getEventMedia.
@GET
@Path("{eventId}/media")
@Produces({ "application/json", "application/v1.0.0+json" })
public Response getEventMedia(@HeaderParam("Accept") String acceptHeader, @PathParam("eventId") String id) throws Exception {
ArrayList<TrackImpl> tracks = new ArrayList<>();
for (final Event event : indexService.getEvent(id, externalIndex)) {
final MediaPackage mp = indexService.getEventMediapackage(event);
for (Track track : mp.getTracks()) {
if (track instanceof TrackImpl) {
tracks.add((TrackImpl) track);
}
}
List<JValue> tracksJson = new ArrayList<>();
for (Track track : tracks) {
List<Field> fields = new ArrayList<>();
if (track.getChecksum() != null)
fields.add(f("checksum", v(track.getChecksum().toString())));
if (track.getDescription() != null)
fields.add(f("description", v(track.getDescription())));
if (track.getDuration() != null)
fields.add(f("duration", v(track.getDuration())));
if (track.getElementDescription() != null)
fields.add(f("element-description", v(track.getElementDescription())));
if (track.getFlavor() != null)
fields.add(f("flavor", v(track.getFlavor().toString())));
if (track.getIdentifier() != null)
fields.add(f("identifier", v(track.getIdentifier())));
if (track.getMimeType() != null)
fields.add(f("identifier", v(track.getMimeType().toString())));
fields.add(f("size", v(track.getSize())));
if (track.getStreams() != null) {
List<Field> streams = new ArrayList<>();
for (Stream stream : track.getStreams()) {
streams.add(f(stream.getIdentifier(), getJsonStream(stream)));
}
fields.add(f("streams", obj(streams)));
}
if (track.getTags() != null) {
List<JValue> tags = new ArrayList<>();
for (String tag : track.getTags()) {
tags.add(v(tag));
}
fields.add(f("tags", arr(tags)));
}
if (track.getURI() != null)
fields.add(f("uri", v(track.getURI().toString())));
tracksJson.add(obj(fields));
}
return ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, arr(tracksJson));
}
return ApiResponses.notFound("Cannot find an event with id '%s'.", id);
}
use of com.entwinemedia.fn.data.json.Field in project opencast by opencast.
the class EventComment method toJValue.
public JValue toJValue() {
JValue authorObj = obj(f("name", v(author.getName(), BLANK)), f("username", v(author.getUsername())), f("email", v(author.getEmail(), BLANK)));
List<JValue> replyArr = new ArrayList<JValue>();
for (EventCommentReply reply : replies) {
replyArr.add(reply.toJValue());
}
JValue idValue = ZERO;
if (id.isSome())
idValue = v(id.get());
List<Field> fields = new ArrayList<Field>();
fields.add(f("id", idValue));
fields.add(f("text", v(text)));
fields.add(f("creationDate", v(DateTimeSupport.toUTC(creationDate.getTime()))));
fields.add(f("modificationDate", v(DateTimeSupport.toUTC(modificationDate.getTime()))));
fields.add(f("author", authorObj));
fields.add(f("reason", v(reason)));
fields.add(f("resolvedStatus", v(resolvedStatus)));
fields.add(f("replies", arr(replyArr)));
return obj(fields);
}
use of com.entwinemedia.fn.data.json.Field in project opencast by opencast.
the class AbstractEventEndpoint method getEventWorkflows.
@GET
@Path("{eventId}/workflows.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "geteventworkflows", description = "Returns all the data related to the workflows tab in the event details modal as JSON", returnDescription = "All the data related to the event workflows tab as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns all the data related to the event workflows tab as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getEventWorkflows(@PathParam("eventId") String id) throws UnauthorizedException, SearchIndexException, JobEndpointException {
Opt<Event> optEvent = getIndexService().getEvent(id, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", id);
try {
if (!optEvent.get().hasRecordingStarted()) {
List<Field> fields = new ArrayList<Field>();
Map<String, String> workflowConfig = getSchedulerService().getWorkflowConfig(id);
for (Entry<String, String> entry : workflowConfig.entrySet()) {
fields.add(f(entry.getKey(), v(entry.getValue(), Jsons.BLANK)));
}
Map<String, String> agentConfiguration = getSchedulerService().getCaptureAgentConfiguration(id);
return okJson(obj(f("workflowId", v(agentConfiguration.get(CaptureParameters.INGEST_WORKFLOW_DEFINITION), Jsons.BLANK)), f("configuration", obj(fields))));
} else {
return okJson(getJobService().getTasksAsJSON(new WorkflowQuery().withMediaPackage(id)));
}
} catch (NotFoundException e) {
return notFound("Cannot find workflows for event %s", id);
} catch (SchedulerException e) {
logger.error("Unable to get workflow data for event with id {}", id);
throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
}
}
use of com.entwinemedia.fn.data.json.Field in project opencast by opencast.
the class JobEndpoint method getTasksAsJSON.
/**
* Returns the single task with the given Id as JSON Object
*
* @param id
* @return The job as JSON Object
* @throws JobEndpointException
* @throws NotFoundException
*/
public JObject getTasksAsJSON(long id) throws JobEndpointException, NotFoundException {
WorkflowInstance instance = getWorkflowById(id);
// Retrieve submission date with the workflow instance main job
Date created;
long duration = 0;
try {
Job job = serviceRegistry.getJob(id);
created = job.getDateCreated();
Date completed = job.getDateCompleted();
if (completed == null)
completed = new Date();
duration = (completed.getTime() - created.getTime());
} catch (ServiceRegistryException e) {
throw new JobEndpointException(String.format("Error when retrieving job %s from the service registry: %s", id, e), e.getCause());
}
MediaPackage mp = instance.getMediaPackage();
List<Field> fields = new ArrayList<>();
for (String key : instance.getConfigurationKeys()) {
fields.add(f(key, v(instance.getConfiguration(key), Jsons.BLANK)));
}
return obj(f("start", v(created != null ? toUTC(created.getTime()) : "", Jsons.BLANK)), f("state", v(instance.getState(), Jsons.BLANK)), f("description", v(instance.getDescription(), Jsons.BLANK)), f("duration", v(duration, Jsons.BLANK)), f("id", v(instance.getId(), Jsons.BLANK)), f("workflow", v(instance.getTitle(), Jsons.BLANK)), f("workflowId", v(instance.getTemplate(), Jsons.BLANK)), f("title", v(mp.getTitle(), Jsons.BLANK)), f("series", v(mp.getSeries(), Jsons.BLANK)), f("series_title", v(mp.getSeriesTitle(), Jsons.BLANK)), f("license", v(mp.getLicense(), Jsons.BLANK)), f("configuration", obj(fields)));
}
Aggregations