List of usage examples for com.mongodb DBCursor hasNext
@Override public boolean hasNext()
From source file:com.fliker.Modal.OSMPreview.java
public String getOSMOperatorCompanyID(String osmmodelid) { // TODO Auto-generated method stub String osmowner = ""; String company = ""; String companyid = ""; MongoConnection mongocondemand = new MongoConnection(); DBCursor resultdemand = mongocondemand.getDBObject("osmid", osmmodelid, "OSM"); if (resultdemand.hasNext()) { DBObject osmdemand = resultdemand.next(); osmowner = (String) osmdemand.get("osmowner"); MongoConnection mongoconcompany = new MongoConnection(); DBCursor resultcompany = mongoconcompany.getDBObject("userid", osmowner, "OSMOperator"); if (resultcompany.hasNext()) { DBObject osmcompany = resultcompany.next(); company = (String) osmcompany.get("activeCompany"); MongoConnection mongoconcompan = new MongoConnection(); DBCursor resultcompan = mongoconcompan.getDBObject("userid", osmowner, "OSMOperator"); if (resultcompan.hasNext()) { DBObject osmcompan = resultcompan.next(); /*Company compinfo = new Company(); compinfo.setCompanyid((String)osmcompan.get("companyid")); compinfo.setCompanyImageid((String)osmcompan.get("companyImageid")); compinfo.setCompanylogoid((String)osmcompan.get("companylogoid"));*/ companyid = (String) osmcompan.get("companyid"); }/*from w ww . ja v a 2 s . c om*/ } } return companyid; }
From source file:com.fliker.Modal.OSMPreview.java
public HashMap generatePaymentOptions(String projectsellerid) { // TODO Auto-generated method stub HashMap totalmap = new HashMap(); ArrayList plantypelist = new ArrayList(); ArrayList contractlist = new ArrayList(); ArrayList licenselist = new ArrayList(); MongoConnection mongocondemand = new MongoConnection(); DBCursor resultdemand = mongocondemand.getDBObject("projectsellerid", projectsellerid, "OSMProjectSeller"); if (resultdemand.hasNext()) { DBObject osmdemand = resultdemand.next(); String[] sellingploanid = (String[]) osmdemand.get("sellingplanid"); String[] sellingcontractid = (String[]) osmdemand.get("sellingcontractid"); String[] sellinglicenseid = (String[]) osmdemand.get("sellinglicenseid"); if (sellingploanid.length > 0) { for (int m = 0; m < sellingploanid.length; m++) { MongoConnection mongoconcompan = new MongoConnection(); DBCursor resultcompan = mongoconcompan.getDBObject("planid", sellingploanid[m], "Plan"); if (resultcompan.hasNext()) { DBObject osmcompan = resultcompan.next(); PlanType plantype = new PlanType(); plantype.setPlanid((String) osmcompan.get("planid")); plantype.setPlanname((String) osmcompan.get("planname")); plantype.setPlanperday((String) osmcompan.get("planperday")); plantype.setPlanamount((String) osmcompan.get("planamount")); plantype.setPlanduration((String) osmcompan.get("planduration")); plantype.setPlanpermonth((String) osmcompan.get("planpermonth")); plantype.setPlanperyear((String) osmcompan.get("planperyear")); plantypelist.add(plantype); }//from w ww . j a va 2 s . c o m } } if (sellingcontractid.length > 0) { for (int n = 0; n < sellingcontractid.length; n++) { MongoConnection mongoconcompan = new MongoConnection(); DBCursor resultcompan = mongoconcompan.getDBObject("planid", sellingcontractid[n], "Plan"); if (resultcompan.hasNext()) { DBObject osmcompan = resultcompan.next(); Contract contract = new Contract(); contract.setContractid((String) osmcompan.get("contractid")); contract.setContractdocid((String) osmcompan.get("contractdocid")); contract.setContractlegalnotice((String) osmcompan.get("contractlegalnotice")); contractlist.add(contract); } } } if (sellinglicenseid.length > 0) { for (int o = 0; o < sellinglicenseid.length; o++) { MongoConnection mongoconcompan = new MongoConnection(); DBCursor resultcompan = mongoconcompan.getDBObject("licenseid", sellinglicenseid[o], "License"); if (resultcompan.hasNext()) { DBObject osmcompan = resultcompan.next(); LicenseType license = new LicenseType(); license.setLicenseid((String) osmcompan.get("licenseid")); license.setLicenseduration((String) osmcompan.get("licenseduration")); license.setLicensetype((String) osmcompan.get("licensetype")); licenselist.add(license); } } } } totalmap.put("plan", plantypelist); totalmap.put("contract", contractlist); totalmap.put("license", licenselist); return totalmap; }
From source file:com.fliker.Modal.OSMPreview.java
public Bill generateInvestBill(String osmmodelid, String investamount, String investpercentage, String stockprice, String stockamount, String ownerid) { // TODO Auto-generated method stub Bill bill = new Bill(); OSMFileUtility osmfileutility = new OSMFileUtility(); String uniqueid = ""; try {//w ww. j a v a 2 s . co m uniqueid = osmfileutility.makeSHA1Hash(osmmodelid + stockamount); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } bill.setBillid(uniqueid); bill.setContractid(""); bill.setInvoiceid(uniqueid); bill.setLicenseid(""); String payto = ""; MongoConnection mongoconcompan = new MongoConnection(); DBCursor resultcompan = mongoconcompan.getDBObject("osmid", osmmodelid, "OSM"); if (resultcompan.hasNext()) { DBObject osmcompan = resultcompan.next(); payto = (String) osmcompan.get("osmowner"); } String totalamount = Double.toString(Double.parseDouble(stockamount) * Double.parseDouble(stockprice)); bill.setPayfromid(ownerid); bill.setPaymentmethods(""); bill.setPaytoid(payto); bill.setPlanid(""); bill.setItem("Stock"); bill.setTotalamount(totalamount); MongoConnection mongoconsearch = new MongoConnection(); // SearchPreview searchprev = new SearchPreview(); BasicDBObject basicreqobjsearch = osmfileutility.formOSMOperatorBillDBObject(bill); mongoconsearch.saveObject(basicreqobjsearch, "Bill"); return bill; }
From source file:com.fliker.Modal.OSMPreview.java
public OSMProjectInfo editProjectInfo(String osmmodelid) { // TODO Auto-generated method stub OSMProjectInfo projectinfo = new OSMProjectInfo(); MongoConnection mongoconcompan = new MongoConnection(); DBCursor resultcompan = mongoconcompan.getDBObject("osmmodelid", osmmodelid, "OSMProjectInfo"); if (resultcompan.hasNext()) { DBObject osmcompan = resultcompan.next(); projectinfo.setOsmmodelid((String) osmcompan.get("osmmodelid")); projectinfo.setOsmtype((String) osmcompan.get("osmtype")); projectinfo.setProjectbuyers((String[]) osmcompan.get("projectbuyers")); projectinfo.setProjectdemandchart((String) osmcompan.get("projectdemandchart")); projectinfo.setProjectdescription((String) osmcompan.get("projectdescription")); projectinfo.setProjectdocs((String[]) osmcompan.get("projectdocs")); projectinfo.setProjectinfoid((String) osmcompan.get("projectinfoid")); projectinfo.setProjectinvestors((String[]) osmcompan.get("projectinvestors")); projectinfo.setProjectmarkettingdoc((String) osmcompan.get("projectmarkettingdoc")); projectinfo.setProjectname((String) osmcompan.get("projectname")); }/*from ww w . j ava2 s. c om*/ return projectinfo; }
From source file:com.fpt.xml.hth.db.lib.DAO.MovieDAO.java
public List<MovieTheaterSessionDTO> getAll() { connection();/* ww w . j a va2 s . c om*/ List<MovieTheaterSessionDTO> lst = new ArrayList<MovieTheaterSessionDTO>(); DBCollection collection = movieCollection; DBCursor cursor = collection.find(); while (cursor.hasNext()) { BasicDBObject basic = (BasicDBObject) cursor.next(); MovieTheaterSessionDTO movieDto = converter.convertBasicObjectToModel(basic); lst.add(movieDto); } cursor.close(); mongoClient.close(); return lst; }
From source file:com.fpt.xml.hth.db.lib.DAO.MovieDAO.java
/** * get list movies by param city//from w ww.ja va 2 s. c o m * * @param city * @return List<MovieTheaterSessionDTO> */ public List<MovieTheaterSessionDTO> getAllByCity(String city) { connection(); List<MovieTheaterSessionDTO> lst = new ArrayList<MovieTheaterSessionDTO>(); DBCollection collection = movieCollection; BasicDBObject dbObject = new BasicDBObject(); dbObject.append("theaters", new BasicDBObject("$elemMatch", new BasicDBObject("theater.city", city))); DBCursor cursor = collection.find(dbObject); while (cursor.hasNext()) { BasicDBObject basic = (BasicDBObject) cursor.next(); MovieTheaterSessionDTO movieDto = converter.convertBasicObjectToModel(basic); // List<TheaterSessionDTO> lstTheaterSession = new ArrayList<TheaterSessionDTO>(); // if (city != null && !city.isEmpty()) { // for (TheaterSessionDTO theaterDTO : movieDto.getTheaters()) { // if (theaterDTO.getTheater().getCity().equals(city)) { // lstTheaterSession.add(theaterDTO); // } // } // } // movieDto.setTheaters(lstTheaterSession); lst.add(movieDto); } cursor.close(); mongoClient.close(); return lst; }
From source file:com.fuction.MongoDB.java
public static void display() { try {/*ww w . j a v a 2 s.co m*/ Mongo mongo = new Mongo(HOST, PORT); DB db = mongo.getDB(DB); DBCollection collection = db.getCollection("Data"); System.out.println("Collection mycol selected successfully"); DBCursor cursor = collection.find(); int i = 1; while (cursor.hasNext()) { System.out.println("Inserted Document: " + i); String jsonString = cursor.next().toString(); System.out.println(jsonString); JSONObject jsonObject = parseJSONObject(jsonString); System.out.println(jsonObject.get("Area")); i++; } } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); } }
From source file:com.fuction.MongoDB.java
public static ArrayList<InformationObj> getObj() { ArrayList<InformationObj> list = new ArrayList<>(); try {// w w w . ja v a 2s. c o m Mongo mongo = new Mongo(HOST, PORT); DB db = mongo.getDB(DB); DBCollection collection = db.getCollection("Data"); System.out.println("Collection mycol selected successfully"); DBCursor cursor = collection.find(); while (cursor.hasNext()) { String jsonString = cursor.next().toString(); //System.out.println(jsonString); JSONObject jsonObject = parseJSONObject(jsonString); String roomNumber = (String) jsonObject.get("RoomNumber"); String area = (String) jsonObject.get("Area"); String address = (String) jsonObject.get("Address"); String direction = (String) jsonObject.get("Direction"); String numberOfBedRooms = (String) jsonObject.get("NumberOfBedRooms"); String numberOfBathRooms = (String) jsonObject.get("NumberOfBathRooms"); String project = (String) jsonObject.get("Project"); String floor = (String) jsonObject.get("Floor"); String utilities = (String) jsonObject.get("Utilities"); String environment = (String) jsonObject.get("Environment"); String description = (String) jsonObject.get("Description"); String pricePerMetreSquare = (String) jsonObject.get("PricePerMetreSquare"); String price = (String) jsonObject.get("Price"); String image = (String) jsonObject.get("Image"); String city = (String) jsonObject.get("City"); String district = (String) jsonObject.get("District"); InformationObj iObj = new InformationObj(roomNumber, area, address, direction, numberOfBedRooms, numberOfBathRooms, project, floor, utilities, environment, description, pricePerMetreSquare, price, image, city, district); list.add(iObj); } } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); } return list; }
From source file:com.gatf.executor.dataprovider.MongoDBTestDataSource.java
License:Apache License
public List<Map<String, String>> provide(GatfTestDataProvider provider, AcceptanceTestContext context) { List<Map<String, String>> result = new ArrayList<Map<String, String>>(); Assert.assertNotNull("provider cannot be null", provider); Assert.assertTrue("provider cannot be null", provider.getArgs() != null && provider.getArgs().length > 0); Assert.assertNotNull("mongodb-collection cannot be empty", provider.getArgs()[0]); Assert.assertNotNull("queryString cannot be empty", provider.getQueryStr()); Assert.assertNotNull("variableNames cannot be empty", provider.getSourceProperties()); Assert.assertNotNull("propertyNames cannot be empty", provider.getProviderProperties()); String dbName = args[2].trim(); String collName = provider.getArgs()[0].trim(); String queryString = provider.getQueryStr().trim(); String variableNames = provider.getProviderProperties(); String propertyNames = provider.getSourceProperties(); Assert.assertNotNull("mongodb-collection cannot be empty", collName.isEmpty()); Assert.assertFalse("queryString cannot be empty", queryString.isEmpty()); List<String> variableNamesArr = new ArrayList<String>(); for (String varName : variableNames.split(",")) { if (!varName.trim().isEmpty()) { variableNamesArr.add(varName); }// www. ja v a 2 s . c o m } Assert.assertTrue("need to define at-least a single variable name", !variableNames.isEmpty() && variableNames.split(",").length > 0 && variableNamesArr.size() > 0); List<String> propertyNamesArr = new ArrayList<String>(); for (String varName : propertyNames.split(",")) { if (!varName.trim().isEmpty()) { propertyNamesArr.add(varName); } } Assert.assertTrue("need to define at-least a single property name", !propertyNames.isEmpty() && propertyNames.split(",").length > 0 && propertyNamesArr.size() > 0); Assert.assertTrue("property name and variable name sizes don't match", propertyNamesArr.size() == variableNamesArr.size()); StringBuilder build = new StringBuilder(); build.append("Provider configuration [\n"); build.append(String.format("dataSource name is %s\n", getDataSourceName())); build.append(String.format("mongodb-collection is %s\n", collName)); build.append(String.format("queryString is %s\n", queryString)); build.append(String.format("propertyNames is %s\n", propertyNames)); build.append(String.format("variableNames is %s]", variableNames)); logger.info(build.toString()); Resource res = null; try { res = getResource(); MongoClient mongoClient = (MongoClient) res.object; DB db = null; try { db = mongoClient.getDB(dbName); DBCollection coll = db.getCollection(collName); Assert.assertNotNull(String.format("Mongodb collection %s not found", collName), coll); DBObject queryObject = null; try { queryObject = (DBObject) JSON.parse(queryString); } catch (Exception e) { Assert.assertNotNull("queryString passed is invalid"); } DBCursor cursor = null; try { cursor = coll.find(queryObject); while (cursor.hasNext()) { DBObject object = cursor.next(); Map<String, String> row = new HashMap<String, String>(); for (int i = 0; i < variableNamesArr.size(); i++) { Assert.assertTrue( String.format("Could not find %s field in the result document returned", propertyNamesArr.get(i)), object.containsField(propertyNamesArr.get(i))); row.put(variableNamesArr.get(i), object.get(propertyNamesArr.get(i)).toString()); } result.add(row); } } catch (Exception e) { throw new AssertionError(e); } finally { if (cursor != null) cursor.close(); } } catch (Exception e) { throw new AssertionError( String.format("Fetching Test Data failed while executing query %s with the error %s", queryString, ExceptionUtils.getStackTrace(e))); } finally { if (mongoClient != null) mongoClient.close(); } } catch (Exception e) { throw new AssertionError( String.format("Fetching Test Data failed while executing query %s with the error %s", queryString, ExceptionUtils.getStackTrace(e))); } finally { if (res != null) releaseToPool(res); } return result; }
From source file:com.gederin.blog.dao.BlogPostDAO.java
License:Apache License
public List<DBObject> findByDateDescending(int limit) { List<DBObject> posts = null; posts = new ArrayList<DBObject>(); DBCursor dbCursor = this.postsCollection.find().sort(new BasicDBObject("date", -1)).limit(limit); try {//from w w w . j av a 2 s . c o m while (dbCursor.hasNext()) { DBObject dbObject = dbCursor.next(); posts.add(dbObject); } } finally { dbCursor.close(); } // XXX HW 3.2, Work Here // Return a list of DBObjects, each one a post from the posts collection return posts; }