Search in sources :

Example 6 with ProjectEvent

use of edu.stanford.bmir.protege.web.shared.event.ProjectEvent in project webprotege by protegeproject.

the class SetDiscussionThreadStatusHandler method execute.

@Nonnull
@Override
public SetDiscussionThreadStatusResult execute(@Nonnull SetDiscussionThreadStatusAction action, @Nonnull ExecutionContext executionContext) {
    EventTag fromTag = eventManager.getCurrentTag();
    ThreadId threadId = action.getThreadId();
    Status status = action.getStatus();
    Optional<EntityDiscussionThread> thread = repository.setThreadStatus(threadId, status);
    int openComments = thread.map(t -> repository.getOpenCommentsCount(projectId, t.getEntity())).orElse(-1);
    eventManager.postEvent(new DiscussionThreadStatusChangedEvent(projectId, threadId, thread.map(EntityDiscussionThread::getEntity), openComments, status));
    EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(fromTag);
    return new SetDiscussionThreadStatusResult(threadId, status, eventList);
}
Also used : edu.stanford.bmir.protege.web.shared.issues(edu.stanford.bmir.protege.web.shared.issues) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) EventList(edu.stanford.bmir.protege.web.shared.event.EventList) EventManager(edu.stanford.bmir.protege.web.server.events.EventManager) Inject(javax.inject.Inject) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) SET_OBJECT_COMMENT_STATUS(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.SET_OBJECT_COMMENT_STATUS) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) EventTag(edu.stanford.bmir.protege.web.shared.event.EventTag) Optional(java.util.Optional) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EventTag(edu.stanford.bmir.protege.web.shared.event.EventTag) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) Nonnull(javax.annotation.Nonnull)

Example 7 with ProjectEvent

use of edu.stanford.bmir.protege.web.shared.event.ProjectEvent in project webprotege by protegeproject.

the class AddEntityCommentHandler method execute.

@Nonnull
@Override
public AddEntityCommentResult execute(@Nonnull AddEntityCommentAction action, @Nonnull ExecutionContext executionContext) {
    UserId createdBy = executionContext.getUserId();
    long createdAt = System.currentTimeMillis();
    CommentRenderer r = new CommentRenderer();
    String rawComment = action.getComment();
    String renderedComment = r.renderComment(rawComment);
    Comment comment = new Comment(CommentId.create(), createdBy, createdAt, Optional.empty(), rawComment, renderedComment);
    ThreadId threadId = action.getThreadId();
    repository.addCommentToThread(threadId, comment);
    EventTag startTag = eventManager.getCurrentTag();
    postCommentPostedEvent(threadId, comment);
    EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(startTag);
    sendOutNotifications(threadId, comment);
    return new AddEntityCommentResult(action.getProjectId(), threadId, comment, renderedComment, eventList);
}
Also used : UserId(edu.stanford.bmir.protege.web.shared.user.UserId) EventTag(edu.stanford.bmir.protege.web.shared.event.EventTag) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) Nonnull(javax.annotation.Nonnull)

Example 8 with ProjectEvent

use of edu.stanford.bmir.protege.web.shared.event.ProjectEvent in project webprotege by protegeproject.

the class EditCommentActionHandler method execute.

@Nonnull
@Override
public EditCommentResult execute(@Nonnull EditCommentAction action, @Nonnull ExecutionContext executionContext) {
    EventTag fromTag = eventManager.getCurrentTag();
    Optional<EntityDiscussionThread> thread = repository.getThread(action.getThreadId());
    if (!thread.isPresent()) {
        throw new RuntimeException("Invalid comment thread");
    }
    EntityDiscussionThread t = thread.get();
    String renderedComment = new CommentRenderer().renderComment(action.getBody());
    Optional<Comment> updatedComment = t.getComments().stream().filter(c -> c.getId().equals(action.getCommentId())).limit(1).map(c -> new Comment(c.getId(), c.getCreatedBy(), c.getCreatedAt(), Optional.of(System.currentTimeMillis()), action.getBody(), renderedComment)).peek(c -> repository.updateComment(t.getId(), c)).findFirst();
    updatedComment.ifPresent(comment -> eventManager.postEvent(new CommentUpdatedEvent(projectId, t.getId(), comment)));
    EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(fromTag);
    return new EditCommentResult(updatedComment, eventList);
}
Also used : edu.stanford.bmir.protege.web.shared.issues(edu.stanford.bmir.protege.web.shared.issues) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) EDIT_OWN_OBJECT_COMMENT(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.EDIT_OWN_OBJECT_COMMENT) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) EventList(edu.stanford.bmir.protege.web.shared.event.EventList) EventManager(edu.stanford.bmir.protege.web.server.events.EventManager) Inject(javax.inject.Inject) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) EventTag(edu.stanford.bmir.protege.web.shared.event.EventTag) Optional(java.util.Optional) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EventTag(edu.stanford.bmir.protege.web.shared.event.EventTag) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) Nonnull(javax.annotation.Nonnull)

Example 9 with ProjectEvent

use of edu.stanford.bmir.protege.web.shared.event.ProjectEvent in project webprotege by protegeproject.

the class CreateEntityDiscussionThreadHandler method execute.

@Nonnull
@Override
public CreateEntityDiscussionThreadResult execute(@Nonnull CreateEntityDiscussionThreadAction action, @Nonnull ExecutionContext executionContext) {
    String rawComment = action.getComment();
    CommentRenderer commentRenderer = new CommentRenderer();
    String renderedComment = commentRenderer.renderComment(rawComment);
    UserId commentingUser = executionContext.getUserId();
    Comment comment = new Comment(CommentId.create(), commentingUser, System.currentTimeMillis(), Optional.empty(), rawComment, renderedComment);
    OWLEntity entity = action.getEntity();
    EntityDiscussionThread thread = new EntityDiscussionThread(ThreadId.create(), action.getProjectId(), entity, Status.OPEN, ImmutableList.of(comment));
    repository.saveThread(thread);
    EventTag startTag = eventManager.getCurrentTag();
    eventManager.postEvent(new DiscussionThreadCreatedEvent(thread));
    int commentCount = repository.getCommentsCount(projectId, entity);
    int openCommentCount = repository.getOpenCommentsCount(projectId, entity);
    Optional<OWLEntityData> rendering = Optional.of(renderer.getRendering(entity));
    eventManager.postEvent(new CommentPostedEvent(projectId, thread.getId(), comment, rendering, commentCount, openCommentCount));
    EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(startTag);
    setOutNotifications(thread, comment);
    List<EntityDiscussionThread> threads = repository.findThreads(projectId, entity);
    return new CreateEntityDiscussionThreadResult(ImmutableList.copyOf(threads), eventList);
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData) EventTag(edu.stanford.bmir.protege.web.shared.event.EventTag) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) Nonnull(javax.annotation.Nonnull)

Aggregations

ProjectEvent (edu.stanford.bmir.protege.web.shared.event.ProjectEvent)9 Nonnull (javax.annotation.Nonnull)8 EventTag (edu.stanford.bmir.protege.web.shared.event.EventTag)7 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)3 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)3 Nullable (javax.annotation.Nullable)3 Inject (javax.inject.Inject)3 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)2 AbstractProjectActionHandler (edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler)2 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)2 EventManager (edu.stanford.bmir.protege.web.server.events.EventManager)2 BuiltInAction (edu.stanford.bmir.protege.web.shared.access.BuiltInAction)2 EventList (edu.stanford.bmir.protege.web.shared.event.EventList)2 edu.stanford.bmir.protege.web.shared.issues (edu.stanford.bmir.protege.web.shared.issues)2 Optional (java.util.Optional)2 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 ProjectResource (edu.stanford.bmir.protege.web.server.access.ProjectResource)1