doc.fromMap(fileContents); boolean cached = fileContents.get(String.valueOf(DocumentAttributes.CACHED)) != null ? Boolean.valueOf((String) fileContents.get(String.valueOf(DocumentAttributes.CACHED))) : true; doc.field(String.valueOf(DocumentAttributes.CACHED), cached);
/** * Get a document by sourceUri and update it from the given map. * @param incomingDocMap The document's db columns. * @return The saved document. * @throws IllegalArgumentException if sourceUri or docType are null, or if the document doesn't exist. */ public ODocument mergeDocument(Map<String, ? extends Object> incomingDocMap) { String sourceUri = (String) incomingDocMap.get(DocumentAttributes.SOURCE_URI.toString()); if (null == sourceUri) throw new IllegalArgumentException("Document sourceUri is null."); String docType = (String) incomingDocMap.get(Crawler.Attributes.TYPE); if (null == docType) throw new IllegalArgumentException("Document docType is null."); // Get a document by sourceUri String sql = "SELECT * FROM " + docType + " WHERE sourceuri=?"; activateOnCurrentThread(); List<ODocument> results = db.command(new OSQLSynchQuery<ODocument>(sql)).execute(sourceUri); if (results.size() == 0) throw new JBakeException("No document with sourceUri '"+sourceUri+"'."); // Update it from the given map. ODocument incomingDoc = new ODocument(docType); incomingDoc.fromMap(incomingDocMap); ODocument merged = results.get(0).merge(incomingDoc, true, false); return merged; }
/** * Deprecated. Use fromMap(Map) instead.<br> Fills a document passing the field names/values as a Map String,Object where the keys * are the field names and the values are the field values. * * @see #fromMap(Map) */ @Deprecated public ODocument fields(final Map<String, Object> iMap) { return fromMap(iMap); }
public void build() { try { if ( ! hasSourceUri() ) { this.withRandomSourceUri(); } if ( ! hasSha1() ) { this.withRandomSha1(); } if ( ! hasDate() ) { this.withCurrentDate(); } ODocument document = new ODocument(type).fromMap(fileModel); document.save(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } }
@Override protected void writeFields(final ODocument document, final HttpClientConfiguration entity) throws Exception { Map<String, Object> fields = objectMapper.convertValue(entity, MAP_STRING_OBJECT); log.trace("Writing fields: {}", fields); document.fromMap(fields); }
@Test public void testMergeDocument() { final String uri = "test/testMergeDocument"; ODocument doc = new ODocument(DOC_TYPE_POST); Map<String, String> values = new HashMap(); values.put(Crawler.Attributes.TYPE, DOC_TYPE_POST); values.put(DocumentAttributes.SOURCE_URI.toString(), uri); values.put("foo", "originalValue"); doc.fromMap(values); doc.save(); // 1st values.put("foo", "newValue"); db.mergeDocument(values); DocumentList docs = db.getDocumentByUri(DOC_TYPE_POST, uri); assertEquals(1, docs.size()); assertEquals("newValue", docs.get(0).get("foo")); // 2nd values.put("foo", "anotherValue"); db.mergeDocument(values); docs = db.getDocumentByUri(DOC_TYPE_POST, uri); assertEquals(1, docs.size()); assertEquals("anotherValue", docs.get(0).get("foo")); db.deleteContent(DOC_TYPE_POST, uri); docs = db.getDocumentByUri(DOC_TYPE_POST, uri); assertEquals(0, docs.size()); }
public ODocument toDoc() { ODocument doc = new ODocument(); doc.fromMap((Map) matched); return doc; }
private ODocument getMetadata(Object[] params) { if (params.length == 2) { return new ODocument() .fromMap((Map<String, ?>) params[1]); } return OLuceneQueryBuilder.EMPTY_METADATA; }
private ODocument getMetadata(Object[] params) { if (params.length == 3) { return new ODocument().fromMap((Map<String, ?>) params[2]); } return OLuceneQueryBuilder.EMPTY_METADATA; }
private ODocument getMetadata(Object[] params) { if (params.length == 3) { return new ODocument().fromMap((Map<String, ?>) params[2]); } return OLuceneQueryBuilder.EMPTY_METADATA; }
private ODocument jsonToDoc(MatchContext matchContext, OCommandContext ctx) { if (returnItems.size() == 1 && (returnItems.get(0).value instanceof OJson) && returnAliases.get(0) == null) { ODocument result = new ODocument(); result.setTrackingChanges(false); result.fromMap(((OJson) returnItems.get(0).value).toMap(matchContext.toDoc(), ctx)); return result; } throw new IllegalStateException("Match RETURN statement is not a plain JSON"); }
private ODocument createDocumentFromMap(OClass embeddedType, Map<String, Object> o) { final ODocument doc = new ODocument(); if (embeddedType != null) doc.setClassName(embeddedType.getName()); doc.fromMap(o); return doc; }
public boolean evaluate(Object currentRecord, OCommandContext ctx) { if (currentRecord instanceof OResult) { return evaluate((OResult) currentRecord, ctx); } else if (currentRecord instanceof OIdentifiable) { return evaluate((OIdentifiable) currentRecord, ctx); } else if (currentRecord instanceof Map) { ODocument doc = new ODocument(); doc.fromMap((Map<String, Object>) currentRecord); return evaluate(doc, ctx); } return false; }
/** * Get a document by sourceUri and update it from the given map. * @param incomingDocMap The document's db columns. * @return The saved document. * @throws IllegalArgumentException if sourceUri or docType are null, or if the document doesn't exist. */ public ODocument mergeDocument(Map<String, ? extends Object> incomingDocMap) { String sourceUri = (String) incomingDocMap.get(DocumentAttributes.SOURCE_URI.toString()); if (null == sourceUri) throw new IllegalArgumentException("Document sourceUri is null."); String docType = (String) incomingDocMap.get(Crawler.Attributes.TYPE); if (null == docType) throw new IllegalArgumentException("Document docType is null."); // Get a document by sourceUri String sql = "SELECT * FROM " + docType + " WHERE sourceuri=?"; activateOnCurrentThread(); List<ODocument> results = db.command(new OSQLSynchQuery<ODocument>(sql)).execute(sourceUri); if (results.size() == 0) throw new JBakeException("No document with sourceUri '"+sourceUri+"'."); // Update it from the given map. ODocument incomingDoc = new ODocument(docType); incomingDoc.fromMap(incomingDocMap); ODocument merged = results.get(0).merge(incomingDoc, true, false); return merged; }
final ODocument doc = new ODocument().fromMap((Map<String, Object>) iThis); return iParams.length == 1 ? doc.toJSON(format) : doc.toJSON();
public void setVertexProperties(Long id, Map<String, Object> properties) { if (properties == null || properties.size() == 0) { return; } settingProperties = true; final int cluster = (int) (id % parallel); if (nextVerticesToCreate[cluster] <= id) { if (oVertexClass == null) { oVertexClass = db.getMetadata().getSchema().getClass(vertexClass); } if (nextVerticesToCreate[cluster] < id) { new BatchImporterJob(cluster, oVertexClass, id - 1).run(db); } new BatchImporterJob(cluster, oVertexClass, id).createVertex(db, id, properties); } else { final ODocument doc = db.load(new ORecordId(getClusterId(id), getClusterPosition(id))); if (doc == null) { throw new RuntimeException("trying to insert properties on non existing document"); } doc.fromMap(properties); db.save(doc); } }
ODocument edgeDoc = new ODocument(edgeClass); edgeDoc.fromMap(properties); edgeDoc.field("out", new ORecordId(getClusterId(from), getClusterPosition(from))); edgeDoc.field("in", new ORecordId(getClusterId(to), getClusterPosition(to)));
removeCollectionChangeListener(entry, value); ODocument newValue = new ODocument(linkedClass); newValue.fromMap((Map) value); entry.value = newValue; newValue.addOwner(this);
doc.merge((ODocument) ((OElement) val).getRecord(), false, false); } else if (val instanceof Map) { doc.merge(new ODocument().fromMap((Map) val), false, false); } else { throw new OCommandExecutionException("Invalid value for UPDATE CONTENT: " + val);
Map<String, Object> ksMap = props.field("keyStore"); ODocument ksDoc = new ODocument().fromMap(ksMap);