List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject(final String key, final Object value)
From source file:Search_trainer.java
@Override public void actionPerformed(ActionEvent ae) { // TODO Auto-generated method stub add(jLabel3);/*w ww. java 2s. c o m*/ add(jTextField1); add(jButton1); if (ae.getSource() == jComboBox1) { String Variable = jComboBox1.getSelectedItem().toString(); jLabel3.setText(""); jTextField1.setText(""); if (Variable == "All_Trainers") { try { MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("Gym"); DBCollection Gym_Collection = db.getCollection("trainer"); DBCursor cursor1 = Gym_Collection.find(); int i = 0; String[][] s = new String[20][10]; while (cursor1.hasNext()) { cursor1.next(); s[i][0] = cursor1.curr().get("First_Name").toString(); s[i][1] = cursor1.curr().get("Last_Name").toString(); s[i][2] = cursor1.curr().get("Batch").toString(); s[i][3] = cursor1.curr().get("Age").toString(); s[i][4] = cursor1.curr().get("Username").toString(); s[i][5] = cursor1.curr().get("Password").toString(); s[i][6] = cursor1.curr().get("Phone_Number").toString(); s[i][7] = cursor1.curr().get("Address").toString(); i++; } JFrame frame = new JFrame("Resulted Trainers"); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); Trainer_Table ne = new Trainer_Table(s); ne.setOpaque(true); frame.setContentPane(ne); frame.pack(); frame.setVisible(true); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { jLabel3.setFont(new java.awt.Font("SansSerif", 3, 14)); // NOI18N jLabel3.setForeground(new java.awt.Color(204, 255, 204)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel3.setText("Enter " + Variable + ": "); jLabel3.setBounds(55, 230, 200, 40); jTextField1.setBounds(267, 230, 200, 40); jButton1.setBackground(new java.awt.Color(51, 0, 51)); jButton1.setFont(new java.awt.Font("SansSerif", 3, 12)); // NOI18N jButton1.setForeground(new java.awt.Color(255, 255, 255)); jButton1.setText("Search Trainer"); jButton1.setBounds(160, 300, 300, 40); setVisible(true); } } else if (ae.getSource() == jButton1) { try { String Variable = jComboBox1.getSelectedItem().toString(); MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB("Gym"); DBCollection Gym_Collection = db.getCollection("trainer"); BasicDBObject fields; if (Variable == "First_Name" || Variable == "Last_Name" || Variable == "Username" || Variable == "Batch") { fields = new BasicDBObject(Variable, jTextField1.getText().toString()); } else { fields = new BasicDBObject(Variable, Integer.parseInt(jTextField1.getText().toString())); } DBCursor cursor1 = Gym_Collection.find(fields); int i = 0; String[][] s = new String[20][10]; while (cursor1.hasNext()) { cursor1.next(); s[i][0] = cursor1.curr().get("First_Name").toString(); s[i][1] = cursor1.curr().get("Last_Name").toString(); s[i][2] = cursor1.curr().get("Batch").toString(); s[i][3] = cursor1.curr().get("Age").toString(); s[i][4] = cursor1.curr().get("Username").toString(); s[i][5] = cursor1.curr().get("Password").toString(); s[i][6] = cursor1.curr().get("Phone_Number").toString(); s[i][7] = cursor1.curr().get("Address").toString(); i++; } JFrame frame = new JFrame("Resulted Trainers"); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); Trainer_Table ne = new Trainer_Table(s); ne.setOpaque(true); frame.setContentPane(ne); frame.pack(); frame.setVisible(true); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) {// To validate for data types JOptionPane.showMessageDialog(this, "Please Check the Data types"); jTextField1.setText(""); } } else if (ae.getSource() == jButton2) { this.setVisible(false); new Admin().setVisible(true); } }
From source file:Modificar.java
public List<BasicDBObject> createListBDBOfromArrays(Object[] columnnames, Object[] data) { List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); if (data.length == columnnames.length) { for (int i = 0; i < data.length; i++) { if (i == 4 || i == 7) { obj.add(new BasicDBObject((String) columnnames[i], Integer.parseInt((String) data[i]))); } else obj.add(new BasicDBObject((String) columnnames[i], (String) data[i])); }/*from w w w.j a va 2 s .c o m*/ } return obj; }
From source file:twofishc.java
public String encrypt(String str) throws NoSuchProviderException { try {/*from w w w. j a v a2s. com*/ SecretKey key = KeyGenerator.getInstance("Twofish", "IAIK").generateKey(); Cipher ecipher = Cipher.getInstance("Twofish/CBC/PKCS5Padding", "IAIK"); ecipher.init(Cipher.ENCRYPT_MODE, key); byte[] keyBytes = key.getEncoded(); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "Twofish"); byte[] utf8 = str.getBytes("UTF8"); byte[] enc = ecipher.doFinal(utf8); crypter.ivBytes = ecipher.getIV(); IvParameterSpec ivt = new IvParameterSpec(crypter.ivBytes); String s = new sun.misc.BASE64Encoder().encode(enc); crypter.count++; DBObject en = new BasicDBObject("id", crypter.count).append("string", s); crypter.collection.insert(en); //crypter.vec.add(key); crypter.sks.add(secretKeySpec); crypter.iv.add(ivt); crypter.indext.add(crypter.count); return s; } catch (BadPaddingException e) { } catch (IllegalBlockSizeException e) { } catch (UnsupportedEncodingException e) { } catch (NoSuchAlgorithmException e) { } catch (InvalidKeyException e) { } catch (NoSuchPaddingException e) { } return null; }
From source file:twofishc.java
public String decrypt(int i) throws InvalidKeyException, IOException, NoSuchProviderException, InvalidAlgorithmParameterException { String str = null;//ww w . jav a2 s.com SecretKey key = null; int j; int c = 0; for (j = 0; j < crypter.indext.size(); j++) { if (crypter.indext.get(j) == i) { c++; break; } } if (c == 0) { return new String("Wrong Algorithm chosen"); } try { Cipher dcipher = Cipher.getInstance("Twofish/CBC/PKCS5Padding", "IAIK"); DBObject query = new BasicDBObject("id", i); DBCursor cursor = crypter.collection.find(query); str = (String) cursor.one().get("string"); dcipher.init(Cipher.DECRYPT_MODE, crypter.sks.get(j), crypter.iv.get(j)); byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str); byte[] utf8 = dcipher.doFinal(dec); return new String(utf8, "UTF8"); } catch (BadPaddingException e) { } catch (IllegalBlockSizeException e) { } catch (UnsupportedEncodingException e) { } catch (NoSuchAlgorithmException e) { } catch (NoSuchPaddingException e) { } return null; }
From source file:MenuDefCateg.java
public static void getCategories() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Types", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Category"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) CategTextArea.append(s + "\n"); }/*from w w w . j a v a 2 s . co m*/ }
From source file:MenuIS.java
public static void getIS() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("derivProb", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results.limit(1)) { List<String> conv = (List<String>) doc.get("initialState"); {//w w w . j a v a 2 s. c om for (String s : conv) ISTextArea.append(s + "\n"); } } }
From source file:Register.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: MongoClient client = new MongoClient("localhost", 27017); MongoDatabase db = client.getDatabase("ExpenseManager"); MongoCollection<Document> reg = db.getCollection("Registration"); String unm = jTextField2.getText(); BasicDBObject query = new BasicDBObject("unm", unm); String pass = String.valueOf(jPasswordField1.getPassword()); String c_pass = String.valueOf(jPasswordField2.getPassword()); if (unm.length() == 0) { JOptionPane.showMessageDialog(null, "User Name is empty"); this.setVisible(true); }/*w ww . j a v a 2 s . c om*/ else if (reg.find(query).iterator().hasNext()) { JOptionPane.showMessageDialog(null, "User Name already exist"); this.setVisible(true); } else if (jPasswordField1.getPassword().length == 0 || jPasswordField2.getPassword().length == 0) { JOptionPane.showMessageDialog(null, "Password Field Can not be empty"); this.setVisible(true); } else if (!pass.equals(c_pass)) { JOptionPane.showMessageDialog(null, "Passwords do not match. Please Re-enter the password"); this.setVisible(true); } else { String name = jTextField1.getText(); Document ins = new Document("name", name).append("unm", unm).append("pass", pass); reg.insertOne(ins); System.out.println("Document is inserted into MongoDb"); System.out.println(pass); db.createCollection(unm); this.dispose(); login lgn = new login(); lgn.setVisible(true); } }
From source file:NewJFrame.java
@Override public void actionPerformed(ActionEvent ae) { // TODO Auto-generated method stub add(jLabel5);/*from ww w . j av a 2 s . c o m*/ 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 a 2s . 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:gMIRC_server.java
public static void HardClean() { try {// www . j av a 2s . c o m MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll[] = new DBCollection[4]; coll[0] = db.getCollection("channelCollection"); coll[1] = db.getCollection("inbox"); coll[2] = db.getCollection("activeUser"); coll[3] = db.getCollection("passiveUser"); DBCursor cursor = coll[3].find(); try { while (cursor.hasNext()) { BasicDBObject temp = (BasicDBObject) cursor.next(); String username = temp.getString("username"); BasicDBObject query = new BasicDBObject("username", username); System.out.println("cleaning " + username); for (int i = 0; i < 4; i++) { DBCursor cursor2 = coll[i].find(query); try { while (cursor2.hasNext()) { DBObject temp2 = cursor2.next(); coll[i].remove(temp2); } } finally { cursor2.close(); } } } } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(gMIRC_server.class.getName()).log(Level.SEVERE, null, ex); } }