List of usage examples for com.mongodb BasicDBList BasicDBList
BasicDBList
From source file:eu.cassandra.server.mongo.MongoCopyEntities.java
License:Apache License
private static void alterAppliances(DBObject obj, Map<String, String> mapping) { if (obj.containsField("containsAppliances")) { BasicDBList alist = (BasicDBList) obj.get("containsAppliances"); BasicDBList blist = new BasicDBList(); for (int i = 0; i < alist.size(); i++) { String key = alist.get(i).toString(); if (mapping.containsKey(key)) { String id = mapping.get(key); blist.add(id);/* w w w .jav a 2 s . co m*/ } } obj.put("containsAppliances", blist); PrettyJSONPrinter.prettyPrint(obj); } }
From source file:eu.cassandra.server.mongo.MongoInstallations.java
License:Apache License
private String withAddedWarnings(String response, boolean ary) { if (Utils.failed(response)) return response; DBObject jsonResponse = (DBObject) JSON.parse(response); DBObject data = (DBObject) jsonResponse.get("data"); System.out.println(response); String objID = new String(); if (ary) {//from www .j av a2 s . c o m objID = (String) ((DBObject) ((BasicDBList) data).get(0)).get("_id"); } else { objID = (String) data.get("_id"); } BasicDBList list = new BasicDBList(); DBObject returnQuery = new MongoDBQueries().getEntity(MongoPersons.COL_PERSONS, MongoPersons.REF_INSTALLATION, objID); if (returnQuery == null) { String warning = "Add at least one person for this installation."; list.add(warning); } returnQuery = new MongoDBQueries().getEntity(MongoAppliances.COL_APPLIANCES, MongoAppliances.REF_INSTALLATION, objID); if (returnQuery == null) { String warning = "Add at least one appliance for this installation."; list.add(warning); } if (!list.isEmpty()) { jsonResponse.put("warnings", list); } return jsonResponse.toString(); }
From source file:eu.cassandra.server.mongo.MongoPersons.java
License:Apache License
private String withAddedWarnings(String response, boolean ary) { if (Utils.failed(response)) return response; DBObject jsonResponse = (DBObject) JSON.parse(response); DBObject data = (DBObject) jsonResponse.get("data"); String objID = new String(); if (ary) {// w ww. j a v a2 s .c o m objID = (String) ((DBObject) ((BasicDBList) data).get(0)).get("_id"); } else { objID = (String) data.get("_id"); } BasicDBList list = new BasicDBList(); DBObject returnQuery = new MongoDBQueries().getEntity(MongoActivities.COL_ACTIVITIES, "pers_id", objID); if (returnQuery == null) { String warning = "Add at least one activity for this person."; list.add(warning); } if (!list.isEmpty()) { jsonResponse.put("warnings", list); } return jsonResponse.toString(); }
From source file:eu.cassandra.server.mongo.MongoPersons.java
License:Apache License
public Response getPersons(HttpHeaders httpHeaders, String scn_id, String filters, String sort, int limit, int skip, boolean count, boolean pertype, boolean lib) { // Search for the installations based on the scenario String installations = (new MongoInstallations()).getInstallations(httpHeaders, scn_id, null, null, 0, 0, false, false);/* w ww . j a v a 2 s . c om*/ DBObject jsonResponse = (DBObject) JSON.parse(installations); BasicDBList list = (BasicDBList) jsonResponse.get("data"); // Retrieve the ids BasicDBList appsList = new BasicDBList(); int totalCount = 0; for (Object o : list) { DBObject dbo = (DBObject) o; String inst_id = (String) dbo.get("_id"); // For each one gather the data and load a DBCursor totalCount += addToList(inst_id, appsList, filters, sort, count, httpHeaders); } if (lib) { // search also in the corresponding lib totalCount += addToList(scn_id, appsList, filters, sort, count, httpHeaders); } // Use limit and skip for creating a sublist => return it Vector<DBObject> vec = new Vector<DBObject>(); for (Object o : appsList) { DBObject dbo = (DBObject) o; vec.add(dbo); } JSONtoReturn jSON2Rrn = new JSONtoReturn(); String page = jSON2Rrn.createJSON(vec, "Persons retrieved successfully").toString(); return Utils.returnResponseWithAppend(page, "total_size", new Integer(totalCount)); }
From source file:eu.cassandra.server.mongo.MongoProjects.java
License:Apache License
private String withAddedWarnings(String response, boolean ary) { if (Utils.failed(response)) return response; DBObject jsonResponse = (DBObject) JSON.parse(response); DBObject data = (DBObject) jsonResponse.get("data"); String objID = new String(); if (ary) {/*from w ww. j a v a2s . co m*/ objID = (String) ((DBObject) ((BasicDBList) data).get(0)).get("_id"); } else { objID = (String) data.get("_id"); } DBObject returnQuery = new MongoDBQueries().getEntity(MongoScenarios.COL_SCENARIOS, MongoScenarios.REF_PROJECT, objID); System.out.println(returnQuery); if (returnQuery == null) { BasicDBList list = new BasicDBList(); String warning = "Add at least one scenario for this project."; list.add(warning); jsonResponse.put("warnings", list); } return jsonResponse.toString(); }
From source file:eu.cassandra.server.mongo.MongoScenarios.java
License:Apache License
private String withAddedWarnings(String response, boolean ary) { if (Utils.failed(response)) return response; DBObject jsonResponse = (DBObject) JSON.parse(response); DBObject data = (DBObject) jsonResponse.get("data"); String objID = new String(); if (ary) {/*from ww w .ja va 2 s .c om*/ objID = (String) ((DBObject) ((BasicDBList) data).get(0)).get("_id"); } else { objID = (String) data.get("_id"); } BasicDBList list = new BasicDBList(); DBObject returnQuery = new MongoDBQueries().getEntity(MongoInstallations.COL_INSTALLATIONS, MongoInstallations.REF_SCENARIO, objID); if (returnQuery == null) { String warning = "Add at least one installation for this scenario."; list.add(warning); } returnQuery = new MongoDBQueries().getEntity(MongoSimParam.COL_SIMPARAM, "scn_id", objID); if (returnQuery == null) { String warning = "Add at least one set of simulation parameters for this scenario."; list.add(warning); } if (!list.isEmpty()) { jsonResponse.put("warnings", list); } return jsonResponse.toString(); }
From source file:eu.cassandra.server.mongo.util.MongoDBQueries.java
License:Apache License
/** * /*from w w w . j a v a 2s . co m*/ * @param dBObject * @param httpHeaders * @param id * @return * @throws JSONSchemaNotValidException * @throws BadParameterException */ private DBObject getValues(DBObject dBObject, HttpHeaders httpHeaders, String dbName, String id, String coll) throws JSONSchemaNotValidException, BadParameterException { if (dbName == null) dbName = getDbNameFromHTTPHeader(httpHeaders); if (coll.equalsIgnoreCase(MongoDistributions.COL_DISTRIBUTIONS)) { double values[] = null; if (dBObject.containsField("parameters")) { String type = MongoActivityModels.REF_DISTR_STARTTIME; if (DBConn.getConn(dbName).getCollection("act_models") .findOne(new BasicDBObject("duration._id", new ObjectId(id))) != null) { type = MongoActivityModels.REF_DISTR_DURATION; } else if (DBConn.getConn(dbName).getCollection("act_models") .findOne(new BasicDBObject("repeatsNrOfTime._id", new ObjectId(id))) != null) { type = MongoActivityModels.REF_DISTR_REPEATS; } values = new GUIDistribution(type, dBObject).getValues(); } if (values == null && dBObject.containsField("values")) { BasicDBList t = (BasicDBList) dBObject.get("values"); values = Utils.dblist2doubleArr(t); } if (values != null) { int exp = Utils.checkExp(values); Utils.upscale(values, exp); BasicDBList list = new BasicDBList(); for (int i = 0; i < values.length; i++) { BasicDBObject dbObj = new BasicDBObject("x", i); dbObj.put("y", values[i]); list.add(dbObj); } dBObject.put("values", list); dBObject.put("exp", exp); } } else if (coll.equalsIgnoreCase(MongoConsumptionModels.COL_CONSMODELS)) { double pvalues[] = null; double qvalues[] = null; double ppoints[] = null; double qpoints[] = null; BasicDBList list = new BasicDBList(); if (dBObject.containsField("pmodel")) { if (((DBObject) dBObject.get("pmodel")).containsField("params")) { GUIConsumptionModel p = new GUIConsumptionModel((DBObject) dBObject.get("pmodel"), "p"); Double[] pvaluesConsModel = p.getValues(GUIConsumptionModel.P); Double[] pointsConsModel = p.getPoints(pvaluesConsModel.length); pvalues = new double[pvaluesConsModel.length]; ppoints = new double[pointsConsModel.length]; for (int i = 0; i < pvaluesConsModel.length; i++) { pvalues[i] = pvaluesConsModel[i]; ppoints[i] = pointsConsModel[i]; } } } if (dBObject.containsField("qmodel")) { if (((DBObject) dBObject.get("qmodel")).containsField("params")) { GUIConsumptionModel q = new GUIConsumptionModel((DBObject) dBObject.get("qmodel"), "q"); Double[] qvaluesConsModel = q.getValues(GUIConsumptionModel.Q); Double[] pointsConsModel = q.getPoints(qvaluesConsModel.length); qvalues = new double[qvaluesConsModel.length]; qpoints = new double[pointsConsModel.length]; for (int i = 0; i < qvaluesConsModel.length; i++) { qvalues[i] = qvaluesConsModel[i]; qpoints[i] = pointsConsModel[i]; } } } if (pvalues != null && qvalues != null) { for (int i = 0; i < Math.min(pvalues.length, qvalues.length); i++) { BasicDBObject dbObj = new BasicDBObject("x", ppoints[i]); dbObj.put("p", pvalues[i]); dbObj.put("q", qvalues[i]); list.add(dbObj); } } dBObject.put("values", list); // Obsolete? // if((pvalues == null || pvalues.length==0) && dBObject.containsField("pvalues")) {; // BasicDBList t = (BasicDBList)dBObject.get("pvalues"); // pvalues = Utils.dblist2doubleArr(t); // } // if((qvalues == null || qvalues.length==0) && dBObject.containsField("qvalues")) {; // BasicDBList t = (BasicDBList)dBObject.get("qvalues"); // qvalues = Utils.dblist2doubleArr(t); // } } return dBObject; }
From source file:eu.cassandra.training.activity.GaussianMixtureModels.java
License:Apache License
@Override public DBObject toJSON(String activityModelID) { double[] values = new double[1]; DBObject temp = new BasicDBObject(); BasicDBList param = new BasicDBList(); for (int i = 0; i < gaussians.length; i++) { DBObject paramItem = new BasicDBObject(); double[] means = new double[gaussians.length]; double[] sigmas = new double[gaussians.length]; means[i] = gaussians[i].mean;//w w w .j a va 2 s .c om sigmas[i] = gaussians[i].sigma; paramItem.put("w", pi[i]); paramItem.put("mean", means[i]); paramItem.put("std", sigmas[i]); param.add(paramItem); } temp.put("name", name); temp.put("type", type); temp.put("description", name + " " + type); temp.put("distrType", type); temp.put("actmod_id", activityModelID); temp.put("parameters", param); temp.put("values", values); return temp; }
From source file:eu.cassandra.training.activity.Histogram.java
License:Apache License
@Override public DBObject toJSON(String activityModelID) { BasicDBList param = new BasicDBList(); DBObject temp = new BasicDBObject(); temp.put("name", name); temp.put("type", type); temp.put("description", name + " " + type); temp.put("distrType", type); temp.put("actmod_id", activityModelID); temp.put("values", values); temp.put("parameters", param); return temp;/*from w w w . j a v a 2 s. co m*/ }
From source file:eu.vital.vitalcep.collector.Collector.java
private void getCollectorList() { try {//from w ww.j a va 2 s. c om MongoClient mongo = new MongoClient(new MongoClientURI(mongoURL)); final MongoDatabase db = mongo.getDatabase(mongoDB); BasicDBObject clause1 = new BasicDBObject("cepType", "CONTINUOUS").append("status", "OK"); BasicDBObject clause2 = new BasicDBObject("cepType", "CEPICO"); BasicDBObject clause3 = new BasicDBObject("cepType", "ALERT"); BasicDBList or = new BasicDBList(); or.add(clause1); or.add(clause2); or.add(clause3); BasicDBObject query = new BasicDBObject("$or", or); FindIterable<Document> coll; coll = db.getCollection("cepinstances").find(query); coll.forEach(new Block<Document>() { @Override public void apply(final Document document) { JSONObject oCollector = new JSONObject(); oCollector.put("id", document.getObjectId("_id").toString()); oCollector.put("mqin", document.getString("mqin")); oCollector.put("mqout", document.getString("mqout")); oCollector.put("cepType", document.getString("cepType")); if (document.getString("cepType").equals("CONTINUOUS")) { final Document doc = new Document("sources", document.get("sources")); final String jsonStringSources = doc.toJson(); JSONObject sources = new JSONObject(jsonStringSources); final Document docproperties = new Document("properties", document.get("properties")); final String jsonStringproperties = docproperties.toJson(); JSONObject sourcesproperties = new JSONObject(jsonStringproperties); oCollector.put("sources", sources.getJSONArray("sources")); oCollector.put("properties", sourcesproperties.getJSONArray("properties")); oCollector.put("username", document.getString("username")); oCollector.put("password", document.getString("password")); } else { final Document doc = new Document("requests", document.get("requests")); final String jsonStringRequests = doc.toJson(); JSONObject requestsObject = new JSONObject(jsonStringRequests); oCollector.put("requests", requestsObject.getJSONArray("requests")); oCollector.put("username", document.getString("username")); oCollector.put("password", document.getString("password")); } oCollector.put("lastRequest", document.getString("lastRequest")); sensors.put(oCollector); } }); } catch (Exception e) { String a = "a"; } finally { if (db != null) db = null; if (mongo != null) { mongo.close(); mongo = null; } } }