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