List of usage examples for com.mongodb DBCollection find
public DBCursor find(final DBObject query)
From source file:Welcome.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed String accno = JOptionPane.showInputDialog(this, "Enter Your Account Number"); if (isInteger(accno)) { int value = JOptionPane.showConfirmDialog(this, "Do You Want to add Account No. " + accno); if (value == 0) { String Banks[] = { "", "Allahabad Bank", "Andhra Bank", "Bank of Baroda", "Bank of India", "Bank of Maharashtra", "Canara Bank", "Central Bank of India", "Corporation Bank", "Dena Bank", "Indian Bank", "Indian Overseas Bank", "Oriental Bank of Commerce", "Punjab & Sind Bank", "Punjab National Bank", "Syndicate Bank", "UCO Bank", "Union Bank of India", "United Bank of India", "Vijaya Bank", "Axis Bank", "City Union Bank", "Dhanlaxmi Bank", "Federal Bank", "HDFC Bank", "ICICI Bank", "IDFC Bank", "Karnataka Bank", "IndusInd Bank", "ING Vysya Bank", "Jammu and Kashmir Bank", "Karur Vysya Bank", "Kotak Mahindra Bank", "Yes bank", "Citi Bank", "State Bank of India", "State Bank of Patiala", "State Bank of Mysore", "State Bank of Travancore", "State Bank of Bikaner and Jaipur", "State Bank of Hyderabad", "State Bank Of Saurashtra" };//from www . jav a 2 s .c om Arrays.sort(Banks); JComboBox jcb = new JComboBox(Banks); jcb.setEditable(true); JOptionPane.showMessageDialog(this, jcb, "Select Your Bank", JOptionPane.QUESTION_MESSAGE); while (jcb.getSelectedItem().equals("")) { JOptionPane.showMessageDialog(this, "Please Select the Bank"); JOptionPane.showMessageDialog(this, jcb, "Select Your Bank", JOptionPane.QUESTION_MESSAGE); } String money = JOptionPane.showInputDialog(this, "Enter the amount present in " + accno + " account"); String Bank = (String) jcb.getSelectedItem(); while (!isInteger(money)) { JOptionPane.showMessageDialog(this, "You entered a Wrong Value. Please Enter Correct Value"); money = JOptionPane.showInputDialog(this, "Enter the amount present in " + accno + " account"); } MongoClient client = new MongoClient("localhost", 27017); DB db; db = client.getDB("ExpenseManager"); DBCollection reg = (DBCollection) db.getCollection("Registration"); DBObject query = new BasicDBObject("unm", unm); DBObject update = new BasicDBObject(); DBCursor find = reg.find(query); while (find.hasNext()) { DBObject next = find.next(); int count = 1; for (int i = 1; i <= 5; i++) { String str1 = "Account" + i; String str2 = "Bank" + i; String str3 = "Money" + i; System.out.println(str1); if (!(next.containsField(str1))) { update.put("$set", new BasicDBObject(str1, accno).append(str2, Bank).append(str3, money)); WriteResult result = reg.update(query, update); setListVal(); break; } } } } } else { JOptionPane.showMessageDialog(this, "You Entered a wrong Number"); } // TODO add your handling code here: }
From source file:mail.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int success = 0; String id = request.getParameter("email"); System.out.println(id);/*from w w w. ja va2 s.c o m*/ //String id="anjaliverma25792@gmail.com"; MongoClient mongo = new MongoClient(); DB db = mongo.getDB("WebDB"); DBCollection table = db.getCollection("User"); Document d = new Document(); d.put("Email", id); DBObject ob = new BasicDBObject(d); DBCursor cur = table.find(ob); System.out.println(cur.size()); System.out.println("Above value"); String user = null; if (cur.hasNext()) { success = 1; cur.next(); DBObject temp = cur.curr(); String pass = (String) temp.get("Password"); HttpSession session = request.getSession(); user = (String) temp.get("Name"); final String username = "nature.lover.ritika@gmail.com"; final String password = "ritika7vision"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session sess = Session.getInstance(props, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(sess); message.setFrom(new InternetAddress("papertree.official@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(id)); //retrive email id from forgot your password form. message.setSubject("PaperTree: Password Reset"); message.setText("Dear, " + user + ". Your password is " + pass + ". \n\n Directly LOGIN And START READING..."); Transport.send(message); // Mongo DB connectivity LEFT // response.sendRedirect("success.jsp"); } catch (MessagingException e) { throw new RuntimeException(e); } } if (success == 1) { response.sendRedirect("success.jsp?success=yes"); } else { response.sendRedirect("success.jsp?success=no"); } }
From source file:TeacherOne.java
private void GetdataBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GetdataBtnActionPerformed // TODO add your handling code here: stuFirst = FirstnameField.getText(); stuMid = MidnameField.getText();/* ww w.j ava 2 s. c om*/ stuLast = LastnameField.getText(); grade = Integer.parseInt(GradeField.getText()); section = Integer.parseInt(SectionField.getText()); DBCollection coll = db.getCollection("student"); BasicDBObject andQuery = new BasicDBObject(); List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); obj.add(new BasicDBObject("firstname", stuFirst)); obj.add(new BasicDBObject("mid_name", stuMid)); obj.add(new BasicDBObject("lastname", stuLast)); obj.add(new BasicDBObject("grade", grade)); obj.add(new BasicDBObject("section", section)); andQuery.put("$and", obj); DBCursor cursor = coll.find(andQuery); if (cursor.count() != 0) { UpdateBtn.setVisible(true); MidField.setVisible(true); FinalField.setVisible(true); jLabel6.setVisible(true); jLabel7.setVisible(true); jLabel8.setVisible(true); BasicDBList marks = (BasicDBList) cursor.next().get("marks"); for (int j = 0; j < marks.size(); ++j) { BasicDBObject mark = (BasicDBObject) marks.get(j); if (mark.getString("teacher").equals(firstname)) { if (mark.get("mid") == null) { MidField.setText("-1"); FinalField.setText("-1"); } else if (mark.get("mid") != null && mark.get("final") == null) { MidField.setText(mark.getString("mid")); FinalField.setText("-1"); } else { MidField.setText(mark.getString("mid")); FinalField.setText(mark.getString("final")); } } } } else { JOptionPane.showMessageDialog(null, "wrong data,try again!"); FirstnameField.setText(""); MidnameField.setText(""); LastnameField.setText(""); GradeField.setText(""); SectionField.setText(""); } }
From source file:NewJFrame.java
@Override public void actionPerformed(ActionEvent ae) { // TODO Auto-generated method stub add(jLabel5);//from w w w . j ava 2s . c om String user = jTextField1.getText().toString(); @SuppressWarnings("deprecation") String pass = jPassword1.getText().toString(); jLabel5.setText(""); if (ae.getSource() == jButton1) { if ((String) jComboBox1.getSelectedItem() == "Admin") { if (user.equals("admin") && pass.equals("admin123")) { this.setVisible(false); new Admin().setVisible(true); } else { jLabel5.setFont(new java.awt.Font("SansSerif", 3, 14)); // NOI18N jLabel5.setForeground(new java.awt.Color(25, 25, 112)); jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel5.setText("Login Not Successful "); jTextField1.setText(""); jPassword1.setText(""); jLabel5.setBounds(120, 245, 170, 50); } } else if ((String) jComboBox1.getSelectedItem() == "Trainer") { try { MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("Gym"); DBCollection Gym_Collection = db.getCollection("trainer"); BasicDBObject fields = new BasicDBObject("Username", user).append("Password", pass); String s; DBCursor cursor1 = Gym_Collection.find(fields); if (cursor1.hasNext()) { cursor1.next(); s = cursor1.curr().get("First_Name").toString(); new Receptionist(s); this.setVisible(false); new Receptionist().setVisible(true); } else { jLabel5.setFont(new java.awt.Font("SansSerif", 3, 14)); // NOI18N jLabel5.setForeground(new java.awt.Color(25, 25, 112)); jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel5.setText("Login Not Successful "); jTextField1.setText(""); jPassword1.setText(""); jLabel5.setBounds(120, 245, 170, 50); } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:RestrictedService.java
License:Open Source License
/** * @param textToAnalize// w ww. ja v a2 s . c o m * @param collectionName * @return * @throws Exception */ public static HttpEntity callANEW(String textToAnalize, String collectionName) throws Exception { String[] wordsInText = (textToAnalize + " ").split(" "); String wordAndValues[][] = new String[wordsInText.length][5]; //initialize the wordAndValues int position = 0; //Aux variable to see the position of each word inside the document String polarityAndValue[] = new String[2]; DBCollection coll = db.getCollection(collectionName); Double positive = 0.0; Double negative = 0.0; for (int i = 0; i < wordsInText.length; i++) { //For each word wordAndValues[i][0] = wordsInText[i]; //We save the word wordAndValues[i][1] = Integer.toString(position); //add its initial position += (wordsInText[i].length() - 1); wordAndValues[i][2] = Integer.toString(position);//and final position position += 2; //This is where the next word starts //We check if this word has a positive or negative annotation and set its value and polarity. BasicDBObject query = new BasicDBObject("Word", wordsInText[i].toLowerCase()); DBCursor cursor = coll.find(query); Double value = 5.0; try { while (cursor.hasNext()) { value = (Double) cursor.next().get("ValMn"); } } finally { cursor.close(); } if (value > 5) { wordAndValues[i][3] = "1.0"; wordAndValues[i][4] = "Positive"; positive++; } else if (value < 5) { wordAndValues[i][3] = "-1.0"; wordAndValues[i][4] = "Negative"; negative++; } else { wordAndValues[i][3] = "0.0"; wordAndValues[i][4] = "Neutral"; } polarityAndValue[0] = Double.toString(0); if ((positive + negative) != 0) { polarityAndValue[0] = Double.toString((positive - negative) / (positive + negative)); } if (new Double(polarityAndValue[0]) > 0) { polarityAndValue[1] = "Positive"; } else if (new Double(polarityAndValue[0]) < 0) { polarityAndValue[1] = "Negative"; } else { polarityAndValue[1] = "Neutral"; } } return callMarl(textToAnalize, wordAndValues, polarityAndValue); }
From source file:aic2013.extractor.MongoDataAccess.java
public void forAllByUserId(long id, Processor<Status> processor) { DB db = mongoClient.getDB("twitterdb"); DBCollection statusCollection = db.getCollection("statuses"); DBCursor cursor = statusCollection.find(new BasicDBObject("user.id", id)); while (cursor.hasNext()) { try {// w ww . j av a2s . co m processor.process(DataObjectFactory.createStatus(cursor.next().toString())); } catch (TwitterException ex) { Logger.getLogger(MongoDataAccess.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static String getSpecialToken(Applango applango, DBCollection coll) { logger.info("Get the email token of : " + applango.getUsername()); String token;// w w w . j a v a 2 s. c o m int maxWait = 10; try { String jsonCustomer = "{'userId' : '" + applango.getUsername() + "'}"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); while ((coll.count(dbObjectRecordQuery) == 0) && maxWait > 0) { sleep(1000); maxWait--; } token = coll.find(dbObjectRecordQuery).next().get("specialToken").toString(); } catch (Exception ex) { token = null; logger.error(ex.getMessage()); } return token; }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static int getPriceByLicenseType(DBCollection appInfoConnection, String licenseType) { String jsonCustomer = "{$and : [{'licenseType' : '" + licenseType + "'}, {'customerId': 'automationCustomer'} ]}"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); Object strPrice = appInfoConnection.find(dbObjectRecordQuery).next().get("price"); System.out.println("The price for " + licenseType + " is " + strPrice); return (Integer) strPrice; }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static String getActivityWeight(DBCollection coll, String weightName) { String activityWeight;/* w ww. j a va2 s . c om*/ int maxWait = 10; try { String jsonCustomer = "{$and : [{'weightName' : '" + weightName + "'}, {'customerId': 'automationCustomer'} ]}"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); while ((coll.count(dbObjectRecordQuery) == 0) && maxWait > 0) { sleep(1000); maxWait--; } activityWeight = coll.find(dbObjectRecordQuery).next().get("activityWeight").toString(); } catch (Exception ex) { activityWeight = null; logger.error(ex.getMessage()); } return activityWeight; }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static DBObject getRollupValue(DBCollection coll, String userId) { logger.info("Getting today's rollup record for user " + userId); DBCursor cursor;/* w w w . j a va2 s. com*/ int maxWait = 10; try { DateTime jsonToday = new DateTime(); DateTime yesterday = new DateTime().minusDays(1); Date yesterdayDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(yesterday.toString()); BasicDBObject dateQueryObj = new BasicDBObject("beginDate", new BasicDBObject("$gt", yesterdayDate)); dateQueryObj.append("userId", userId); dateQueryObj.append("customerId", "automationCustomer"); dateQueryObj.append("appName", "salesforce"); cursor = coll.find(dateQueryObj); while ((cursor.count() == 0) && maxWait > 0) { sleep(1000); maxWait--; } } catch (Exception ex) { cursor = null; logger.error(ex.getMessage()); } return cursor.next(); }