use of edu.stanford.bmir.protege.web.shared.diff.DiffElement 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);
}
use of edu.stanford.bmir.protege.web.shared.diff.DiffElement in project webprotege by protegeproject.
the class ChangeListViewPresenter method insertChangesIntoView.
private void insertChangesIntoView(ImmutableList<ProjectChange> changes, SubjectDisplay subjectDisplay, boolean revertChangesVisible, boolean downloadVisible) {
List<ProjectChange> projectChanges = new ArrayList<>(changes);
Collections.sort(projectChanges, Ordering.compound(Collections.singletonList(Ordering.from(new ProjectChangeTimestampComparator()).reverse())));
long previousTimeStamp = 0;
for (final ProjectChange projectChange : projectChanges) {
long changeTimeStamp = projectChange.getTimestamp();
if (!TimeUtil.isSameCalendarDay(previousTimeStamp, changeTimeStamp)) {
previousTimeStamp = changeTimeStamp;
Date date = new Date(changeTimeStamp);
view.addSeparator("\u25C9 " + messages.change_changesOn() + " " + DateTimeFormat.getFormat("EEE, d MMM yyyy").format(date));
}
ChangeDetailsView view = new ChangeDetailsViewImpl();
if (subjectDisplay == SubjectDisplay.DISPLAY_SUBJECT) {
// List<OWLEntityData> subjects = new ArrayList<>(projectChange.getSubjects());
// Collections.sort(subjects, OWLEntityData::compareToIgnoreCase);
// view.setSubjects(subjects);
}
view.setRevision(projectChange.getRevisionNumber());
view.setAuthor(projectChange.getAuthor());
view.setHighLevelDescription(projectChange.getSummary());
view.setRevertRevisionVisible(false);
if (revertChangesVisible) {
permissionChecker.hasPermission(REVERT_CHANGES, view::setRevertRevisionVisible);
}
view.setRevertRevisionHandler(revisionNumber -> ChangeListViewPresenter.this.handleRevertRevision(projectChange));
view.setDownloadRevisionHandler(revisionNumber -> {
ProjectRevisionDownloader downloader = new ProjectRevisionDownloader(projectId.get(), revisionNumber, DownloadFormatExtension.owl);
downloader.download();
});
view.setDownloadRevisionVisible(downloadVisible);
Page<DiffElement<String, SafeHtml>> page = projectChange.getDiff();
List<DiffElement<String, SafeHtml>> pageElements = page.getPageElements();
view.setDiff(pageElements, (int) page.getTotalElements());
view.setChangeCount(projectChange.getChangeCount());
view.setTimestamp(changeTimeStamp);
this.view.addChangeDetailsView(view);
}
}
use of edu.stanford.bmir.protege.web.shared.diff.DiffElement in project webprotege by protegeproject.
the class ComputeProjectMergeActionHandler method execute.
@Nonnull
@Override
public ComputeProjectMergeResult execute(@Nonnull ComputeProjectMergeAction action, @Nonnull ExecutionContext executionContext) {
try {
DocumentId documentId = action.getProjectDocumentId();
OWLOntology uploadedRootOntology = loadUploadedOntology(documentId);
Set<OntologyDiff> diffs = computeDiff(uploadedRootOntology, projectRootOntology);
List<DiffElement<String, SafeHtml>> transformedDiff = renderDiff(uploadedRootOntology, diffs);
return new ComputeProjectMergeResult(transformedDiff);
} catch (Exception e) {
logger.info("An error occurred whilst merging ontologies", e);
throw new RuntimeException(e);
}
}
use of edu.stanford.bmir.protege.web.shared.diff.DiffElement in project webprotege by protegeproject.
the class ComputeProjectMergeActionHandler method renderDiff.
private List<DiffElement<String, SafeHtml>> renderDiff(OWLOntology uploadedRootOntology, Set<OntologyDiff> diffs) {
final ShortFormProvider dualShortFormProvider = getShortFormProvider(uploadedRootOntology);
final OWLObjectRenderer renderer = getManchesterSyntaxObjectRenderer(projectRootOntology, uploadedRootOntology, dualShortFormProvider);
List<DiffElement<String, OWLAxiom>> diffElements = getDiffElements(diffs);
sortDiff(diffElements);
// Transform from OWLAxiom to SafeHtml
List<DiffElement<String, SafeHtml>> transformedDiff = new ArrayList<>();
for (DiffElement<String, OWLAxiom> element : diffElements) {
String html = renderer.render(element.getLineElement());
SafeHtml rendering = new SafeHtmlBuilder().appendHtmlConstant(html).toSafeHtml();
transformedDiff.add(new DiffElement<>(element.getDiffOperation(), element.getSourceDocument(), rendering));
}
return transformedDiff;
}
Aggregations