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 web; import dao.*; import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import model.Blog; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import util.*; /** * * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ * * Directories can be added only the login users who have permissions to add * */ public class Viewtop10Controller extends BaseController implements Controller { /** Logger for this class and subclasses */ protected final Log logger = LogFactory.getLog(getClass()); protected volatile MysqlSearch sqlSearch; /** * This method is called by the spring framework. The configuration * for this controller to be invoked is based on the pagetype and * is set in the urlMapping property in the spring config file. * * @param request the <code>HttpServletRequest</code> * @param response the <code>HttpServletResponse</code> * @throws ServletException * @throws IOException * @return ModelAndView this instance is returned to spring */ public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /** * For subscription model don't show unless the user has session */ try { ModelAndView m = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in Viewtop10Controller", e); } if (WebUtil.isProductPremiumSubscription()) { outOfSession(request, response); } if (getDaoMapper() == null) { handleError("DaoMapper is null, Viewtop10Controller."); } UserpageDao userpageDao = (UserpageDao) daoMapper.getDao(DbConstants.USER_PAGE); if (userpageDao == null) { return handleError("userpageDao is null in ToptenusersController"); } List recentUsers = null; List topUsers = null; List recentDirImages = null; List topDirs = null; List recentPhotos = null; List photoHitsList = null; List recentPersonalBlogs = null; List popularPersonalBlogs = null; HashSet tagSet = null; PblogDao pblogDao = (PblogDao) daoMapper.getDao(DbConstants.PERSONAL_BLOG); if (pblogDao == null) { return handleError("pblogDao is null in toptenblogsController"); } PblogTopicDao pblogTopicDao = (PblogTopicDao) daoMapper.getDao(DbConstants.PBLOG_TOPIC); if (pblogTopicDao == null) { return handleError("pblogTopicDao is null in toptenblogsController"); } MemberDao memberDao = (MemberDao) getDaoMapper().getDao(DbConstants.MEMBER); if (memberDao == null) { return handleError("memberDao is null pblogaddController"); } CarryonDao carryonDao = (CarryonDao) daoMapper.getDao(DbConstants.CARRYON); if (carryonDao == null) { return handleError("carryonDao is null in viewtop10Controller"); } DirectoryDao dirDao = (DirectoryDao) daoMapper.getDao(DbConstants.DIRECTORY); if (dirDao == null) { return handleError("dirDao is null in viewtop10Controller"); } /** * admin can search in any business. */ boolean isBizAware = false; HashSet blogTagSet = null; List randDirImages = null; String bid = null; if (WebUtil.isProductPremiumSubscription()) { if (!RegexStrUtil.isNull(login)) { if (!DiaryAdmin.isDiaryAdmin(login)) { isBizAware = true; } } if (userpage != null) { bid = userpage.getValue(DbConstants.BID); } } if (isBizAware) { try { if (!RegexStrUtil.isNull(bid)) { topUsers = userpageDao.getTopHitsBizAware(bid, DbConstants.READ_FROM_SLAVE); //recentPersonalBlogs = pblogDao.getRecentBlogsBizAware(bid, DbConstants.READ_FROM_SLAVE); recentPersonalBlogs = pblogTopicDao.getBizCurrentTopics(bid, DbConstants.READ_FROM_SLAVE); if (recentPersonalBlogs != null) { for (int i = 0; i < recentPersonalBlogs.size(); i++) { if (recentPersonalBlogs.get(i) != null) { String userId = ((Blog) recentPersonalBlogs.get(i)).getValue(DbConstants.BLOG_ID); String photoId = memberDao.getPhotoEntryId(userId); ((Blog) recentPersonalBlogs.get(i)).setValue(DbConstants.PHOTO_ID, photoId); } } } popularPersonalBlogs = pblogDao.getPopularBlogsBizAware(bid, DbConstants.READ_FROM_SLAVE); photoHitsList = carryonDao.getCarryonHitsBizAware(bid, DbConstants.READ_FROM_SLAVE); } } catch (BaseDaoException e) { return handleError( "Exception in either getTopHitsBizAware()/getRecentBlogsBizAware/getPopularBlogsBizAware", e); } } else { try { topUsers = userpageDao.getTopHits(DbConstants.READ_FROM_SLAVE); recentUsers = userpageDao.getRecentUsers(DbConstants.READ_FROM_SLAVE); //recentPersonalBlogs = pblogDao.getRecentBlogs(); recentPersonalBlogs = pblogTopicDao.getCurrentTopics(DbConstants.READ_FROM_SLAVE); if (recentPersonalBlogs != null && recentPersonalBlogs.size() > 0) { for (int i = 0; i < recentPersonalBlogs.size(); i++) { if (recentPersonalBlogs.get(i) != null) { String userId = ((Blog) recentPersonalBlogs.get(i)).getValue(DbConstants.BLOG_ID); String photoId = memberDao.getPhotoEntryId(userId); ((Blog) recentPersonalBlogs.get(i)).setValue(DbConstants.PHOTO_ID, photoId); } } } popularPersonalBlogs = pblogDao.getPopularBlogs(); if (!RegexStrUtil.isNull(GlobalConst.PortalServer)) { if (GlobalConst.hddomain.contains(GlobalConst.PortalServer)) { recentDirImages = dirDao.getRecentSelectDirImages(DbConstants.INDIA_CENTURY, DbConstants.READ_FROM_MASTER); } else { recentDirImages = dirDao.getRecentDirImages(DbConstants.READ_FROM_MASTER); } } randDirImages = dirDao.getRandDirImages(DbConstants.PHOTO_CATEGORY_INT, GlobalConst.directoryId, DbConstants.READ_FROM_MASTER); photoHitsList = carryonDao.getCarryonHits(); recentPhotos = carryonDao.getRecentCarryon(DbConstants.READ_FROM_SLAVE, DbConstants.PHOTO_CATEGORY); if (photoHitsList != null) { tagSet = carryonDao.getUniqueTags(photoHitsList); } if (recentPersonalBlogs != null) { blogTagSet = pblogDao.getPblogTags(recentPersonalBlogs); } if (popularPersonalBlogs != null) { HashSet tagSet2 = pblogDao.getPblogTags(popularPersonalBlogs); if (tagSet2 != null) { blogTagSet = sqlSearch.getUniqueTags(blogTagSet, tagSet2); } } } catch (BaseDaoException e) { return handleError("Exception in either getRecentBlogs()/getPopularBlogs() in pblogDao", e); } } //if (!RegexStrUtil.isNull(login)) { try { if (rbDirectoryExists.equals("1")) { topDirs = userpageDao.getTopDirs(DbConstants.READ_FROM_MASTER); if (!RegexStrUtil.isNull(GlobalConst.PortalServer)) { if (GlobalConst.hddomain.contains(GlobalConst.PortalServer)) { recentDirImages = dirDao.getRecentSelectDirImages(DbConstants.INDIA_CENTURY, DbConstants.READ_FROM_MASTER); } else { recentDirImages = dirDao.getRecentDirImages(DbConstants.READ_FROM_MASTER); } } if (topDirs != null) { topDirs = dirDao.setDirPhotos(topDirs); } } } catch (BaseDaoException e) { return handleError("Exception in either getTopDirs()", e); } //} String viewName = "viewtop10"; Map myModel = new HashMap(); myModel.put(DbConstants.RECENT_USERS, recentUsers); myModel.put(DbConstants.RECENT_CARRYON, recentPhotos); myModel.put(DbConstants.RECENT_DIR_IMAGES, recentDirImages); myModel.put(DbConstants.RAND_DIR_IMAGES, randDirImages); myModel.put(DbConstants.RECENT_BLOGS, recentPersonalBlogs); myModel.put(DbConstants.POPULAR_BLOGS, popularPersonalBlogs); myModel.put(DbConstants.TOP_USERS, topUsers); myModel.put(DbConstants.TOP_CARRYON, photoHitsList); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); String dirTagString = null; if (rbDirectoryExists.equals("1")) { if (topDirs != null && topDirs.size() > 0) { dirTagString = RegexStrUtil.getDirKeysAsString(topDirs); } myModel.put(DbConstants.TOP_DIRS, topDirs); } StringBuffer sb = new StringBuffer(); if (sb != null) { if (tagSet != null && tagSet.size() > 0) { sb.append(RegexStrUtil.goodText(tagSet.toString())); sb.append(" "); } if (blogTagSet != null) { sb.append(RegexStrUtil.getUsertagsAsString(blogTagSet)); sb.append(" "); } if (!RegexStrUtil.isNull(dirTagString)) { sb.append(dirTagString); } myModel.put(DbConstants.USER_TAGS, sb.toString()); } if (!RegexStrUtil.isNull(login)) { myModel.put(DbConstants.LOGIN_INFO, loginInfo); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); } return new ModelAndView(viewName, "model", myModel); } /** * BaseDaoModel set by the spring framework. It maps the DAO implementation * to the pagetype. * * @param daoMapper set the BaseDaoModel instance */ public void setDaoMapper(BaseDaoModel daoMapper) { this.daoMapper = daoMapper; } /** * BaseDaoModel set by the spring framework. It maps the DAO implementation * to the pagetype. * * @return BaseDaoModel get the BaseDaoModel instance */ public BaseDaoModel getDaoMapper() { return daoMapper; } public void setmysqlSearch(MysqlSearch mysqlSearch) { this.sqlSearch = mysqlSearch; } }