List of usage examples for com.mongodb.client MongoCollection find
FindIterable<TDocument> find(ClientSession clientSession);
From source file:com.shampan.model.PageModel.java
public JSONObject getSliderPhotos(String userId, String referenceId) { JSONObject userStatusInfo = new JSONObject(); try {//from ww w.ja v a2s. co m MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEPHOTOS.toString(), PagePhotoDAO.class); Document selectionDocument = new Document(); selectionDocument.put("referenceId", referenceId); MongoCursor<PagePhotoDAO> photoList = mongoCollection.find(selectionDocument).iterator(); List<JSONObject> photoInfoList = getPhotoInfo(userId, photoList); userStatusInfo.put("photoList", photoInfoList); userStatusInfo.put("userCurrentTime", utility.getCurrentTime()); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return userStatusInfo; }
From source file:com.shampan.model.PageModel.java
public ResultEvent getTimelinePhotos(String pageId) { try {/*from ww w . jav a2s . c om*/ MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEPHOTOS.toString(), PagePhotoDAO.class); Document selectionDocument = new Document(); selectionDocument.put("pageId", pageId); selectionDocument.put("albumId", PropertyProvider.get("TIMELINE_PHOTOS_ALBUM_ID")); MongoCursor<PagePhotoDAO> photoList = mongoCollection.find(selectionDocument).iterator(); List<PagePhotoDAO> photoInfoList = IteratorUtils.toList(photoList); this.getResultEvent().setResult(photoInfoList); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }
From source file:com.shampan.model.PageModel.java
public List<PagePhotoDAO> getPhotos(String mappingId, String albumId) { MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.ALBUMPHOTOS.toString(), PagePhotoDAO.class); Document selectDocument = new Document(); selectDocument.put("pageId", mappingId); selectDocument.put("albumId", albumId); Document pQurey = new Document(); pQurey.put("photoId", "$all"); pQurey.put("albumId", "$all"); pQurey.put("pageId", "$all"); pQurey.put("image", "$all"); MongoCursor<PagePhotoDAO> cursorStatusInfoList = mongoCollection.find(selectDocument).projection(pQurey) .iterator();// w ww .j av a 2 s . c o m List<PagePhotoDAO> photoList = IteratorUtils.toList(cursorStatusInfoList); return photoList; }
From source file:com.shampan.model.PageModel.java
public JSONObject getSliderAlbum(String mappingId, String albumId, String userId) { JSONObject userStatusInfo = new JSONObject(); try {//www . j a v a2 s .c om MongoCollection<PagePhotoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEPHOTOS.toString(), PagePhotoDAO.class); Document selectionDocument = new Document(); selectionDocument.put("albumId", albumId); selectionDocument.put("pageId", mappingId); MongoCursor<PagePhotoDAO> photoList = mongoCollection.find(selectionDocument).iterator(); List<JSONObject> photoInfoList = getPhotoInfo(userId, photoList); userStatusInfo.put("photoList", photoInfoList); userStatusInfo.put("pageInfo", getPageInfo(mappingId)); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return userStatusInfo; }
From source file:com.shampan.model.SearchModel.java
/** * This method will return users// www .j a v a 2s. c o m * * @param requestPatten, request String * @return users */ public List<UserDAO> getUsers(String searchValue, int offset, int limit) { MongoCollection<UserDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), UserDAO.class); String attrUserId = PropertyProvider.get("USER_ID"); String attrFirstName = PropertyProvider.get("FIRST_NAME"); String attrLastName = PropertyProvider.get("LAST_NAME"); Document selectDocument = new Document(); selectDocument.put("$regex", searchValue); selectDocument.put("$options", 'i'); List<Document> orDocument = new ArrayList<Document>(); orDocument.add(new Document(attrFirstName, selectDocument)); orDocument.add(new Document(attrLastName, selectDocument)); Document sDocument = new Document(); sDocument.put("$or", orDocument); Document projectionDocument = new Document(); projectionDocument.put(attrUserId, "$all"); projectionDocument.put(attrFirstName, "$all"); projectionDocument.put(attrLastName, "$all"); projectionDocument.put("gender", "$all"); MongoCursor<UserDAO> userList = mongoCollection.find(sDocument).projection(projectionDocument).skip(offset) .limit(limit).iterator(); List<UserDAO> userInfoList = IteratorUtils.toList(userList); return userInfoList; }
From source file:com.shampan.model.SearchModel.java
public List<PageDAO> getPages(String searchValue, int offset, int limit) { MongoCollection<PageDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGES.toString(), PageDAO.class); Document selectDocument = new Document(); selectDocument.put("$regex", searchValue); selectDocument.put("$options", 'i'); List<Document> orDocument = new ArrayList<Document>(); orDocument.add(new Document("title", selectDocument)); Document sDocument = new Document(); sDocument.put("$or", orDocument); Document projectionDocument = new Document(); projectionDocument.put("pageId", "$all"); projectionDocument.put("title", "$all"); MongoCursor<PageDAO> pageList = mongoCollection.find(sDocument).projection(projectionDocument).skip(offset) .limit(limit).iterator();//from www . j av a 2 s . c om List<PageDAO> pageInfoList = IteratorUtils.toList(pageList); return pageInfoList; }
From source file:com.shampan.model.UserModel.java
public ResultEvent emailAndUserNameCheck(String email, String userName) { MongoCollection<UserDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), UserDAO.class); String attrEmail = PropertyProvider.get("EMAIL"); String attrUserName = PropertyProvider.get("USER_NAME"); String attrUserId = PropertyProvider.get("USER_ID"); List<Document> orSelectionDocument = new ArrayList<Document>(); Document emailDocument = new Document(); emailDocument.put(attrEmail, email); Document userNameDocument = new Document(); userNameDocument.put(attrUserName, userName); orSelectionDocument.add(emailDocument); orSelectionDocument.add(userNameDocument); Document selectDocument = new Document(); selectDocument.put("$or", orSelectionDocument); Document projectionDocument = new Document(); projectionDocument.put(attrEmail, "$all"); projectionDocument.put(attrUserName, "$all"); projectionDocument.put(attrUserId, "$all"); UserDAO userInfo = mongoCollection.find(selectDocument).projection(projectionDocument).first(); if (userInfo != null) { if (email.equals(userInfo.getEmail())) { this.getResultEvent().setResponseCode(PropertyProvider.get("EMAIL_VALIDATION_EXIST")); } else if (userName.equals(userInfo.getUserName())) { this.getResultEvent().setResponseCode(PropertyProvider.get("USER_NAME_VALIDATION_EXIST")); }//from w w w.ja v a 2s .c o m } else { this.getResultEvent().setResponseCode(PropertyProvider.get("USER_ALLOW_FOR_REGISTRATION")); } return this.resultEvent; }
From source file:com.shampan.model.UserModel.java
public ResultEvent getUserInfoByUserId(String userId) { try {/*from w w w. j av a2 s . co m*/ MongoCollection<UserDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), UserDAO.class); String attrUserId = PropertyProvider.get("USER_ID"); String attrFirstName = PropertyProvider.get("FIRST_NAME"); String attrLastName = PropertyProvider.get("LAST_NAME"); String attrEmail = PropertyProvider.get("EMAIL"); String attrPassword = PropertyProvider.get("PASSWORD"); String attrGroups = PropertyProvider.get("GROUPS"); String attrAccountStatusId = PropertyProvider.get("ACCOUNT_STATUS_ID"); String attrLastLogin = PropertyProvider.get("LAST_LOGIN"); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start(attrUserId).is(userId).get(); Document pQueryDocument = new Document(); pQueryDocument.put(attrUserId, "$all"); pQueryDocument.put(attrFirstName, "$all"); pQueryDocument.put(attrLastName, "$all"); pQueryDocument.put(attrEmail, "$all"); pQueryDocument.put(attrPassword, "$all"); pQueryDocument.put(attrGroups, "$all"); pQueryDocument.put(attrAccountStatusId, "$all"); pQueryDocument.put(attrLastLogin, "$all"); UserDAO userInfo = mongoCollection.find(selectQuery).projection(pQueryDocument).first(); if (userInfo != null) { this.getResultEvent().setResult(userInfo); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { this.getResultEvent().setResponseCode(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }
From source file:com.shampan.model.UserModel.java
public ResultEvent getUSerInfoByEmail(String email) { try {/* w w w . ja va2 s . co m*/ MongoCollection<UserDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), UserDAO.class); String attrUserId = PropertyProvider.get("USER_ID"); String attrFirstName = PropertyProvider.get("FIRST_NAME"); String attrLastName = PropertyProvider.get("LAST_NAME"); String attrEmail = PropertyProvider.get("EMAIL"); String attrPassword = PropertyProvider.get("PASSWORD"); String attrGroups = PropertyProvider.get("GROUPS"); String attrAccountStatusId = PropertyProvider.get("ACCOUNT_STATUS_ID"); String attrLastLogin = PropertyProvider.get("LAST_LOGIN"); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("email").is(email).get(); UserDAO userInfo = mongoCollection.find(selectQuery).first(); if (userInfo != null) { this.getResultEvent().setResult(userInfo); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { this.getResultEvent().setResponseCode(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }
From source file:com.shampan.model.UserModel.java
public ResultEvent hashPasswordDB(String userId) { try {/*from ww w. j a v a 2 s .c o m*/ MongoCollection<UserDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), UserDAO.class); String attrUserId = PropertyProvider.get("USER_ID"); String attrPassword = PropertyProvider.get("PASSWORD"); String attrSalt = PropertyProvider.get("SALT"); Document selectDocument = new Document(); selectDocument.put(attrUserId, userId); Document projectionDocument = new Document(); Document pQueryDocument = new Document(); pQueryDocument.put(attrPassword, "$all"); pQueryDocument.put(attrSalt, "$all"); UserDAO userInfo = mongoCollection.find(selectDocument).projection(pQueryDocument).first(); if (userInfo != null) { this.getResultEvent().setResult(userInfo); this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { this.getResultEvent().setResponseCode(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }