web.SaveglobalquotaController.java Source code

Java tutorial

Introduction

Here is the source code for web.SaveglobalquotaController.java

Source

/**
* 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.BaseDaoException;
import dao.BaseDaoModel;
import dao.CobrandDao;
import dao.DirectoryDao;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ldap.LdapApi;
import model.Userpage;
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 SaveglobalquotaController extends BaseController implements Controller {

    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());

    /**
     * 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 {

        // ***************************************************************************
        // This will initialize common data in the abstract class and the return result is of no value.
        // The abstract class initializes protected variables, login, collabrum, logininfo.
        // Which can be accessed in all controllers if they want to.
        // ***************************************************************************

        try {
            ModelAndView m = super.handleRequest(request, response);
        } catch (Exception e) {
            return handleError("error in handleRequest", e);
        }

        if (!WebUtil.isLicenseProfessional(login)) {
            return handleError("Cannot manage SaveglobalquotaController feature in deluxe version.");
        }

        // ***************************************************************************
        // This is the only line of code you need to get all session info initialized!
        // Always be the first line before anything else is done. Add to each controller's
        // handlRequest method. Also recollabrum to extend SessionObject.
        // ***************************************************************************
        outOfSession(request, response);

        if (RegexStrUtil.isNull(login) || (loginInfo == null)) {
            return handleUserpageError("Login/loginInfo is null in SaveglobalquotaController.");
        }

        String strSize = request.getParameter(DbConstants.SIZE);
        String strQCnt = request.getParameter(DbConstants.QCNT);

        logger.info("qcnt = " + strQCnt);
        logger.info("size = " + strSize);

        int size = 0;
        int qcnt = 0;

        if (!RegexStrUtil.isNull(strSize)) {
            size = new Integer(strSize).intValue();
        }

        if (!RegexStrUtil.isNull(strQCnt)) {
            qcnt = new Integer(strQCnt).intValue();
        }

        ArrayList entryIdList = new ArrayList();
        ArrayList entryListVals = new ArrayList();

        if (entryIdList == null || entryListVals == null) {
            return handleError("cannot new ArrayList() for either entryListVals or entryIdList vals");
        } else {
            for (int i = 0; i < size; i++) {
                String val = new Integer(i).toString();
                logger.info("val = " + val);
                String myString = "col" + val;
                logger.info("myString = " + myString);
                entryIdList.add(RegexStrUtil.goodNameStr(request.getParameter(myString)));
                logger.info("entryidnum = " + i + "=" + request.getParameter(myString));
                myString = "colentry" + val;
                logger.info("myString = " + myString);
                entryListVals.add(RegexStrUtil.goodNameStr(request.getParameter(myString)));
                logger.info("entryidval = " + i + " = " + request.getParameter(myString));
            }
        }

        ArrayList qNameListVals = new ArrayList();
        ArrayList qNameList = new ArrayList();
        ArrayList qTypeList = new ArrayList();

        if (qNameListVals == null || qNameList == null || qTypeList == null) {
            return handleError("cannot new ArrayList() for qNameListVals");
        } else {
            for (int i = 0; i < qcnt; i++) {
                String val = new Integer(i).toString();
                //if (!RegexStrUtil.isNull(request.getParameter(val))) {  
                if (!RegexStrUtil.isNull(val)) {
                    String myString = "qcol" + val;
                    qNameList.add(RegexStrUtil.goodNameStr(request.getParameter(myString)));
                    logger.info(i + request.getParameter(myString));
                    myString = "qcolname" + val;
                    qNameListVals.add(RegexStrUtil.goodNameStr(request.getParameter(myString)));
                    logger.info(i + request.getParameter(myString));
                    myString = "qtype" + val;
                    qTypeList.add(RegexStrUtil.goodNameStr(request.getParameter(myString)));
                    logger.info(i + request.getParameter(myString));
                }
            }
        }
        logger.info("qNameList = " + qNameList.toString());
        logger.info("qNameListVals = " + qNameListVals.toString());
        logger.info("qTypeList = " + qTypeList.toString());
        logger.info("entryIdList = " + entryIdList.toString());
        logger.info("entryListVals = " + entryListVals.toString());

        /**
        *  show the quota size
        */
        List quotaList = null;
        List divisions = null;
        List areas = null;
        List sections = null;
        List groups = null;
        try {
            LdapApi ldapConnection = new LdapApi();
            if (ldapConnection == null) {
                return handleError("ldapConnection is null, SaveglobalquotaController");
            } else {
                areas = ldapConnection.getStructureValues(LdapConstants.ldapArea);
                groups = ldapConnection.getStructureValues(LdapConstants.ldapGroup);
                sections = ldapConnection.getStructureValues(LdapConstants.ldapSection);
                divisions = ldapConnection.getStructureValues(LdapConstants.ldapDivision);
                if (areas != null && areas.size() > 0) {
                    logger.info("areas = " + areas.toString());
                }
                if (groups != null && groups.size() > 0) {
                    logger.info("groups = " + groups.toString());
                }
                if (sections != null && sections.size() > 0) {
                    logger.info("sections = " + sections.toString());
                }
                if (divisions != null && divisions.size() > 0) {
                    logger.info("divisions = " + divisions.toString());
                }
            }
        } catch (Exception e) {
            return handleError("ldap error while retrieving quota types getStructureValues()", e);
        }

        /**
        *  dirDao
        */
        DirectoryDao dirDao = (DirectoryDao) daoMapper.getDao(DbConstants.DIRECTORY);
        try {
            if ((dirDao == null)) {
                return handleError("dirDao is null in SaveglobalquotaController collabrum, " + login);
            } else {
                dirDao.saveGlobalQuotas(login, entryIdList, entryListVals, qNameList, qNameListVals, qTypeList);

                quotaList = dirDao.getGlobalQuotas(login, DbConstants.READ_FROM_MASTER);
                quotaList = dirDao.getGlobalMatch(areas, groups, sections, divisions, quotaList,
                        LdapUtil.getOrganization());
            }
        } catch (BaseDaoException e) {
            return handleError("Exception occured, getQuotaSize(), SaveglobalquotaController for login " + login,
                    e);
        }

        CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND);
        if (cobrandDao == null) {
            return handleUserpageError("CobrandDao is null, SaveglobalquotaController");
        }

        Userpage cobrand = null;
        try {
            cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID));
        } catch (BaseDaoException e) {
            return handleError("Exception occured, getUserCobrand(), SaveglobalquotaController for login " + login,
                    e);
        }

        String viewName = DbConstants.VIEW_GLOBAL_QUOTAS;
        Map myModel = new HashMap();
        myModel.put(DbConstants.LOGIN_INFO, loginInfo);
        myModel.put(DbConstants.QUOTAS, quotaList);
        myModel.put(DbConstants.COBRAND, cobrand);
        myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists);
        myModel.put(DbConstants.USER_PAGE, userpage);
        if (DiaryAdmin.isDiaryAdmin(login)) {
            myModel.put(DbConstants.BUSINESS_EXISTS, "1");
        } else {
            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;
    }
}