Search in sources :

Example 1 with EventCommentReply

use of org.opencastproject.event.comment.EventCommentReply 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 2 with EventCommentReply

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

the class AbstractEventEndpoint method deleteEventCommentReply.

@DELETE
@Path("{eventId}/comment/{commentId}/{replyId}")
@RestQuery(name = "deleteeventreply", description = "Delete 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), @RestParameter(name = "replyId", isRequired = true, description = "The comment reply identifier", type = STRING) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "No event comment or reply with this identifier was found."), @RestResponse(responseCode = SC_OK, description = "The updated comment as JSON.") })
public Response deleteEventCommentReply(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId, @PathParam("replyId") long replyId) throws Exception {
    Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
    if (optEvent.isNone())
        return notFound("Cannot find an event with id '%s'.", eventId);
    EventComment comment = null;
    EventCommentReply reply = null;
    try {
        comment = getEventCommentService().getComment(commentId);
        for (EventCommentReply r : comment.getReplies()) {
            if (r.getId().isNone() || replyId != r.getId().get().longValue())
                continue;
            reply = r;
            break;
        }
        if (reply == null)
            throw new NotFoundException("Reply with id " + replyId + " not found!");
        comment.removeReply(reply);
        EventComment updatedComment = getEventCommentService().updateComment(comment);
        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.warn("Could not remove event comment reply {} from comment {}: {}", replyId, commentId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    }
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) WebApplicationException(javax.ws.rs.WebApplicationException) Event(org.opencastproject.index.service.impl.index.event.Event) NotFoundException(org.opencastproject.util.NotFoundException) 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) DELETE(javax.ws.rs.DELETE) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 3 with EventCommentReply

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

the class AbstractEventEndpoint method updateEventCommentReply.

@PUT
@Path("{eventId}/comment/{commentId}/{replyId}")
@RestQuery(name = "updateeventcommentreply", description = "Updates 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), @RestParameter(name = "replyId", isRequired = true, description = "The comment reply identifier", type = STRING) }, restParameters = { @RestParameter(name = "text", isRequired = true, description = "The comment reply text", type = TEXT) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "The event or comment to extend with a reply or the 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 updateEventCommentReply(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId, @PathParam("replyId") long replyId, @FormParam("text") String text) 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;
    EventCommentReply reply = null;
    try {
        comment = getEventCommentService().getComment(commentId);
        for (EventCommentReply r : comment.getReplies()) {
            if (r.getId().isNone() || replyId != r.getId().get().longValue())
                continue;
            reply = r;
            break;
        }
        if (reply == null)
            throw new NotFoundException("Reply with id " + replyId + " not found!");
        EventCommentReply updatedReply = EventCommentReply.create(reply.getId(), text.trim(), reply.getAuthor(), reply.getCreationDate(), new Date());
        comment.removeReply(reply);
        comment.addReply(updatedReply);
        EventComment updatedComment = getEventCommentService().updateComment(comment);
        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.warn("Could not update event comment reply {} from comment {}: {}", replyId, commentId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    }
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) WebApplicationException(javax.ws.rs.WebApplicationException) Event(org.opencastproject.index.service.impl.index.event.Event) NotFoundException(org.opencastproject.util.NotFoundException) EventCommentReply(org.opencastproject.event.comment.EventCommentReply) Date(java.util.Date) 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) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 4 with EventCommentReply

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

the class EventCommentDto method from.

public static EventCommentDto from(EventComment comment) {
    EventCommentDto dto = new EventCommentDto();
    if (comment.getId().isSome())
        dto.id = comment.getId().get().longValue();
    dto.organization = comment.getOrganization();
    dto.eventId = comment.getEventId();
    dto.text = comment.getText();
    dto.creationDate = comment.getCreationDate();
    dto.modificationDate = comment.getModificationDate();
    dto.author = comment.getAuthor().getUsername();
    dto.reason = comment.getReason();
    dto.resolvedStatus = comment.isResolvedStatus();
    for (final EventCommentReply reply : comment.getReplies()) {
        dto.addReply(EventCommentReplyDto.from(reply));
    }
    return dto;
}
Also used : EventCommentReply(org.opencastproject.event.comment.EventCommentReply)

Aggregations

EventCommentReply (org.opencastproject.event.comment.EventCommentReply)4 ParseException (java.text.ParseException)3 Path (javax.ws.rs.Path)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 JSONException (org.codehaus.jettison.json.JSONException)3 JobEndpointException (org.opencastproject.adminui.exception.JobEndpointException)3 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)3 EventComment (org.opencastproject.event.comment.EventComment)3 EventCommentException (org.opencastproject.event.comment.EventCommentException)3 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)3 Event (org.opencastproject.index.service.impl.index.event.Event)3 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)3 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)3 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)3 UrlSigningException (org.opencastproject.security.urlsigning.exception.UrlSigningException)3 NotFoundException (org.opencastproject.util.NotFoundException)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)3 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)3 Date (java.util.Date)2