Search in sources :

Example 1 with BinaryOWLOntologyChangeLog

use of org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog in project webprotege by protegeproject.

the class HeadRevisionNumberFinder method getHeadRevisionNumber.

/**
 * Computes the head revision number for the specified project.
 *
 * @param projectId The project.
 * @return The {@link RevisionNumber}
 */
@Nonnull
public RevisionNumber getHeadRevisionNumber(@Nonnull ProjectId projectId) throws IOException {
    /*
            This method works fairly well, even for large
            projects, but it is only intended to be a stopgap and needs replacing.
         */
    File projectDir = projectDirectoryFactory.getProjectDirectory(projectId);
    ChangeHistoryFileProvider changeHistoryFileProvider = new ChangeHistoryFileProvider(projectDir);
    File changeHistoryFile = changeHistoryFileProvider.get();
    try (BufferedInputStream bufferedInputStream = new BufferedInputStream(Files.newInputStream(changeHistoryFile.toPath()))) {
        BinaryOWLOntologyChangeLog log = new BinaryOWLOntologyChangeLog();
        RevisionExtractor extractor = new RevisionExtractor();
        log.readChanges(bufferedInputStream, new OWLDataFactoryImpl(), extractor, SKIP_DATA);
        return RevisionNumber.getRevisionNumber(extractor.getLastRevision());
    }
}
Also used : ChangeHistoryFileProvider(edu.stanford.bmir.protege.web.server.inject.project.ChangeHistoryFileProvider) BufferedInputStream(java.io.BufferedInputStream) BinaryOWLOntologyChangeLog(org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog) File(java.io.File) OWLDataFactoryImpl(uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl) Nonnull(javax.annotation.Nonnull)

Example 2 with BinaryOWLOntologyChangeLog

use of org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog in project webprotege by protegeproject.

the class RevisionStoreImpl method load.

public void load() {
    try {
        writeLock.lock();
        if (!changeHistoryFile.exists()) {
            changeHistoryFile.getParentFile().mkdirs();
            return;
        }
        final ImmutableList.Builder<Revision> revisionsBuilder = ImmutableList.builder();
        try {
            logger.info("{} Loading change history", projectId);
            Stopwatch stopwatch = Stopwatch.createStarted();
            BinaryOWLOntologyChangeLog changeLog = new BinaryOWLOntologyChangeLog();
            final BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(changeHistoryFile));
            final Interner<OWLAxiom> axiomInterner = Interners.newStrongInterner();
            final Interner<String> metadataInterner = Interners.newStrongInterner();
            changeLog.readChanges(inputStream, dataFactory, (list, skipSetting, l) -> {
                BinaryOWLMetadata metadata = list.getMetadata();
                String userName = metadataInterner.intern(metadata.getStringAttribute(RevisionSerializationVocabulary.USERNAME_METADATA_ATTRIBUTE.getVocabularyName(), ""));
                Long revisionNumberValue = metadata.getLongAttribute(RevisionSerializationVocabulary.REVISION_META_DATA_ATTRIBUTE.getVocabularyName(), 0L);
                RevisionNumber revisionNumber = RevisionNumber.getRevisionNumber(revisionNumberValue);
                String description = metadataInterner.intern(metadata.getStringAttribute(RevisionSerializationVocabulary.DESCRIPTION_META_DATA_ATTRIBUTE.getVocabularyName(), ""));
                // RevisionType type = RevisionType.valueOf(metadata.getStringAttribute(RevisionSerializationVocabulary.REVISION_TYPE_META_DATA_ATTRIBUTE.getVocabularyName(), RevisionType.EDIT.name()));
                final UserId userId = UserId.getUserId(userName);
                final List<OWLOntologyChangeRecord> changeRecords = internChangeRecords(list, axiomInterner);
                Revision revision = new Revision(userId, revisionNumber, ImmutableList.copyOf(changeRecords), list.getTimestamp(), description);
                revisionsBuilder.add(revision);
            }, SkipSetting.SKIP_NONE);
            inputStream.close();
            stopwatch.stop();
            revisions = revisionsBuilder.build();
            logger.info("{} Change history loading complete.  Loaded {} revisions in {} ms.", projectId, revisions.size(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
        } catch (Exception e) {
            logger.error("{} Failed to load change history for project.  Cause: {}", projectId, e.getMessage(), e);
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Stopwatch(com.google.common.base.Stopwatch) RevisionNumber(edu.stanford.bmir.protege.web.shared.revision.RevisionNumber) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) BinaryOWLMetadata(org.semanticweb.binaryowl.BinaryOWLMetadata) BufferedInputStream(java.io.BufferedInputStream) BinaryOWLOntologyChangeLog(org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) AtomicLong(java.util.concurrent.atomic.AtomicLong) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom)

Example 3 with BinaryOWLOntologyChangeLog

use of org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog in project webprotege by protegeproject.

the class RevisionSerializationTask method call.

public Integer call() throws IOException {
    BinaryOWLMetadata metadata = new BinaryOWLMetadata();
    metadata.setStringAttribute(RevisionSerializationVocabulary.USERNAME_METADATA_ATTRIBUTE.getVocabularyName(), revision.getUserId().getUserName());
    metadata.setLongAttribute(RevisionSerializationVocabulary.REVISION_META_DATA_ATTRIBUTE.getVocabularyName(), revision.getRevisionNumber().getValue());
    metadata.setStringAttribute(RevisionSerializationVocabulary.DESCRIPTION_META_DATA_ATTRIBUTE.getVocabularyName(), revision.getHighLevelDescription());
    metadata.setStringAttribute(RevisionSerializationVocabulary.REVISION_TYPE_META_DATA_ATTRIBUTE.getVocabularyName(), RevisionType.EDIT.name());
    BinaryOWLOntologyChangeLog changeLog = new BinaryOWLOntologyChangeLog();
    changeLog.appendChanges(new OntologyChangeRecordList(revision.getTimestamp(), metadata, revision.getChanges()), file);
    return 0;
}
Also used : OntologyChangeRecordList(org.semanticweb.binaryowl.change.OntologyChangeRecordList) BinaryOWLMetadata(org.semanticweb.binaryowl.BinaryOWLMetadata) BinaryOWLOntologyChangeLog(org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog)

Aggregations

BinaryOWLOntologyChangeLog (org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog)3 BufferedInputStream (java.io.BufferedInputStream)2 BinaryOWLMetadata (org.semanticweb.binaryowl.BinaryOWLMetadata)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableList (com.google.common.collect.ImmutableList)1 ChangeHistoryFileProvider (edu.stanford.bmir.protege.web.server.inject.project.ChangeHistoryFileProvider)1 RevisionNumber (edu.stanford.bmir.protege.web.shared.revision.RevisionNumber)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Nonnull (javax.annotation.Nonnull)1 OntologyChangeRecordList (org.semanticweb.binaryowl.change.OntologyChangeRecordList)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1 OWLDataFactoryImpl (uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl)1