Search in sources :

Example 21 with EventComment

use of org.opencastproject.event.comment.EventComment in project opencast by opencast.

the class EventCommentDatabaseImplTest method testUpdateCommentReplies.

@Test
public void testUpdateCommentReplies() throws Exception {
    final EventComment persistedComment = persistence.updateComment(COMMENT_1);
    assertEquals(COMMENT_1, persistedComment);
    persistedComment.addReply(EventCommentReply.create(none(Long.class), "comment1", USER));
    persistedComment.addReply(EventCommentReply.create(none(Long.class), "comment2", USER));
    final EventComment updatedComment = persistence.updateComment(persistedComment);
    updatedComment.removeReply(updatedComment.getReplies().get(0));
    updatedComment.addReply(EventCommentReply.create(none(Long.class), "comment3", USER));
    final EventComment modifiedComment = persistence.updateComment(updatedComment);
    assertEquals(2, modifiedComment.getReplies().size());
    assertEquals("comment2", modifiedComment.getReplies().get(0).getText());
    assertEquals("comment3", modifiedComment.getReplies().get(1).getText());
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) Test(org.junit.Test)

Example 22 with EventComment

use of org.opencastproject.event.comment.EventComment in project opencast by opencast.

the class CommentWorkflowOperationHandlerTest method testDuplicateComments.

@Test
public void testDuplicateComments() 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 action = "create";
    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);
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(action).anyTimes();
    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();
    // Test no previous comments
    EventCommentService eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>());
    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(creator, eventCommentService, mediaPackage, workflowInstance, workflowOperationInstance);
    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());
    // Test previous comment with same reason and description
    List<EventComment> comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(13L), mediaPackageId, org.getId(), description, creator, reason, true));
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments);
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    assertTrue(comment.hasCaptured());
    assertEquals(creator, comment.getValue().getAuthor());
    assertEquals(description, comment.getValue().getText());
    assertEquals(reason, comment.getValue().getReason());
    // Test previous comment with different reasons and descriptions
    comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), "Different description", creator, reason, true));
    comments.add(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator, "Different reason", true));
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments);
    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 = 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());
}
Also used : Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) EventComment(org.opencastproject.event.comment.EventComment) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) EventCommentService(org.opencastproject.event.comment.EventCommentService) Test(org.junit.Test)

Example 23 with EventComment

use of org.opencastproject.event.comment.EventComment in project opencast by opencast.

the class CommentWorkflowOperationHandler method createComment.

/**
 * Create a new comment if one doesn't already exist with the reason and description.
 *
 * @param workflowInstance
 *          The {@link WorkflowInstance} to handle.
 * @param reason
 *          The reason for the comment.
 * @param description
 *          The descriptive text of the comment.
 * @throws EventCommentException
 *           Thrown if unable to create the comment.
 */
private void createComment(WorkflowInstance workflowInstance, String reason, String description) throws EventCommentException {
    Opt<EventComment> optComment = findComment(workflowInstance.getMediaPackage().getIdentifier().toString(), reason, description);
    if (optComment.isNone()) {
        EventComment comment = EventComment.create(Option.<Long>none(), workflowInstance.getMediaPackage().getIdentifier().toString(), securityService.getOrganization().getId(), description, workflowInstance.getCreator(), reason, false);
        eventCommentService.updateComment(comment);
    } else {
        logger.debug("Not creating comment with '{}' text and '{}' reason as it already exists for this event.", description, reason);
    }
}
Also used : EventComment(org.opencastproject.event.comment.EventComment)

Aggregations

EventComment (org.opencastproject.event.comment.EventComment)23 EventCommentException (org.opencastproject.event.comment.EventCommentException)9 NotFoundException (org.opencastproject.util.NotFoundException)9 Path (javax.ws.rs.Path)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 Event (org.opencastproject.index.service.impl.index.event.Event)8 RestQuery (org.opencastproject.util.doc.rest.RestQuery)8 ParseException (java.text.ParseException)7 JSONException (org.codehaus.jettison.json.JSONException)7 JobEndpointException (org.opencastproject.adminui.exception.JobEndpointException)7 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)7 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)7 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)7 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)7 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)7 User (org.opencastproject.security.api.User)7 UrlSigningException (org.opencastproject.security.urlsigning.exception.UrlSigningException)7 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)7 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)7 Test (org.junit.Test)6