Search in sources :

Example 6 with ExecutionContext

use of edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext in project webprotege by protegeproject.

the class GetEntityHierarchyChildrenActionHandler method execute.

@Nonnull
@Override
public GetHierarchyChildrenResult execute(@Nonnull GetHierarchyChildrenAction action, @Nonnull ExecutionContext executionContext) {
    HierarchyId hierarchyId = action.getHierarchyId();
    Optional<HierarchyProvider<OWLEntity>> hierarchyProvider = hierarchyProviderMapper.getHierarchyProvider(hierarchyId);
    if (!hierarchyProvider.isPresent()) {
        return emptyResult();
    }
    OWLEntity parent = action.getEntity();
    GraphNode<EntityHierarchyNode> parentNode = nodeRenderer.toGraphNode(parent, hierarchyProvider.get());
    SuccessorMap.Builder<EntityHierarchyNode> successorMap = SuccessorMap.builder();
    hierarchyProvider.get().getChildren(parent).stream().filter(child -> isNotDeprecatedTopLevelEntity(parent, child)).map(child -> nodeRenderer.toGraphNode(child, hierarchyProvider.get())).forEach(childNode -> successorMap.add(parentNode, childNode));
    successorMap.sort(comparing(GraphNode::getUserObject));
    return new GetHierarchyChildrenResult(successorMap.build());
}
Also used : HierarchyId(edu.stanford.bmir.protege.web.shared.hierarchy.HierarchyId) GetHierarchyChildrenAction(edu.stanford.bmir.protege.web.shared.hierarchy.GetHierarchyChildrenAction) GraphNode(edu.stanford.protege.gwt.graphtree.shared.graph.GraphNode) VIEW_PROJECT(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) SuccessorMap(edu.stanford.protege.gwt.graphtree.shared.graph.SuccessorMap) DeprecatedEntityChecker(edu.stanford.bmir.protege.web.server.mansyntax.render.DeprecatedEntityChecker) EntityHierarchyNode(edu.stanford.bmir.protege.web.shared.hierarchy.EntityHierarchyNode) Inject(javax.inject.Inject) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) HierarchyId(edu.stanford.bmir.protege.web.shared.hierarchy.HierarchyId) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Optional(java.util.Optional) GetHierarchyChildrenResult(edu.stanford.bmir.protege.web.shared.hierarchy.GetHierarchyChildrenResult) Comparator.comparing(java.util.Comparator.comparing) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EntityHierarchyNode(edu.stanford.bmir.protege.web.shared.hierarchy.EntityHierarchyNode) GetHierarchyChildrenResult(edu.stanford.bmir.protege.web.shared.hierarchy.GetHierarchyChildrenResult) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) SuccessorMap(edu.stanford.protege.gwt.graphtree.shared.graph.SuccessorMap) Nonnull(javax.annotation.Nonnull)

Example 7 with ExecutionContext

use of edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext 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

AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)7 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)7 Nonnull (javax.annotation.Nonnull)7 Inject (javax.inject.Inject)7 AbstractProjectActionHandler (edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler)6 BuiltInAction (edu.stanford.bmir.protege.web.shared.access.BuiltInAction)5 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)5 Nullable (javax.annotation.Nullable)5 List (java.util.List)4 Optional (java.util.Optional)4 Collectors.toList (java.util.stream.Collectors.toList)4 edu.stanford.bmir.protege.web.shared.issues (edu.stanford.bmir.protege.web.shared.issues)3 EventManager (edu.stanford.bmir.protege.web.server.events.EventManager)2 RootOntology (edu.stanford.bmir.protege.web.server.inject.project.RootOntology)2 Pager (edu.stanford.bmir.protege.web.server.pagination.Pager)2 VIEW_PROJECT (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT)2 EventList (edu.stanford.bmir.protege.web.shared.event.EventList)2 EventTag (edu.stanford.bmir.protege.web.shared.event.EventTag)2 ProjectEvent (edu.stanford.bmir.protege.web.shared.event.ProjectEvent)2 PageRequest (edu.stanford.bmir.protege.web.shared.pagination.PageRequest)2