@Override public boolean writeEntry(JSONObject json) throws IOException { if (json == null) return false; if (this.elasticsearch_client == null) return true; if (!json.has(AbstractObjectEntry.TIMESTAMP_FIELDNAME)) json.put(AbstractObjectEntry.TIMESTAMP_FIELDNAME, AbstractObjectEntry.utcFormatter.print(System.currentTimeMillis())); boolean newDoc = this.elasticsearch_client.writeMap(this.index_name, json.toMap(), "local", String.valueOf(json.get("id_str"))); this.indexWrite.incrementAndGet(); return newDoc; }
/** * Returns a java.util.List containing all of the elements in this array. * If an element in the array is a JSONArray or JSONObject it will also * be converted. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return a java.util.List containing the elements of this array */ public List<Object> toList() { List<Object> results = new ArrayList<Object>(this.myArrayList.size()); for (Object element : this.myArrayList) { if (element == null || JSONObject.NULL.equals(element)) { results.add(null); } else if (element instanceof JSONArray) { results.add(((JSONArray) element).toList()); } else if (element instanceof JSONObject) { results.add(((JSONObject) element).toMap()); } else { results.add(element); } } return results; } }
/** * Returns a java.util.Map containing all of the entries in this object. * If an entry in the object is a JSONArray or JSONObject it will also * be converted. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return a java.util.Map containing the entries of this object */ public Map<String, Object> toMap() { Map<String, Object> results = new HashMap<String, Object>(); for (Entry<String, Object> entry : this.entrySet()) { Object value; if (entry.getValue() == null || NULL.equals(entry.getValue())) { value = null; } else if (entry.getValue() instanceof JSONObject) { value = ((JSONObject) entry.getValue()).toMap(); } else if (entry.getValue() instanceof JSONArray) { value = ((JSONArray) entry.getValue()).toList(); } else { value = entry.getValue(); } results.put(entry.getKey(), value); } return results; } }
private List<BulkWriteEntry> testBulk(int from, int to) { List<BulkWriteEntry> bulk = new ArrayList<>(); for (int i = from; i < to; i++) { JSONObject testJson = JSONObjectTest.testJson(true); BulkWriteEntry entry = new BulkWriteEntry("id_" + i, "testtype", null, null, testJson.toMap()); bulk.add(entry); } return bulk; }
@Override public boolean writeEntry(IndexEntry<IndexObject> entry) throws IOException { boolean newDoc = this.objectCache.put(entry.getId(), entry.getObject()) == null; this.existCache.add(entry.getId()); // record user into search index JSONObject json = entry.getObject().toJSON(); if (json == null) return false; if (!json.has(AbstractObjectEntry.TIMESTAMP_FIELDNAME)) json.put(AbstractObjectEntry.TIMESTAMP_FIELDNAME, AbstractObjectEntry.utcFormatter.print(System.currentTimeMillis())); if (this.elasticsearch_client == null) return newDoc; newDoc = this.elasticsearch_client.writeMap(this.index_name, json.toMap(), entry.getType().toString(), entry.getId()); this.indexWrite.incrementAndGet(); return newDoc; }
@Override public BulkWriteResult writeEntries(List<Post> entries) throws IOException { List<BulkWriteEntry> jsonMapList = new ArrayList<BulkWriteEntry>(); for (Post entry: entries) { this.objectCache.put(entry.getPostId(), entry); this.existCache.add(entry.getPostId()); Map<String, Object> jsonMap = entry.toJSON().toMap(); assert jsonMap != null; if (jsonMap == null) continue; BulkWriteEntry be = new BulkWriteEntry( entry.getPostId(), "local", "timestamp_id", null, jsonMap); jsonMapList.add(be); } if (jsonMapList.size() == 0) return ElasticsearchClient.EMPTY_BULK_RESULT; if (this.elasticsearch_client == null) return new BulkWriteResult(); BulkWriteResult result = elasticsearch_client.writeMapBulk(this.index_name, jsonMapList); this.indexWrite.addAndGet(jsonMapList.size()); return result; }
if (queryList != null) for (QueryEntry t: queryList) queries.add(t.toJSON().toMap());
@Override public BulkWriteResult writeEntries(Collection<IndexEntry<IndexObject>> entries) throws IOException { List<BulkWriteEntry> jsonMapList = new ArrayList<BulkWriteEntry>(); for (IndexEntry<IndexObject> entry: entries) { this.objectCache.put(entry.getId(), entry.getObject()); this.existCache.add(entry.getId()); Map<String, Object> jsonMap = entry.getObject().toJSON().toMap(); assert jsonMap != null; if (jsonMap == null) continue; BulkWriteEntry be = new BulkWriteEntry(entry.getId(), entry.getType().toString(), AbstractObjectEntry.TIMESTAMP_FIELDNAME, null, jsonMap); jsonMapList.add(be); } if (jsonMapList.size() == 0) return ElasticsearchClient.EMPTY_BULK_RESULT; if (this.elasticsearch_client == null) return new BulkWriteResult(); BulkWriteResult result = this.elasticsearch_client.writeMapBulk(this.index_name, jsonMapList); this.indexWrite.addAndGet(jsonMapList.size()); return result; }
public WebDocument(JSONObject obj) { super(obj.toMap()); }
public Document(JSONObject obj) { super(obj.toMap()); }
@Override public IndexFactory add(String indexName, String typeName, String id, JSONObject object) throws IOException { ElasticIndexFactory.this.elasticsearchClient.writeMap(indexName, typeName, id, object.toMap()); return ElasticIndexFactory.this; }
/** * Returns a java.util.List containing all of the elements in this array. * If an element in the array is a JSONArray or JSONObject it will also * be converted. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return a java.util.List containing the elements of this array */ public List<Object> toList() { List<Object> results = new ArrayList<Object>(this.myArrayList.size()); for (Object element : this.myArrayList) { if (element == null || JSONObject.NULL.equals(element)) { results.add(null); } else if (element instanceof JSONArray) { results.add(((JSONArray) element).toList()); } else if (element instanceof JSONObject) { results.add(((JSONObject) element).toMap()); } else { results.add(element); } } return results; }
/** * Returns a java.util.Map containing all of the entries in this object. * If an entry in the object is a JSONArray or JSONObject it will also * be converted. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return a java.util.Map containing the entries of this object */ public Map<String, Object> toMap() { Map<String, Object> results = new HashMap<String, Object>(); for (Entry<String, Object> entry : this.entrySet()) { Object value; if (entry.getValue() == null || NULL.equals(entry.getValue())) { value = null; } else if (entry.getValue() instanceof JSONObject) { value = ((JSONObject) entry.getValue()).toMap(); } else if (entry.getValue() instanceof JSONArray) { value = ((JSONArray) entry.getValue()).toList(); } else { value = entry.getValue(); } results.put(entry.getKey(), value); } return results; } }
public AuditLogChange createAuditLogChange(JSONObject change) { final String key = change.getString("key"); Object oldValue = change.isNull("old_value") ? null : change.get("old_value"); Object newValue = change.isNull("new_value") ? null : change.get("new_value"); // Don't confront users with JSON if (oldValue instanceof JSONArray || newValue instanceof JSONArray) { oldValue = oldValue instanceof JSONArray ? ((JSONArray) oldValue).toList() : oldValue; newValue = newValue instanceof JSONArray ? ((JSONArray) newValue).toList() : newValue; } else if (oldValue instanceof JSONObject || newValue instanceof JSONObject) { oldValue = oldValue instanceof JSONObject ? ((JSONObject) oldValue).toMap() : oldValue; newValue = newValue instanceof JSONObject ? ((JSONObject) newValue).toMap() : newValue; } return new AuditLogChange(oldValue, newValue, key); }
? new CaseInsensitiveMap<>(options.toMap()) : null;
String url = json.getString(WebMapping.url_s.getMapping().name()); String urlid = MultiProtocolURL.getDigest(url); boolean created = Data.gridIndex.getElasticClient().writeMap("web", "crawler", urlid, json.toMap()); Data.logger.info("MCP.processAction indexed " + ((line + 1)/2) + "/" + jsonlist.length()/2 + "(" + (created ? "created" : "updated")+ "): " + url);
public SchemaLoaderBuilder schemaJson(Object schema) { if (schema instanceof JSONObject) { schema = (((JSONObject) schema).toMap()); } this.schemaJson = schema; return this; }
/** * Underscore-like extend function. Merges the properties of {@code additional} and * {@code original}. Neither {@code additional} nor {@code original} will be modified, but the * returned object may be referentially the same as one of the parameters (in case the other * parameter is an empty object). */ @Deprecated static JSONObject extend(final JSONObject additional, final JSONObject original) { return new JSONObject(extend(additional.toMap(), original.toMap())); }
static Object toJavaValue(Object orig) { if (orig instanceof JSONArray) { return ((JSONArray) orig).toList(); } else if (orig instanceof JSONObject) { return ((JSONObject) orig).toMap(); } else { return orig; } }
@Override public Object execute(FunctionRequest request) { List<Object> fnParams = request.maximumNumberOfArguments(2) .minimumNumberOfArguments(2) .getArguments(); String text = fnParams.get(0).toString(); String extension = fnParams.get(1).toString(); return context.compile(extension, text, new JSONObject(context.getOptionsData().toMap())); } }