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