Search in sources :

Example 1 with DiffElement

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);
}
Also used : DiffElement(edu.stanford.bmir.protege.web.shared.diff.DiffElement) Page(edu.stanford.bmir.protege.web.shared.pagination.Page) ProjectChange(edu.stanford.bmir.protege.web.shared.change.ProjectChange) Revision2DiffElementsTranslator(edu.stanford.bmir.protege.web.server.diff.Revision2DiffElementsTranslator) OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) ImmutableList(com.google.common.collect.ImmutableList)

Example 2 with DiffElement

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);
    }
}
Also used : DiffElement(edu.stanford.bmir.protege.web.shared.diff.DiffElement) ProjectRevisionDownloader(edu.stanford.bmir.protege.web.client.download.ProjectRevisionDownloader)

Example 3 with DiffElement

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);
    }
}
Also used : DiffElement(edu.stanford.bmir.protege.web.shared.diff.DiffElement) ComputeProjectMergeResult(edu.stanford.bmir.protege.web.shared.merge.ComputeProjectMergeResult) DocumentId(edu.stanford.bmir.protege.web.shared.csv.DocumentId) OntologyDiff(edu.stanford.bmir.protege.web.shared.merge.OntologyDiff) IOException(java.io.IOException) Nonnull(javax.annotation.Nonnull)

Example 4 with DiffElement

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;
}
Also used : DiffElement(edu.stanford.bmir.protege.web.shared.diff.DiffElement) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) WebProtegeShortFormProvider(edu.stanford.bmir.protege.web.server.shortform.WebProtegeShortFormProvider) WebProtegeIRIShortFormProvider(edu.stanford.bmir.protege.web.server.shortform.WebProtegeIRIShortFormProvider) ShortFormProvider(org.semanticweb.owlapi.util.ShortFormProvider) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) OWLObjectRenderer(org.semanticweb.owlapi.io.OWLObjectRenderer)

Aggregations

DiffElement (edu.stanford.bmir.protege.web.shared.diff.DiffElement)4 ImmutableList (com.google.common.collect.ImmutableList)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 ProjectRevisionDownloader (edu.stanford.bmir.protege.web.client.download.ProjectRevisionDownloader)1 Revision2DiffElementsTranslator (edu.stanford.bmir.protege.web.server.diff.Revision2DiffElementsTranslator)1 WebProtegeIRIShortFormProvider (edu.stanford.bmir.protege.web.server.shortform.WebProtegeIRIShortFormProvider)1 WebProtegeShortFormProvider (edu.stanford.bmir.protege.web.server.shortform.WebProtegeShortFormProvider)1 ProjectChange (edu.stanford.bmir.protege.web.shared.change.ProjectChange)1 DocumentId (edu.stanford.bmir.protege.web.shared.csv.DocumentId)1 ComputeProjectMergeResult (edu.stanford.bmir.protege.web.shared.merge.ComputeProjectMergeResult)1 OntologyDiff (edu.stanford.bmir.protege.web.shared.merge.OntologyDiff)1 Page (edu.stanford.bmir.protege.web.shared.pagination.Page)1 IOException (java.io.IOException)1 Nonnull (javax.annotation.Nonnull)1 OWLOntologyChangeRecord (org.semanticweb.owlapi.change.OWLOntologyChangeRecord)1 OWLObjectRenderer (org.semanticweb.owlapi.io.OWLObjectRenderer)1 ShortFormProvider (org.semanticweb.owlapi.util.ShortFormProvider)1