List of usage examples for com.mongodb.client MongoCollection find
FindIterable<TDocument> find(ClientSession clientSession);
From source file:com.shampan.model.UserModel.java
public ResultEvent loginRememberedUser(String email, String rememberCode) { try {//from w w w .j a va 2s. c om MongoCollection<UserDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), UserDAO.class); String attrEmail = PropertyProvider.get("EMAIL"); String attrRememberCode = PropertyProvider.get("REMEMBER_CODE"); String attrUserId = PropertyProvider.get("USER_ID"); String attrFirstName = PropertyProvider.get("FIRST_NAME"); String attrLastName = PropertyProvider.get("LAST_NAME"); String attrGroups = PropertyProvider.get("GROUPS"); String attrLastLogin = PropertyProvider.get("LAST_LOGIN"); Document selectDocument = new Document(); selectDocument.put(attrEmail, email); selectDocument.put(attrRememberCode, rememberCode); Document projectionDocument = new Document(); Document pQueryDocument = new Document(); pQueryDocument.put(attrUserId, "$all"); pQueryDocument.put(attrFirstName, "$all"); pQueryDocument.put(attrLastName, "$all"); pQueryDocument.put(attrEmail, "$all"); pQueryDocument.put(attrGroups, "$all"); pQueryDocument.put(attrLastLogin, "$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; }
From source file:com.shampan.model.UserModel.java
/** * This method will get a userInfo/*w ww . ja v a2s.co m*/ * * @param userId user id */ public UserDAO getUserInfo(String userId) { 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"); 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("gender", "$all"); UserDAO userInfo = mongoCollection.find(selectQuery).projection(pQueryDocument).first(); return userInfo; }
From source file:com.shampan.model.UserModel.java
/** * This method will get user info list/*from w ww .j a va 2 s .c om*/ * * @param userIdList user id list of users */ public List<UserDAO> getUserInfoList(String userIdList) { 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"); JSONArray userIds = new JSONArray(userIdList); int userIdsSize = userIds.length(); List<Document> orSelectionDocument = new ArrayList<Document>(); List<UserDAO> userList = null; if (userIdsSize > 0) { for (int i = 0; i < userIdsSize; i++) { Document userSelectionDocument = new Document(); userSelectionDocument.put(attrUserId, userIds.get(i)); orSelectionDocument.add(userSelectionDocument); } Document selectDocument = new Document(); selectDocument.put("$or", orSelectionDocument); Document pQueryDocument = new Document(); pQueryDocument.put(attrUserId, "$all"); pQueryDocument.put(attrFirstName, "$all"); pQueryDocument.put(attrLastName, "$all"); pQueryDocument.put("gender", "$all"); MongoCursor<UserDAO> userInfoList = mongoCollection.find(selectDocument).projection(pQueryDocument) .iterator(); userList = IteratorUtils.toList(userInfoList); } return userList; }
From source file:com.shampan.model.UserModel.java
public UserDAO getUserCountryInfo(String userId) { MongoCollection<UserDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), UserDAO.class); String attrUserId = PropertyProvider.get("USER_ID"); String attrCountry = PropertyProvider.get("COUNTRY"); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start(attrUserId).is(userId).get(); Document pQueryDocument = new Document(); pQueryDocument.put(attrCountry, "$all"); UserDAO userInfo = mongoCollection.find(selectQuery).projection(pQueryDocument).first(); return userInfo; }
From source file:com.shampan.model.UserModel.java
public String getUserGenderInfo(String userId) { MongoCollection<UserDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.USERS.toString(), UserDAO.class); String attrUserId = PropertyProvider.get("USER_ID"); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start(attrUserId).is(userId).get(); Document pQueryDocument = new Document(); pQueryDocument.put("gender", "$all"); UserDAO userInfo = mongoCollection.find(selectQuery).projection(pQueryDocument).first(); String userGenderId = ""; if (userInfo != null) { if (userInfo.getGender() != null) { userGenderId = userInfo.getGender().getGenderId(); }/*w w w . ja v a 2 s . c o m*/ } return userGenderId; }
From source file:com.shampan.model.VideoModel.java
/** * This method will return a video information * * @param videoId video Id/*from ww w .ja v a 2 s. c o m*/ * @author created by Rashida on 21 October */ public List<VideoDAO> getVideos(String userId) { MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.VIDEOS.toString(), VideoDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("userId").is(userId).get(); Document pQuery = new Document(); pQuery.put("videoId", "$all"); pQuery.put("categoryId", "$all"); pQuery.put("userInfo", "$all"); pQuery.put("imageUrl", "$all"); MongoCursor<VideoDAO> cursorVideoList = mongoCollection.find(selectQuery).projection(pQuery).iterator(); List<VideoDAO> videoList = IteratorUtils.toList(cursorVideoList); return videoList; }
From source file:com.shampan.model.VideoModel.java
/** * This method will return a video information * * @param videoId video Id// ww w.j a va 2 s. com * @author created by Rashida on 21 October */ public String getVideo(String userId, String videoId) { MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.VIDEOS.toString(), VideoDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("videoId").is(videoId).get(); VideoDAO videoInfo = mongoCollection.find(selectQuery).first(); JSONObject videoInfoJson = new JSONObject(); try { videoInfoJson.put("videoId", videoInfo.getVideoId()); videoInfoJson.put("userId", videoInfo.getUserId()); videoInfoJson.put("userInfo", videoInfo.getUserInfo()); videoInfoJson.put("imageUrl", videoInfo.getImageUrl()); videoInfoJson.put("url", videoInfo.getUrl()); if (videoInfo.getLike() != null) { int likeSize = videoInfo.getLike().size(); if (likeSize > 0) { videoInfoJson.put("likeCounter", likeSize); } int i = 0; while (likeSize > 0) { String tempUserId = videoInfo.getLike().get(i).getUserInfo().getUserId(); if (tempUserId.equals(userId)) { videoInfoJson.put("likeStatus", "1"); } likeSize--; i++; } } if (videoInfo.getComment() != null) { int commentSize = videoInfo.getComment().size(); List<Comment> commentList = new ArrayList(); if (commentSize >= 1) { Comment lastComment = videoInfo.getComment().get(commentSize - 1); commentList.add(lastComment); } if (commentSize >= 2) { Comment secondlastComment = videoInfo.getComment().get(commentSize - 2); commentList.add(secondlastComment); } if (commentSize > 2) { videoInfoJson.put("commentCounter", commentSize - 2); } videoInfoJson.put("comment", commentList); } if (videoInfo.getShare() != null) { int shareSize = videoInfo.getShare().size(); if (shareSize > 0) { videoInfoJson.put("shareCounter", shareSize); } } } catch (NullPointerException npe) { LogWriter.getErrorLog().error(npe); } return videoInfoJson.toString(); }
From source file:com.shampan.model.VideoModel.java
public String getVideoLikeList(String videoId) { MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.VIDEOS.toString(), VideoDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("videoId").is(videoId).get(); Document pQuery = new Document(); pQuery.put("like", "$all"); VideoDAO videoLikeList = mongoCollection.find(selectQuery).projection(pQuery).first(); if (videoLikeList != null) { return videoLikeList.toString(); } else {/*w ww . j a va 2s.c o m*/ resultEvent.setResponseCode(PropertyProvider.get("Null")); return resultEvent.toString(); } }
From source file:com.shampan.model.VideoModel.java
public String getVideoComments(String videoId) { MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.VIDEOS.toString(), VideoDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("videoId").is(videoId).get(); Document pQuery = new Document(); pQuery.put("comment", "$all"); VideoDAO videoCommentList = mongoCollection.find(selectQuery).projection(pQuery).first(); if (videoCommentList != null) { return videoCommentList.toString(); } else {// ww w . j ava 2s . c o m resultEvent.setResponseCode(PropertyProvider.get("Null")); return resultEvent.toString(); } }
From source file:com.sitewhere.asset.persistence.mongodb.MongoAssetManagement.java
License:Open Source License
@Override public IAssetType getAssetTypeByToken(String token) throws SiteWhereException { try {/*from ww w. jav a2s. c o m*/ MongoCollection<Document> types = getMongoClient().getAssetTypesCollection(); Document query = new Document(MongoAssetType.PROP_TOKEN, token); Document dbAssetType = types.find(query).first(); if (dbAssetType != null) { return MongoAssetType.fromDocument(dbAssetType); } return null; } catch (MongoClientException e) { throw MongoPersistence.handleClientException(e); } }