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()));
}
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()));
}
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));
}
}
}
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);
}
}
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);
}
}
Aggregations