use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class AbstractEventEndpoint method deleteEventCommentReply.
@DELETE
@Path("{eventId}/comment/{commentId}/{replyId}")
@RestQuery(name = "deleteeventreply", description = "Delete an event comment reply", returnDescription = "The updated comment as JSON.", 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), @RestParameter(name = "replyId", isRequired = true, description = "The comment reply identifier", type = STRING) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "No event comment or reply with this identifier was found."), @RestResponse(responseCode = SC_OK, description = "The updated comment as JSON.") })
public Response deleteEventCommentReply(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId, @PathParam("replyId") long replyId) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", eventId);
EventComment comment = null;
EventCommentReply reply = null;
try {
comment = getEventCommentService().getComment(commentId);
for (EventCommentReply r : comment.getReplies()) {
if (r.getId().isNone() || replyId != r.getId().get().longValue())
continue;
reply = r;
break;
}
if (reply == null)
throw new NotFoundException("Reply with id " + replyId + " not found!");
comment.removeReply(reply);
EventComment updatedComment = getEventCommentService().updateComment(comment);
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.warn("Could not remove event comment reply {} from comment {}: {}", replyId, commentId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e);
}
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class AbstractEventEndpoint method updateEventComment.
@PUT
@Path("{eventId}/comment/{commentId}")
@RestQuery(name = "updateeventcomment", description = "Updates an event comment", returnDescription = "The updated comment as JSON.", 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) }, restParameters = { @RestParameter(name = "text", isRequired = false, description = "The comment text", type = TEXT), @RestParameter(name = "reason", isRequired = false, description = "The comment reason", type = STRING), @RestParameter(name = "resolved", isRequired = false, description = "The comment resolved status", type = RestParameter.Type.BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "The event or comment to update has not been found."), @RestResponse(responseCode = SC_OK, description = "The updated comment as JSON.") })
public Response updateEventComment(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId, @FormParam("text") String text, @FormParam("reason") String reason, @FormParam("resolved") Boolean resolved) 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);
if (StringUtils.isNotBlank(text)) {
text = text.trim();
} else {
text = dto.getText();
}
if (StringUtils.isNotBlank(reason)) {
reason = reason.trim();
} else {
reason = dto.getReason();
}
if (resolved == null)
resolved = dto.isResolvedStatus();
EventComment updatedComment = EventComment.create(dto.getId(), eventId, getSecurityService().getOrganization().getId(), text, dto.getAuthor(), reason, resolved, 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("Unable to update the comments catalog on event {}: {}", eventId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e);
}
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class AbstractEventEndpoint method updateEventCommentReply.
@PUT
@Path("{eventId}/comment/{commentId}/{replyId}")
@RestQuery(name = "updateeventcommentreply", description = "Updates an event comment reply", returnDescription = "The updated comment as JSON.", 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), @RestParameter(name = "replyId", isRequired = true, description = "The comment reply identifier", type = STRING) }, restParameters = { @RestParameter(name = "text", isRequired = true, description = "The comment reply text", type = TEXT) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "The event or comment to extend with a reply or the reply has not been found."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "If no text is set."), @RestResponse(responseCode = SC_OK, description = "The updated comment as JSON.") })
public Response updateEventCommentReply(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId, @PathParam("replyId") long replyId, @FormParam("text") String text) throws Exception {
if (StringUtils.isBlank(text))
return Response.status(Status.BAD_REQUEST).build();
Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", eventId);
EventComment comment = null;
EventCommentReply reply = null;
try {
comment = getEventCommentService().getComment(commentId);
for (EventCommentReply r : comment.getReplies()) {
if (r.getId().isNone() || replyId != r.getId().get().longValue())
continue;
reply = r;
break;
}
if (reply == null)
throw new NotFoundException("Reply with id " + replyId + " not found!");
EventCommentReply updatedReply = EventCommentReply.create(reply.getId(), text.trim(), reply.getAuthor(), reply.getCreationDate(), new Date());
comment.removeReply(reply);
comment.addReply(updatedReply);
EventComment updatedComment = getEventCommentService().updateComment(comment);
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.warn("Could not update event comment reply {} from comment {}: {}", replyId, commentId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e);
}
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class SeriesEndpoint method hasProcessingEvents.
/**
* Check if the series with the given Id has events being currently processed
*
* @param seriesId
* the series Id
* @return true if events being part of the series are currently processed
*/
private boolean hasProcessingEvents(String seriesId) {
EventSearchQuery query = new EventSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
long elementsCount = 0;
query.withSeriesId(seriesId);
try {
query.withWorkflowState(WorkflowInstance.WorkflowState.RUNNING.toString());
SearchResult<Event> events = searchIndex.getByQuery(query);
elementsCount = events.getHitCount();
query.withWorkflowState(WorkflowInstance.WorkflowState.INSTANTIATED.toString());
events = searchIndex.getByQuery(query);
elementsCount += events.getHitCount();
} catch (SearchIndexException e) {
logger.warn("Could not perform search query: {}", ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
}
return elementsCount > 0;
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class EventsEndpoint method updateEvent.
private Response updateEvent(String eventId, HttpServletRequest request) {
try {
Opt<String> startDatePattern = configuredMetadataFields.containsKey("startDate") ? configuredMetadataFields.get("startDate").getPattern() : Opt.none();
Opt<String> startTimePattern = configuredMetadataFields.containsKey("startTime") ? configuredMetadataFields.get("startTime").getPattern() : Opt.none();
for (final Event event : indexService.getEvent(eventId, externalIndex)) {
EventHttpServletRequest eventHttpServletRequest = EventHttpServletRequest.updateFromHttpServletRequest(event, request, getEventCatalogUIAdapters(), startDatePattern, startTimePattern);
if (eventHttpServletRequest.getMetadataList().isSome()) {
indexService.updateEventMetadata(eventId, eventHttpServletRequest.getMetadataList().get(), externalIndex);
}
if (eventHttpServletRequest.getAcl().isSome()) {
indexService.updateEventAcl(eventId, eventHttpServletRequest.getAcl().get(), externalIndex);
}
return ApiResponses.Json.noContent(ApiVersion.VERSION_1_0_0);
}
return ApiResponses.notFound("Cannot find an event with id '%s'.", eventId);
} catch (NotFoundException e) {
return ApiResponses.notFound("Cannot find an event with id '%s'.", eventId);
} catch (UnauthorizedException e) {
return Response.status(Status.UNAUTHORIZED).build();
} catch (IllegalArgumentException e) {
logger.debug("Unable to update event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
return RestUtil.R.badRequest(e.getMessage());
} catch (IndexServiceException e) {
logger.error("Unable to get multi part fields or file for event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
} catch (SearchIndexException e) {
logger.error("Unable to update event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations