List of usage examples for com.mongodb BasicDBList get
public Object get(final String key)
From source file:eu.vital.vitalcep.restApp.vuaippi.Sensor.java
private String createQuery(BasicDBList sensor, String property, String from, String to) { String mongoquery = ""; JSONObject completequery = new JSONObject(); if (sensor.size() <= 1) { try {/*from w ww .j a v a 2 s.c om*/ String sensor1 = (String) sensor.get(0); JSONObject cQO = createQueryOr(sensor1, property, from, to); mongoquery = cQO.toString(); return mongoquery; } catch (Exception ex) { java.util.logging.Logger.getLogger(DMSListener.class.getName()).log(Level.SEVERE, null, ex); } } else { try { JSONArray ors = new JSONArray(); for (Object sensor1 : sensor) { ors.put(createQueryOr((String) sensor1, property, from, to)); } completequery.put("$or", ors); // DMSManager oDMS = new DMSManager(dmsURL,cookie); // aData = oDMS.getObservations(completequery.toString()); return completequery.toString(); } catch (Exception ex) { java.util.logging.Logger.getLogger(DMSListener.class.getName()).log(Level.SEVERE, null, ex); } } return mongoquery; }
From source file:ezbake.data.mongo.EzMongoHandler.java
License:Apache License
@Override public long getCountFromQuery(String collectionName, String jsonQuery, EzSecurityToken security) throws TException, EzMongoBaseException { try {//from w ww .j ava2 s .c o m HashMap<String, String> auditParamsMap = new HashMap<>(); auditParamsMap.put("action", "getCountFromQuery"); auditParamsMap.put("collectionName", collectionName); auditParamsMap.put("jsonQuery", jsonQuery); auditLog(security, AuditEventType.FileObjectAccess, auditParamsMap); TokenUtils.validateSecurityToken(security, this.getConfigurationProperties()); if (StringUtils.isEmpty(collectionName)) { throw new EzMongoBaseException("collectionName is required."); } final DBObject queryCommand = (DBObject) JSON.parse(jsonQuery); final DBObject query = new BasicDBObject("$match", queryCommand); final String finalCollectionName = getCollectionName(collectionName); appLog.info("getCountFromQuery, finalCollectionName: {}, {}", finalCollectionName, jsonQuery); final DBObject[] aggregationCommandsArray = mongoFindHelper .getFindAggregationCommandsArray_withcounter(0, 0, null, null, security, true, READ_OPERATION); final AggregationOutput aggregationOutput = db.getCollection(finalCollectionName).aggregate(query, aggregationCommandsArray); final BasicDBList resultsList = (BasicDBList) aggregationOutput.getCommandResult().get("result"); long count = 0; if (resultsList.size() > 0) { final BasicDBObject resultsObj = (BasicDBObject) resultsList.get(0); count = resultsObj.getLong("count"); } return count; } catch (final Exception e) { throw enrichException("getCountFromQuery", e); } }
From source file:gr.ntua.ivml.awareness.search.SearchServiceAccess.java
public BasicDBObject searchEuropeana(String originalTerm, String type, int startPage) throws Exception { String[] termsarray = originalTerm.split(" "); List terms = Arrays.asList(termsarray); URI uri = constructURI(terms, type, startPage - 1); httpGet = new HttpGet(uri); BasicDBObject response = new BasicDBObject(); httpRes = httpClient.execute(httpGet); httpEntity = httpRes.getEntity();/* w w w .j a v a 2 s . c om*/ ByteArrayOutputStream out = new ByteArrayOutputStream(); httpEntity.writeTo(out); String resp = new String(out.toByteArray(), "UTF-8"); BasicDBObject obj = (BasicDBObject) JSON.parse(resp); response.put("itemsCount", obj.getString("itemsCount")); response.put("totalResults", obj.getString("totalResults")); response.put("term", originalTerm); response.put("type", type); response.put("pageNumber", startPage); @SuppressWarnings("unchecked") ArrayList<Object> items = (ArrayList<Object>) obj.get("items"); if (items != null) { Iterator<Object> it = items.iterator(); ArrayList<BasicDBObject> responseItems = new ArrayList<BasicDBObject>(); while (it.hasNext()) { BasicDBObject tmp = (BasicDBObject) it.next(); BasicDBObject re = new BasicDBObject(); String recid = tmp.getString("id"); re.put("europeanaid", recid); re.put("type", tmp.getString("type")); re.put("source", tmp.getString("guid")); BasicDBList titleslist = (BasicDBList) tmp.get("title"); if (titleslist != null) re.put("title", StringUtils.join(titleslist, ',')); BasicDBList providerslist = (BasicDBList) tmp.get("dataProvider"); if (providerslist != null) re.put("dataProvider", providerslist.get(0)); providerslist = (BasicDBList) tmp.get("provider"); if (providerslist != null) re.put("provider", providerslist.get(0)); BasicDBList creatorlist = (BasicDBList) tmp.get("dcCreator"); if (creatorlist != null) re.put("dcCreator", creatorlist.get(0)); BasicDBList languagelist = (BasicDBList) tmp.get("language"); if (languagelist != null) re.put("language", languagelist.get(0)); BasicDBList thumbslist = (BasicDBList) tmp.get("edmPreview"); if (thumbslist != null) re.put("url", thumbslist.get(0)); BasicDBList rightslist = (BasicDBList) tmp.get("rights"); if (rightslist != null) re.put("license", rightslist.get(0)); responseItems.add(re); } response.put("items", responseItems); } return response; }
From source file:io.liveoak.mongo.MongoAggregationItem.java
License:Open Source License
@Override protected Object getResourceCollection(Object object) { if (object instanceof BasicDBObject) { return new MongoAggregationItem(this, (DBObject) object); } else if (object instanceof BasicDBList) { BasicDBList dbList = ((BasicDBList) object); ArrayList list = new ArrayList(); for (int i = 0; i < dbList.size(); i++) { Object child = dbList.get(i); list.add(getResourceCollection(child)); }/*from w w w . java2 s . c o m*/ return list; } else { return object; } }
From source file:io.liveoak.mongo.MongoObjectResource.java
License:Open Source License
protected Object getResourceCollection(Object object) throws Exception { if (object instanceof BasicDBObject) { return new MongoEmbeddedObjectResource(this, (DBObject) object); } else if (object instanceof BasicDBList) { BasicDBList dbList = ((BasicDBList) object); ArrayList list = new ArrayList(); for (int i = 0; i < dbList.size(); i++) { Object child = dbList.get(i); list.add(getResourceCollection(child)); }//from ww w. j a va 2 s. co m return list; } else if (object instanceof DBRef) { return getResource((DBRef) object, true); } else { return object; } }
From source file:it.csi.smartdata.odata.datadiscovery.MongoDbStore.java
public List<Map<String, Object>> getDatasetFields(Long datasetKey) { List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>(); DB db = mongoClient.getDB(mongoParams.get("MONGO_DB_META")); DBCollection coll = db.getCollection(mongoParams.get("MONGO_COLLECTION_DATASET")); BasicDBObject query = new BasicDBObject(); query.append("idDataset", datasetKey); query.put("configData.current", 1); query.put("configData.subtype", new BasicDBObject("$ne", "binaryDataset")); DBCursor cursor = coll.find(query);/* w w w .j a v a2 s .c om*/ while (cursor.hasNext()) { DBObject obj = cursor.next(); DBObject dataset = (DBObject) obj.get("info"); BasicDBList fieldsList = (BasicDBList) dataset.get("fields"); for (int i = 0; i < fieldsList.size(); i++) { DBObject measure = (DBObject) fieldsList.get(i); String fieldName = (String) measure.get("fieldName"); String fieldAlias = (String) measure.get("fieldAlias"); String dataType = (String) measure.get("dataType"); Integer sourceColumn = measure.get("sourceColumn") == null ? null : ((Number) measure.get("sourceColumn")).intValue(); Integer isKey = measure.get("isKey") == null ? null : ((Number) measure.get("isKey")).intValue(); String measureUnit = (String) measure.get("measureUnit"); Map<String, Object> cur = new HashMap<String, Object>(); cur.put("fieldName", fieldName); cur.put("fieldAlias", fieldAlias); cur.put("dataType", dataType); cur.put("sourceColumn", sourceColumn); cur.put("isKey", isKey); cur.put("measureUnit", measureUnit); ret.add(cur); } } return ret; }
From source file:it.csi.smartdata.odata.datadiscovery.MongoDbStore.java
private Map<String, Object> extractDataFromStream(DBObject found) { Map<String, Object> cur = null; if (found != null) { cur = new HashMap<String, Object>(); DBObject streams = (DBObject) found.get("streams"); DBObject stream = (DBObject) streams.get("stream"); DBObject configData = (DBObject) found.get("configData"); String streamCode = (String) found.get("streamCode"); String streamName = (String) found.get("streamName"); String streamDescription = (String) stream.get("virtualEntityDescription"); Integer IdStream = (Integer) found.get("idStream"); Integer IdSensor = (Integer) stream.get("idVirtualEntity"); Integer idDataset = (Integer) configData.get("idDataset"); Integer datasetVersion = (Integer) configData.get("datasetVersion"); String tenantCode = (String) configData.get("tenantCode"); String code = (String) stream.get("virtualEntityCode"); String name = (String) stream.get("virtualEntityName"); String type = (String) stream.get("virtualEntityType"); String category = (String) stream.get("virtualEntityCategory"); String visibility = (String) stream.get("visibility"); cur.put("idStream", IdStream); cur.put("idSensor", IdSensor); cur.put("idDataset", idDataset); cur.put("datasetVersion", datasetVersion); cur.put("tenantCode", tenantCode); cur.put("visibility", visibility); cur.put("streamCode", streamCode); cur.put("streamName", streamName); cur.put("streamDescription", streamDescription); cur.put("smartOName", name); cur.put("smartOCode", code); cur.put("smartOType", type); cur.put("smartOCategory", category); cur.put("twtResultType", (String) stream.get("twtResultType")); cur.put("twtMaxStreamsOfVE", (Integer) stream.get("twtMaxStreamsOfVE")); cur.put("twtRatePercentage", (Integer) stream.get("twtRatePercentage")); cur.put("twtCount", (Integer) stream.get("twtCount")); cur.put("twtUntil", (String) stream.get("twtUntil")); cur.put("twtLocale", (String) stream.get("twtLocale")); cur.put("twtLang", (String) stream.get("twtLang")); cur.put("twtGeolocUnit", (String) stream.get("twtGeolocUnit")); cur.put("twtQuery", (String) stream.get("twtQuery")); cur.put("twtGeolocLat", (Double) stream.get("twtGeolocLat")); cur.put("twtGeolocLon", (Double) stream.get("twtGeolocLon")); cur.put("twtGeolocRadius", (Double) stream.get("twtGeolocRadius")); DBObject vePos = (DBObject) stream.get("virtualEntityPositions"); // FIXME return all the positions if required if (vePos != null) { BasicDBList pos = (BasicDBList) vePos.get("position"); if (pos != null && pos.size() > 0) { DBObject veSingPos = (DBObject) pos.get(0); cur.put("latitude", veSingPos.get("lat")); cur.put("longitude", veSingPos.get("lon")); cur.put("elevation", veSingPos.get("elevation")); }/* ww w . ja v a2s. co m*/ } SimpleDateFormat sdp = new SimpleDateFormat("dd/MM/yyyy"); String externalReference = (String) stream.get("externalReference"); DBObject opendata = (DBObject) stream.get("opendata"); Boolean isOpendata = null; String author = null; String dataUpdateDate = null; String language = null; if (opendata != null) { isOpendata = (Boolean) opendata.get("isOpendata"); author = (String) opendata.get("author"); if (null != opendata.get("dataUpdateDate")) dataUpdateDate = sdp.format(new Date(new Long("" + opendata.get("dataUpdateDate")))); language = (String) opendata.get("language"); } cur.put("externalReference", externalReference); // opendata cur.put("isOpendata", isOpendata); cur.put("author", author); cur.put("dataUpdateDate", dataUpdateDate); cur.put("language", language); } return cur; }
From source file:it.csi.smartdata.odata.datadiscovery.MongoDbStore.java
private Map<String, Object> extractOdataPropertyFromMongo(DBCollection collapi, DBCollection collstream, DBObject datasetFound) {//from w w w. java2s . co m Long id = datasetFound.get("idDataset") == null ? null : ((Number) datasetFound.get("idDataset")).longValue(); Long datasetVersion = datasetFound.get("datasetVersion") == null ? null : ((Number) datasetFound.get("datasetVersion")).longValue(); String datasetCode = (String) datasetFound.get("datasetCode"); DBObject configData = (DBObject) datasetFound.get("configData"); String tenant = configData.get("tenantCode").toString(); String datasetStatus = (String) configData.get("datasetStatus"); DBObject info = (DBObject) datasetFound.get("info"); String license = (String) info.get("license"); String dataDomain = (String) info.get("dataDomain"); String codSubDomain = (String) info.get("codSubDomain"); String description = (String) info.get("description"); Double fps = info.get("fps") == null ? null : ((Number) info.get("fps")).doubleValue(); String datasetName = (String) info.get("datasetName"); String visibility = (String) info.get("visibility"); String registrationDate = (String) info.get("registrationDate"); String startIngestionDate = (String) info.get("startIngestionDate"); String endIngestionDate = (String) info.get("endIngestionDate"); String importFileType = (String) info.get("importFileType"); String disclaimer = (String) info.get("disclaimer"); String copyright = (String) info.get("copyright"); String externalReference = (String) info.get("externalReference"); // opendata SimpleDateFormat sdp = new SimpleDateFormat("dd/MM/yyyy"); DBObject opendata = (DBObject) datasetFound.get("opendata"); Boolean isOpendata = null; String author = null; String dataUpdateDate = null; String language = null; if (opendata != null) { isOpendata = (Boolean) opendata.get("isOpendata"); author = (String) opendata.get("author"); //dataUpdateDate = sdp.format(new Date((Long) opendata.get("dataUpdateDate"))); if (null != opendata.get("dataUpdateDate")) dataUpdateDate = sdp.format(new Date(new Long("" + opendata.get("dataUpdateDate")))); language = (String) opendata.get("language"); } StringBuilder fieldsBuilder = new StringBuilder(); BasicDBList fieldsList = (BasicDBList) info.get("fields"); String prefix = ""; for (int i = 0; i < fieldsList.size(); i++) { DBObject measure = (DBObject) fieldsList.get(i); String mis = measure.get("measureUnit") == null ? null : measure.get("measureUnit").toString(); if (mis != null) { fieldsBuilder.append(prefix); prefix = ","; fieldsBuilder.append(mis); } } String unitaMisura = fieldsBuilder.toString(); StringBuilder tagsBuilder = new StringBuilder(); BasicDBList tagsList = (BasicDBList) info.get("tags"); String tags = null; prefix = ""; if (tagsList != null) { for (int i = 0; i < tagsList.size(); i++) { DBObject tagObj = (DBObject) tagsList.get(i); tagsBuilder.append(prefix); prefix = ","; tagsBuilder.append(tagObj.get("tagCode").toString()); } tags = tagsBuilder.toString(); } String tenantsharing = null; /* * if you want to return all the tenants that a dataset is shared with * decomment this code ; */ DBObject tenantssharingDB = (DBObject) info.get("tenantssharing"); StringBuilder tenantsBuilder = new StringBuilder(); if (tenantssharingDB != null) { BasicDBList tenantsList = (BasicDBList) tenantssharingDB.get("tenantsharing"); prefix = ""; if (tenantsList != null) { for (int i = 0; i < tenantsList.size(); i++) { DBObject tenantsObj = (DBObject) tenantsList.get(i); tenantsBuilder.append(prefix); prefix = ","; tenantsBuilder.append(tenantsObj.get("tenantCode").toString()); } tenantsharing = tenantsBuilder.toString(); } } Map<String, Object> cur = new HashMap<String, Object>(); cur.put("idDataset", id); cur.put("tenantCode", tenant); cur.put("tenantsharing", tenantsharing); cur.put("dataDomain", dataDomain); cur.put("codSubDomain", codSubDomain); cur.put("license", license); cur.put("description", description); cur.put("fps", fps); cur.put("measureUnit", unitaMisura); cur.put("tags", tags); // BasicDBObject findapi = new BasicDBObject(); // findapi.append("dataset.idDataset", id); // findapi.append("dataset.datasetVersion", datasetVersion); StringBuilder apibuilder = new StringBuilder(); // DBObject config = (DBObject) parent.get("configData"); apibuilder.append(mongoParams.get("MONGO_API_ADDRESS")); apibuilder.append("name=" + datasetCode); apibuilder.append("_odata"); apibuilder.append("&version=1.0&provider=admin"); cur.put("API", apibuilder.toString()); BasicDBObject findstream = new BasicDBObject(); findstream.append("configData.idDataset", id); findstream.append("configData.datasetVersion", datasetVersion); DBObject streams = collstream.findOne(findstream); StringBuilder streambuilder = new StringBuilder(); if (streams != null) { DBObject nx = streams; DBObject config = (DBObject) nx.get("configData"); DBObject streamsObj = (DBObject) nx.get("streams"); DBObject stream = (DBObject) streamsObj.get("stream"); streambuilder.append(mongoParams.get("MONGO_API_ADDRESS")); streambuilder.append("name=" + config.get("tenantCode")); streambuilder.append("."); streambuilder.append(stream.get("virtualEntityCode")); streambuilder.append("_"); streambuilder.append(nx.get("streamCode")); streambuilder.append("_stream"); streambuilder.append("&version=1.0&provider=admin"); } String download = mongoParams.get("MONGO_DOWNLOAD_ADDRESS") + "/" + tenant + "/" + datasetCode + "/csv"; cur.put("STREAM", streambuilder.toString()); cur.put("download", download); cur.put("datasetName", datasetName); cur.put("visibility", visibility); cur.put("registrationDate", registrationDate); cur.put("startIngestionDate", startIngestionDate); cur.put("endIngestionDate", endIngestionDate); cur.put("importFileType", importFileType); cur.put("datasetStatus", datasetStatus); cur.put("datasetVersion", (datasetVersion == null) ? null : datasetVersion.toString()); cur.put("datasetCode", datasetCode); cur.put("disclaimer", disclaimer); cur.put("copyright", copyright); cur.put("externalReference", externalReference); // opendata cur.put("isOpendata", isOpendata); cur.put("author", author); cur.put("dataUpdateDate", dataUpdateDate); cur.put("language", language); return cur; }
From source file:models.NodeContent.java
License:Open Source License
public static List<NodeContent> getThreadedChildren(ObjectId id, Integer start, Integer count) { List<NodeContent> thread = null; try {// ww w . j a va 2s . c om // ach jaj String evalQuery = "return getThreadedChildren(ObjectId(\"" + id.toString() + "\"), " + start + "," + count + ");"; DBObject iobj = MongoDB.getDB().doEval(evalQuery, ""); if (iobj != null) { // Logger.info("getThreadedChildren:: " + iobj.toString()); BasicDBList oo = (BasicDBList) iobj.get("retval"); // Logger.info(oo.getClass().getCanonicalName()); if (oo != null) { thread = new LinkedList<NodeContent>(); for (Object ooo : oo) { BasicDBList nodef = (BasicDBList) ooo; ObjectId nodeId = (ObjectId) nodef.get(0); Double depth = (Double) nodef.get(1); NodeContent nc = NodeContent.load(nodeId); nc.depth = depth.intValue(); thread.add(nc); // Logger.info("bla:: " + ooo.toString() + " " + ooo.getClass().getCanonicalName() + "0:" + nodeId + "1:" + depth); } } } } catch (Exception ex) { Logger.info("getThreadedChildren"); ex.printStackTrace(); Logger.info(ex.toString()); } return thread; }
From source file:models.utils.Mongo2gson.java
License:Apache License
/** * Convert the given mongo BasicDBList object to JsonArray. * * @param object BasicDBList//from www .j av a2 s. co m * @return JsonArray */ public static JsonArray getAsJsonArray(DBObject object) { if (!(object instanceof BasicDBList)) { throw new IllegalArgumentException("Expected BasicDBList as argument type!"); } BasicDBList list = (BasicDBList) object; JsonArray jsonArray = new JsonArray(); for (int i = 0; i < list.size(); i++) { Object dbObject = list.get(i); if (dbObject instanceof BasicDBList) { jsonArray.add(getAsJsonArray((BasicDBList) dbObject)); } else if (dbObject instanceof BasicDBObject) { // it's an object jsonArray.add(getAsJsonObject((BasicDBObject) dbObject)); } else { // it's a primitive type number or string jsonArray.add(getAsJsonPrimitive(dbObject)); } } return jsonArray; }