use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method getEvents.
@GET
@Path("events.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getevents", description = "Returns all the events as JSON", returnDescription = "All the events as JSON", restParameters = { @RestParameter(name = "filter", isRequired = false, description = "The filter used for the query. They should be formated like that: 'filter1:value1,filter2:value2'", type = STRING), @RestParameter(name = "sort", description = "The order instructions used to sort the query result. Must be in the form '<field name>:(ASC|DESC)'", isRequired = false, type = STRING), @RestParameter(name = "limit", description = "The maximum number of items to return per page.", isRequired = false, type = RestParameter.Type.INTEGER), @RestParameter(name = "offset", description = "The page number.", isRequired = false, type = RestParameter.Type.INTEGER) }, reponses = { @RestResponse(description = "Returns all events as JSON", responseCode = HttpServletResponse.SC_OK) })
public Response getEvents(@QueryParam("id") String id, @QueryParam("commentReason") String reasonFilter, @QueryParam("commentResolution") String resolutionFilter, @QueryParam("filter") String filter, @QueryParam("sort") String sort, @QueryParam("offset") Integer offset, @QueryParam("limit") Integer limit) {
Option<Integer> optLimit = Option.option(limit);
Option<Integer> optOffset = Option.option(offset);
Option<String> optSort = Option.option(trimToNull(sort));
ArrayList<JValue> eventsList = new ArrayList<>();
EventSearchQuery query = new EventSearchQuery(getSecurityService().getOrganization().getId(), getSecurityService().getUser());
// 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 (EventListQuery.FILTER_PRESENTERS_BIBLIOGRAPHIC_NAME.equals(name))
query.withPresenter(filters.get(name));
if (EventListQuery.FILTER_PRESENTERS_TECHNICAL_NAME.equals(name))
query.withTechnicalPresenters(filters.get(name));
if (EventListQuery.FILTER_CONTRIBUTORS_NAME.equals(name))
query.withContributor(filters.get(name));
if (EventListQuery.FILTER_LOCATION_NAME.equals(name))
query.withLocation(filters.get(name));
if (EventListQuery.FILTER_AGENT_NAME.equals(name))
query.withAgentId(filters.get(name));
if (EventListQuery.FILTER_TEXT_NAME.equals(name))
query.withText(QueryPreprocessor.sanitize(filters.get(name)));
if (EventListQuery.FILTER_SERIES_NAME.equals(name))
query.withSeriesId(filters.get(name));
if (EventListQuery.FILTER_STATUS_NAME.equals(name))
query.withEventStatus(filters.get(name));
if (EventListQuery.FILTER_OPTEDOUT_NAME.equals(name))
query.withOptedOut(Boolean.parseBoolean(filters.get(name)));
if (EventListQuery.FILTER_REVIEW_STATUS_NAME.equals(name))
query.withReviewStatus(filters.get(name));
if (EventListQuery.FILTER_COMMENTS_NAME.equals(name)) {
switch(Comments.valueOf(filters.get(name))) {
case NONE:
query.withComments(false);
break;
case OPEN:
query.withOpenComments(true);
break;
case RESOLVED:
query.withComments(true);
query.withOpenComments(false);
break;
default:
logger.info("Unknown comment {}", filters.get(name));
return Response.status(SC_BAD_REQUEST).build();
}
}
if (EventListQuery.FILTER_STARTDATE_NAME.equals(name)) {
try {
Tuple<Date, Date> fromAndToCreationRange = RestUtils.getFromAndToDateRange(filters.get(name));
query.withTechnicalStartFrom(fromAndToCreationRange.getA());
query.withTechnicalStartTo(fromAndToCreationRange.getB());
} catch (IllegalArgumentException e) {
return RestUtil.R.badRequest(e.getMessage());
}
}
}
if (optSort.isSome()) {
Set<SortCriterion> sortCriteria = RestUtils.parseSortQueryParameter(optSort.get());
for (SortCriterion criterion : sortCriteria) {
switch(criterion.getFieldName()) {
case EventIndexSchema.TITLE:
query.sortByTitle(criterion.getOrder());
break;
case EventIndexSchema.PRESENTER:
query.sortByPresenter(criterion.getOrder());
break;
case EventIndexSchema.TECHNICAL_START:
case "technical_date":
query.sortByTechnicalStartDate(criterion.getOrder());
break;
case EventIndexSchema.TECHNICAL_END:
query.sortByTechnicalEndDate(criterion.getOrder());
break;
case EventIndexSchema.PUBLICATION:
query.sortByPublicationIgnoringInternal(criterion.getOrder());
break;
case EventIndexSchema.START_DATE:
case "date":
query.sortByStartDate(criterion.getOrder());
break;
case EventIndexSchema.END_DATE:
query.sortByEndDate(criterion.getOrder());
break;
case EventIndexSchema.SERIES_NAME:
query.sortBySeriesName(criterion.getOrder());
break;
case EventIndexSchema.LOCATION:
query.sortByLocation(criterion.getOrder());
break;
case EventIndexSchema.EVENT_STATUS:
query.sortByEventStatus(criterion.getOrder());
break;
default:
throw new WebApplicationException(Status.BAD_REQUEST);
}
}
}
// TODO: Add the comment resolution filter to the query
EventCommentsListProvider.RESOLUTION resolution = null;
if (StringUtils.isNotBlank(resolutionFilter)) {
try {
resolution = EventCommentsListProvider.RESOLUTION.valueOf(resolutionFilter);
} catch (Exception e) {
logger.warn("Unable to parse comment resolution filter {}", resolutionFilter);
return Response.status(Status.BAD_REQUEST).build();
}
}
if (optLimit.isSome())
query.withLimit(optLimit.get());
if (optOffset.isSome())
query.withOffset(offset);
// TODO: Add other filters to the query
SearchResult<Event> results = null;
try {
results = getIndex().getByQuery(query);
} catch (SearchIndexException e) {
logger.error("The admin UI Search Index was not able to get the events list:", e);
return RestUtil.R.serverError();
}
// If the results list if empty, we return already a response.
if (results.getPageSize() == 0) {
logger.debug("No events match the given filters.");
return okJsonList(eventsList, nul(offset).getOr(0), nul(limit).getOr(0), 0);
}
for (SearchResultItem<Event> item : results.getItems()) {
Event source = item.getSource();
source.updatePreview(getAdminUIConfiguration().getPreviewSubtype());
eventsList.add(eventToJSON(source));
}
return okJsonList(eventsList, nul(offset).getOr(0), nul(limit).getOr(0), results.getHitCount());
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method deleteEventComment.
@DELETE
@Path("{eventId}/comment/{commentId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "deleteeventcomment", description = "Deletes a event related comment by its identifier", returnDescription = "No content", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "commentId", description = "The comment id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "The event related comment has been deleted.", responseCode = HttpServletResponse.SC_NO_CONTENT), @RestResponse(description = "No event or comment with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response deleteEventComment(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", eventId);
try {
getEventCommentService().deleteComment(commentId);
List<EventComment> comments = getEventCommentService().getComments(eventId);
getIndexService().updateCommentCatalog(optEvent.get(), comments);
return Response.noContent().build();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Unable to delete comment {} on event {}: {}", commentId, eventId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e);
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method hasActiveTransaction.
@GET
@Path("{eventId}/hasActiveTransaction")
@Produces(MediaType.TEXT_PLAIN)
@RestQuery(name = "hasactivetransaction", description = "Returns whether there is currently a transaction in progress for the given event", returnDescription = "Whether there is currently a transaction in progress for the given event", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns whether there is currently a transaction in progress for the given event", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response hasActiveTransaction(@PathParam("eventId") String eventId) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", eventId);
JSONObject json = new JSONObject();
if (WorkflowInstance.WorkflowState.RUNNING.toString().equals(optEvent.get().getWorkflowState())) {
json.put("active", true);
} else {
json.put("active", false);
}
return Response.ok(json.toJSONString()).build();
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method resolveEventComment.
@POST
@Path("{eventId}/comment/{commentId}")
@RestQuery(name = "resolveeventcomment", description = "Resolves an event comment", returnDescription = "The resolved comment.", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "commentId", isRequired = true, description = "The comment identifier", type = STRING) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "The event or comment to resolve has not been found."), @RestResponse(responseCode = SC_OK, description = "The resolved comment as JSON.") })
public Response resolveEventComment(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", eventId);
try {
EventComment dto = getEventCommentService().getComment(commentId);
EventComment updatedComment = EventComment.create(dto.getId(), dto.getEventId(), dto.getOrganization(), dto.getText(), dto.getAuthor(), dto.getReason(), true, dto.getCreationDate(), new Date(), dto.getReplies());
updatedComment = getEventCommentService().updateComment(updatedComment);
List<EventComment> comments = getEventCommentService().getComments(eventId);
getIndexService().updateCommentCatalog(optEvent.get(), comments);
return Response.ok(updatedComment.toJson().toJson()).build();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not resolve comment {}: {}", commentId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e);
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method getMediaList.
@GET
@Path("{eventId}/asset/media/media.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getMediaList", description = "Returns a list of media from the given event as JSON", returnDescription = "The list of media from the given event as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns a list of media from the given event as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getMediaList(@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);
MediaPackage mp = getIndexService().getEventMediapackage(optEvent.get());
return okJson(arr(getEventMediaPackageElements(mp.getTracks())));
}
Aggregations