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());
}
}
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();
}
}
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;
}
Aggregations