private void preprocess(final Record record) throws Throwable { // Ignore ks:storedAs possibly supplied by clients, as it is computed with file upload if (KS.RESOURCE.equals(record.getSystemType())) { record.set(KS.STORED_AS, null); } // TODO: add here filtering logic to be applied to records coming from the client }
@Override public synchronized void init() throws IOException, IllegalStateException { Preconditions.checkState(!this.initialized && !this.closed); this.initialized = true; InputStream stream = null; try { if (this.fileSystem.exists(this.filePath)) { stream = Files.readWithBackup(this.fileSystem, this.filePath); final RDFFormat format = RDFFormat.forFileName(this.filePath.getName()); final List<Record> records = Record.decode( RDFUtil.readRDF(stream, format, null, null, false), ImmutableSet.of(KS.RESOURCE, KS.MENTION, KS.ENTITY, KS.CONTEXT), false) .toList(); for (final Record record : records) { final URI id = Preconditions.checkNotNull(record.getID()); final URI type = Preconditions.checkNotNull(record.getSystemType()); MemoryDataStore.this.tables.get(type).put(id, record); } MemoryDataStore.LOGGER.info("{} initialized, {} records loaded", this.getClass() .getSimpleName(), records.size()); } else { MemoryDataStore.LOGGER.info("{} initialized, no record loaded", this.getClass() .getSimpleName()); } } finally { Util.closeQuietly(stream); } }
private Map<URI, Record> extractRelated(final Record record) throws Throwable { // TODO: this has to be done better using some Schema object final URI id = record.getID(); final URI type = record.getSystemType(); final Map<URI, Record> map = Maps.newHashMap(); if (type.equals(KS.RESOURCE)) { for (final URI mentionID : record.get(KS.HAS_MENTION, URI.class)) { map.put(mentionID, Record.create(mentionID, KS.MENTION).add(KS.MENTION_OF, id)); } } else if (type.equals(KS.MENTION)) { final URI resourceID = record.getUnique(KS.MENTION_OF, URI.class); if (resourceID != null) { map.put(resourceID, Record.create(resourceID, KS.RESOURCE).add(KS.HAS_MENTION, id)); } } else { // TODO: handle entities, axioms and contexts throw new Error("Unexpected type: " + type); } return map; }
final URI type = MoreObjects.firstNonNull(oldRel, newRel).getSystemType(); if (oldRel != null && newRel != null) { for (final URI property : oldRel.getProperties()) { transaction.store(record.getSystemType(), record); transaction.delete(record.getSystemType(), record.getID());