List of usage examples for com.mongodb BasicDBList get
public Object get(final String key)
From source file:dao.CocinaDAO.java
public Integer actualizarEstado(int idPedido, String username) { int idestado; ConexionMLab con = new ConexionMLab(); MongoClient mongo = con.getConexion(); DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Date fecha = new Date(); int fields = 0; try {//from w ww . j a va2 s .c om DB db = mongo.getDB("pizzaplaneta"); DBCollection coleccion = db.getCollection("pedido"); BasicDBObject query = new BasicDBObject(); query.put("_id", idPedido); DBCursor cursor = coleccion.find(query); DBObject dbo = cursor.next(); BasicDBList dbo1 = (BasicDBList) dbo.get("estados"); idestado = (Integer) ((DBObject) (dbo1.get(dbo1.size() - 1))).get("id"); gEstado = new Estado(); switch (idestado + 1) { case 1: gEstado.setId(1); gEstado.setFechaHora(df.format(fecha)); gEstado.setUsername(username); break; case 2: gEstado.setId(2); gEstado.setFechaHora(df.format(fecha)); gEstado.setUsername(username); agregarPedidoDistribuidor(2); break; case 3: gEstado.setId(2); gEstado.setFechaHora(df.format(fecha)); gEstado.setUsername(username); agregarPedidoDistribuidor(2); break; } DBObject dbo3 = new BasicDBObject(); dbo3.put("id", gEstado.getId()); dbo3.put("fechaHora", gEstado.getFechaHora()); dbo3.put("username", gEstado.getUsername()); DBObject dbo4 = new BasicDBObject(); dbo4.put("estados", dbo3); DBObject dbo5 = new BasicDBObject(); dbo5.put("$push", dbo4); coleccion.update(query, dbo5).getN(); fields = idestado + 1; } catch (Exception e) { e.printStackTrace(); } finally { mongo.close(); } return fields; }
From source file:de.ifgi.fmt.mongo.conv.LineStringConverter.java
License:Open Source License
/** * //from ww w .ja v a 2 s.c o m * @param mc * @param o * @param m * @return * @throws MappingException */ @Override public LineString decode(Class mc, Object o, MappedField m) throws MappingException { if (o == null) { return null; } else if (o instanceof LineString) { return (LineString) o; } else if (o instanceof double[][]) { double[][] a = (double[][]) o; Coordinate[] c = new Coordinate[a.length]; for (int i = 0; i < c.length; ++i) c[i] = new Coordinate(a[i][0], a[i][1]); return f.createLineString(c); } else if (o instanceof BasicDBList) { BasicDBList list = (BasicDBList) o; Coordinate[] c = new Coordinate[list.size()]; for (int i = 0; i < c.length; ++i) c[i] = pc.decode(Point.class, list.get(i), null).getCoordinate(); return f.createLineString(c); } else { throw new RuntimeException("Can not decode " + o.getClass().toString()); } }
From source file:de.ifgi.fmt.mongo.conv.PointConverter.java
License:Open Source License
/** * //from ww w . java 2s . c o m * @param c * @param o * @param i * @return * @throws MappingException */ @Override public Point decode(Class c, Object o, MappedField i) throws MappingException { Point p = null; if (o == null) { return null; } else if (o instanceof Point) { return (Point) o; } else if (o instanceof Point2D) { Point2D a = (Point2D) o; p = f.createPoint(new Coordinate(a.getX(), a.getY())); } else if (o instanceof double[]) { double[] a = (double[]) o; p = f.createPoint(new Coordinate(a[0], a[1])); } else if (o instanceof BasicDBList) { BasicDBList list = (BasicDBList) o; p = f.createPoint(new Coordinate((Double) list.get(0), (Double) list.get(1))); } else { throw new RuntimeException("Can not decode " + o.getClass().toString()); } p.setSRID(4326); return p; }
From source file:eu.cassandra.server.api.Installations.java
License:Apache License
/** * /*from w ww .j a v a 2 s.c o m*/ * Gets the installations under a scenario id * @param message contains the scenario_id to search the related scenarios * @return */ @GET public Response getInstallations(@QueryParam("scn_id") String scn_id, @QueryParam("filter") String filters, @QueryParam("sort") String sort, @QueryParam("limit") int limit, @QueryParam("skip") int skip, @QueryParam("count") boolean count, @QueryParam("pertype") boolean pertype, @Context HttpHeaders httpHeaders) { String page = new MongoInstallations().getInstallations(httpHeaders, scn_id, filters, sort, limit, skip, count, pertype); String countResponse = (new MongoInstallations()).getInstallations(httpHeaders, scn_id, null, null, 0, 0, true, false); DBObject jsonResponse = (DBObject) JSON.parse(countResponse); BasicDBList list = (BasicDBList) jsonResponse.get("data"); DBObject object = (DBObject) list.get(0); return Utils.returnResponseWithAppend(page, "total_size", (Integer) object.get("count")); }
From source file:eu.cassandra.server.mongo.csn.MongoCluster.java
License:Apache License
/** * /*from w w w . java 2 s.co m*/ * @param clusterBasedOn * @param graph_id * @param httpHeaders * @return */ private Instances getInstances(String clusterBasedOn, String graph_id) { FastVector attributes = new FastVector(); if (clusterBasedOn.equalsIgnoreCase("hoursP") || clusterBasedOn.equalsIgnoreCase("hoursQ") || clusterBasedOn.equalsIgnoreCase("hoursE")) { for (int i = 0; i < 24; i++) { attributes.addElement(new Attribute("att" + i)); } } else { attributes.addElement(new Attribute("att0")); } Instances instances = new Instances("data", attributes, 0); DBCursor nodes = DBConn.getConn().getCollection(MongoGraphs.COL_CSN_NODES) .find(new BasicDBObject("graph_id", graph_id)); //Get all nodes while (nodes.hasNext()) { double[] values = null; DBObject installationDBObj = nodes.next(); nodeIDs.add(installationDBObj.get("_id").toString()); //If graph was build based on Person or Installation Type do nothing if (clusterBasedOn.equalsIgnoreCase(MongoEdges.PersonType) || clusterBasedOn.equalsIgnoreCase(MongoEdges.InstallationType) || clusterBasedOn.equalsIgnoreCase(MongoEdges.TransformerID) || clusterBasedOn.equalsIgnoreCase(MongoEdges.TopologicalDistance) || clusterBasedOn.equalsIgnoreCase(MongoEdges.Location) || clusterBasedOn.equalsIgnoreCase(MongoEdges.Location) || clusterBasedOn.equalsIgnoreCase(MongoEdges.SocialDistance)) { continue; } else { Object vS = installationDBObj.get(CSNTypes.getCsnTypes(clusterBasedOn)); if (vS != null) { if (clusterBasedOn.equalsIgnoreCase("hoursP") || clusterBasedOn.equalsIgnoreCase("hoursQ") || clusterBasedOn.equalsIgnoreCase("hoursE")) { if (vS instanceof BasicDBList) { BasicDBList v = (BasicDBList) vS; values = new double[v.size()]; for (int i = 0; i < v.size(); i++) { Object d = v.get(i); if (d instanceof Double) { values[i] = (Double) d; } } } } else { Double v = Double.parseDouble(vS.toString()); values = new double[1]; values[0] = v; } } } if (values != null) { Instance instance = new Instance(1, values); instances.add(instance); } } nodes.close(); return instances; }
From source file:eu.cassandra.server.mongo.MongoActivities.java
License:Apache License
public static String getParentId(String id) { BasicDBList list = ((BasicDBList) ((DBObject) JSON.parse(new MongoActivities().getActivity(null, id))) .get("data")); if (list == null || list.isEmpty()) return null; return (String) ((DBObject) list.get(0)).get(REF_PERSON); }
From source file:eu.cassandra.server.mongo.MongoAppliances.java
License:Apache License
public static String getParentId(String id) { BasicDBList list = ((BasicDBList) ((DBObject) JSON.parse(new MongoAppliances().getAppliance(null, id))) .get("data")); if (list == null || list.isEmpty()) return null; return (String) ((DBObject) list.get(0)).get(REF_INSTALLATION); }
From source file:eu.cassandra.server.mongo.MongoAppliances.java
License:Apache License
private int addToList(String ref_id, BasicDBList list, String filters, String sort, boolean count, HttpHeaders httpHeaders) {/*from w w w .j av a2s.c om*/ String apps = new MongoDBQueries().getEntity(httpHeaders, COL_APPLIANCES, "inst_id", ref_id, filters, sort, 0, 0, "Appliances retrieved successfully", count).toString(); String countResponse = new MongoDBQueries().getEntity(httpHeaders, COL_APPLIANCES, "inst_id", ref_id, null, null, 0, 0, "Appliances retrieved successfully", true).toString(); DBObject response = (DBObject) JSON.parse(countResponse); BasicDBList alist = (BasicDBList) response.get("data"); DBObject object = (DBObject) alist.get(0); Integer aint = (Integer) object.get("count"); DBObject jsonResponse = (DBObject) JSON.parse(apps); BasicDBList appsInstList = (BasicDBList) jsonResponse.get("data"); list.addAll(appsInstList); return aint.intValue(); }
From source file:eu.cassandra.server.mongo.MongoAppliances.java
License:Apache License
/** * curl -i http://localhost:8080/cassandra/api/app?actmod_id=5040bca5e4b03aeba2cd907 * /*from w w w .ja v a2s. c om*/ * @param actmod_id * @return */ @SuppressWarnings("unchecked") public String getApplianceFromActivityModel(HttpHeaders httpHeaders, String actmod_id) { DBObject o = new MongoDBQueries().getEntity(httpHeaders, MongoActivityModels.COL_ACTMODELS, "_id", actmod_id, "Activity Model retrieved successfully"); Vector<DBObject> appliances = new Vector<DBObject>(); Vector<DBObject> dataVec = (Vector<DBObject>) o.get("data"); if (dataVec != null && dataVec.size() > 0) { DBObject data = dataVec.get(0); com.mongodb.BasicDBList apps = (com.mongodb.BasicDBList) data.get("containsAppliances"); if (apps != null) { for (int i = 0; i < apps.size(); i++) { String appID = apps.get(i).toString(); DBObject appObj = new MongoDBQueries().getEntity(httpHeaders, COL_APPLIANCES, "_id", appID, "Appliance retrieved successfully"); Vector<DBObject> appIn = (Vector<DBObject>) appObj.get("data"); if (appIn != null && appIn.size() > 0) { appliances.add(appIn.get(0)); } } } return new JSONtoReturn().createJSON(appliances, "Appliance Retrieved from activity Model").toString(); } else { return PrettyJSONPrinter.prettyPrint(o.toString()); } }
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 ww. ja v a 2s. c o m } } obj.put("containsAppliances", blist); PrettyJSONPrinter.prettyPrint(obj); } }