List of usage examples for com.mongodb DBObject get
Object get(String key);
From source file:com.exorath.service.connector.service.MongoDatabaseProvider.java
License:Apache License
@Override public ServerInfo getServerInfo(Filter filter, Long minLastUpdate) { //Fingers crossed BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); if (filter.getGameId() != null) builder.append("gameId", filter.getGameId()); if (filter.getMapId() != null) builder.append("mapId", filter.getMapId()); if (filter.getFlavorId() != null) builder.append("flavorId", filter.getFlavorId()); builder.append("expiry", new BasicDBObject("$gte", System.currentTimeMillis())); MapReduceCommand mapReduceCommand = new MapReduceCommand(datastore.getDB().getCollection(collectionName), "function(){" + "var ret = {pc:0, opc:0, sc:0, osc:0};" + "ret.pc = this.pc; ret.sc = 1;" + "if(this.joinable && this.pc < this.mpc){ ret.opc = this.mpc - this.pc; ret.osc = 1;}" + "emit('server', ret);}", "function(key, values){" + "var ret = {pc:0, opc:0, sc:0, osc:0};" + "values.forEach( function(value) {" + " ret.pc+= value.pc; ret.sc++;" + " ret.osc+= value.osc; ret.opc+= value.opc" + " });" + "return ret;" + "}", null, MapReduceCommand.OutputType.INLINE, builder.get()); MapReduceOutput results = datastore.getDB().getCollection(collectionName).mapReduce(mapReduceCommand); if (results.getOutputCount() == 0) return new ServerInfo(0, 0, 0, 0, System.currentTimeMillis()); if (results.getOutputCount() > 1) throw new IllegalStateException("mapReduce returned multiple results."); for (DBObject res : results.results()) { DBObject val = (DBObject) res.get("value"); return new ServerInfo(((Double) val.get("pc")).intValue(), ((Double) val.get("sc")).intValue(), ((Double) val.get("osc")).intValue(), ((Double) val.get("opc")).intValue(), System.currentTimeMillis()); }//from ww w . ja va 2 s. c om //// MapreduceResults<ServerInfo> results = datastore.mapReduce(MapreduceType.INLINE, getFilterQuery(filter), ServerInfo.class, mapReduceCommand); //// if(results.getCounts().getOutputCount() == 0) { //// System.out.println("output 0 :*"); // return null; // } // System.out.println("ms: " + results.getElapsedMillis()); // results.forEach(info -> System.out.println(info.getOpenSlotCount())); return null; }
From source file:com.eywa.impl.app.controllers.central.Activity.java
License:Open Source License
public Object getData(final String key) { final DBObject data = getData(); if (null != data && data.containsField(key)) { return data.get(key); }/* w w w. j a v a 2s . c o m*/ return null; }
From source file:com.eywa.impl.app.mongo.entities.items.session.cart.ItemSessionDataCartItem.java
License:Open Source License
public Object getAttribute(final String key) { final DBObject attributes = getAttributes(this); return attributes.get(key); }
From source file:com.ff.reportgenerator.mongodb.DynamicDatabase.java
public String query() { String records = "<table>" + Utility.formTableHead() + "<tbody>"; DB myDB = getDB(DB_NAME);//from www . jav a 2s .com DBCollection coll = myDB.getCollection("projects"); DBCursor ret = coll.find(); BasicDBObject sort = new BasicDBObject("PROJECT_ID", 1); ret.sort(sort); try { while (ret.hasNext()) { records = records + "<tr>"; DBObject rec = (DBObject) ret.next(); Iterator keys = Utility.DATA_KEYS.iterator(); while (keys.hasNext()) { String key = (String) keys.next(); String value = (String) rec.get(key); if (key.equals("PROJECT_ID")) { records = records + "<td><a href=\"" + Utility.PROJECT_URL_PREFIX + value + "\">" + value + "</td>"; } else { records = records + "<td>" + value + "</td>"; } } records = records + "</tr>"; //System.out.println(rec); } } finally { ret.close(); } records = records + "</tbody></table>"; return records; }
From source file:com.fileoperations.CopyClass.java
public CopyClass(String userID, String parentPath, String name, String newPath) throws UnknownHostException { this.userID = userID; this.parentPath = parentPath; this.name = name; this.newPath = newPath; mymongo = new Connection(); DBCollection usercol = mymongo.getMembersCol(); BasicDBObject query = new BasicDBObject(); query.put("_id", userID); DBCursor cursor = usercol.find(query); DBObject col = cursor.next(); userCollectionName = col.get("collection").toString(); collection = mymongo.getCollection(userCollectionName); }
From source file:com.fileoperations.CopyClass.java
public Boolean forSingleFile() { try {/* w ww . j a v a 2 s. com*/ if (name.contains(".")) { BasicDBObject query = new BasicDBObject(); query.put("_id", parentPath + pathMerger + name); DBCursor cursor = collection.find(query); if (cursor.hasNext()) { BasicDBObject checknewquery = new BasicDBObject(); checknewquery.put("_id", newPath + pathMerger + name); DBCursor tempCursor = collection.find(checknewquery); if (tempCursor.hasNext()) { return false; } DBObject copyFile = cursor.next(); GridFS fileDB = new GridFS(mymongo.getDB(), userCollectionName); InputStream data = fileDB.findOne(query).getInputStream(); BasicDBObject document = new BasicDBObject(); document.append("_id", newPath + pathMerger + name); document.append("folder", "0"); document.append("parent", newPath); document.append("name", name); document.append("type", copyFile.get("type").toString()); collection.insert(document); GridFSInputFile inputFile = fileDB.createFile(data); inputFile.setId(newPath + pathMerger + name); inputFile.put("path", newPath); inputFile.setFilename(name); inputFile.save(); return true; } else { return false; } } else { return false; } } finally { mymongo.closeConnection(); } }
From source file:com.fileoperations.FolderDownload.java
public FolderDownload(String userID, String parentPath, String folderName) throws UnknownHostException { this.userID = userID; this.parentPath = parentPath; this.folderName = folderName; mymongo = new Connection(); DBCollection usercol = mymongo.getMembersCol(); BasicDBObject query = new BasicDBObject(); query.put("_id", userID); DBCursor cursor = usercol.find(query); DBObject col = cursor.next(); userCollectionName = col.get("collection").toString(); collection = mymongo.getCollection(userCollectionName); }
From source file:com.fileoperations.FolderDownload.java
private void getPathOfAllChildrenFolder(String parentPath, String folderName) { BasicDBObject toFindAllFolderInFolder = new BasicDBObject(); pathOfChildrenFolders.add(new BasicDBObject("path", parentPath + pathMerger + folderName)); pathOfChildrenEmptyFolders.add(new BasicDBObject("parent", parentPath + pathMerger + folderName)); // pathOfChildrenEmptyFolders.add(new BasicDBObject("path",parentPath+pathMerger+folderName)); toFindAllFolderInFolder.put("parent", parentPath + pathMerger + folderName); DBCursor allFolder = collection.find(toFindAllFolderInFolder); while (allFolder.hasNext()) { DBObject indivFolder = allFolder.next(); getPathOfAllChildrenFolder(indivFolder.get("parent").toString(), indivFolder.get("name").toString()); }/*from w w w.ja v a 2 s . c om*/ }
From source file:com.fileoperations.FolderDownload.java
public File makeFolder() throws IOException { try {/* ww w. java 2s . c o m*/ String mongoFolder = parentPath + pathMerger + folderName; BasicDBObject query = new BasicDBObject(); query.put("_id", mongoFolder); DBCursor cursor = collection.find(query); if (cursor.hasNext()) { getPathOfAllChildrenFolder(parentPath, folderName); BasicDBObject toFindAllFilesInFolder = new BasicDBObject(); toFindAllFilesInFolder.put("$or", pathOfChildrenFolders); GridFS fileStore = new GridFS(mymongo.getDB(), userCollectionName); List<GridFSDBFile> AllFiles = fileStore.find(toFindAllFilesInFolder); File zip = new File(folderName + ".zip"); ZipOutputStream folderToZip = new ZipOutputStream(new FileOutputStream(zip)); for (int i = 0; i < AllFiles.size(); i++) { GridFSDBFile indivFile = AllFiles.get(i); ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream in = indivFile.getInputStream(); int data = in.read(); while (data >= 0) { out.write((char) data); data = in.read(); } out.flush(); String zipPath; zipPath = indivFile.get("path").toString() + pathMerger + indivFile.getFilename(); zipPath = zipPath.replaceFirst(parentPath, ""); zipPath = zipPath.replaceFirst(pathMerger, ""); ZipEntry add = new ZipEntry(zipPath); folderToZip.putNextEntry(add); folderToZip.write(out.toByteArray(), 0, out.toByteArray().length); } BasicDBObject toFindAllEmptyFilesInFolder = new BasicDBObject(); toFindAllEmptyFilesInFolder.put("$or", pathOfChildrenEmptyFolders); DBCursor emptyFolder = collection.find(toFindAllEmptyFilesInFolder); List<String> emptyFolderPathToAdd = new ArrayList<String>(); while (emptyFolder.hasNext()) { DBObject temp = emptyFolder.next(); BasicDBObject isEmpty = new BasicDBObject(); isEmpty.put("parent", temp.get("_id").toString()); if (!collection.find(isEmpty).hasNext()) { if (!temp.get("_id").toString().contains(".")) { emptyFolderPathToAdd.add(temp.get("_id").toString()); } } } for (int i = 0; i < emptyFolderPathToAdd.size(); i++) { String temp = emptyFolderPathToAdd.get(i).replaceFirst(parentPath, ""); temp = temp.replaceFirst(pathMerger, ""); ZipEntry add = new ZipEntry(temp + pathMerger); folderToZip.putNextEntry(add); } folderToZip.closeEntry(); folderToZip.close(); return zip; } else { return null; } } finally { mymongo.closeConnection(); } }
From source file:com.fileoperations.FolderDownload.java
public Boolean copyFolder(String newPath) throws IOException { try {//from w ww. j a v a 2 s . co m String mongoFolder = parentPath + pathMerger + folderName; BasicDBObject query = new BasicDBObject(); query.put("_id", mongoFolder); DBCursor cursor = collection.find(query); if (cursor.hasNext()) { BasicDBObject newquery = new BasicDBObject(); newquery.put("_id", newPath + pathMerger + folderName); if (collection.find(newquery).hasNext()) { return false; } getPathOfAllChildrenFolder(parentPath, folderName); BasicDBObject toFindAllFilesInFolder = new BasicDBObject(); toFindAllFilesInFolder.put("$or", pathOfChildrenFolders); GridFS fileStore = new GridFS(mymongo.getDB(), userCollectionName); List<GridFSDBFile> AllFiles = fileStore.find(toFindAllFilesInFolder); for (int i = 0; i < AllFiles.size(); i++) { GridFSDBFile indivFile = AllFiles.get(i); InputStream data = indivFile.getInputStream(); String zipPath; zipPath = indivFile.get("path").toString(); String tempFileName = indivFile.getFilename(); zipPath = zipPath.replaceFirst(parentPath, newPath); BasicDBObject document = new BasicDBObject(); document.append("_id", zipPath + pathMerger + tempFileName); document.append("folder", "0"); document.append("parent", zipPath); document.append("name", tempFileName); int index = tempFileName.lastIndexOf("."); document.append("type", tempFileName.substring(index)); collection.insert(document); GridFSInputFile inputFile = fileStore.createFile(data); inputFile.setId(zipPath + pathMerger + tempFileName); inputFile.put("path", zipPath); inputFile.setFilename(tempFileName); inputFile.save(); } BasicDBObject toFindAllEmptyFilesInFolder = new BasicDBObject(); toFindAllEmptyFilesInFolder.put("$or", pathOfChildrenEmptyFolders); DBCursor allFolders = collection.find(toFindAllEmptyFilesInFolder); while (allFolders.hasNext()) { DBObject temp = allFolders.next(); if (temp.get("folder").toString().equals("1")) { String tempPath = temp.get("parent").toString().replaceFirst(parentPath, newPath); BasicDBObject document = new BasicDBObject(); document.put("_id", tempPath + pathMerger + temp.get("name")); document.put("folder", "1"); document.put("name", temp.get("name")); document.put("parent", tempPath); document.put("type", "1"); collection.insert(document); } } return true; } else { return false; } } finally { mymongo.closeConnection(); } }