Search in sources :

Example 1 with EventCommentException

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

use of org.opencastproject.event.comment.EventCommentException 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)

Example 3 with EventCommentException

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

the class IndexServiceImpl method removeEvent.

@Override
public boolean removeEvent(String id) throws NotFoundException, UnauthorizedException {
    boolean unauthorizedScheduler = false;
    boolean notFoundScheduler = false;
    boolean removedScheduler = true;
    try {
        schedulerService.removeEvent(id);
    } catch (NotFoundException e) {
        notFoundScheduler = true;
    } catch (UnauthorizedException e) {
        unauthorizedScheduler = true;
    } catch (SchedulerException e) {
        removedScheduler = false;
        logger.error("Unable to remove the event '{}' from scheduler service: {}", id, getStackTrace(e));
    }
    boolean unauthorizedWorkflow = false;
    boolean notFoundWorkflow = false;
    boolean removedWorkflow = true;
    try {
        WorkflowQuery workflowQuery = new WorkflowQuery().withMediaPackage(id);
        WorkflowSet workflowSet = workflowService.getWorkflowInstances(workflowQuery);
        if (workflowSet.size() == 0)
            notFoundWorkflow = true;
        for (WorkflowInstance instance : workflowSet.getItems()) {
            workflowService.stop(instance.getId());
            workflowService.remove(instance.getId());
        }
    } catch (NotFoundException e) {
        notFoundWorkflow = true;
    } catch (UnauthorizedException e) {
        unauthorizedWorkflow = true;
    } catch (WorkflowDatabaseException e) {
        removedWorkflow = false;
        logger.error("Unable to remove the event '{}' because removing workflow failed: {}", id, getStackTrace(e));
    } catch (WorkflowException e) {
        removedWorkflow = false;
        logger.error("Unable to remove the event '{}' because removing workflow failed: {}", id, getStackTrace(e));
    }
    boolean unauthorizedArchive = false;
    boolean notFoundArchive = false;
    boolean removedArchive = true;
    try {
        final AQueryBuilder q = assetManager.createQuery();
        final Predicate p = q.organizationId().eq(securityService.getOrganization().getId()).and(q.mediaPackageId(id));
        final AResult r = q.select(q.nothing()).where(p).run();
        if (r.getSize() > 0)
            q.delete(DEFAULT_OWNER, q.snapshot()).where(p).run();
    } catch (AssetManagerException e) {
        if (e.getCause() instanceof UnauthorizedException) {
            unauthorizedArchive = true;
        } else if (e.getCause() instanceof NotFoundException) {
            notFoundArchive = true;
        } else {
            removedArchive = false;
            logger.error("Unable to remove the event '{}' from the archive: {}", id, getStackTrace(e));
        }
    }
    if (notFoundScheduler && notFoundWorkflow && notFoundArchive)
        throw new NotFoundException("Event id " + id + " not found.");
    if (unauthorizedScheduler || unauthorizedWorkflow || unauthorizedArchive)
        throw new UnauthorizedException("Not authorized to remove event id " + id);
    try {
        eventCommentService.deleteComments(id);
    } catch (EventCommentException e) {
        logger.error("Unable to remove comments for event '{}': {}", id, getStackTrace(e));
    }
    return removedScheduler && removedWorkflow && removedArchive;
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) NotFoundException(org.opencastproject.util.NotFoundException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) EventCommentException(org.opencastproject.event.comment.EventCommentException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Predicate(org.opencastproject.assetmanager.api.query.Predicate) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) AResult(org.opencastproject.assetmanager.api.query.AResult)

Aggregations

EventCommentException (org.opencastproject.event.comment.EventCommentException)3 EventComment (org.opencastproject.event.comment.EventComment)2 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AssetManagerException (org.opencastproject.assetmanager.api.AssetManagerException)1 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)1 AResult (org.opencastproject.assetmanager.api.query.AResult)1 Predicate (org.opencastproject.assetmanager.api.query.Predicate)1 Event (org.opencastproject.index.service.impl.index.event.Event)1 ConflictingEvent (org.opencastproject.scheduler.api.ConflictingEvent)1 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)1 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)1 Val (org.opencastproject.util.Jsons.Val)1 NotFoundException (org.opencastproject.util.NotFoundException)1 RestQuery (org.opencastproject.util.doc.rest.RestQuery)1 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)1 WorkflowException (org.opencastproject.workflow.api.WorkflowException)1