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