예제 #1
0
 public String getUserNameWithEmail(final String email) {
   try {
     final MongoDatabase mdb = MongoDBConnManager.getInstance().getConnection();
     final MongoCollection<Document> coll = mdb.getCollection(DBConstants.COLL_USERS);
     final Document bson = new Document();
     bson.put(DBConstants.EMAIL, email);
     final List<Document> users = coll.find(bson).into(new ArrayList<Document>());
     if (users == null || (users != null && users.size() == 0)) {
       return "";
     } else {
       // '0' index is accessed because email is uniquely maintained at DB level
       return users.get(0).getString(DBConstants.USER_NAME);
     }
   } catch (Exception e) {
     if (e instanceof com.mongodb.MongoTimeoutException) {
       throw new ApplicationException(MessagesEnum.MONGODB_IS_DOWN.getMessage(), e);
     }
     throw new ApplicationException(MessagesEnum.RETRIVAL_FAILED.getMessage(email), e);
   }
 }
예제 #2
0
 public String getBoxOwner(final String boxName) {
   try {
     final MongoDatabase mdb = MongoDBConnManager.getInstance().getConnection();
     final MongoCollection<Document> coll = mdb.getCollection(DBConstants.COLL_BOXES);
     final Document bson = new Document();
     bson.put(DBConstants.BOX_NAME, boxName);
     final List<Document> boxes = coll.find(bson).into(new ArrayList<Document>());
     if (boxes == null || (boxes != null && boxes.size() == 0)) {
       return "";
     } else {
       // '0' index is accessed because boxes are uniquely maintained at DB level
       return boxes.get(0).getString(DBConstants.OWNER);
     }
   } catch (Exception e) {
     if (e instanceof com.mongodb.MongoTimeoutException) {
       throw new ApplicationException(MessagesEnum.MONGODB_IS_DOWN.getMessage(), e);
     }
     throw new ApplicationException(MessagesEnum.RETRIVAL_FAILED.getMessage(), e);
   }
 }