List of usage examples for com.mongodb BasicDBObject append
@Override public BasicDBObject append(final String key, final Object val)
From source file:DataAccess.DAO.OrderDAO.java
public String createOrder(Order order) { try {/*from www. ja v a 2 s. co m*/ if (connectDB()) { BasicDBObject doc = new BasicDBObject("id_order", order.getId()).append("date", order.getDate()) .append("total_price", order.getTotalPrice()).append("user_id", order.getUserId()); BasicDBList solditemsBDL = new BasicDBList(); Collection<Solditems> list = order.getSolditemsCollection(); for (Solditems soleditem : list) { BasicDBObject soleditemBDO = new BasicDBObject("id_item", soleditem.getItems()) .append("quantity", soleditem.getQuantity()); solditemsBDL.add(soleditemBDO); } doc.append("solditems", solditemsBDL); coll.insert(doc); System.out.println("Document (Order) inserted successfully"); //return "Save Item " + order.getId() + " sucess"; return "Tu orden fue procesada y recibirs tus productos dentro de poco"; } else { return "Fail"; } } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); return "Fail"; } }
From source file:DataAccess.Entity.Restaurant.java
public BasicDBObject toDBObjectRestaurant() { // Creamos una instancia BasicDBObject BasicDBObject dBObjectRs = new BasicDBObject(); dBObjectRs.append("name", this.getName()); dBObjectRs.append("direccion", this.getAddress()); dBObjectRs.append("phone", this.getPhone()); return dBObjectRs; }
From source file:DataAccess.Entity.Restaurant.java
public DBObject toDBObjectRestaurant2(DBObject dboj) { name = dboj.toString();/*from ww w . j a v a2 s.co m*/ // Creamos una instancia BasicDBObject BasicDBObject dBObjectRs = new BasicDBObject(); dBObjectRs.append("name", this.getName()); dBObjectRs.append("direccion", this.getAddress()); dBObjectRs.append("phone", this.getPhone()); return dBObjectRs; }
From source file:Datos.DatosPersona.java
public void update(Persona oldP, Persona newP) { BasicDBObject documentSearch = new BasicDBObject(); documentSearch.append("id", oldP.getId()); BasicDBObject newDocument = new BasicDBObject(); newDocument.put("id", newP.getId()); newDocument.put("nombre", newP.getNombre()); newDocument.put("paterno", newP.getPaterno()); newDocument.put("materno", newP.getMaterno()); newDocument.put("telefono", newP.getTelefono()); newDocument.put("correo", newP.getCorreo()); newDocument.put("direccion", newP.getDireccion()); SM.getCollection().update(documentSearch, newDocument); }
From source file:Datos.DatosPersona.java
public void delete(Persona p) { BasicDBObject document = new BasicDBObject(); document.append("id", p.getId()); SM.getCollection().remove(document); }
From source file:de.uni_koeln.spinfo.maalr.login.UserInfoDB.java
License:Apache License
List<MaalrUserInfo> getAllUsers(Role role, String text, String sortColumn, boolean sortAscending, int from, int length) { BasicDBObject query = new BasicDBObject(); Pattern pattern = Pattern.compile(".*" + text + ".*", Pattern.CASE_INSENSITIVE); if (role != null) { query.put(Constants.Users.ROLE, role.toString()); }// w w w . j a va 2 s . c o m if (text != null && text.trim().length() > 0) { BasicDBList attributes = new BasicDBList(); DBObject firstName = new BasicDBObject(); firstName.put(Constants.Users.FIRSTNAME, pattern); attributes.add(firstName); DBObject lastName = new BasicDBObject(); lastName.put(Constants.Users.LASTNAME, pattern); attributes.add(lastName); DBObject login = new BasicDBObject(); login.put(Constants.Users.LOGIN, pattern); attributes.add(login); query.append("$or", attributes); } DBCursor cursor = userCollection.find(query); if (sortColumn != null) { BasicDBObject sort = new BasicDBObject(); sort.put(sortColumn, sortAscending ? 1 : -1); cursor.sort(sort); } cursor = cursor.skip(from).limit(length); List<MaalrUserInfo> all = new ArrayList<MaalrUserInfo>(); while (cursor.hasNext()) { DBObject o = cursor.next(); MaalrUserInfo user = new MaalrUserInfo(o); all.add(user); } cursor.close(); return all; }
From source file:de.uni_koeln.spinfo.maalr.mongo.core.Database.java
License:Apache License
private DBCursor query(String loginOrIP, Role role, Verification verification, String verifier, long startTime, long endTime, Status[] states, int limit, int offset, String orderField, boolean ascending) { // TODO: Add querying for 'current' state BasicDBObject query = new BasicDBObject(); BasicDBObject attributes = new BasicDBObject(); if (loginOrIP != null && loginOrIP.trim().length() > 0) { BasicDBList or = new BasicDBList(); DBObject creator = new BasicDBObject(); creator.put(QUERY_VERSION_CREATOR, loginOrIP); or.add(creator);//www. j a va 2 s .co m DBObject ip = new BasicDBObject(); ip.put(QUERY_VERSION_IP, loginOrIP); or.add(ip); attributes.put("$or", or); } if (verifier != null && verifier.trim().length() > 0) { attributes.put(QUERY_VERSION_VERIFIER, verifier); } if (role != null) { attributes.put(QUERY_VERSION_ROLE, role.toString()); } if (verification != null) { attributes.put(QUERY_VERSION_VERIFICATION, verification.toString()); } if (states != null && states.length > 0) { BasicDBList or = new BasicDBList(); for (Status s : states) { or.add(s.toString()); } DBObject nestedOr = new BasicDBObject(); nestedOr.put("$in", or); attributes.put(QUERY_VERSION_STATE, nestedOr); } if (startTime > 0) { attributes.put(QUERY_VERSION_TIMESTAMP, new BasicDBObject("$gt", startTime)); } if (endTime > 0) { attributes.put(QUERY_VERSION_TIMESTAMP, new BasicDBObject("$lt", endTime)); } if (startTime > 0 && endTime > 0) { DBObject obj = new BasicDBObject("$lt", endTime); obj.put("$gt", startTime); attributes.put(QUERY_VERSION_TIMESTAMP, obj); } DBCursor found; if (attributes.size() > 0) { BasicDBObject elemMatch = new BasicDBObject("$elemMatch", attributes); query.append(LexEntry.VERSIONS, elemMatch); // query.append("$and", attributes); // query.append("$elemMatch", attributes); found = entryCollection.find(query); } else { found = entryCollection.find(); } if (orderField != null) { DBObject order = new BasicDBObject(); order.put(LexEntry.VERSIONS + "." + orderField, ascending ? 1 : -1); found.sort(order); } // TODO: This is inefficient! However, it should be ok for // small queries, which is the expected usecase. if (offset > 0) { found = found.skip(offset); } if (limit > 0) { found = found.limit(limit); } return found; }
From source file:de.uni_koeln.spinfo.maalr.mongo.core.Database.java
License:Apache License
public DatabaseStatistics getStatistics() { DatabaseStatistics stats = new DatabaseStatistics(); stats.setNumberOfEntries((int) entryCollection.getCount()); Map<Verification, Integer> count = new HashMap<Verification, Integer>(); DBCursor cursor = entryCollection.find(); int entryCount = 0, lemmaCount = 0; Verification[] values = Verification.values(); for (Verification verification : values) { count.put(verification, 0);// w w w .j av a 2s .com } count.put(null, 0); while (cursor.hasNext()) { LexEntry entry = Converter.convertToLexEntry(cursor.next()); List<LemmaVersion> history = entry.getVersionHistory(); entryCount++; lemmaCount += history.size(); for (LemmaVersion lemma : history) { Integer old = count.get(lemma.getVerification()); count.put(lemma.getVerification(), old + 1); } } stats.setNumberOfApproved(count.get(Verification.ACCEPTED)); stats.setNumberOfSuggestions(count.get(Verification.UNVERIFIED)); stats.setNumberOfDeleted(count.get(Verification.REJECTED)); stats.setNumberOfOutdated(count.get(Verification.OUTDATED)); stats.setNumberOfUndefined(count.get(null)); stats.setNumberOfEntries(entryCount); stats.setNumberOfLemmata(lemmaCount); /* * TODO: - Create a separate "System/Diagnostics"-Tab, containing a) * general information about - RAM - Free Disk Space - CPU - Network b) * DB-Statistics - general - entries - users * * Check if this will work with sigar: * * * * - Add green and red 'lamps' to each entry, each sub-statistic * (entries, users, general) - Add one lamp to the navigation bar, to * summarize the server state: should always be green. */ CommandResult dbStats = entryCollection.getDB().getStats(); NumberFormat nf = NumberFormat.getInstance(); stats.addDBProperty("Server", dbStats.getString("serverUsed")); Double serverStatus = dbStats.getDouble("ok"); if (Double.compare(1D, serverStatus) == 0) { stats.addDBProperty("Server Status", "ok"); } else { stats.addDBProperty("Server Status", "not ok: " + serverStatus, Category.ERROR); } long collections = dbStats.getLong("collections"); if (collections == 0) { stats.addDBProperty("Number of Collections", nf.format(dbStats.getLong("collections")), Category.ERROR); } else { stats.addDBProperty("Number of Collections", nf.format(dbStats.getLong("collections"))); } stats.addDBProperty("Number of Indexes", nf.format(dbStats.getLong("indexes"))); stats.addDBProperty("Average Object Size", nf.format(dbStats.getDouble("avgObjSize") / 1024) + " KB"); stats.addDBProperty("Data Size", nf.format(dbStats.getLong("dataSize") / (1024 * 1024)) + " MB"); stats.addDBProperty("Storage Size", nf.format(dbStats.getLong("storageSize") / (1024 * 1024)) + " MB"); stats.addDBProperty("Index Size", nf.format(dbStats.getLong("indexSize") / (1024 * 1024)) + " MB"); stats.addDBProperty("File Size", nf.format(dbStats.getLong("fileSize") / (1024 * 1024)) + " MB"); BasicDBObject query; BasicDBList attributes; query = new BasicDBObject(); attributes = new BasicDBList(); DBObject lemmata = new BasicDBObject(); lemmata.put(QUERY_VERSION_TIMESTAMP, new BasicDBObject("$gt", -1)); attributes.add(lemmata); query.append("$and", attributes); // stats.setNumberOfLemmata((int) entryCollection.count(query)); return stats; }
From source file:directorio.ETL.java
public static void ETL() throws UnknownHostException, ParseException { try {// w w w. jav a 2s.c o m FotoDAO f = new FotoDAO(); fotos = f.getFotos(); DirectorioDAO d = new DirectorioDAO(); directorios = d.getDirectorios(); CarpetaDAO c = new CarpetaDAO(); carpetas = c.getCarpetas(); etiquetas = EtiquetaDAO.getEtiquetas(); } catch (InstantiationException | IllegalAccessException | SQLException ex) { Logger.getLogger(ETL.class.getName()).log(Level.SEVERE, null, ex); } for (Foto foto : fotos) { System.out.println("\n\n" + "nombreFoto: " + foto.getNombreFoto()); System.out.println("\n" + "ruta: " + carpetas.get(foto.getIdCarpeta())); System.out.println("\n" + "tamao: " + foto.getTamanio()); tienePhotoshop = false; try { InfoDAO i = new InfoDAO(); info = i.getInfo(foto.getIdFoto()); } catch (InstantiationException | IllegalAccessException | SQLException ex) { Logger.getLogger(ETL.class.getName()).log(Level.SEVERE, null, ex); } BasicDBObject fotoo = new BasicDBObject("nombre", foto.getNombreFoto()) .append("ruta", carpetas.get(foto.getIdCarpeta())).append("tamao", foto.getTamanio()); for (Info infoo : info) { Etiqueta etiqueta = etiquetas.get(infoo.getIdEqtiqueta()); if (etiqueta != null) { if (directorios.get(etiqueta.getIdDirectorio()).equals("Photoshop")) { tienePhotoshop = true; } switch (etiqueta.getNombre()) { case "Image Height": if (directorios.get(etiqueta.getIdDirectorio()).equals("Jpeg")) { String valor = infoo.getValor(); String[] partes = valor.split(" "); fotoo.append("alto", Integer.parseInt(partes[0])); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + "alto" + ": " + partes[0]); } break; case "Image Width": if (directorios.get(etiqueta.getIdDirectorio()).equals("Jpeg")) { String valor = infoo.getValor(); String[] partes = valor.split(" "); fotoo.append("ancho", Integer.parseInt(partes[0])); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + "ancho" + ": " + partes[0]); } break; case "Flash": if (directorios.get(etiqueta.getIdDirectorio()).equals("Exif SubIFD")) { boolean flash = true; if (infoo.getValor().equals("Flash did not fire") || infoo.getValor().equals("Flash did not fire, auto")) { flash = false; } fotoo.append(etiqueta.getNombre(), flash); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + etiqueta.getNombre() + ": " + flash); } break; case "Make": if (directorios.get(etiqueta.getIdDirectorio()).equals("Exif IFD0")) { fotoo.append("marca", infoo.getValor()); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + "marca" + ": " + infoo.getValor()); } break; case "Model": if (directorios.get(etiqueta.getIdDirectorio()).equals("Exif IFD0")) { fotoo.append("modelo", infoo.getValor()); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + "modelo" + ": " + infoo.getValor()); } break; case "Date/Time": if (directorios.get(etiqueta.getIdDirectorio()).equals("Exif IFD0")) { DateFormat format = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); Date fecha = format.parse(infoo.getValor()); fotoo.append("fecha", fecha); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + "fecha" + ": " + infoo.getValor() + " " + fecha); } break; case "GPS Latitude Ref": if (directorios.get(etiqueta.getIdDirectorio()).equals("GPS")) { fotoo.append("latitudRef", infoo.getValor()); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + "latitudRef" + ": " + infoo.getValor()); } break; case "GPS Latitude": if (directorios.get(etiqueta.getIdDirectorio()).equals("GPS")) { String valor = infoo.getValor(); String[] partes = valor.split(" "); String grados = partes[0]; String minutos = partes[1]; String segundos = partes[2]; String[] partesGrados = grados.split("\\."); String[] partesMinutos = minutos.split("\\."); String[] partesSegundos = segundos.split("\\."); String gradosFinal = partesGrados[0] + ""; String minutosFinal = partesMinutos[0] + "'"; String segundosFinal = partesSegundos[0]; String latitud = gradosFinal + minutosFinal + segundosFinal; fotoo.append("latitud", latitud); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + "latitud" + ": " + latitud); } break; case "GPS Longitude Ref": if (directorios.get(etiqueta.getIdDirectorio()).equals("GPS")) { fotoo.append("longitudRef", infoo.getValor()); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + "longitudRef" + ": " + infoo.getValor()); } break; case "GPS Longitude": if (directorios.get(etiqueta.getIdDirectorio()).equals("GPS")) { String valor = infoo.getValor(); String[] partes = valor.split(" "); String grados = partes[0]; String minutos = partes[1]; String segundos = partes[2]; String[] partesGrados = grados.split("\\."); String[] partesMinutos = minutos.split("\\."); String[] partesSegundos = segundos.split("\\."); String gradosFinal = partesGrados[0] + ""; String minutosFinal = partesMinutos[0] + "'"; String segundosFinal = partesSegundos[0]; String longitud = gradosFinal + minutosFinal + segundosFinal; fotoo.append("longitud", longitud); System.out.println("\n" + directorios.get(etiqueta.getIdDirectorio()) + ": " + "longitud" + ": " + longitud); } break; } } } if (tienePhotoshop) { fotoo.append("Photoshop", true); System.out.println("\n" + "Photoshop" + ": " + "true"); } else { fotoo.append("Photoshop", false); System.out.println("\n" + "Photoshop" + ": " + "false"); } MongoDAO.insertarFoto(fotoo); } }
From source file:dsll.pinterest.crawler.Reduce.java
private static Text updatePinContent(String url, DBCollection pinsCollection) throws JSONException, IOException { // add more related pins, include more boards String id = url.split("/pin/")[1]; DBCursor c = pinsCollection.find(new BasicDBObject("ID", id)); DBObject oldPin = c.next();// w ww . j av a 2 s .co m JSONArray oldBoards = new JSONArray(oldPin.get("board").toString()); JSONArray oldRltPin = new JSONArray(oldPin.get("related_pins").toString()); Document doc = Jsoup.connect(url).get(); Element bottomDoc = doc.select("div[class=Module CloseupSidebar]").first(); //pin board Element boardEle = bottomDoc.select("div[class=boardHeader]").first(); JSONArray board = new JSONArray(); JSONObject b = new JSONObject(); String boardName = ""; try { boardName = boardEle.select("h3[class=title]").text().trim(); } catch (Exception ee) { } String boardSrc = ""; try { boardSrc = "https://www.pinterest.com" + boardEle.select("a").attr("href").trim(); } catch (Exception ee) { } b.append("name", boardName); b.append("src", boardSrc); board.put(b); //related pins bottomDoc = doc .select("div[class=closeupBottom] div[class=Module CloseupBottom] div[class=relatedPinsWrapper]") .first(); JSONArray relatedPins = new JSONArray(); Elements relatedPinsConts = bottomDoc.select("div[class=pinWrapper]"); for (Element relatedPinsCont : relatedPinsConts) { JSONObject relatedPin = new JSONObject(); relatedPin.append("src", "https://www.pinterest.com" + relatedPinsCont.select("div[class=pinHolder] > a").attr("href")); relatedPins.put(relatedPin); } // process new boards List<String> oldBoardNames = new ArrayList<String>(); for (int i = 0; i < oldBoards.length(); i++) { oldBoardNames.add(oldBoards.getJSONObject(i).getString("name")); } for (int i = 0; i < board.length(); i++) { JSONObject tmp = board.getJSONObject(i); if (oldBoardNames.contains(tmp.getString("name"))) { continue; } oldBoards.put(board.get(i)); } // process new related pins List<String> oldRelatedPins = new ArrayList<String>(); for (int i = 0; i < oldRltPin.length(); i++) { oldRelatedPins.add(oldRltPin.getJSONObject(i).getString("src")); } for (int i = 0; i < relatedPins.length(); i++) { if (oldRelatedPins.contains(relatedPins.getJSONObject(i).get("src"))) { continue; } oldRltPin.put(relatedPins.getJSONObject(i)); } BasicDBObject newAttr = new BasicDBObject(); newAttr.append("board", oldBoards); newAttr.append("related_pins", oldRltPin); BasicDBObject update = new BasicDBObject().append("$set", newAttr); pinsCollection.update(new BasicDBObject("ID", id), update); return new Text("Pin " + id + " updated."); }