List of usage examples for com.mongodb.client MongoCollection find
FindIterable<TDocument> find(ClientSession clientSession);
From source file:com.shampan.model.LoginAttemptModel.java
/** * this method will return total number of login attempts of a user * * @param email */* w ww . j a v a 2 s . c o m*/ */ public ResultEvent getAttemptsNum(String email) { try { MongoCollection<LoginAttemptDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.LOGINATTEMPTS.toString(), LoginAttemptDAO.class); String attrEmail = PropertyProvider.get("EMAIL"); int count = 0; Document selectDocument = new Document(); selectDocument.put(attrEmail, email); Document groupDocument = new Document(); groupDocument.put("", email); List<ArrayList> array = new ArrayList<>(); // mongoCollection.aggregate(); MongoCursor<LoginAttemptDAO> loginattemptList = mongoCollection.find(selectDocument).iterator(); while (loginattemptList.hasNext()) { count = count + 1; this.getResultEvent().setResult(count); } 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 ResultEvent getPageExist(String title, String categoryId) { try {/*from w ww . j ava 2 s . c om*/ MongoCollection<PageDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGES.toString(), PageDAO.class); Document selectDocument = new Document(); selectDocument.put("title", title); selectDocument.put("category.categoryId", categoryId); PageDAO pageInfo = mongoCollection.find(selectDocument).first(); if (pageInfo != null) { this.getResultEvent().setResponseCode(PropertyProvider.get("PAGE_IS_EXIST")); } else { this.getResultEvent().setResponseCode(PropertyProvider.get("USER_ALLOW_TO_CREATE_PAGE")); } } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return this.resultEvent; }
From source file:com.shampan.model.PageModel.java
public ResultEvent getPageInfo(String pageId) { ResultEvent resultEvent1 = new ResultEvent(); try {/*from ww w . j a v a 2 s. c om*/ MongoCollection<PageDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGES.toString(), PageDAO.class); Document selectDocument = new Document(); selectDocument.put("pageId", pageId); PageDAO pageInfo = mongoCollection.find(selectDocument).first(); if (pageInfo != null) { resultEvent1.setResult(pageInfo); resultEvent1.setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { resultEvent1.setResponseCode(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { resultEvent1.setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return resultEvent1; }
From source file:com.shampan.model.PageModel.java
public PageDAO getPageBasicInfo(String pageId) { MongoCollection<PageDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGES.toString(), PageDAO.class); Document selectDocument = new Document(); selectDocument.put("pageId", pageId); PageDAO pageInfo = mongoCollection.find(selectDocument).first(); return pageInfo; }
From source file:com.shampan.model.PageModel.java
public JSONObject getMemeberInfo(String pageId, String userId) { JSONObject memberInfo = new JSONObject(); try {//from w ww .j a v a2s.co m MongoCollection<PageMemberDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEMEMBERS.toString(), PageMemberDAO.class); Document selectDocument = new Document(); selectDocument.put("pageId", pageId); PageMemberDAO pageInfo = mongoCollection.find(selectDocument).first(); if (pageInfo != null) { String relationTypeId = PropertyProvider.get("PAGE_MEMBER_STATUS_ID_LIKED"); List<MemberInfo> memberList = pageInfo.getMemberList(); int memberCounter = memberList.size(); if (memberCounter > 0) { int counter = 0; for (int j = 0; j < memberList.size(); j++) { if (memberList.get(j).getRelationTypeId().equals(relationTypeId)) { counter = counter + 1; } if (userId.equals(memberList.get(j).getUserId())) { memberInfo.put("memberShipStatus", memberList.get(j).getRelationTypeId()); } } memberInfo.put("counter", counter); } logger.debug(PropertyProvider.get("SUCCESSFUL_OPERATION")); } else { logger.debug(PropertyProvider.get("NULL_POINTER_EXCEPTION")); } } catch (Exception ex) { logger.debug(ex.getMessage()); } return memberInfo; }
From source file:com.shampan.model.PageModel.java
public List<JSONObject> getInviteFriendList(String pageId, String userId, int offset, int limit) { List<JSONObject> jsonFriendList = new ArrayList<>(); try {/* www . j av a2 s . c o m*/ MongoCollection<PageMemberDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEMEMBERS.toString(), PageMemberDAO.class); Document selectDocument = new Document(); selectDocument.put("pageId", pageId); PageMemberDAO pageInfo = mongoCollection.find(selectDocument).first(); List<MemberInfo> memberList = new ArrayList<>(); if (pageInfo != null) { memberList = pageInfo.getMemberList(); } RelationModel friends = new RelationModel(); String relationTypeId = PropertyProvider.get("RELATION_TYPE_FRIEND_ID"); List<RelationInfo> friendList = friends.getRelationList(userId, relationTypeId, offset, limit); if (friendList.size() > 0) { for (int i = 0; i < friendList.size(); i++) { JSONObject jsonFriend = new JSONObject(); jsonFriend.put("friendInfo", friendList.get(i)); if (memberList.size() > 0) { for (int j = 0; j < memberList.size(); j++) { if (friendList.get(i).getUserId().equals(memberList.get(j).getUserId())) { jsonFriend.put("status", memberList.get(j).getRelationTypeId()); } } } jsonFriendList.add(jsonFriend); } } this.getResultEvent().setResponseCode(PropertyProvider.get("SUCCESSFUL_OPERATION")); } catch (Exception ex) { this.getResultEvent().setResponseCode(PropertyProvider.get("ERROR_EXCEPTION")); } return jsonFriendList; }
From source file:com.shampan.model.PageModel.java
public ResultEvent addPageMember(String pageId, String memberInfo) { try {// w w w .ja v a2 s . c o m MongoCollection<PageMemberDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEMEMBERS.toString(), PageMemberDAO.class); Document selectDocument = new Document(); selectDocument.put("pageId", pageId); MemberInfo mInfo = MemberInfo.getMemberInfo(memberInfo); if (mInfo != null) { PageMemberDAO pageInfo = mongoCollection.find(selectDocument).first(); boolean userIsExist = false; if (pageInfo != null) { List<MemberInfo> memberList = pageInfo.getMemberList(); List<MemberInfo> tempMemberList = new ArrayList<>(); if (memberList.size() > 0) { for (int i = 0; i < memberList.size(); i++) { MemberInfo tempMemberInfo = memberList.get(i); if (tempMemberInfo.getUserId().equals(mInfo.getUserId())) { tempMemberInfo .setRelationTypeId(PropertyProvider.get("PAGE_MEMBER_STATUS_ID_LIKED")); userIsExist = true; } tempMemberList.add(tempMemberInfo); } } if (userIsExist != false) { mongoCollection.findOneAndUpdate(selectDocument, new Document("$set", new Document("memberList", JSON.parse(tempMemberList.toString())))); } else { mongoCollection.findOneAndUpdate(selectDocument, new Document("$push", new Document("memberList", JSON.parse(mInfo.toString())))); } } else { List<MemberInfo> mList = new ArrayList<MemberInfo>(); mList.add(mInfo); PageMemberDAO pageMember = new PageMemberDAO(); pageMember.setPageId(pageId); pageMember.setMemberList(mList); mongoCollection.insertOne(pageMember); } 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.PageModel.java
public PageAlbumDAO getAlbumInfo(String pageId, String albumId) { MongoCollection<PageAlbumDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEALBUMS.toString(), PageAlbumDAO.class); String attUserId = PropertyProvider.get("USER_ID"); String attAlbumId = PropertyProvider.get("ALBUM_ID"); String attPhotoId = PropertyProvider.get("PHOTO_ID"); String attTotalImg = PropertyProvider.get("TOTAL_IMG"); String attReferenceId = PropertyProvider.get("REFERENCE_ID"); Document sQuery = new Document(); sQuery.put("pageId", pageId); sQuery.put(attAlbumId, albumId);/*from w ww. j a v a 2s. c o m*/ Document pQuery = new Document(); pQuery.put("pageId", "$all"); pQuery.put(attAlbumId, "$all"); pQuery.put(attPhotoId, "$all"); pQuery.put(attTotalImg, "$all"); pQuery.put(attReferenceId, "$all"); PageAlbumDAO albumInfo = mongoCollection.find(sQuery).projection(pQuery).first(); return albumInfo; }
From source file:com.shampan.model.PageModel.java
public List<PageAlbumDAO> getAlbums(String pageId) { MongoCollection<PageAlbumDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.PAGEALBUMS.toString(), PageAlbumDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("pageId").is(pageId).get(); Document pQuery = new Document(); pQuery.put("albumId", "$all"); pQuery.put("title", "$all"); pQuery.put("totalImg", "$all"); pQuery.put("defaultImg", "$all"); MongoCursor<PageAlbumDAO> cursorAlbumList = mongoCollection.find(selectQuery).projection(pQuery).iterator(); List<PageAlbumDAO> albumList = IteratorUtils.toList(cursorAlbumList); return albumList; }
From source file:com.shampan.model.PageModel.java
public String getAlbum(String userId, String pageId, String albumId) { MongoCollection<PageAlbumDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERALBUMS.toString(), PageAlbumDAO.class); Document selectDocument = new Document(); selectDocument.put("pageId", pageId); selectDocument.put("albumId", albumId); PageAlbumDAO albumInfo = mongoCollection.find(selectDocument).first(); JSONObject albumInfoJson = new JSONObject(); try {//from ww w . jav a 2 s .c o m albumInfoJson.put("albumId", albumInfo.getAlbumId()); albumInfoJson.put("referenceId", albumInfo.getReferenceId()); albumInfoJson.put("pageId", albumInfo.getPageId()); albumInfoJson.put("title", albumInfo.getTitle()); albumInfoJson.put("description", albumInfo.getDescription()); albumInfoJson.put("totalImg", albumInfo.getTotalImg()); albumInfoJson.put("defaultImg", albumInfo.getTotalImg()); if (albumInfo.getLike() != null) { int likeSize = albumInfo.getLike().size(); if (likeSize > 0) { albumInfoJson.put("likeCounter", likeSize); } int i = 0; while (likeSize > 0) { String tempUserId = albumInfo.getLike().get(i).getUserInfo().getUserId(); if (tempUserId.equals(userId)) { albumInfoJson.put("likeStatus", "1"); } likeSize--; i++; } } if (albumInfo.getComment() != null) { int commentSize = albumInfo.getComment().size(); List<Comment> commentList = new ArrayList(); if (commentSize >= 1) { Comment lastComment = albumInfo.getComment().get(commentSize - 1); commentList.add(lastComment); } if (commentSize >= 2) { Comment secondlastComment = albumInfo.getComment().get(commentSize - 2); commentList.add(secondlastComment); } if (commentSize > 2) { albumInfoJson.put("commentCounter", commentSize - 2); } albumInfoJson.put("comment", commentList); } if (albumInfo.getShare() != null) { int shareSize = albumInfo.getShare().size(); if (shareSize > 0) { albumInfoJson.put("shareCounter", shareSize); } } } catch (NullPointerException npe) { LogWriter.getErrorLog().error(npe); } return albumInfoJson.toString(); }