Search in sources :

Example 16 with EventComment

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

the class AbstractEventEndpoint method createEventComment.

@POST
@Path("{eventId}/comment")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "createeventcomment", description = "Creates a comment related to the event given by the identifier", returnDescription = "The comment related to the event as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(name = "text", isRequired = true, description = "The comment text", type = TEXT), @RestParameter(name = "resolved", isRequired = false, description = "The comment resolved status", type = RestParameter.Type.BOOLEAN), @RestParameter(name = "reason", isRequired = false, description = "The comment reason", type = STRING) }, reponses = { @RestResponse(description = "The comment has been created.", responseCode = HttpServletResponse.SC_CREATED), @RestResponse(description = "If no text ist set.", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response createEventComment(@PathParam("eventId") String eventId, @FormParam("text") String text, @FormParam("reason") String reason, @FormParam("resolved") Boolean resolved) throws Exception {
    Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
    if (optEvent.isNone())
        return notFound("Cannot find an event with id '%s'.", eventId);
    if (StringUtils.isBlank(text))
        return Response.status(Status.BAD_REQUEST).build();
    User author = getSecurityService().getUser();
    try {
        EventComment createdComment = EventComment.create(Option.<Long>none(), eventId, getSecurityService().getOrganization().getId(), text, author, reason, BooleanUtils.toBoolean(reason));
        createdComment = getEventCommentService().updateComment(createdComment);
        List<EventComment> comments = getEventCommentService().getComments(eventId);
        getIndexService().updateCommentCatalog(optEvent.get(), comments);
        return Response.created(getCommentUrl(eventId, createdComment.getId().get())).entity(createdComment.toJson().toJson()).build();
    } catch (Exception e) {
        logger.error("Unable to create a comment on the event {}: {}", eventId, 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) 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) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 17 with EventComment

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

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

the class AbstractEventEndpoint method updateEventComment.

@PUT
@Path("{eventId}/comment/{commentId}")
@RestQuery(name = "updateeventcomment", description = "Updates an event comment", 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 = false, description = "The comment text", type = TEXT), @RestParameter(name = "reason", isRequired = false, description = "The comment reason", type = STRING), @RestParameter(name = "resolved", isRequired = false, description = "The comment resolved status", type = RestParameter.Type.BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "The event or comment to update has not been found."), @RestResponse(responseCode = SC_OK, description = "The updated comment as JSON.") })
public Response updateEventComment(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId, @FormParam("text") String text, @FormParam("reason") String reason, @FormParam("resolved") Boolean resolved) throws Exception {
    Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
    if (optEvent.isNone())
        return notFound("Cannot find an event with id '%s'.", eventId);
    try {
        EventComment dto = getEventCommentService().getComment(commentId);
        if (StringUtils.isNotBlank(text)) {
            text = text.trim();
        } else {
            text = dto.getText();
        }
        if (StringUtils.isNotBlank(reason)) {
            reason = reason.trim();
        } else {
            reason = dto.getReason();
        }
        if (resolved == null)
            resolved = dto.isResolvedStatus();
        EventComment updatedComment = EventComment.create(dto.getId(), eventId, getSecurityService().getOrganization().getId(), text, dto.getAuthor(), reason, resolved, dto.getCreationDate(), new Date(), dto.getReplies());
        updatedComment = getEventCommentService().updateComment(updatedComment);
        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.error("Unable to update the comments catalog on event {}: {}", eventId, 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) 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 19 with EventComment

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

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

the class EventCommentDatabaseServiceImpl method deleteComments.

@Override
public void deleteComments(String eventId) throws NotFoundException, EventCommentDatabaseException {
    // Similar to deleteComment but we want to avoid sending a message for each deletion
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();
        List<EventComment> comments = getComments(eventId);
        for (EventComment comment : comments) {
            long commentId = comment.getId().get().intValue();
            EventCommentDto event = getEventComment(commentId, em);
            if (event == null)
                throw new NotFoundException("Event comment with ID " + commentId + " does not exist");
            em.remove(event);
        }
        tx.commit();
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not delete event comments: {}", ExceptionUtils.getStackTrace(e));
        if (tx.isActive())
            tx.rollback();
        throw new EventCommentDatabaseException(e);
    } finally {
        if (em != null)
            em.close();
    }
    sendMessageUpdate(eventId);
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EventComment(org.opencastproject.event.comment.EventComment) EntityManager(javax.persistence.EntityManager) NotFoundException(org.opencastproject.util.NotFoundException) ServiceException(org.osgi.framework.ServiceException) NoResultException(javax.persistence.NoResultException) NotFoundException(org.opencastproject.util.NotFoundException)

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