use of com.entwinemedia.fn.data.json.JValue in project opencast by opencast.
the class SeriesEndpoint method getSeries.
@GET
@Path("{seriesId}")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "getseries", description = "Returns a single series.", returnDescription = "", pathParameters = { @RestParameter(name = "seriesId", description = "The series id", isRequired = true, type = STRING) }, reponses = { @RestResponse(description = "The series is returned.", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "The specified series does not exist.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getSeries(@HeaderParam("Accept") String acceptHeader, @PathParam("seriesId") String id) throws Exception {
for (final Series s : indexService.getSeries(id, externalIndex)) {
JValue subjects;
if (s.getSubject() == null) {
subjects = arr();
} else {
subjects = arr(splitSubjectIntoArray(s.getSubject()));
}
Date createdDate = s.getCreatedDateTime();
return ApiResponses.Json.ok(VERSION_1_0_0, obj(f("identifier", v(s.getIdentifier())), f("title", v(s.getTitle())), f("description", v(s.getDescription(), BLANK)), f("creator", v(s.getCreator(), BLANK)), f("subjects", subjects), f("organization", v(s.getOrganization())), f("created", v(createdDate != null ? toUTC(createdDate.getTime()) : null, BLANK)), f("contributors", arr($(s.getContributors()).map(Functions.stringToJValue))), f("organizers", arr($(s.getOrganizers()).map(Functions.stringToJValue))), f("publishers", arr($(s.getPublishers()).map(Functions.stringToJValue))), f("opt_out", v(s.isOptedOut()))));
}
return ApiResponses.notFound("Cannot find an series with id '%s'.", id);
}
use of com.entwinemedia.fn.data.json.JValue 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.JValue in project opencast by opencast.
the class AbstractEventEndpoint method getNewProcessing.
@GET
@Path("new/processing")
@RestQuery(name = "getNewProcessing", description = "Returns all the data related to the processing tab in the new event modal as JSON", returnDescription = "All the data related to the event processing tab as JSON", restParameters = { @RestParameter(name = "tags", isRequired = false, description = "A comma separated list of tags to filter the workflow definitions", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Returns all the data related to the event processing tab as JSON") })
public Response getNewProcessing(@QueryParam("tags") String tagsString) {
List<String> tags = RestUtil.splitCommaSeparatedParam(Option.option(tagsString)).value();
List<JValue> workflows = new ArrayList<>();
try {
List<WorkflowDefinition> workflowsDefinitions = getWorkflowService().listAvailableWorkflowDefinitions();
for (WorkflowDefinition wflDef : workflowsDefinitions) {
if (wflDef.containsTag(tags)) {
workflows.add(obj(f("id", v(wflDef.getId())), f("title", v(nul(wflDef.getTitle()).getOr(""))), f("description", v(nul(wflDef.getDescription()).getOr(""))), f("configuration_panel", v(nul(wflDef.getConfigurationPanel()).getOr("")))));
}
}
} catch (WorkflowDatabaseException e) {
logger.error("Unable to get available workflow definitions: {}", ExceptionUtils.getStackTrace(e));
return RestUtil.R.serverError();
}
JValue data = obj(f("workflows", arr(workflows)), f("default_workflow_id", v(defaultWorkflowDefinionId, Jsons.NULL)));
return okJson(data);
}
use of com.entwinemedia.fn.data.json.JValue in project opencast by opencast.
the class AbstractEventEndpoint method getEventGeneralTab.
@GET
@Path("{eventId}/general.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "geteventgeneral", description = "Returns all the data related to the general tab in the event details modal as JSON", returnDescription = "All the data related to the event general tab as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id (mediapackage id).", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns all the data related to the event general tab as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getEventGeneralTab(@PathParam("eventId") String id) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(id, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", id);
// Quick actions have been temporally removed from the general tab
// ---------------------------------------------------------------
// List<JValue> actions = new ArrayList<JValue>();
// List<WorkflowDefinition> workflowsDefinitions = getWorkflowService().listAvailableWorkflowDefinitions();
// for (WorkflowDefinition wflDef : workflowsDefinitions) {
// if (wflDef.containsTag(WORKFLOWDEF_TAG)) {
//
// actions.add(obj(f("id", v(wflDef.getId())), f("title", v(Opt.nul(wflDef.getTitle()).or(""))),
// f("description", v(Opt.nul(wflDef.getDescription()).or(""))),
// f("configuration_panel", v(Opt.nul(wflDef.getConfigurationPanel()).or("")))));
// }
// }
Event event = optEvent.get();
List<JValue> pubJSON = eventPublicationsToJson(event);
return okJson(obj(f("publications", arr(pubJSON)), f("optout", v(event.getOptedOut(), Jsons.BLANK)), f("blacklisted", v(event.getBlacklisted(), Jsons.BLANK)), f("review-status", v(event.getReviewStatus(), Jsons.BLANK)), f("start-date", v(event.getRecordingStartDate(), Jsons.BLANK)), f("end-date", v(event.getRecordingEndDate(), Jsons.BLANK))));
}
use of com.entwinemedia.fn.data.json.JValue in project opencast by opencast.
the class GroupsEndpoint method membersToJSON.
/**
* Generate a JSON array based on the given set of members
*
* @param members
* the members source
* @return a JSON array ({@link JValue}) with the given members
*/
private JValue membersToJSON(Set<String> members) {
List<JValue> membersJSON = new ArrayList<>();
for (String username : members) {
User user = userDirectoryService.loadUser(username);
String name = username;
if (user != null && StringUtils.isNotBlank(user.getName())) {
name = user.getName();
}
membersJSON.add(obj(f("username", v(username)), f("name", v(name))));
}
return arr(membersJSON);
}
Aggregations