Search in sources :

Example 6 with EventComment

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

the class CommentWorkflowOperationHandlerTest method testPossibleActions.

@Test
public void testPossibleActions() throws WorkflowOperationException, EventCommentException, NotFoundException {
    // Testing that a duplicate comment won't be created but a different one will still be created.
    Long workflowId = 10L;
    Long deleteCommentId = 21L;
    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);
    // Create
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.create.toString());
    // Resolve
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.resolve.toString());
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.resolve.toString());
    // Deletes
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.delete.toString());
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.delete.toString());
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.delete.toString());
    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 create
    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.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(17L), mediaPackageId, org.getId(), description, creator));
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(19L), 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());
    assertEquals(false, comment.getValue().isResolvedStatus());
    // Test resolve
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    List<EventComment> comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(deleteCommentId), mediaPackageId, org.getId(), description, creator, reason, false));
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments).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());
    assertEquals(true, comment.getValue().isResolvedStatus());
    // Test resolve with no comment
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    // Test delete with no result, no delete
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    // Test delete with result
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(deleteCommentId), mediaPackageId, org.getId(), description, creator, reason, false));
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments).anyTimes();
    eventCommentService.deleteComment(deleteCommentId);
    EasyMock.expectLastCall();
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    // Test delete with unrelated comments
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(35L), mediaPackageId, org.getId(), description, creator, "", false));
    comments.add(EventComment.create(Option.option(37L), mediaPackageId, org.getId(), "Different Description", creator, reason, false));
    comments.add(EventComment.create(Option.option(39L), mediaPackageId, org.getId(), description, creator, "Different Reason", false));
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments).anyTimes();
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
}
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 7 with EventComment

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

the class EventCommentDatabaseServiceImpl method updateComment.

@Override
public EventComment updateComment(EventComment comment) throws EventCommentDatabaseException {
    final EventCommentDto commentDto = EventCommentDto.from(comment);
    final EventComment updatedComment = env.tx(persistOrUpdate(commentDto)).toComment(userDirectoryService);
    sendMessageUpdate(updatedComment.getEventId());
    return updatedComment;
}
Also used : EventComment(org.opencastproject.event.comment.EventComment)

Example 8 with EventComment

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

the class EventCommentDatabaseServiceImpl method getComments.

@Override
@SuppressWarnings("unchecked")
public List<EventComment> getComments(String eventId) throws EventCommentDatabaseException {
    EntityManager em = emf.createEntityManager();
    try {
        Query q = em.createNamedQuery("EventComment.findByEvent");
        q.setParameter("eventId", eventId);
        q.setParameter("org", securityService.getOrganization().getId());
        List<EventComment> comments = Monadics.mlist(q.getResultList()).map(new Function<EventCommentDto, EventComment>() {

            @Override
            public EventComment apply(EventCommentDto a) {
                return a.toComment(userDirectoryService);
            }
        }).sort(new Comparator<EventComment>() {

            @Override
            public int compare(EventComment c1, EventComment c2) {
                boolean v1 = c1.isResolvedStatus();
                boolean v2 = c2.isResolvedStatus();
                return (v1 ^ v2) ? ((v1 ^ false) ? 1 : -1) : 0;
            }
        }).value();
        return new ArrayList<>(comments);
    } catch (Exception e) {
        logger.error("Could not retreive comments for event {}: {}", eventId, ExceptionUtils.getStackTrace(e));
        throw new EventCommentDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) ServiceException(org.osgi.framework.ServiceException) NoResultException(javax.persistence.NoResultException) NotFoundException(org.opencastproject.util.NotFoundException) Comparator(java.util.Comparator)

Example 9 with EventComment

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

the class EventCommentDatabaseServiceImpl method sendMessageUpdate.

private void sendMessageUpdate(String eventId) throws EventCommentDatabaseException {
    List<EventComment> comments = getComments(eventId);
    boolean openComments = !Stream.$(comments).filter(filterOpenComments).toList().isEmpty();
    boolean needsCutting = !Stream.$(comments).filter(filterNeedsCuttingComment).toList().isEmpty();
    CommentItem update = CommentItem.update(eventId, !comments.isEmpty(), openComments, needsCutting);
    messageSender.sendObjectMessage(CommentItem.COMMENT_QUEUE, MessageSender.DestinationType.Queue, update);
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) CommentItem(org.opencastproject.message.broker.api.comments.CommentItem)

Example 10 with EventComment

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

the class EventCommentDto method toComment.

/**
 * Returns the business object of this comment
 *
 * @return the business object model of this comment
 */
public EventComment toComment(UserDirectoryService userDirectoryService) {
    User user = userDirectoryService.loadUser(author);
    EventComment comment = EventComment.create(Option.option(id), eventId, organization, text, user, reason, resolvedStatus, creationDate, modificationDate);
    for (EventCommentReplyDto reply : replies) {
        comment.addReply(reply.toCommentReply(userDirectoryService));
    }
    return comment;
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) User(org.opencastproject.security.api.User)

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