List of usage examples for com.mongodb DBObject keySet
Set<String> keySet();
From source file:org.elasticsearch.river.mongodb.util.GridFSHelper.java
License:Apache License
public static XContentBuilder serialize(GridFSDBFile file) throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead;//from w w w .j av a2 s .c o m byte[] data = new byte[1024]; InputStream stream = file.getInputStream(); while ((nRead = stream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); stream.close(); String encodedContent = Base64.encodeBytes(buffer.toByteArray()); // Probably not necessary... buffer.close(); builder.startObject(); builder.startObject("content"); builder.field("content_type", file.getContentType()); builder.field("title", file.getFilename()); builder.field("content", encodedContent); builder.endObject(); builder.field("filename", file.getFilename()); builder.field("contentType", file.getContentType()); builder.field("md5", file.getMD5()); builder.field("length", file.getLength()); builder.field("chunkSize", file.getChunkSize()); builder.field("uploadDate", file.getUploadDate()); builder.startObject("metadata"); DBObject metadata = file.getMetaData(); if (metadata != null) { for (String key : metadata.keySet()) { builder.field(key, metadata.get(key)); } } builder.endObject(); builder.endObject(); return builder; }
From source file:org.elasticsearch.river.mongodb.util.MongoDBHelper.java
License:Apache License
public static XContentBuilder serialize(GridFSDBFile file) throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead;//ww w .j a va 2s.co m byte[] data = new byte[1024]; try (InputStream stream = file.getInputStream()) { while ((nRead = stream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); } String encodedContent = Base64.encodeBytes(buffer.toByteArray()); // Probably not necessary... buffer.close(); builder.startObject(); builder.startObject("content"); builder.field("_content_type", file.getContentType()); builder.field("_title", file.getFilename()); builder.field("_content", encodedContent); builder.endObject(); builder.field("filename", file.getFilename()); builder.field("contentType", file.getContentType()); builder.field("md5", file.getMD5()); builder.field("length", file.getLength()); builder.field("chunkSize", file.getChunkSize()); builder.field("uploadDate", file.getUploadDate()); builder.startObject("metadata"); DBObject metadata = file.getMetaData(); if (metadata != null) { for (String key : metadata.keySet()) { builder.field(key, metadata.get(key)); } } builder.endObject(); builder.endObject(); return builder; }
From source file:org.elasticsearch.river.mongodb.util.MongoDBHelper.java
License:Apache License
public static DBObject applyIncludeFields(DBObject bsonObject, final Set<String> includeFields) { if (includeFields == null) { return bsonObject; }/*from w w w. j a v a2 s . c o m*/ DBObject filteredObject = new BasicDBObject(); for (String field : bsonObject.keySet()) { if (includeFields.contains(field)) { filteredObject.put(field, bsonObject.get(field)); } } for (String field : includeFields) { if (field.contains(".")) { String rootObject = field.substring(0, field.indexOf(".")); // String childObject = field.substring(field.indexOf(".") + 1); Object object = bsonObject.get(rootObject); if (object instanceof DBObject) { DBObject object2 = (DBObject) object; // object2 = applyIncludeFields(object2, new // HashSet<String>(Arrays.asList(childObject))); System.out.println(getChildItems(rootObject, includeFields)); object2 = applyIncludeFields(object2, getChildItems(rootObject, includeFields)); filteredObject.put(rootObject, object2); } } } return filteredObject; }
From source file:org.fastmongo.odm.dbobject.mapping.core.DbObjectToDomainConverter.java
License:Apache License
/** * Fills the result <tt>map</tt> with data from <tt>dbMap</tt> (JSON object from MongoDB). * * @param map the result map.//from www . jav a 2s . c o m * @param dbMap the DBObject. * @param mapValueType the class of values in the result map, determined from the instance variable * that holds this map. */ private void fillMap(final Map<String, Object> map, DBObject dbMap, Type mapValueType, Context context) { for (String key : dbMap.keySet()) { Object dbValue = dbMap.get(key); key = unescape(key); Object objValue; if (dbValue instanceof BasicDBObject) { objValue = fillMapObjectValue(map, mapValueType, key, (BasicDBObject) dbValue, context); } else if (dbValue instanceof BasicDBList) { objValue = fillMapCollectionValue(mapValueType, (BasicDBList) dbValue, context); } else if (mapValueType instanceof Class) { objValue = toSimpleType((Class<?>) mapValueType, dbValue); } else { objValue = dbValue; } map.put(key, objValue); } }
From source file:org.forgerock.openidm.repo.mongodb.impl.query.Queries.java
License:Open Source License
public void setQueriesConfig(String queriesConfig) { DBObject o = (DBObject) JSON.parse(queriesConfig); for (String key : o.keySet()) { QueryInfo qi = new QueryInfo(false); qi.setQuery(o.get(key).toString()); this.configuredQueries.put(key, qi); }/*from w ww .j a v a 2 s.co m*/ }
From source file:org.forgerock.openidm.repo.mongodb.impl.query.Queries.java
License:Open Source License
public void setFieldsConfig(String fieldsConfig) { DBObject o = (DBObject) JSON.parse(fieldsConfig); for (String key : o.keySet()) { QueryInfo qi = new QueryInfo(false); if (configuredQueries.containsKey(key)) { qi = configuredQueries.get(key); }/* ww w . ja va 2 s.c om*/ qi.setFileds(o.get(key).toString()); this.configuredQueries.put(key, qi); } }
From source file:org.forgerock.openidm.repo.mongodb.impl.query.Queries.java
License:Open Source License
public void setSortConfig(String sortConfig) { DBObject o = (DBObject) JSON.parse(sortConfig); for (String key : o.keySet()) { QueryInfo qi = new QueryInfo(false); if (configuredQueries.containsKey(key)) { qi = configuredQueries.get(key); }//ww w . j a v a 2 s .c om qi.setSort(o.get(key).toString()); this.configuredQueries.put(key, qi); } }
From source file:org.forgerock.openidm.repo.mongodb.impl.query.Queries.java
License:Open Source License
public void setAggregationConfig(String aggregationCofnig) { DBObject o = (DBObject) JSON.parse(aggregationCofnig); for (String key : o.keySet()) { QueryInfo qi = new QueryInfo(true); List<Object> list = (List<Object>) o.get(key); List<String> params = new ArrayList<String>(); for (Object obj : list) { params.add(obj.toString());// w w w. ja v a2 s. com } qi.setAggregationParams(params); this.configuredQueries.put(key, qi); } }
From source file:org.fracturedatlas.athena.apa.impl.MongoApaAdapter.java
License:Open Source License
private PTicket toRecord(DBObject recordObject, Boolean includeProps) { PTicket t = null;/*from w w w . ja va 2 s .co m*/ if (recordObject != null) { t = new PTicket(); t.setId(recordObject.get("_id").toString()); t.setType((String) recordObject.get("type")); if (includeProps) { DBObject propsObj = (DBObject) recordObject.get("props"); for (String key : propsObj.keySet()) { Object val = propsObj.get(key); if (key.contains(":")) { t.getSystemProps().putSingle(key, coerceToClientTicketValue(key, val)); } else { t.put(key, coerceToClientTicketValue(key, val)); } } } } return t; }
From source file:org.fudgemsg.mapping.mongo.MongoDBFudgeBuilder.java
License:Apache License
@Override public MutableFudgeMsg buildMessage(FudgeSerializer serializer, DBObject dbObject) { if (dbObject == null) { return null; }// w ww . j a v a 2 s. c om MutableFudgeMsg msg = serializer.newMessage(); for (String key : dbObject.keySet()) { Object value = dbObject.get(key); if (value instanceof List<?>) { for (Object element : (List<?>) value) { msg.add(key, decodeObjectValue(serializer, element)); } } else { msg.add(key, decodeObjectValue(serializer, value)); } } return msg; }