List of usage examples for com.mongodb DBObject get
Object get(String key);
From source file:at.ac.tuwien.dsg.smartcom.services.dao.MongoDBMessageInfoDAO.java
License:Apache License
MessageInformation deserializeMessageInfo(DBObject dbObject) { MessageInformation info = new MessageInformation(); if (dbObject.containsField("_id")) { info.setKey(deserializeKey((DBObject) dbObject.get("_id"))); }// w w w. ja v a 2 s. com if (dbObject.containsField("purpose")) { info.setPurpose((String) dbObject.get("purpose")); } if (dbObject.containsField("validAnswer")) { info.setValidAnswer((String) dbObject.get("validAnswer")); } if (dbObject.containsField("validAnswerTypes")) { List<MessageInformation.Key> validAnswers = new ArrayList<>(); BasicDBList list = (BasicDBList) dbObject.get("validAnswerTypes"); for (Object o : list) { validAnswers.add(deserializeKey((DBObject) o)); } info.setValidAnswerTypes(validAnswers); } if (dbObject.containsField("relatedMessages")) { List<MessageInformation.Key> related = new ArrayList<>(); BasicDBList list = (BasicDBList) dbObject.get("relatedMessages"); for (Object o : list) { related.add(deserializeKey((DBObject) o)); } info.setRelatedMessages(related); } return info; }
From source file:at.ac.tuwien.dsg.smartcom.services.dao.MongoDBMessageInfoDAO.java
License:Apache License
MessageInformation.Key deserializeKey(DBObject dbObject) { String type = (String) dbObject.get("type"); String subtype = (String) dbObject.get("subtype"); return new MessageInformation.Key(type, subtype); }
From source file:at.tuwien.aic.Main.java
private static void classifyTopic() { String topic = getNonEmptyString("Enter a topic you want to query"); Mongo mongo;/*from ww w . j a va 2s. c om*/ DB db = null; try { mongo = new Mongo(_prop.getProperty("db_host")); db = mongo.getDB(_prop.getProperty("db_name")); } catch (UnknownHostException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); return; } Classifier c = ClassifyTweet.loadModel("resources/classifier.model"); TweetScorer scorer = new TweetScorer(); DBCollection tweetCollection = db.getCollection("tweets"); Pattern pattern = Pattern.compile("^.+" + topic + ".+$"); DBObject query = QueryBuilder.start("text").regex(pattern).get(); DBCursor resultSet = tweetCollection.find(query); int count = 0; double value = 0; double tweetClassifiedScore = 0; double tweetPosUserScore = 0; double tweetNegUserScore = 0; while (resultSet.hasNext()) { try { DBObject obj = resultSet.next(); String tweetText = (String) obj.get("text"); tweetClassifiedScore += ClassifyTweet.classifyTweet(c, tweetText); double score = scorer.scoreTweet(obj); if (tweetClassifiedScore > 0) { tweetPosUserScore += score; } else { tweetNegUserScore += score; } ++count; } catch (NumberFormatException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } // Normalizing between 0 an 1 value = tweetPosUserScore / (tweetPosUserScore + tweetNegUserScore); System.out.println("This topic has a sentiment value of: " + value); }
From source file:backend.facades.UserController.java
public List<UserEntity> getUserList() { List<UserEntity> userList = new ArrayList<UserEntity>(); String sort = "registeredDate"; String order = "desc"; DBObject sortCriteria = new BasicDBObject(sort, "desc".equals(order) ? -1 : 1); BasicDBObject query = new BasicDBObject(); DBCursor cursor = userCollection.find(query).sort(sortCriteria); try {/*from w ww .j av a2s .co m*/ while (cursor.hasNext()) { DBObject document = cursor.next(); UserEntity userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); Integer value = (Integer) document.get("subscribe"); userEntity.setPersonalWebPage((String) document.get("webpage")); if (value != null && value.equals(StatusTypes.ACCEPT_LICENSE)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } userList.add(userEntity); } } finally { cursor.close(); } return userList; }
From source file:backend.facades.UserController.java
public List<UserEntity> getSubscribersList() { UserEntity userEntity = null;/* ww w . j a v a 2 s . c o m*/ List<UserEntity> userList = new ArrayList<UserEntity>(); BasicDBObject query = new BasicDBObject(); query.put("subscribe", StatusTypes.ACCEPT_SUBSCRB); DBCursor cursor = userCollection.find(query); try { while (cursor.hasNext()) { DBObject document = cursor.next(); userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); userEntity.setPersonalWebPage((String) document.get("webpage")); Integer value = (Integer) document.get("subscribe"); if (value != null && value.equals(StatusTypes.ACCEPT_LICENSE)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } userList.add(userEntity); } } finally { cursor.close(); } return userList; }
From source file:backend.facades.UserController.java
public UserEntity getUserByEmail(String email) { UserEntity userEntity = null;/*from w w w . j a v a 2 s.c om*/ BasicDBObject query = new BasicDBObject(); query.put("email", email); DBCursor cursor = userCollection.find(query); try { if (cursor.count() > 0) { DBObject document = cursor.next(); userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); userEntity.setPersonalWebPage((String) document.get("webpage")); Integer value = (Integer) document.get("subscribe"); if (value != null && value.equals(StatusTypes.ACCEPT_LICENSE)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } } } finally { cursor.close(); } return userEntity; }
From source file:backend.facades.UserController.java
public UserEntity getUserById(Long id) { UserEntity userEntity = null;/* ww w. j av a 2 s . c o m*/ BasicDBObject query = new BasicDBObject(); query.put("_id", id); DBCursor cursor = userCollection.find(query); try { if (cursor.count() > 0) { DBObject document = cursor.next(); userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); Integer value = (Integer) document.get("subscribe"); userEntity.setPersonalWebPage((String) document.get("webpage")); if (value != null && value.equals(StatusTypes.ACCEPT_SUBSCRB)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } } } finally { cursor.close(); } return userEntity; }
From source file:backend.facades.UserController.java
public Long getUserIdByEmail(String email) { Long id = 0L;/*from ww w .j av a 2s .c o m*/ BasicDBObject query = new BasicDBObject(); query.put("email", email); DBCursor cursor = userCollection.find(query); try { if (cursor.count() > 0) { DBObject document = cursor.next(); id = (Long) document.get("_id"); } } finally { cursor.close(); } return id; }
From source file:backend.facades.UserController.java
protected static String getNextId(DB db, String seq_name) { String sequence_collection = "seq"; // the name of the sequence collection String sequence_field = "seq"; // the name of the field which holds the sequence DBCollection seq = db.getCollection(sequence_collection); // get the collection (this will create it if needed) if (seq == null) { seq = db.createCollection(sequence_collection, null); }/*from w w w . ja v a 2 s . c om*/ // this object represents your "query", its analogous to a WHERE clause in SQL DBObject query = new BasicDBObject(); query.put("_id", seq_name); // where _id = the input sequence name // this object represents the "update" or the SET blah=blah in SQL DBObject change = new BasicDBObject(sequence_field, 1); DBObject update = new BasicDBObject("$inc", change); // the $inc here is a mongodb command for increment // Atomically updates the sequence field and returns the value for you DBObject res = seq.findAndModify(query, new BasicDBObject(), new BasicDBObject(), false, update, true, true); return res.get(sequence_field).toString(); }
From source file:be.solidx.hot.data.mongo.DBObjectMapTransformer.java
License:Open Source License
public Map<String, Object> dbObjectTomap(DBObject dbObject) { if (dbObject == null) return null; Map<String, Object> map = new LinkedHashMap<String, Object>(); for (String key : dbObject.keySet()) { if (dbObject.get(key) instanceof List<?>) { map.put(key.toString(), transformList((List<?>) dbObject.get(key))); } else if (dbObject.get(key) instanceof DBObject) { map.put(key.toString(), dbObjectTomap((DBObject) dbObject.get(key))); } else {//from w w w . ja v a2 s. co m map.put(key.toString(), key.equals("_id") ? dbObject.get(key).toString() : dbObject.get(key)); } } return map; }