use of org.opencastproject.event.comment.EventComment 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.event.comment.EventComment 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.event.comment.EventComment in project opencast by opencast.
the class CommentWorkflowOperationHandler method resolveComment.
/**
* Resolve a comment with matching reason and description.
*
* @param workflowInstance
* The {@link WorkflowInstance} to handle.
* @param reason
* The reason for the comment.
* @param description
* The comment's descriptive text.
* @throws EventCommentException
* Thrown if unable to update the comment.
*/
private void resolveComment(WorkflowInstance workflowInstance, String reason, String description) throws EventCommentException {
Opt<EventComment> optComment = findComment(workflowInstance.getMediaPackage().getIdentifier().toString(), reason, description);
if (optComment.isSome()) {
EventComment comment = EventComment.create(optComment.get().getId(), workflowInstance.getMediaPackage().getIdentifier().toString(), securityService.getOrganization().getId(), optComment.get().getText(), optComment.get().getAuthor(), optComment.get().getReason(), true, optComment.get().getCreationDate(), optComment.get().getModificationDate(), optComment.get().getReplies());
eventCommentService.updateComment(comment);
} else {
logger.debug("Not resolving comment with '{}' text and/or '{}' reason as it doesn't exist.", description, reason);
}
}
use of org.opencastproject.event.comment.EventComment in project opencast by opencast.
the class CommentWorkflowOperationHandler method findComment.
/**
* Find a comment by its reason, description or both
*
* @param eventId
* The event id to search the comments for.
* @param reason
* The reason for the comment (optional)
* @param description
* The description for the comment (optional)
* @return The comment if one is found matching the reason and description.
* @throws EventCommentException
* Thrown if there was a problem finding the comment.
*/
private Opt<EventComment> findComment(String eventId, String reason, String description) throws EventCommentException {
Opt<EventComment> comment = Opt.none();
List<EventComment> eventComments = eventCommentService.getComments(eventId);
for (EventComment existingComment : eventComments) {
// Match on reason and description
if (reason != null && description != null && reason.equals(existingComment.getReason()) && description.equals(existingComment.getText())) {
comment = Opt.some(existingComment);
break;
}
// Match on reason only
if (reason != null && description == null && reason.equals(existingComment.getReason())) {
comment = Opt.some(existingComment);
break;
}
// Match on description only
if (reason == null && description != null && description.equals(existingComment.getText())) {
comment = Opt.some(existingComment);
break;
}
}
return comment;
}
use of org.opencastproject.event.comment.EventComment in project opencast by opencast.
the class CommentWorkflowOperationHandlerTest method testDifferentCaseAction.
@Test
public void testDifferentCaseAction() throws WorkflowOperationException, EventCommentException {
// Testing that a duplicate comment won't be created but a different one will still be created.
Long workflowId = 10L;
String mediaPackageId = "abc-def";
String reason = "Waiting for Trim";
String description = "The comment description";
Organization org = createNiceMock(Organization.class);
expect(org.getId()).andStubReturn("demo");
replay(org);
SecurityService secSrv = createNiceMock(SecurityService.class);
expect(secSrv.getOrganization()).andStubReturn(org);
replay(secSrv);
// Setup WorkflowOperation Instance
WorkflowOperationInstance workflowOperationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
// Standard
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn("create");
// Mixed case
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn("CrEaTe");
// All Caps
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn("CREATE");
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.REASON)).andReturn(reason).anyTimes();
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.DESCRIPTION)).andReturn(description).anyTimes();
// Setup mediaPackage
MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
EasyMock.expect(mediaPackage.getIdentifier()).andReturn(new IdImpl(mediaPackageId)).anyTimes();
// Setup user
User creator = EasyMock.createMock(User.class);
// Setup WorkflowInstance
WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getId()).andReturn(workflowId).anyTimes();
EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(workflowOperationInstance).anyTimes();
EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
EasyMock.expect(workflowInstance.getCreator()).andReturn(creator).anyTimes();
EasyMock.replay(creator, mediaPackage, workflowInstance, workflowOperationInstance);
// Test no previous comments
EventCommentService eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
Capture<EventComment> comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
EasyMock.replay(eventCommentService);
CommentWorkflowOperationHandler commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
assertTrue(comment.hasCaptured());
assertEquals(creator, comment.getValue().getAuthor());
assertEquals(description, comment.getValue().getText());
assertEquals(reason, comment.getValue().getReason());
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(17L), mediaPackageId, org.getId(), description, creator));
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
assertTrue(comment.hasCaptured());
assertEquals(creator, comment.getValue().getAuthor());
assertEquals(description, comment.getValue().getText());
assertEquals(reason, comment.getValue().getReason());
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(19L), mediaPackageId, org.getId(), description, creator));
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
assertTrue(comment.hasCaptured());
assertEquals(creator, comment.getValue().getAuthor());
assertEquals(description, comment.getValue().getText());
assertEquals(reason, comment.getValue().getReason());
}
Aggregations