Java tutorial
/** * Copyright (c) 2001-2012 "Redbasin Networks, INC" [http://redbasin.org] * * This file is part of Redbasin OpenDocShare community project. * * Redbasin OpenDocShare is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package dao; import java.sql.Connection; import java.util.HashSet; import java.util.Iterator; import java.util.List; import javax.sql.DataSource; import model.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jboss.cache.Fqn; import util.DbConstants; import util.DiaryAdmin; import util.DirectoryScopeConstants; import util.RegexStrUtil; /** * This object implements UserpageDao - business citizen page * @author Smitha Gudur */ public class UserpageDaoDb extends BaseDao implements UserpageDao { private int rowIndex = 0; protected final Log logger = LogFactory.getLog(getClass()); private volatile DiaryAdmin diaryAdmin; private volatile IncrementVisitsQuery incrementVisitsQuery; private volatile DataSource geoDs; private volatile DirectoryScopeConstants dirScope; //private volatile HdprofileAddQuery hdprofileAddQuery; //private volatile HdloginAddQuery hdloginAddQuery; //private volatile PersonalinfoAddQuery personalinfoAddQuery; // private volatile DisplaypageAddQuery displaypageAddQuery; //private volatile BaseCommonQuery personalinfoAddQuery; private volatile BaseCommonQuery hdprofileAddQuery; private volatile BaseCommonQuery hdloginAddQuery; // private volatile UserTrafficAddQuery addTrafficQuery; //private volatile UserTrafficQuery trafficQuery; /** not required any more * private volatile BaseCommonQuery addTrafficQuery; * private volatile BasicQuery trafficQuery; */ // these variables should be set only by spring. //private volatile FriendQuery friendQuery; //private volatile FriendCheckQuery friendCheckQuery; //private volatile IsFriendQuery isFriendQuery; //private volatile GuestQuery guestQuery; //private volatile PhotoQuery photoQuery; //private volatile HdprofileQuery hdprofileQuery; //private volatile PendingfriendoutQuery pendingfriendoutQuery; //private volatile PendingfriendinQuery pendingfriendinQuery; //private volatile CarryonCategoryQuery categoryQuery; //private volatile CarryonByCategoryQuery carryonByCategoryQuery; //private volatile CarryonDefaultPhotoQuery defaultPhotoQuery; // checks for both inboxandoutboxcount //private volatile InboxCountQuery inboxOutboxCountQuery; //private volatile UserpageQuery userpageQuery; //private volatile FriendFirstQuery friendFirstQuery; //private volatile CollabrumExistsQuery collabrumExistsQuery; //private volatile DirectoryExistsQuery directoryExistsQuery; //private volatile CollMemberOrganizerQuery isMemberOrganizerQuery; //private volatile DirMemberAuthorQuery isMemberAuthorQuery; //private volatile DirUserAuthorQuery isUserAuthorQuery; //private volatile CollUserOrganizerQuery isUserOrganizerQuery; //private volatile CollabrumIdListQuery listCollabrumsIdQuery; //private volatile PblogTopicExistsQuery existsQuery; //private volatile UserCobrandQuery cobrandQuery; //private volatile UserTop10HitsQuery usertop10hitsQuery; //private volatile DirectoryTop10Query dirTopHitsQuery; //private volatile DirUserQuery isMemberDirUserQuery; private volatile BasicQuery loginCountQuery; private volatile BasicQuery friendQuery; private volatile BasicQuery friendCheckQuery; private volatile BasicQuery isFriendQuery; private volatile BasicQuery guestQuery; private volatile BasicQuery photoQuery; private volatile BasicQuery hdprofileQuery; private volatile BasicQuery pendingfriendoutQuery; private volatile BasicQuery pendingfriendinQuery; private volatile BasicQuery categoryQuery; private volatile BasicQuery carryonByCategoryQuery; private volatile BasicQuery defaultPhotoQuery; private volatile BasicQuery inboxOutboxCountQuery; private volatile BasicQuery userpageQuery; private volatile BasicQuery friendFirstQuery; private volatile BasicQuery collabrumExistsQuery; private volatile BasicQuery directoryExistsQuery; private volatile BasicQuery isMemberOrganizerQuery; private volatile BasicQuery isMemberAuthorQuery; private volatile BasicQuery isUserAuthorQuery; private volatile BasicQuery isUserOrganizerQuery; private volatile BasicQuery listCollabrumsIdQuery; private volatile BasicQuery existsQuery; private volatile BasicQuery usertop10hitsQuery; private volatile BasicQuery dirTopHitsQuery; private volatile BasicQuery cobrandQuery; private volatile BasicQuery isMemberDirUserQuery; private volatile GeoTargetQuery geoTargetQuery; private volatile BasicQuery yourkeywordsQuery; private volatile BasicQuery mykeywordsQuery; //private volatile MostRecentUsersQuery recentUsersQuery; private volatile BasicQuery recentUsersQuery; //private volatile MostRecentUsersBizAwareQuery recentUsersBizAwareQuery private volatile BasicQuery recentUsersBizAwareQuery; // private volatile UserTop10HitsBizAwareQuery usertop10hitsBizAwareQuery private volatile BasicQuery usertop10hitsBizAwareQuery; /** * Given a login return the Userpage * @param login - the user login * @param accessFlag - indicates the datasource access from master(1) or slave (0) * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect * @return Userpage the login bean returned */ public Userpage getUserpage(String login, int accessFlag) throws BaseDaoException { if (login == null) { return null; } /** * Jboss methods * fqn - full qualified name * check if the userpage already set in the cache * If it exists, return the userpage from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.USER_PAGE); Object obj = treeCache.get(fqn, login); if (obj != null) { ((Userpage) obj).setValue(DbConstants.IS_ORGANIZER, "0"); ((Userpage) obj).setValue(DbConstants.IS_MEMBER_ORGANIZER, "0"); ((Userpage) obj).setValue(DbConstants.IS_AUTHOR, "0"); ((Userpage) obj).setValue(DbConstants.IS_MEMBER_AUTHOR, "0"); ((Userpage) obj).setValue(DbConstants.ADD_MODERATOR, "0"); return (Userpage) obj; } Userpage userpage = getUserpageInfo(login, accessFlag); if (userpage != null) { userpage.setValue(DbConstants.IS_ORGANIZER, "0"); userpage.setValue(DbConstants.IS_MEMBER_ORGANIZER, "0"); userpage.setValue(DbConstants.IS_AUTHOR, "0"); userpage.setValue(DbConstants.IS_MEMBER_AUTHOR, "0"); userpage.setValue(DbConstants.ADD_MODERATOR, "0"); } /** * add it to the jboss cache */ treeCache.put(fqn, login, userpage); return userpage; } private Userpage getUserpageInfo(String login, int accessFlag) throws BaseDaoException { if (login == null) { return null; } Hdlogin hdlogin = getLoginid(login); if (hdlogin == null) { return null; } String loginid = hdlogin.getValue(DbConstants.LOGIN_ID); if (loginid == null) { return null; } /** * Get scalability usertab - not partitioned * not being used right now. */ String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("userpagequery"); } else { queryName = scalabilityManager.getReadZeroScalability("userpagequery"); } userpageQuery = getQueryMapper().getQuery(queryName); /** loginid missing, add to usertab, hdprofile * fname, lname, email */ List uResult = null; Object[] params = { (Object) loginid }; try { uResult = userpageQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query", e); } if (uResult == null) { throw new BaseDaoException("userpage is null" + userpageQuery.getSql()); } Userpage userpage = null; if (uResult.size() > 0) { userpage = (Userpage) uResult.get(0); } else { throw new BaseDaoException("userpage result size is 0" + login); } hdlogin = getLoginid(login); if (hdlogin != null) { userpage.setValue(DbConstants.LOGIN, login); userpage.setValue(DbConstants.FIRST_NAME, hdlogin.getValue(DbConstants.FIRST_NAME)); userpage.setValue(DbConstants.LAST_NAME, hdlogin.getValue(DbConstants.LAST_NAME)); userpage.setValue(DbConstants.MIDDLE_NAME, hdlogin.getValue(DbConstants.MIDDLE_NAME)); userpage.setValue(DbConstants.EMAIL, hdlogin.getValue(DbConstants.EMAIL)); userpage.setValue(DbConstants.MEMBER_FULL_NAME, hdlogin.getValue(DbConstants.OWNER_NAME)); userpage.setValue(DbConstants.BID, hdlogin.getValue(DbConstants.BID)); userpage.setValue(DbConstants.BUDGET, hdlogin.getValue(DbConstants.BUDGET)); userpage.setValue(DbConstants.HEAR, hdlogin.getValue(DbConstants.HEAR)); userpage.setValue(DbConstants.CONTACT, hdlogin.getValue(DbConstants.CONTACT)); } if (diaryAdmin.isDiaryAdmin(login)) { userpage.setValue(DbConstants.IS_ADMIN, "true"); } else { userpage.setValue(DbConstants.IS_ADMIN, "false"); } userpage.setValue(DbConstants.BLOG_EXISTS, topicExists(loginid, accessFlag)); /** * hdlogin and hdfriends - not partitioned * for friends entries multiple rows are returned. */ Object[] myParams = { (Object) loginid, (Object) loginid }; uResult = null; queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("friendfirstquery"); } else { queryName = scalabilityManager.getReadZeroScalability("friendfirstquery"); } friendFirstQuery = getQueryMapper().getQuery(queryName); try { uResult = friendFirstQuery.execute(myParams); } catch (Exception e) { throw new BaseDaoException("error executing Query" + friendFirstQuery.getSql(), e); } if (uResult != null && uResult.size() > 0) { userpage.setFriends(uResult); } /** * for guestbook entries multiple rows are returned. * guestbook is partitioned on loginid */ /* sourceName = scalabilityManager.getReadScalability(loginid); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null " + sourceName); } */ queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("guestquery"); } else { queryName = scalabilityManager.getReadZeroScalability("guestquery"); } guestQuery = getQueryMapper().getQuery(queryName); uResult = null; try { uResult = guestQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query", e); } if (uResult != null && uResult.size() > 0) { userpage.setGuests(uResult); } /** * check if there are any messages either inbox or outbox * set the flag to 1 if either of them have any message */ queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("inboxcountquery"); } else { queryName = scalabilityManager.getReadZeroScalability("inboxcountquery"); } inboxOutboxCountQuery = getQueryMapper().getQuery(queryName); uResult = null; try { uResult = inboxOutboxCountQuery.execute(myParams); } catch (Exception e) { throw new BaseDaoException("error executing Query", e); } if ((uResult != null) && (uResult.size() > 0)) { userpage.setValue("msgs", "1"); } else { userpage.setValue("msgs", "0"); } /** * carryon blobs - partitioned on blobs * for photos entries multiple rows are returned. */ /* sourceName = scalabilityManager.getReadBlobScalability(loginid); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null " + sourceName); } */ boolean getDefaultPhoto = false; Fqn fqn = cacheUtil.fqn(DbConstants.DEFAULT_PHOTO); Object obj = treeCache.get(fqn, loginid); if (obj != null) { userpage.setPhoto((Photo) obj); } else { getDefaultPhoto = true; queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("userdefaultphotoQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("userdefaultphotoQuery"); } defaultPhotoQuery = getQueryMapper().getQuery(queryName); } String catQueryName = null; if (accessFlag == 1) { catQueryName = scalabilityManager.getWriteZeroScalability("carryoncategoryQuery"); } else { catQueryName = scalabilityManager.getReadZeroScalability("carryoncategoryQuery"); } uResult = null; try { if (getDefaultPhoto) { uResult = defaultPhotoQuery.execute(params); if (uResult != null && (uResult.size() > 0)) { userpage.setPhoto((Photo) uResult.get(0)); treeCache.put(fqn, loginid, (Photo) uResult.get(0)); } } uResult = null; categoryQuery = getQueryMapper().getQuery(catQueryName); Object[] xparams = { loginid, (Object) DbConstants.PHOTO_CATEGORY }; uResult = categoryQuery.execute(xparams); if (uResult != null && uResult.size() > 0) { userpage.setValue(DbConstants.PHOTO_GALLERY, DbConstants.PHOTO_CATEGORY); } else { userpage.setValue(DbConstants.PHOTO_GALLERY, "0"); } } catch (Exception e) { throw new BaseDaoException("error executing Query " + categoryQuery.getSql(), e); } queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("carryonbycategoryQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("carryonbycategoryQuery"); } carryonByCategoryQuery = getQueryMapper().getQuery(queryName); try { Object[] xparams = { loginid, (Object) DbConstants.FILE_CATEGORY }; uResult = carryonByCategoryQuery.execute(xparams); if (uResult != null && uResult.size() > 0) { userpage.setObject(DbConstants.FILES, uResult); userpage.setValue(DbConstants.DOCUMENTS, DbConstants.FILE_CATEGORY); } else { userpage.setValue(DbConstants.DOCUMENTS, "0"); } } catch (Exception e) { throw new BaseDaoException("error executing Query " + carryonByCategoryQuery.getSql(), e); } queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("yourkeywordsQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("yourkeywordsQuery"); } yourkeywordsQuery = getQueryMapper().getQuery(queryName); try { Object[] xparams = { loginid }; uResult = yourkeywordsQuery.execute(xparams); if (uResult != null && uResult.size() > 0) { userpage.setObject(DbConstants.YOURKEYWORDS, uResult); //userpage.setValue(DbConstants.YOURKEYWORDS, uResult.toString()); } } catch (Exception e) { throw new BaseDaoException("error executing Query " + yourkeywordsQuery.getSql(), e); } queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("mykeywordsQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("mykeywordsQuery"); } mykeywordsQuery = getQueryMapper().getQuery(queryName); try { Object[] xparams = { loginid }; uResult = mykeywordsQuery.execute(xparams); if (uResult != null && uResult.size() > 0) { userpage.setObject(DbConstants.MYKEYWORDS, uResult); } } catch (Exception e) { throw new BaseDaoException("error executing Query " + mykeywordsQuery.getSql(), e); } getPendingfriendInfo(userpage, loginid, accessFlag); getCobrand(loginid, userpage, accessFlag); return userpage; } /** * Given a login increment hits * @param member * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void incrementHits(String member) throws BaseDaoException { if (member == null) { return; } /** * update usertab with hits */ Hdlogin hdlogin = getLoginid(member); if (hdlogin == null) { return; } String memberid = hdlogin.getValue(DbConstants.LOGIN_ID); try { incrementVisitsQuery.run(memberid); } catch (Exception e) { throw new BaseDaoException("incrementVisitsQuery", e); } } /** * This method checks if this member exists in the database. * @param member login * @return boolean */ public boolean isMember(String member) throws BaseDaoException { if (RegexStrUtil.isNull(member)) { return false; //throw new BaseDaoException("isMember() in UserpageDao, params are null"); } Hdlogin hdlogin = getLoginid(member); if (hdlogin == null) { return false; } String memberid = hdlogin.getValue(DbConstants.LOGIN_ID); if (memberid == null) { return false; } else { return true; } } /** * this method sets the pendingfriend value in userpage. * @param userpage - the userpage * @param loginid - loginid * @throws BaseDaoException - when an error occurs */ private void getPendingfriendInfo(Userpage userpage, String loginid, int accessFlag) throws BaseDaoException { /** * default value */ if ((userpage == null) || (loginid == null)) { return; } userpage.setValue("pending", "0"); /** * hdlogin, pendingfriends - no partitioned */ /* String sourceName = null; sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null " + sourceName); } */ String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("pendingfriendinquery"); } else { queryName = scalabilityManager.getReadZeroScalability("pendingfriendinquery"); } pendingfriendinQuery = getQueryMapper().getQuery(queryName); /** * if pending is set, don't check further, return */ List result = null; try { result = pendingfriendinQuery.execute(loginid); if ((result != null) && (result.size() > 0)) { userpage.setValue("pending", "1"); return; } } catch (Exception e) { throw new BaseDaoException("error executing Query", e); } queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("pendingfriendoutquery"); } else { queryName = scalabilityManager.getReadZeroScalability("pendingfriendoutquery"); } pendingfriendoutQuery = getQueryMapper().getQuery(queryName); result = null; try { result = pendingfriendoutQuery.execute(loginid); if ((result != null) && (result.size() > 0)) { userpage.setValue("pending", "1"); } } catch (Exception e) { throw new BaseDaoException("error executing Query", e); } } /** * this method returns the second degree of friends * @param userpage - the userpage * @param friend1 - the friend1 * @param friend2 - the friend2 * @throws BaseDaoException - when error occurs */ private void getMySecondFriends(Userpage userpage, String friend1, String friend2, int accessFlag) throws BaseDaoException { if ((userpage == null) || (friend1 == null) || (friend2 == null)) { userpage.setSecondFriends(null); return; } /** * friend1 */ Hdlogin hdlogin = getLoginid(friend1); if (hdlogin == null) { return; } String friendid1 = hdlogin.getValue(DbConstants.LOGIN_ID); /** * friend2 */ hdlogin = getLoginid(friend2); if (hdlogin == null) { return; } /** * first query */ String friendid2 = hdlogin.getValue(DbConstants.LOGIN_ID); Object[] params = { (Object) friendid1, (Object) friendid1 }; List result = null; /** * hdlogin, pendingfriends - no partitioned */ /* String sourceName = null; sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null " + sourceName); } */ String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("friendcheckquery"); } else { queryName = scalabilityManager.getReadZeroScalability("friendcheckquery"); } friendCheckQuery = getQueryMapper().getQuery(queryName); try { result = friendCheckQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query" + friendCheckQuery.getSql(), e); } HashSet hs1 = new HashSet(); if ((result != null) && (result.size() > 0)) { for (int i = 0; i < result.size(); i++) { hs1.add(((Friend) result.get(i)).getValue(DbConstants.FID)); } } Iterator it1; it1 = hs1.iterator(); /** * second query */ params[0] = friendid2; params[1] = friendid2; List result2 = null; try { result2 = friendCheckQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error executing Query", e); } HashSet hs2 = new HashSet(); if (result2 != null) { if (result2.size() > 0) { for (int i = 0; i < result2.size(); i++) { hs2.add(((Friend) result2.get(i)).getValue(DbConstants.FID)); } } } /** return the intersection of the two sets */ boolean f = hs1.retainAll(hs2); if (hs1.size() == 0) return; /** get the friendids and get the login names */ Iterator it3; it3 = hs1.iterator(); HashSet friendSet = new HashSet(); Hdlogin friendLogin = null; while (it3.hasNext()) { //HdloginidQuery hQuery = new HdloginidQuery(ds); // friendResult = hdloginidQuery.execute(myParams); friendLogin = getLoginid((String) it3.next()); if (friendLogin != null) { friendSet.add(friendLogin); } } userpage.setSecondFriends(friendSet); } /** * Given a login return the Userpage and friends connection information * @param member - page is the userpage (login) that is being accessed * @param visitorLogin - the visitor's login who is visiting this member * @param accessFlag - indicates the datasource access from master(1) or slave (0) * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect * @return Userpage the login bean returned */ public Userpage getUserpage(String member, String visitorLogin, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(member)) { return null; } Hdlogin hdlogin = getLoginid(member); if (hdlogin == null) { return null; } String memberId = hdlogin.getValue(DbConstants.LOGIN_ID); if (RegexStrUtil.isNull(memberId)) { return null; } /** * Jboss methods * fqn - full qualified name * check if the userpage already set in the cache * If it exists, return the userpage from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.USER_PAGE); Object obj = treeCache.get(fqn, member); if (obj != null) { setVisitorAttributes((Userpage) obj, member, memberId, visitorLogin, accessFlag); return (Userpage) obj; } Userpage userpage = getUserpageInfo(member, accessFlag); if (userpage == null) { return null; } treeCache.put(fqn, member, userpage); /** * set visitors collaboration information */ if (!RegexStrUtil.isNull(visitorLogin)) { setVisitorAttributes(userpage, member, memberId, visitorLogin, accessFlag); } return userpage; } /** * Set visitors collaboration attributes */ private void setVisitorAttributes(Userpage userpage, String member, String memberId, String visitorLogin, int accessFlag) { String visitorId = null; Hdlogin hdlogin = getLoginid(visitorLogin); if (hdlogin == null) { return; } /** * set login information */ visitorId = hdlogin.getValue(DbConstants.LOGIN_ID); userpage.setValue(DbConstants.SESSION_USER_FULL_NAME, hdlogin.getValue(DbConstants.OWNER_NAME)); /* not required anymore */ //addTraffic(memberId, visitorId); /* not required anymore */ /** * set friends information */ userpage.setValue(DbConstants.FRIEND, isMyFriend(memberId, visitorId, accessFlag)); getMySecondFriends(userpage, member, visitorLogin, accessFlag); /** * directory, collabrum, colladmin, diradmin - not partitioned */ /* String sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null " + sourceName); } */ if (diaryAdmin.isDiaryAdmin(member)) { /** check if this visitor is an author and an organizer */ userpage.setValue(DbConstants.IS_MEMBER_AUTHOR, "0"); userpage.setValue(DbConstants.IS_MEMBER_ORGANIZER, "0"); /** Admin is an author, organizer, can add moderator */ if (isDirectoryExists(accessFlag)) { userpage.setValue(DbConstants.IS_AUTHOR, "1"); userpage.setValue(DbConstants.IS_MEMBER_AUTHOR, isUserAuthor(visitorId, accessFlag)); } if (isCollabrumExists(accessFlag)) { userpage.setValue(DbConstants.IS_ORGANIZER, "1"); userpage.setValue(DbConstants.ADD_MODERATOR, "1"); userpage.setValue(DbConstants.IS_MEMBER_ORGANIZER, isUserOrganizer(visitorId, accessFlag)); } return; } /** * set the flags for organizer/author/moderator/owner for directories/social networks */ if (isCollabrumExists(accessFlag)) { String isUserOrganizer = isUserOrganizer(memberId, accessFlag); userpage.setValue(DbConstants.IS_ORGANIZER, isUserOrganizer); userpage.setValue(DbConstants.IS_MEMBER_ORGANIZER, isMemberOrganizer(visitorId, memberId, accessFlag)); userpage.setValue(DbConstants.ADD_MODERATOR, isUserOrganizer); //userpage.setValue(DbConstants.ADD_MODERATOR, isAddModerator(memberId, visitorId)); } else { userpage.setValue(DbConstants.IS_ORGANIZER, "0"); userpage.setValue(DbConstants.IS_MEMBER_ORGANIZER, "0"); } if (isDirectoryExists(accessFlag)) { userpage.setValue(DbConstants.IS_AUTHOR, isUserAuthor(memberId, accessFlag)); userpage.setValue(DbConstants.IS_MEMBER_AUTHOR, isMemberAuthor(visitorId, memberId, accessFlag)); userpage.setValue(DbConstants.IS_DIR_USER, isMemberDirUser(visitorId, memberId, accessFlag)); } else { userpage.setValue(DbConstants.IS_AUTHOR, "0"); userpage.setValue(DbConstants.IS_MEMBER_AUTHOR, "0"); userpage.setValue(DbConstants.ADD_MODERATOR, "0"); } } /** * Given a login add the user in hdlogin, hdprofile and usertab tables. * @param login * @param fname * @param lname * @param mname * @param email * @param password * @param aflag * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ /* public void addUser(String login, String fname, String lname, String mname, String email, String password, String aflag, String hear, String budget, String contact) throws BaseDaoException { if (RegexStrUtil.isNull(login) || RegexStrUtil.isNull(email) || RegexStrUtil.isNull(password) ) { throw new BaseDaoException("params are null"); } Hdlogin hdlogin = getLoginid(login); String loginid = null; boolean addLogin = true; */ /** * set the flag to false, if user exists */ /* if (hdlogin != null) { loginid = hdlogin.getValue(DbConstants.LOGIN_ID); if (loginid != null) { addLogin = false; return; } } /** * hdlogin, hdprofile, usertab - no partitioned */ /* String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); String queryName = null; */ /** * add login, new user, get the latest id of the login */ /* if (addLogin) { if (fname == null ) fname = ""; if (lname == null) lname = ""; if (mname == null) mname = ""; String[] params = new String[8]; params[0] = login; params[1] = fname; params[2] = lname; params[3] = mname; params[4] = email; params[5] = password; params[6] = "0"; params[7] = aflag; params[8] = hear; params[9] = budget; params[10] = contact; queryName = scalabilityManager.getWriteZeroScalability("hdloginaddquery"); hdloginAddQuery = getQueryMapper().getCommonQuery(queryName); hdloginAddQuery.run(conn, params); loginid = "LAST_INSERT_ID()"; } */ /** * set inform flags to zero */ /* queryName = scalabilityManager.getWriteZeroScalability("hdprofileaddquery"); hdprofileAddQuery = getQueryMapper().getCommonQuery(queryName); String[] params = new String[3]; params[0] = "0"; params[1] = "0"; params[2] = "0"; hdprofileAddQuery.run(conn, params); queryName = scalabilityManager.getWriteZeroScalability("personalinfoaddquery"); personalinfoAddQuery = getQueryMapper().getCommonQuery(queryName); params = new String[35]; for (int i = 0; i < 35; i++) params[i] = ""; params[16] = "1"; // male (gender) personalinfoAddQuery.run(conn, params); */ /** * displayuser is partitioned - on loginid * DisplaypageAddQuery dQuery = new DisplaypageAddQuery(); * display page set it default values **/ /* int dfname, dlname, dmname; dfname = dlname = dmname = 1; displaypageAddQuery.run(conn, dfname, dlname, dmname, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, loginid); */ /* } catch(Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception", e2); } throw new BaseDaoException("error occured while rollingback entries from hdlogin/hdprofile/usertab", e1); } throw new BaseDaoException("error occured while making entries from hdlogin/hdprofile/usertab", e); } try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("commit exception", e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException("connection close exception", e4); } } */ /** * This method provides members details from the database based on member's login; * @param memberLogin * @return Hdlogin * @return throws BaseDaoException */ public Hdlogin getMemberName(String memberLogin) { Hdlogin hdlogin = getLoginid(memberLogin); return hdlogin; } /** * This method returns "1" if this member is an organizer of collabrum * return "0" if this member is not an organizer of this collabrum */ private String isMemberOrganizer(String userId, String memberId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(memberId)) { throw new BaseDaoException("params are null"); } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("ismemberorganizerquery"); } else { queryName = scalabilityManager.getReadZeroScalability("ismemberorganizerquery"); } isMemberOrganizerQuery = getQueryMapper().getQuery(queryName); try { Object[] params = { (Object) userId, (Object) memberId }; List result = isMemberOrganizerQuery.execute(params); if ((result != null) && (result.size() > 0)) { return "1"; } else { return "0"; } } catch (Exception e) { throw new BaseDaoException("exception error in isMemberOrganizer, " + isMemberOrganizerQuery.getSql() + " userId = " + userId + " memberId = " + memberId); } } /** * Checks if this member is an admin of the same collabrum that this user belongs to. */ private String isMemberAuthor(String userId, String memberId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(memberId)) { throw new BaseDaoException("params are null"); } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("ismemberauthorquery"); } else { queryName = scalabilityManager.getReadZeroScalability("ismemberauthorquery"); } isMemberAuthorQuery = getQueryMapper().getQuery(queryName); try { Object[] params = { (Object) userId, (Object) memberId }; List result = isMemberAuthorQuery.execute(params); if ((result != null) && (result.size() > 0)) { return "1"; } else { return "0"; } } catch (Exception e) { throw new BaseDaoException("exception error in isMemberAuthor, " + isMemberAuthorQuery.getSql() + " userId = " + userId + " memberId = " + memberId); } } /** * Checks if this member is a user of a directory (scopeid = 3) */ private String isMemberDirUser(String userId, String memberId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(memberId)) { throw new BaseDaoException("params are null"); } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("ismemberdiruserquery"); } else { queryName = scalabilityManager.getReadZeroScalability("ismemberdiruserquery"); } isMemberDirUserQuery = getQueryMapper().getQuery(queryName); try { String scopeId = dirScope.getUserspecificscopeid(); Object[] params = { (Object) scopeId, (Object) userId, (Object) memberId }; List result = isMemberDirUserQuery.execute(params); if ((result != null) && (result.size() > 0)) { return "1"; } else { return "0"; } } catch (Exception e) { throw new BaseDaoException("exception error in isMemberDirUserQuery, " + isMemberDirUserQuery.getSql() + " userId = " + userId + " memberId = " + memberId); } } /** * checks if this user is the author of this directory * @param userId - the user id * @return String - "1" if the user is the author of the directory, or "0" if the user is not the author * @throws BaseDaoException */ private String isUserAuthor(String userId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(userId)) { throw new BaseDaoException("params are null"); } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("isuserauthorquery"); } else { queryName = scalabilityManager.getReadZeroScalability("isuserauthorquery"); } isUserAuthorQuery = getQueryMapper().getQuery(queryName); try { Object[] myparams = { (Object) userId }; List adminResult = isUserAuthorQuery.execute(myparams); if ((adminResult != null) && (adminResult.size() > 0)) { return "1"; } else { return "0"; } } catch (Exception e) { throw new BaseDaoException( "error in isUserAuthor()" + isUserAuthorQuery.getSql() + " userId = " + userId); } } /** * checks if this user is the organizer of this directory * @param userId - the user id * @return String - "1" if the user is the author of the directory, or "0" if the user is not the author * @throws BaseDaoException */ private String isUserOrganizer(String userId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(userId)) { throw new BaseDaoException("params are null"); } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("isuserorganizerquery"); } else { queryName = scalabilityManager.getReadZeroScalability("isuserorganizerquery"); } isUserOrganizerQuery = getQueryMapper().getQuery(queryName); try { Object[] myparams = { (Object) userId }; List adminResult = isUserOrganizerQuery.execute(myparams); if ((adminResult != null) && (adminResult.size() > 0)) { return "1"; } else { return "0"; } } catch (Exception e) { throw new BaseDaoException( "error in isUserOrganizer()" + isUserOrganizerQuery.getSql() + " userId = " + userId); } } /** * this method checks if there are any rows in collabrum tables * @return boolean - true if there are collabrums in the database, false otherwise * @throws BaseDaoException */ private boolean isCollabrumExists(int accessFlag) throws BaseDaoException { String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("collabrumexistsquery"); } else { queryName = scalabilityManager.getReadZeroScalability("collabrumexistsquery"); } collabrumExistsQuery = getQueryMapper().getQuery(queryName); try { List result = collabrumExistsQuery.execute(); if ((result != null) && (result.size() > 0)) { return true; } else { return false; } } catch (Exception e) { throw new BaseDaoException("error in isCollabrumExists()" + collabrumExistsQuery.getSql()); } } /** * This method checks if there are any rows in directory tables * @return boolean - true if there are directories in the database, false otherwise * @throws BaseDaoException */ private boolean isDirectoryExists(int accessFlag) throws BaseDaoException { String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("directoryexistsquery"); } else { queryName = scalabilityManager.getReadZeroScalability("directoryexistsquery"); } directoryExistsQuery = getQueryMapper().getQuery(queryName); try { List result = directoryExistsQuery.execute(); if ((result != null) && (result.size() > 0)) { return true; } else { return false; } } catch (Exception e) { throw new BaseDaoException("error in isDirectoryExists()" + directoryExistsQuery.getSql()); } } /** * checks to see if this user to be shown the "Add Moderator" link on member's userpage * @param userId - the user id ( check if this user is the organizer of the collabrums * @param memeberId - the member id (check if this member is already the organizer of user's collabrums * @return String - returns "1" if there are no matches between the user's and members collabrums * returns "0" if there are matches between the user's and member's collabrums * @throws BaseDaoException - error occurs */ private String isAddModerator(String userId, String memberId, int accessFlag) { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(memberId)) { throw new BaseDaoException("params are null"); } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("listcollabrumsidquery"); } else { queryName = scalabilityManager.getReadZeroScalability("listcollabrumsidquery"); } listCollabrumsIdQuery = getQueryMapper().getQuery(queryName); List colList = null; List memCollList = null; try { Object[] params = { (Object) userId }; colList = listCollabrumsIdQuery.execute(params); Object[] memParams = { (Object) memberId }; memCollList = listCollabrumsIdQuery.execute(memParams); } catch (Exception e) { throw new BaseDaoException("error in listing collabrums, " + listCollabrumsIdQuery.getSql()); } boolean matches = false; Collabrum collabrum, memCollabrum; collabrum = memCollabrum = null; String collabrumid, memCollId; collabrumid = memCollId = ""; if (colList != null) { for (int i = 0; i < colList.size(); i++) { collabrum = (Collabrum) colList.get(i); collabrumid = collabrum.getValue(DbConstants.COLLABRUM_ID); matches = false; if (memCollList != null) { for (int j = 0; j < memCollList.size(); j++) { memCollabrum = (Collabrum) memCollList.get(j); if (memCollabrum != null) { memCollId = memCollabrum.getValue(DbConstants.COLLABRUM_ID); if (RegexStrUtil.isNull(memCollId)) continue; if (memCollId.equals((Object) collabrumid)) { matches = true; break; } } } } if (!matches) { return "1"; } } } return "0"; } /** * @param guestId - the guest id * @param loginId - the login id * @param accessFlag - access flag * @return String - String "1" - is friend, "0" - not a friend */ private String isMyFriend(String guestId, String loginId, int accessFlag) { StringBuffer sb = new StringBuffer(guestId); sb.append("-"); sb.append(loginId); Fqn fqn = cacheUtil.fqn(DbConstants.FRIEND); Object obj = treeCache.get(fqn, sb.toString()); if (obj != null) { return ((Friend) obj).getValue(DbConstants.IS_FRIEND); } StringBuffer loginBuf = new StringBuffer(loginId); loginBuf.append("-"); loginBuf.append(guestId); obj = treeCache.get(fqn, loginBuf.toString()); if (obj != null) { return ((Friend) obj).getValue(DbConstants.IS_FRIEND); } /** * Get scalability datasource for pendingfriends - not partitioned */ /* String sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, isMyFriend() " + sourceName); } */ /** * Get scalability datasource for pendingfriends - not partitioned */ String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("isfriendQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("isfriendQuery"); } isFriendQuery = getQueryMapper().getQuery(queryName); Object[] params = { (Object) loginId, (Object) guestId }; List result1 = isFriendQuery.execute(params); if (result1 != null) { if (result1.size() > 0) { ((Friend) result1.get(0)).setValue(DbConstants.IS_FRIEND, "1"); treeCache.put(fqn, loginBuf.toString(), ((Friend) result1.get(0))); return "1"; } } else { params[0] = guestId; params[1] = loginId; result1 = isFriendQuery.execute(params); if (result1 != null) { if (result1.size() > 0) { ((Friend) result1.get(0)).setValue(DbConstants.IS_FRIEND, "1"); treeCache.put(fqn, sb.toString(), ((Friend) result1.get(0))); return "1"; } } } return "0"; } /** * This method checks if posts/topics exist for a personal blog * @param userId - the user id of the blogger * @param tid - the thread id based on which the messages are retrieved * @return String - "1" (if messages exist for this thread), "0" - otherwise * @throws BaseDaoException */ private String topicExists(String userId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(userId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for pblogtopics partitioned on userId */ /* String sourceName = scalabilityManager.getReadScalability(userId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, UserpageDao topicExists() " + sourceName + " userId = " + userId); } */ String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("pblogtopicexistsQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("pblogtopicexistsQuery"); } existsQuery = getQueryMapper().getQuery(queryName); try { Object[] params = { (Object) userId }; List result = existsQuery.execute(params); if ((result != null) && (result.size() > 0)) { return "1"; } } catch (Exception e) { throw new BaseDaoException("UserpageDao, error in existence of pblog topics , " + existsQuery.getSql() + " params (1) pblogid/userId = " + userId, e); } return "0"; } /** * addTraffic method - adds traffic to usertraffic * @param userId - the userid * @param visitorid - the visitorid * @throws BaseDaoException - when error occurs */ /* not required anymore private void addTraffic(String userId, String visitorid ) throws BaseDaoException { if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(visitorid) ) { throw new BaseDaoException("params are null"); } String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, addTraffic() " + sourceName + " userId = " + userId); } Connection conn = null; try { conn = ds.getConnection(); String[] params = {userId, visitorid}; String queryName = scalabilityManager.getWriteZeroScalability("addusertrafficQuery"); addTrafficQuery = getQueryMapper().getCommonQuery(queryName); addTrafficQuery.run(conn, params); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch(Exception e2) { throw new BaseDaoException("addTraffic in userpage conn.close() error ", e2); } throw new BaseDaoException("exception in addtraffic query", e); } try { if (conn != null) { conn.close(); } } catch(Exception e) { throw new BaseDaoException("addTraffic conn.close() error ", e); } } */ /** * getTopHitsBizAware method - gets the top 10 hits in users who match this bid * @return List - the list of userids (userpage beans) * @throws BaseDaoException - when error occurs */ public List getTopHitsBizAware(String bid, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(bid)) { throw new BaseDaoException("getTopHitsBizAware params are null"); } /** * Get scalability datasource not partitioned */ Fqn fqn = cacheUtil.fqn(DbConstants.TOP_USERS); Object obj = treeCache.get(fqn, DbConstants.TOP_USERS); if (obj != null) { return (List) obj; } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("userhitsbizawareQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("userhitsbizawareQuery"); } usertop10hitsBizAwareQuery = getQueryMapper().getQuery(queryName); try { List result = usertop10hitsBizAwareQuery.execute(bid); treeCache.put(fqn, DbConstants.TOP_USERS, result); return result; } catch (Exception e) { throw new BaseDaoException("UserpageDao, get hitsQuery() " + usertop10hitsBizAwareQuery.getSql(), e); } } /** * getTopHits method - gets the top 10 hits in users * @return List - the list of userids (userpage beans) * @throws BaseDaoException - when error occurs */ public List getTopHits(int accessFlag) throws BaseDaoException { /** * Get scalability datasource for partitioned on userid */ Fqn fqn = cacheUtil.fqn(DbConstants.TOP_USERS); Object obj = treeCache.get(fqn, DbConstants.TOP_USERS); if (obj != null) { return (List) obj; } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("userhitsQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("userhitsQuery"); } usertop10hitsQuery = getQueryMapper().getQuery(queryName); try { List result = usertop10hitsQuery.execute(); treeCache.put(fqn, DbConstants.TOP_USERS, result); return result; } catch (Exception e) { throw new BaseDaoException("UserpageDao, get hitsQuery() " + usertop10hitsQuery.getSql(), e); } } /** * getRecentUsersBizAware method - gets recent users * @return List - the list of users with names and userids * @throws BaseDaoException - when error occurs */ public List getRecentUsersBizAware(String bid, int accessFlag) throws BaseDaoException { Fqn fqn = cacheUtil.fqn(DbConstants.RECENT_USERS); Object obj = treeCache.get(fqn, DbConstants.RECENT_USERS); if (obj != null) { return (List) obj; } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("recentusersbizawarequery"); } else { queryName = scalabilityManager.getReadZeroScalability("recentusersbizawarequery"); } recentUsersBizAwareQuery = getQueryMapper().getQuery(queryName); try { Object[] params = { (Object) bid }; List result = recentUsersBizAwareQuery.execute(params); if (result != null && result.size() > 0) { treeCache.put(fqn, DbConstants.RECENT_USERS, result); } return result; } catch (Exception e) { throw new BaseDaoException( "UserpageDao, get recentUsersBizAwareQuery() " + recentUsersBizAwareQuery.getSql(), e); } } /** * getRecentUsers method - gets recent users * @return List - the list of users with names and userids * @throws BaseDaoException - when error occurs */ public List getRecentUsers(int accessFlag) throws BaseDaoException { Fqn fqn = cacheUtil.fqn(DbConstants.RECENT_USERS); Object obj = treeCache.get(fqn, DbConstants.RECENT_USERS); if (obj != null) { return (List) obj; } String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("recentusersquery"); } else { queryName = scalabilityManager.getReadZeroScalability("recentusersquery"); } recentUsersQuery = getQueryMapper().getQuery(queryName); try { List result = recentUsersQuery.execute(); treeCache.put(fqn, DbConstants.RECENT_USERS, result); return result; } catch (Exception e) { throw new BaseDaoException("UserpageDao, get recentUsersQuery() " + recentUsersQuery.getSql(), e); } } /** * getTraffic method - gets the 10 most recent user traffic * @return List - the list of user traffic (userpage beans) * @throws BaseDaoException - when error occurs */ /* not required anymore public List getTraffic(int accessFlag) throws BaseDaoException { String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("usertrafficQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("usertrafficQuery"); } trafficQuery = getQueryMapper().getQuery(queryName); try { List result = trafficQuery.execute(); return result; } catch (Exception e) { throw new BaseDaoException("UserpageDao, get trafficQuery() " + trafficQuery.getSql(), e); } } */ /** * getCobrand method - gets the cobranding information for this user and sets it in the userpage * @throws BaseDaoException - when error occurs */ private void getCobrand(String loginid, Userpage userpage, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginid) || (userpage == null)) { throw new BaseDaoException("params are null"); } Fqn fqn = cacheUtil.fqn(DbConstants.USER_COBRAND); Object obj = treeCache.get(fqn, loginid); if (obj != null) { userpage.setValue(DbConstants.COBRAND, "1"); userpage.setValue(DbConstants.HEADER, ((Userpage) obj).getValue(DbConstants.HEADER)); userpage.setValue(DbConstants.FOOTER, ((Userpage) obj).getValue(DbConstants.FOOTER)); return; } /** * Get scalability datasource for partitioned on loginid */ String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteScalability(loginid, "usercobrandQuery"); } else { queryName = scalabilityManager.getReadScalability(loginid, "usercobrandQuery"); } cobrandQuery = getQueryMapper().getQuery(queryName); try { Object[] params = { (Object) loginid }; List result = cobrandQuery.execute(params); if ((result != null) && (result.size() > 0)) { userpage.setValue(DbConstants.COBRAND, "1"); userpage.setValue(DbConstants.HEADER, ((Userpage) result.get(0)).getValue(DbConstants.HEADER)); userpage.setValue(DbConstants.FOOTER, ((Userpage) result.get(0)).getValue(DbConstants.FOOTER)); treeCache.put(fqn, loginid, result.get(0)); } } catch (Exception e) { throw new BaseDaoException("UserpageDao, get cobrandQuery() " + cobrandQuery.getSql(), e); } } /** * isAllowed method - checks if this user is allowed * @return boolean - return true if this user is allowed, false otherwise * @throws BaseDaoException - when error occurs */ public boolean isAllowed(String ipAddress) throws BaseDaoException { /** * Get scalability datasource */ String sourceName = "geoSource"; geoDs = scalabilityManager.getSource(sourceName); if (geoDs == null) { throw new BaseDaoException("geoDs is null"); } Connection conn = null; try { conn = geoDs.getConnection(); if (conn == null) { throw new BaseDaoException("isAllowed(), conn is null, geoTargetQuery error "); } List result = geoTargetQuery.run(conn, ipAddress); // user is not allowed as the user belongs to CA or NY if (result != null && result.size() > 0) { return false; } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("UserpageDao, conn.close() error for geoTargetQuery error ", e1); } throw new BaseDaoException("UserpageDaoDb, isAllowed(), geoTargetQuery error ", e); } try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("UserpageDao, conn.close() error for geoTargetQuery error ", e1); } return true; } /** /** * getTopDirs method - gets the top 10 hits in directories * @return List - the list of directories (directory beans) * @throws BaseDaoException - when error occurs */ public List getTopDirs(int accessFlag) throws BaseDaoException { Fqn fqn = cacheUtil.fqn(DbConstants.TOP_DIRS); Object obj = treeCache.get(fqn, DbConstants.TOP_DIRS); if (obj != null) { return (List) obj; } /** * Get scalability datasource */ String queryName = null; if (accessFlag == 1) { queryName = scalabilityManager.getWriteZeroScalability("dirtophitsQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("dirtophitsQuery"); } dirTopHitsQuery = getQueryMapper().getQuery(queryName); try { List result = dirTopHitsQuery.execute(); if (result != null) { treeCache.put(fqn, DbConstants.TOP_DIRS, result); } return result; } catch (Exception e) { throw new BaseDaoException("UserpageDao, dirTopHitsQuery " + dirTopHitsQuery.getSql(), e); } } /** * getLoginCounts - get the number of people who are logged in today * @return - String the count * @throws exception */ public String getLoginCounts() throws BaseDaoException { /** * Get scalability datasource for dirtree, dirscope, directory - * not partitioned */ String queryName = scalabilityManager.getReadZeroScalability("logincountquery"); loginCountQuery = getQueryMapper().getQuery(queryName); if (loginCountQuery == null) { throw new BaseDaoException("LoginCountQuery is null, may be not set in servlet.xml file"); } try { List result = loginCountQuery.execute(); if (result != null && result.size() > 0) { if (result.get(0) != null) { logger.info("counts = " + result.toString()); return ((Hdlogin) result.get(0)).getValue(DbConstants.COUNT); } } } catch (BaseDaoException e) { throw new BaseDaoException("error in loginCountQuery()" + loginCountQuery.getSql(), e); } return null; } /** * checks to see if these properties are set by spring */ public void setJdbcSource(DataSource ds) { this.ds = ds; } public void setGeoSource(DataSource gds) { this.geoDs = gds; } public void setFriendQuery(BasicQuery fq) { this.friendQuery = fq; } /* public void setFriendcheckQuery(BasicQuery fcq) { this.friendCheckQuery = fcq; } */ public void setHdprofileaddQuery(BaseCommonQuery haq) { this.hdprofileAddQuery = haq; } public void setHdloginaddQuery(BaseCommonQuery haq) { this.hdloginAddQuery = haq; } /* not used public void setPersonalinfoaddQuery(BaseCommonQuery paq) { this.personalinfoAddQuery = paq; } */ /* public void setGuestQuery(BasicQuery gq) { this.guestQuery = gq; } */ public void setPhotoQuery(BasicQuery pq) { this.photoQuery = pq; } public void setHdprofileQuery(BasicQuery hpq) { this.hdprofileQuery = hpq; } public void setIncrementvisitsQuery(IncrementVisitsQuery ivq) { this.incrementVisitsQuery = ivq; } public void setPendingfriendoutQuery(BasicQuery pfoq) { this.pendingfriendoutQuery = pfoq; } public void setgeotargetQuery(GeoTargetQuery pfoq) { this.geoTargetQuery = pfoq; } /* public void setPendingfriendinQuery(BasicQuery pfiq) { this.pendingfriendinQuery = pfiq; } */ /* not being used public void setDisplaypageaddQuery(DisplaypageAddQuery daq) { this.displaypageAddQuery = daq; } */ /* public void setInboxcountQuery(BasicQuery icq) { this.inboxOutboxCountQuery = icq; } public void setuserpageQuery(BasicQuery icq) { this.userpageQuery = icq; } public void setFriendfirstQuery(BasicQuery icq) { this.friendFirstQuery = icq; } */ /* public void setismemberorganizerQuery(BasicQuery daq ) { this.isMemberOrganizerQuery = daq; } public void setismemberauthorQuery(BasicQuery daq ) { this.isMemberAuthorQuery = daq; } public void setisuserauthorQuery(BasicQuery daq ) { this.isUserAuthorQuery = daq; } public void setisuserorganizerQuery(BasicQuery daq ) { this.isUserOrganizerQuery = daq; } */ public void setdiaryadmin(DiaryAdmin daq) { this.diaryAdmin = daq; } public void setdirscopeconstants(DirectoryScopeConstants dirscope) { this.dirScope = dirscope; } /* public void setlistcollabrumsidQuery(BasicQuery daq ) { this.listCollabrumsIdQuery = daq; } public void setdirectoryexistsQuery(BasicQuery daq) { this.directoryExistsQuery = daq; } public void setcollabrumexistsQuery(BasicQuery daq) { this.collabrumExistsQuery = daq; } public void setisfriendQuery(BasicQuery daq) { this.isFriendQuery = daq; } public void setpblogtopicexistsQuery(BasicQuery daq) { this.existsQuery = daq; } */ /* not required anymore public void setaddusertrafficQuery(BaseCommonQuery daq) { this.addTrafficQuery = daq; } public void setusertrafficQuery(BasicQuery daq) { this.trafficQuery = daq; } */ /* public void setuserhitsQuery(BasicQuery daq) { this.usertop10hitsQuery = daq; } public void setusercobrandQuery(BasicQuery daq) { this.cobrandQuery = daq; } public void setcarryoncategoryQuery(BasicQuery daq) { this.categoryQuery = daq; } public void setcarryonbycategoryQuery(BasicQuery daq) { this.carryonByCategoryQuery = daq; } public void setuserdefaultphotoQuery(BasicQuery daq) { this.defaultPhotoQuery = daq; } */ }