Search in sources :

Example 41 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class GetCommentedEntitiesActionHandler method execute.

@Nonnull
@Override
public GetCommentedEntitiesResult execute(@Nonnull GetCommentedEntitiesAction action, @Nonnull ExecutionContext executionContext) {
    PageRequest request = action.getPageRequest();
    List<EntityDiscussionThread> allThreads = repository.getThreadsInProject(action.getProjectId());
    Map<OWLEntity, List<EntityDiscussionThread>> commentsByEntity = allThreads.stream().collect(groupingBy(EntityDiscussionThread::getEntity));
    List<CommentedEntityData> result = new ArrayList<>();
    commentsByEntity.forEach((entity, threads) -> {
        if (rootOntology.containsEntityInSignature(entity)) {
            int totalThreadCount = threads.size();
            int openThreadCount = (int) threads.stream().filter(thread -> thread.getStatus().isOpen()).count();
            List<Comment> entityComments = threads.stream().flatMap(thread -> thread.getComments().stream()).collect(toList());
            Comment lastComment = entityComments.stream().max(comparing(c -> c.getUpdatedAt().orElse(c.getCreatedAt()))).get();
            List<UserId> participants = entityComments.stream().map(Comment::getCreatedBy).collect(toList());
            result.add(new CommentedEntityData(renderer.getRendering(entity), totalThreadCount, openThreadCount, entityComments.size(), lastComment.getUpdatedAt().orElse(lastComment.getCreatedAt()), lastComment.getCreatedBy(), participants));
        }
    });
    if (action.getSortingKey() == SortingKey.SORT_BY_ENTITY) {
        result.sort(byEntity);
    } else {
        result.sort(byLastModified);
    }
    Pager<CommentedEntityData> pager = Pager.getPagerForPageSize(result, request.getPageSize());
    return new GetCommentedEntitiesResult(action.getProjectId(), pager.getPage(request.getPageNumber()));
}
Also used : HasGetRendering(edu.stanford.bmir.protege.web.server.mansyntax.render.HasGetRendering) CommentedEntityData.byLastModified(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData.byLastModified) edu.stanford.bmir.protege.web.shared.issues(edu.stanford.bmir.protege.web.shared.issues) RootOntology(edu.stanford.bmir.protege.web.server.inject.project.RootOntology) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Pager(edu.stanford.bmir.protege.web.server.pagination.Pager) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CommentedEntityData.byEntity(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData.byEntity) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) Map(java.util.Map) CommentedEntityData(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Comparator.comparing(java.util.Comparator.comparing) Nonnull(javax.annotation.Nonnull) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ArrayList(java.util.ArrayList) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CommentedEntityData(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData) Nonnull(javax.annotation.Nonnull)

Example 42 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity 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 43 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity 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)

Example 44 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class OWLObjectStringFormatter method renderObject.

private String renderObject(Object object) {
    if (!(object instanceof OWLObject)) {
        return object.toString();
    }
    if (object instanceof OWLEntity) {
        return shortFormProvider.getShortForm((OWLEntity) object);
    } else if (object instanceof IRI) {
        return iriShortFormProvider.getShortForm((IRI) object);
    } else if (object instanceof OWLLiteral) {
        OWLLiteral literal = (OWLLiteral) object;
        String rendering;
        if (literal.isRDFPlainLiteral() || literal.getDatatype().isString()) {
            rendering = "\"" + literal.getLiteral() + "\"";
        } else {
            rendering = this.render.render((OWLLiteral) object);
        }
        int startIndex = rendering.indexOf("\"");
        int endIndex = rendering.lastIndexOf("\"");
        if (startIndex == -1 || endIndex == -1) {
            return rendering;
        }
        if (endIndex - startIndex < 10) {
            return rendering;
        }
        if (rendering.length() < MAX_LITERAL_LENGTH) {
            return rendering;
        }
        String withoutQuotes = rendering.substring(startIndex + 1, endIndex);
        String abbreviatedLexicalValue = StringUtils.abbreviate(withoutQuotes, MAX_LITERAL_LENGTH);
        String prefix = rendering.substring(0, startIndex + 1);
        String suffix = rendering.substring(endIndex);
        return prefix + abbreviatedLexicalValue + suffix;
    } else {
        String rendering = this.render.render((OWLObject) object);
        return escape(rendering);
    }
}
Also used : OWLObject(org.semanticweb.owlapi.model.OWLObject) IRI(org.semanticweb.owlapi.model.IRI) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLEntity(org.semanticweb.owlapi.model.OWLEntity)

Example 45 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class IssueEventReadConverter method convert.

@Override
public IssueEvent convert(BasicDBObject dbObject) {
    String eventClass = dbObject.getString("_class");
    UserId userId = UserId.getUserId(dbObject.getString("userId"));
    long timestamp = dbObject.getLong("timestamp");
    if ("IssueAssigned".equals(eventClass)) {
        UserId assignee = UserId.getUserId(dbObject.getString("assignee"));
        return new IssueAssigned(userId, timestamp, assignee);
    } else if ("IssueUnassigned".equals(eventClass)) {
        UserId assignee = UserId.getUserId(dbObject.getString("assignee"));
        return new IssueUnassigned(userId, timestamp, assignee);
    } else if ("IssueLabelled".equals(eventClass)) {
        return new IssueLabelled(userId, timestamp, dbObject.getString("label"));
    } else if ("IssueUnlabelled".equals(eventClass)) {
        return new IssueUnlabelled(userId, timestamp, dbObject.getString("label"));
    } else if ("IssueMilestoned".equals(eventClass)) {
        return new IssueMilestoned(userId, timestamp, new Milestone(dbObject.getString("milestone")));
    } else if ("IssueDemilestoned".equals(eventClass)) {
        return new IssueDemilestoned(userId, timestamp, new Milestone(dbObject.getString("milestone")));
    } else if ("IssueLocked".equals(eventClass)) {
        return new IssueLocked(userId, timestamp);
    } else if ("IssueUnlocked".equals(eventClass)) {
        return new IssueUnlocked(userId, timestamp);
    } else if ("IssueRenamed".equals(eventClass)) {
        String from = dbObject.getString("from");
        String to = dbObject.getString("to");
        return new IssueRenamed(userId, timestamp, from, to);
    } else if ("IssueClosed".equals(eventClass)) {
        return new IssueClosed(userId, timestamp);
    } else if ("IssueReopened".equals(eventClass)) {
        return new IssueReopened(userId, timestamp);
    } else if ("IssueTargetAdded".equals(eventClass)) {
        OWLEntity targetEntity = entityReadConverter.convert((DBObject) dbObject.get("entity"));
        return new IssueTargetAdded(userId, timestamp, targetEntity);
    } else if ("IssueTargetRemoved".equals(eventClass)) {
        OWLEntity targetEntity = entityReadConverter.convert((DBObject) dbObject.get("entity"));
        return new IssueTargetRemoved(userId, timestamp, targetEntity);
    } else if ("IssueReferenced".equals(eventClass)) {
        int issueNumber = dbObject.getInt("issueNumber");
        int referencedByIssueNumber = dbObject.getInt("referencedByIssueNumber");
        return new IssueReferenced(userId, timestamp, issueNumber, referencedByIssueNumber);
    }
    // }
    throw new RuntimeException("Unknown IssueEvent class: " + eventClass);
}
Also used : Milestone(edu.stanford.bmir.protege.web.shared.issues.Milestone) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId)

Aggregations

OWLEntity (org.semanticweb.owlapi.model.OWLEntity)45 Test (org.junit.Test)13 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)7 OWLEntityData (edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)6 ArrayList (java.util.ArrayList)6 Nonnull (javax.annotation.Nonnull)6 Inject (javax.inject.Inject)6 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)5 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)4 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)3 IRI (org.semanticweb.owlapi.model.IRI)3 DBObject (com.mongodb.DBObject)2 EntitySuggestion (edu.stanford.bmir.protege.web.client.library.suggest.EntitySuggestion)2 AbstractProjectActionHandler (edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler)2 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)2 VIEW_PROJECT (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT)2 ColumnType (edu.stanford.bmir.protege.web.shared.csv.ColumnType)2 OWLPrimitiveData (edu.stanford.bmir.protege.web.shared.entity.OWLPrimitiveData)2 ProjectEvent (edu.stanford.bmir.protege.web.shared.event.ProjectEvent)2 Comparator.comparing (java.util.Comparator.comparing)2