Search in sources :

Example 6 with OWLOntologyChangeRecord

use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.

the class RevisionManagerImpl_TestCase method should_addRevision.

@Test
public void should_addRevision() {
    UserId userId = mock(UserId.class);
    List<OWLOntologyChangeRecord> changes = Arrays.asList(new OWLOntologyChangeRecord(new OWLOntologyID(), new AddAxiomData(mock(OWLAxiom.class))));
    manager.addRevision(userId, changes, HIGHLEVEL_DESC);
    ArgumentCaptor<Revision> revisionCaptor = ArgumentCaptor.forClass(Revision.class);
    verify(revisionStore, times(1)).addRevision(revisionCaptor.capture());
    Revision addedRevision = revisionCaptor.getValue();
    assertThat(addedRevision.getUserId(), is(userId));
    assertThat(addedRevision.getHighLevelDescription(), is(HIGHLEVEL_DESC));
    assertThat(addedRevision.getRevisionNumber(), is(nextRevisionNumber));
}
Also used : OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) Revision(edu.stanford.bmir.protege.web.server.revision.Revision) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) AddAxiomData(org.semanticweb.owlapi.change.AddAxiomData) Test(org.junit.Test)

Example 7 with OWLOntologyChangeRecord

use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord 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 8 with OWLOntologyChangeRecord

use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.

the class RevisionReverterChangeListGenerator method generateChanges.

@Override
public OntologyChangeList<Boolean> generateChanges(ChangeGenerationContext context) {
    Optional<Revision> revision = revisionManager.getRevision(revisionNumber);
    if (!revision.isPresent()) {
        return OntologyChangeList.<Boolean>builder().build(false);
    }
    List<OWLOntologyChange> changes = new ArrayList<>();
    for (OWLOntologyChangeRecord record : revision.get()) {
        OWLOntologyChangeData revertingChangeData = changeDataReverter.getRevertingChange(record);
        OWLOntologyChangeRecord revertingRecord = new OWLOntologyChangeRecord(record.getOntologyID(), revertingChangeData);
        OWLOntologyManager manager = rootOntology.getOWLOntologyManager();
        OWLOntologyChange change = revertingRecord.createOntologyChange(manager);
        changes.add(0, change);
    }
    return OntologyChangeList.<Boolean>builder().addAll(changes).build(true);
}
Also used : OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) Revision(edu.stanford.bmir.protege.web.server.revision.Revision) OWLOntologyChange(org.semanticweb.owlapi.model.OWLOntologyChange) ArrayList(java.util.ArrayList) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLOntologyChangeData(org.semanticweb.owlapi.change.OWLOntologyChangeData)

Aggregations

OWLOntologyChangeRecord (org.semanticweb.owlapi.change.OWLOntologyChangeRecord)8 Revision (edu.stanford.bmir.protege.web.server.revision.Revision)4 ArrayList (java.util.ArrayList)2 OWLOntologyChangeData (org.semanticweb.owlapi.change.OWLOntologyChangeData)2 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)2 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)2 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Revision2DiffElementsTranslator (edu.stanford.bmir.protege.web.server.diff.Revision2DiffElementsTranslator)1 ProjectChange (edu.stanford.bmir.protege.web.shared.change.ProjectChange)1 DiffElement (edu.stanford.bmir.protege.web.shared.diff.DiffElement)1 Page (edu.stanford.bmir.protege.web.shared.pagination.Page)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 HashSet (java.util.HashSet)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.Test)1 BinaryOWLOntologyDocumentSerializer (org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer)1 OntologyChangeDataList (org.semanticweb.binaryowl.change.OntologyChangeDataList)1 AddAxiomData (org.semanticweb.owlapi.change.AddAxiomData)1