use of org.semanticweb.binaryowl.BinaryOWLMetadata in project webprotege by protegeproject.
the class ImportsCacheManager method toBinaryOWLMetadata.
/**
* Translates an {@link ImportedOntologyMetadata} object to {@link BinaryOWLMetadata}.
* @param value The value to be translated.
* @return The translation. Not {@code null}.
*/
private BinaryOWLMetadata toBinaryOWLMetadata(ImportedOntologyMetadata value) {
BinaryOWLMetadata metadata = new BinaryOWLMetadata();
metadata.setLongAttribute(META_DATA_TIME_STAMP_ATTR, value.getAccessTimestamp());
metadata.setStringAttribute(METADATA_DOCUMENT_IRI_ATTR, value.getOriginalDocumentLocation().toString());
return metadata;
}
use of org.semanticweb.binaryowl.BinaryOWLMetadata in project webprotege by protegeproject.
the class ImportsCacheManager method cacheOntologyIfNotAlreadyCached.
private void cacheOntologyIfNotAlreadyCached(OWLOntology ont) {
try {
WRITE_LOCK.lock();
if (ontologyIDs.contains(ont.getOntologyID())) {
return;
}
final File file = getFreshImportCacheFile();
try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) {
final long timestamp = System.currentTimeMillis();
IRI documentIRI = ont.getOWLOntologyManager().getOntologyDocumentIRI(ont);
final ImportedOntologyMetadata value = new ImportedOntologyMetadata(ont.getOntologyID(), documentIRI, timestamp);
BinaryOWLMetadata metadata = toBinaryOWLMetadata(value);
BinaryOWLOntologyDocumentSerializer serializer = new BinaryOWLOntologyDocumentSerializer();
serializer.write(new OWLOntologyWrapper(ont), os, metadata);
ontologyIDs.add(ont.getOntologyID());
metadataMap.put(ont.getOntologyID(), value);
logger.info("Cached imported ontology: " + ont.getOntologyID() + " in " + file.getName());
} catch (IOException e) {
logger.error("An error occurred whilst caching an ontology: {}", e.getMessage(), e);
}
} finally {
WRITE_LOCK.unlock();
}
}
use of org.semanticweb.binaryowl.BinaryOWLMetadata 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.BinaryOWLMetadata 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