use of com.entwinemedia.fn.data.json.Field in project opencast by opencast.
the class AbstractEventEndpoint method getCatalogAdapters.
@GET
@Path("catalogAdapters")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getcataloguiadapters", description = "Returns the available catalog UI adapters as JSON", returnDescription = "The catalog UI adapters as JSON", reponses = { @RestResponse(description = "Returns the available catalog UI adapters as JSON", responseCode = HttpServletResponse.SC_OK) })
public Response getCatalogAdapters() {
List<JValue> adapters = new ArrayList<>();
for (EventCatalogUIAdapter adapter : getIndexService().getEventCatalogUIAdapters()) {
List<Field> fields = new ArrayList<>();
fields.add(f("flavor", v(adapter.getFlavor().toString())));
fields.add(f("title", v(adapter.getUITitle())));
adapters.add(obj(fields));
}
return okJson(arr(adapters));
}
use of com.entwinemedia.fn.data.json.Field in project opencast by opencast.
the class AbstractEventEndpoint method streamsToJSON.
private List<Field> streamsToJSON(org.opencastproject.mediapackage.Stream[] streams) {
List<Field> fields = new ArrayList<>();
List<JValue> audioList = new ArrayList<>();
List<JValue> videoList = new ArrayList<>();
for (org.opencastproject.mediapackage.Stream stream : streams) {
// TODO There is a bug with the stream ids, see MH-10325
if (stream instanceof AudioStreamImpl) {
List<Field> audio = new ArrayList<>();
AudioStream audioStream = (AudioStream) stream;
audio.add(f("id", v(audioStream.getIdentifier(), BLANK)));
audio.add(f("type", v(audioStream.getFormat(), BLANK)));
audio.add(f("channels", v(audioStream.getChannels(), BLANK)));
audio.add(f("bitrate", v(audioStream.getBitRate(), BLANK)));
audio.add(f("bitdepth", v(audioStream.getBitDepth(), BLANK)));
audio.add(f("samplingrate", v(audioStream.getSamplingRate(), BLANK)));
audio.add(f("framecount", v(audioStream.getFrameCount(), BLANK)));
audio.add(f("peakleveldb", v(audioStream.getPkLevDb(), BLANK)));
audio.add(f("rmsleveldb", v(audioStream.getRmsLevDb(), BLANK)));
audio.add(f("rmspeakdb", v(audioStream.getRmsPkDb(), BLANK)));
audioList.add(obj(audio));
} else if (stream instanceof VideoStreamImpl) {
List<Field> video = new ArrayList<>();
VideoStream videoStream = (VideoStream) stream;
video.add(f("id", v(videoStream.getIdentifier(), BLANK)));
video.add(f("type", v(videoStream.getFormat(), BLANK)));
video.add(f("bitrate", v(videoStream.getBitRate(), BLANK)));
video.add(f("framerate", v(videoStream.getFrameRate(), BLANK)));
video.add(f("resolution", v(videoStream.getFrameWidth() + "x" + videoStream.getFrameHeight(), BLANK)));
video.add(f("framecount", v(videoStream.getFrameCount(), BLANK)));
video.add(f("scantype", v(videoStream.getScanType(), BLANK)));
video.add(f("scanorder", v(videoStream.getScanOrder(), BLANK)));
videoList.add(obj(video));
} else {
throw new IllegalArgumentException("Stream must be either audio or video");
}
}
fields.add(f("audio", arr(audioList)));
fields.add(f("video", arr(videoList)));
return fields;
}
use of com.entwinemedia.fn.data.json.Field in project opencast by opencast.
the class MessageTemplate method toJValue.
public JValue toJValue() {
JObject creatorObj = obj(f("name", v(creator.getName(), BLANK)), f("username", v(creator.getUsername())), f("email", v(creator.getEmail(), BLANK)));
List<Field> fields = new ArrayList<>();
fields.add(f("id", v(id)));
fields.add(f("name", v(name)));
fields.add(f("subject", v(getSubject())));
fields.add(f("body", v(body)));
fields.add(f("creator", creatorObj));
fields.add(f("hidden", v(hidden)));
fields.add(f("type", v(type.getType().toString())));
fields.add(f("creationDate", v(DateTimeSupport.toUTC(creationDate.getTime()))));
return obj(fields);
}
use of com.entwinemedia.fn.data.json.Field in project opencast by opencast.
the class GroupsEndpoint method getGroups.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("groups.json")
@RestQuery(name = "allgroupsasjson", description = "Returns a list of groups", returnDescription = "List of groups for the current user's organization as JSON.", restParameters = { @RestParameter(name = "filter", isRequired = false, type = STRING, description = "Filter used for the query, formatted like: 'filter1:value1,filter2:value2'"), @RestParameter(name = "sort", isRequired = false, type = STRING, description = "The sort order. May include any of the following: NAME, DESCRIPTION, ROLE. " + "Add '_DESC' to reverse the sort order (e.g. NAME_DESC)."), @RestParameter(name = "limit", isRequired = false, type = INTEGER, defaultValue = "100", description = "The maximum number of items to return per page."), @RestParameter(name = "offset", isRequired = false, type = INTEGER, defaultValue = "0", description = "The page number.") }, reponses = { @RestResponse(responseCode = SC_OK, description = "The groups.") })
public Response getGroups(@QueryParam("filter") String filter, @QueryParam("sort") String sort, @QueryParam("offset") int offset, @QueryParam("limit") int limit) throws IOException {
GroupSearchQuery query = new GroupSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
Opt<String> optSort = Opt.nul(trimToNull(sort));
Option<Integer> optOffset = Option.option(offset);
Option<Integer> optLimit = Option.option(limit);
// If the limit is set to 0, this is not taken into account
if (optLimit.isSome() && limit == 0) {
optLimit = Option.none();
}
Map<String, String> filters = RestUtils.parseFilter(filter);
for (String name : filters.keySet()) {
if (GroupsListQuery.FILTER_NAME_NAME.equals(name)) {
query.withName(filters.get(name));
} else if (GroupsListQuery.FILTER_TEXT_NAME.equals(name)) {
query.withText(QueryPreprocessor.sanitize(filters.get(name)));
}
}
if (optSort.isSome()) {
Set<SortCriterion> sortCriteria = RestUtils.parseSortQueryParameter(optSort.get());
for (SortCriterion criterion : sortCriteria) {
switch(criterion.getFieldName()) {
case GroupIndexSchema.NAME:
query.sortByName(criterion.getOrder());
break;
case GroupIndexSchema.DESCRIPTION:
query.sortByDescription(criterion.getOrder());
break;
case GroupIndexSchema.ROLE:
query.sortByRole(criterion.getOrder());
break;
case GroupIndexSchema.MEMBERS:
query.sortByMembers(criterion.getOrder());
break;
case GroupIndexSchema.ROLES:
query.sortByRoles(criterion.getOrder());
break;
default:
throw new WebApplicationException(Status.BAD_REQUEST);
}
}
}
if (optLimit.isSome())
query.withLimit(optLimit.get());
if (optOffset.isSome())
query.withOffset(optOffset.get());
SearchResult<Group> results;
try {
results = searchIndex.getByQuery(query);
} catch (SearchIndexException e) {
logger.error("The External Search Index was not able to get the groups list.", e);
return RestUtil.R.serverError();
}
List<JValue> groupsJSON = new ArrayList<>();
for (SearchResultItem<Group> item : results.getItems()) {
Group group = item.getSource();
List<Field> fields = new ArrayList<>();
fields.add(f("id", v(group.getIdentifier())));
fields.add(f("name", v(group.getName(), Jsons.BLANK)));
fields.add(f("description", v(group.getDescription(), Jsons.BLANK)));
fields.add(f("role", v(group.getRole())));
fields.add(f("users", membersToJSON(group.getMembers())));
groupsJSON.add(obj(fields));
}
return okJsonList(groupsJSON, offset, limit, results.getHitCount());
}
use of com.entwinemedia.fn.data.json.Field in project opencast by opencast.
the class JobEndpoint method getOperationsAsJSON.
/**
* Returns the list of operations for a given workflow instance
*
* @param jobId
* the workflow instance id
* @return the list of workflow operations as JSON object
* @throws JobEndpointException
* @throws NotFoundException
*/
public JValue getOperationsAsJSON(long jobId) throws JobEndpointException, NotFoundException {
WorkflowInstance instance = getWorkflowById(jobId);
List<WorkflowOperationInstance> operations = instance.getOperations();
List<JValue> operationsJSON = new ArrayList<>();
for (WorkflowOperationInstance wflOp : operations) {
List<Field> fields = new ArrayList<>();
for (String key : wflOp.getConfigurationKeys()) {
fields.add(f(key, v(wflOp.getConfiguration(key), Jsons.BLANK)));
}
operationsJSON.add(obj(f("status", v(wflOp.getState(), Jsons.BLANK)), f("title", v(wflOp.getTemplate(), Jsons.BLANK)), f("description", v(wflOp.getDescription(), Jsons.BLANK)), f("id", v(wflOp.getId(), Jsons.BLANK)), f("configuration", obj(fields))));
}
return arr(operationsJSON);
}
Aggregations