Search in sources :

Example 11 with EventComment

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

the class EventCommentDatabaseImplTest method testAddNewComment.

@Test
public void testAddNewComment() throws Exception {
    final EventComment persistedComment = persistence.updateComment(COMMENT_1);
    assertEquals(COMMENT_1, persistence.getComment(persistedComment.getId().get()));
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) Test(org.junit.Test)

Example 12 with EventComment

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

the class EventCommentDatabaseImplTest method testGetEventsWithComments.

@Test
public void testGetEventsWithComments() throws Exception {
    Organization org1 = EasyMock.createNiceMock(Organization.class);
    EasyMock.expect(org1.getId()).andReturn("org1").anyTimes();
    EasyMock.expect(org1.getName()).andReturn("org1").anyTimes();
    Organization org2 = EasyMock.createNiceMock(Organization.class);
    EasyMock.expect(org2.getId()).andReturn("org2").anyTimes();
    EasyMock.expect(org2.getName()).andReturn("org2").anyTimes();
    EasyMock.replay(org1, org2);
    User userOrg1 = new JaxbUser("userOrg1", "default", JaxbOrganization.fromOrganization(org1));
    User userOrg2 = new JaxbUser("userOrg2", "default", JaxbOrganization.fromOrganization(org2));
    EventComment eventComment1 = EventComment.create(none(Long.class), "event1", org1.getId(), "test", userOrg1);
    EventComment eventComment2 = EventComment.create(none(Long.class), "event2", org1.getId(), "test", userOrg1);
    EventComment eventComment3 = EventComment.create(none(Long.class), "event3", org2.getId(), "test", userOrg2);
    persistence.updateComment(eventComment1);
    persistence.updateComment(eventComment2);
    persistence.updateComment(eventComment3);
    Map<String, List<String>> eventsWithComments = persistence.getEventsWithComments();
    assertEquals(2, eventsWithComments.keySet().size());
    assertTrue(eventsWithComments.keySet().contains(org1.getId()));
    assertTrue(eventsWithComments.keySet().contains(org2.getId()));
    assertTrue(eventsWithComments.get(org1.getId()).contains(eventComment1.getEventId()));
    assertTrue(eventsWithComments.get(org1.getId()).contains(eventComment2.getEventId()));
    assertTrue(eventsWithComments.get(org2.getId()).contains(eventComment3.getEventId()));
    assertFalse(eventsWithComments.get(org1.getId()).contains(eventComment3.getEventId()));
    assertFalse(eventsWithComments.get(org2.getId()).contains(eventComment1.getEventId()));
    assertFalse(eventsWithComments.get(org2.getId()).contains(eventComment2.getEventId()));
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbUser(org.opencastproject.security.api.JaxbUser) List(java.util.List) Test(org.junit.Test)

Example 13 with EventComment

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

the class CommentSchedulerConflictNotifier method notifyConflicts.

@Override
public void notifyConflicts(List<ConflictingEvent> conflicts) {
    for (ConflictingEvent c : conflicts) {
        StringBuilder sb = new StringBuilder("This scheduled event has been overwritten with conflicting (data from the scheduling source OR manual changes). ");
        if (Strategy.OLD.equals(c.getConflictStrategy())) {
            sb.append("Find below the new version:").append(CharUtils.LF);
            sb.append(CharUtils.LF);
            sb.append(toHumanReadableString(workspace, getEventCatalogUIAdapterFlavors(), c.getNewEvent()));
        } else {
            sb.append("Find below the preceding version:").append(CharUtils.LF);
            sb.append(CharUtils.LF);
            sb.append(toHumanReadableString(workspace, getEventCatalogUIAdapterFlavors(), c.getOldEvent()));
        }
        try {
            EventComment comment = EventComment.create(Option.<Long>none(), c.getNewEvent().getEventId(), securityService.getOrganization().getId(), sb.toString(), securityService.getUser(), COMMENT_REASON, false);
            eventCommentService.updateComment(comment);
        } catch (EventCommentException e) {
            logger.error("Unable to create a comment on the event {}: {}", c.getOldEvent().getEventId(), ExceptionUtils.getStackTrace(e));
        }
    }
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) ConflictingEvent(org.opencastproject.scheduler.api.ConflictingEvent) EventCommentException(org.opencastproject.event.comment.EventCommentException)

Example 14 with EventComment

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

the class AbstractEventEndpoint method createEventCommentReply.

@POST
@Path("{eventId}/comment/{commentId}/reply")
@RestQuery(name = "createeventcommentreply", description = "Creates 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) }, restParameters = { @RestParameter(name = "text", isRequired = true, description = "The comment reply text", type = TEXT), @RestParameter(name = "resolved", isRequired = false, description = "Flag defining if this reply solve or not the comment.", type = BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "The event or comment to extend with a 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 createEventCommentReply(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId, @FormParam("text") String text, @FormParam("resolved") Boolean resolved) 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;
    try {
        comment = getEventCommentService().getComment(commentId);
        EventComment updatedComment;
        if (resolved != null && resolved) {
            // If the resolve flag is set to true, change to comment to resolved
            updatedComment = EventComment.create(comment.getId(), comment.getEventId(), comment.getOrganization(), comment.getText(), comment.getAuthor(), comment.getReason(), true, comment.getCreationDate(), new Date(), comment.getReplies());
        } else {
            updatedComment = comment;
        }
        User author = getSecurityService().getUser();
        EventCommentReply reply = EventCommentReply.create(Option.<Long>none(), text, author);
        updatedComment.addReply(reply);
        updatedComment = getEventCommentService().updateComment(updatedComment);
        List<EventComment> comments = getEventCommentService().getComments(eventId);
        getIndexService().updateCommentCatalog(optEvent.get(), comments);
        return Response.ok(updatedComment.toJson().toJson()).build();
    } catch (Exception e) {
        logger.warn("Could not create event comment reply on comment {}: {}", comment, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    }
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) User(org.opencastproject.security.api.User) WebApplicationException(javax.ws.rs.WebApplicationException) Event(org.opencastproject.index.service.impl.index.event.Event) Date(java.util.Date) EventCommentReply(org.opencastproject.event.comment.EventCommentReply) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) EventCommentException(org.opencastproject.event.comment.EventCommentException) JSONException(org.codehaus.jettison.json.JSONException) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 15 with EventComment

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

the class AbstractEventEndpoint method getEventComments.

@GET
@Path("{eventId}/comments")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "geteventcomments", description = "Returns all the data related to the comments tab in the event details modal as JSON", returnDescription = "All the data related to the event comments tab as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns all the data related to the event comments tab as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getEventComments(@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);
    try {
        List<EventComment> comments = getEventCommentService().getComments(eventId);
        List<Val> commentArr = new ArrayList<>();
        for (EventComment c : comments) {
            commentArr.add(c.toJson());
        }
        return Response.ok(org.opencastproject.util.Jsons.arr(commentArr).toJson(), MediaType.APPLICATION_JSON_TYPE).build();
    } catch (EventCommentException e) {
        logger.error("Unable to get comments from event {}: {}", eventId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    }
}
Also used : Val(org.opencastproject.util.Jsons.Val) EventComment(org.opencastproject.event.comment.EventComment) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) Event(org.opencastproject.index.service.impl.index.event.Event) EventCommentException(org.opencastproject.event.comment.EventCommentException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

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