Search in sources :

Example 51 with Event

use of org.opencastproject.index.service.impl.index.event.Event 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 52 with Event

use of org.opencastproject.index.service.impl.index.event.Event 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 53 with Event

use of org.opencastproject.index.service.impl.index.event.Event 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 54 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class SeriesEndpoint method hasProcessingEvents.

/**
 * Check if the series with the given Id has events being currently processed
 *
 * @param seriesId
 *          the series Id
 * @return true if events being part of the series are currently processed
 */
private boolean hasProcessingEvents(String seriesId) {
    EventSearchQuery query = new EventSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
    long elementsCount = 0;
    query.withSeriesId(seriesId);
    try {
        query.withWorkflowState(WorkflowInstance.WorkflowState.RUNNING.toString());
        SearchResult<Event> events = searchIndex.getByQuery(query);
        elementsCount = events.getHitCount();
        query.withWorkflowState(WorkflowInstance.WorkflowState.INSTANTIATED.toString());
        events = searchIndex.getByQuery(query);
        elementsCount += events.getHitCount();
    } catch (SearchIndexException e) {
        logger.warn("Could not perform search query: {}", ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
    return elementsCount > 0;
}
Also used : SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) WebApplicationException(javax.ws.rs.WebApplicationException) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) Event(org.opencastproject.index.service.impl.index.event.Event)

Example 55 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class EventsEndpoint method updateEvent.

private Response updateEvent(String eventId, HttpServletRequest request) {
    try {
        Opt<String> startDatePattern = configuredMetadataFields.containsKey("startDate") ? configuredMetadataFields.get("startDate").getPattern() : Opt.none();
        Opt<String> startTimePattern = configuredMetadataFields.containsKey("startTime") ? configuredMetadataFields.get("startTime").getPattern() : Opt.none();
        for (final Event event : indexService.getEvent(eventId, externalIndex)) {
            EventHttpServletRequest eventHttpServletRequest = EventHttpServletRequest.updateFromHttpServletRequest(event, request, getEventCatalogUIAdapters(), startDatePattern, startTimePattern);
            if (eventHttpServletRequest.getMetadataList().isSome()) {
                indexService.updateEventMetadata(eventId, eventHttpServletRequest.getMetadataList().get(), externalIndex);
            }
            if (eventHttpServletRequest.getAcl().isSome()) {
                indexService.updateEventAcl(eventId, eventHttpServletRequest.getAcl().get(), externalIndex);
            }
            return ApiResponses.Json.noContent(ApiVersion.VERSION_1_0_0);
        }
        return ApiResponses.notFound("Cannot find an event with id '%s'.", eventId);
    } catch (NotFoundException e) {
        return ApiResponses.notFound("Cannot find an event with id '%s'.", eventId);
    } catch (UnauthorizedException e) {
        return Response.status(Status.UNAUTHORIZED).build();
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to update event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
        return RestUtil.R.badRequest(e.getMessage());
    } catch (IndexServiceException e) {
        logger.error("Unable to get multi part fields or file for event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    } catch (SearchIndexException e) {
        logger.error("Unable to update event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : EventHttpServletRequest(org.opencastproject.index.service.impl.index.event.EventHttpServletRequest) WebApplicationException(javax.ws.rs.WebApplicationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Event(org.opencastproject.index.service.impl.index.event.Event) NotFoundException(org.opencastproject.util.NotFoundException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Aggregations

Event (org.opencastproject.index.service.impl.index.event.Event)67 Path (javax.ws.rs.Path)35 RestQuery (org.opencastproject.util.doc.rest.RestQuery)34 NotFoundException (org.opencastproject.util.NotFoundException)26 WebApplicationException (javax.ws.rs.WebApplicationException)24 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)22 Produces (javax.ws.rs.Produces)21 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)19 MediaPackage (org.opencastproject.mediapackage.MediaPackage)19 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)19 ParseException (java.text.ParseException)17 JSONException (org.codehaus.jettison.json.JSONException)17 UrlSigningException (org.opencastproject.security.urlsigning.exception.UrlSigningException)17 GET (javax.ws.rs.GET)16 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)16 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)16 EventCommentException (org.opencastproject.event.comment.EventCommentException)15 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)15 JobEndpointException (org.opencastproject.adminui.exception.JobEndpointException)14 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)14