List of usage examples for com.mongodb QueryBuilder start
public static QueryBuilder start(final String key)
From source file:com.shampan.model.UserModel.java
public ResultEvent getUserInfoByUserId(String userId) { try {//from w w w .j a v 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 {/*from w ww .jav a 2s.c o 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
/** * This method will get a userInfo/*from w w w . j a v a 2 s . c om*/ * * @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
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(); }//from w ww.jav a2s. co m } return userGenderId; }
From source file:com.shampan.model.VideoModel.java
/** * This method will return a video information * * @param videoId video Id//from w w w .j a v a 2 s . co 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//w ww. java2s. 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
/** * This method will update a video information * * @param videoId video Id// ww w . j av a2s .c o m * @author created by Rashida on 21 October */ public String updateVideo(String videoId, String url) { MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.VIDEOS.toString(), VideoDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("videoId").is(videoId).get(); VideoDAO result = mongoCollection.findOneAndUpdate(selectQuery, new Document("$set", new Document("url", url))); if (result != null) { resultEvent.setResponseCode(PropertyProvider.get("Updated")); return resultEvent.toString(); } else { resultEvent.setResponseCode(PropertyProvider.get("Null")); return resultEvent.toString(); } }
From source file:com.shampan.model.VideoModel.java
/** * This method will delete a video/*w ww.j ava 2s .co m*/ * * @param videoId video Id * @author created by Rashida on 21 October */ public String deleteVideo(String videoId) { MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.VIDEOS.toString(), VideoDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("videoId").is(videoId).get(); VideoDAO result = mongoCollection.findOneAndDelete(selectQuery); if (result != null) { resultEvent.setResponseCode(PropertyProvider.get("Deleted")); return resultEvent.toString(); } else { resultEvent.setResponseCode(PropertyProvider.get("BadRequest")); return resultEvent.toString(); } }
From source file:com.shampan.model.VideoModel.java
public String addVideoLike(String videoId, String likeInfo) { MongoCollection<VideoDAO> mongoCollection = DBConnection.getInstance().getConnection() .getCollection(Collections.VIDEOS.toString(), VideoDAO.class); BasicDBObject selectQuery = (BasicDBObject) QueryBuilder.start("videoId").is(videoId).get(); Like videolikeInfo = Like.getLikeInfo(likeInfo); if (videolikeInfo != null) { VideoDAO result = mongoCollection.findOneAndUpdate(selectQuery, new Document("$push", new Document("like", JSON.parse(videolikeInfo.toString())))); resultEvent.setResponseCode(PropertyProvider.get("Created")); return resultEvent.toString(); } else {// w ww . j a va 2 s . c om resultEvent.setResponseCode(PropertyProvider.get("BadRequest")); return resultEvent.toString(); } }