use of edu.stanford.bmir.protege.web.server.diff.Revision2DiffElementsTranslator in project webprotege by protegeproject.
the class ProjectChangesManager method getProjectChangesForRevision.
private void getProjectChangesForRevision(Revision revision, Optional<OWLEntity> subject, ImmutableList.Builder<ProjectChange> changesBuilder) {
if (subject.isPresent() && !entitiesByRevisionCache.containsEntity(revision, subject.get())) {
return;
}
Map<Optional<IRI>, List<OWLOntologyChangeRecord>> recordsBySubject = getChangeRecordsBySubject(revision);
List<OWLOntologyChangeRecord> limitedRecords = new ArrayList<>();
final int totalChanges;
if (subject.isPresent()) {
List<OWLOntologyChangeRecord> records = recordsBySubject.get(subject.map(OWLEntity::getIRI));
if (records == null) {
// Nothing in this revision that changes the subject
return;
}
totalChanges = records.size();
limitedRecords.addAll(records);
} else {
totalChanges = revision.getSize();
for (Map.Entry<Optional<IRI>, List<OWLOntologyChangeRecord>> entry : recordsBySubject.entrySet()) {
limitedRecords.addAll(entry.getValue());
if (limitedRecords.size() >= DEFAULT_CHANGE_LIMIT) {
break;
}
}
}
Revision2DiffElementsTranslator translator = new Revision2DiffElementsTranslator(ontologyIRIShortFormProvider);
List<DiffElement<String, OWLOntologyChangeRecord>> axiomDiffElements = translator.getDiffElementsFromRevision(limitedRecords);
sortDiff(axiomDiffElements);
List<DiffElement<String, SafeHtml>> renderedDiffElements = renderDiffElements(axiomDiffElements);
int pageElements = renderedDiffElements.size();
int pageCount;
if (pageElements == 0) {
pageCount = 1;
} else {
pageCount = totalChanges / pageElements + (totalChanges % pageElements);
}
Page<DiffElement<String, SafeHtml>> page = new Page<>(1, pageCount, renderedDiffElements, totalChanges);
ProjectChange projectChange = new ProjectChange(revision.getRevisionNumber(), revision.getUserId(), revision.getTimestamp(), revision.getHighLevelDescription(), totalChanges, page);
changesBuilder.add(projectChange);
}
Aggregations