Search in sources :

Example 51 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId 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)

Aggregations

ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)51 Nonnull (javax.annotation.Nonnull)19 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)16 Inject (javax.inject.Inject)14 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)8 java.util (java.util)7 HasProjectId (edu.stanford.bmir.protege.web.shared.project.HasProjectId)6 Collectors.toList (java.util.stream.Collectors.toList)6 Nullable (javax.annotation.Nullable)6 Test (org.junit.Test)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)5 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)5 Optional (java.util.Optional)5 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)5 Subject.forUser (edu.stanford.bmir.protege.web.server.access.Subject.forUser)4 ProjectDetails (edu.stanford.bmir.protege.web.shared.project.ProjectDetails)4 List (java.util.List)4 ImmutableSet (com.google.common.collect.ImmutableSet)3