home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/TutorWebHandler.java,v 1.8 2005/01/18 11:52:12 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.8 $
 * $Date: 2005/01/18 11:52:12 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2005 by MyVietnam.net
 *
 * This program 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 2
 * of the License, or any later version.
 *
 * All copyright notices regarding mvnForum MUST remain intact
 * in the scripts and in the outputted HTML.
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in the
 * footer of the pages MUST remain visible when the pages
 * are viewed on the internet or intranet.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Mai  Nguyen  mai.nh@MyVietnam.net
 */

package com.mvnforum.admin;

/**
 *
 * @author  mainh
 */
import java.sql.Timestamp;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;

import com.mvnforum.MVNForumConfig;
import com.mvnforum.auth.*;
import com.mvnforum.db.*;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvncore.util.ParamUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class TutorWebHandler {

    private static Log log = LogFactory.getLog(TutorWebHandler.class);

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    /** Creates a new instance of TutorWebHandler */
    TutorWebHandler() {
    }

    void prepareShowTutorManagement(HttpServletRequest request)
        throws DatabaseException, AssertionException, BadInputException, ObjectNotFoundException, AuthenticationException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        int groupID = DAOFactory.getGroupsDAO().getGroupIDFromGroupName(GroupsDAO.TUTOR_GROUP_NAME);
        int totalTutors = DAOFactory.getMemberGroupDAO().getNumberOfBeans_inGroup(groupID);

        if (offset > totalTutors) {
            //@todo : localize me
            throw new BadInputException("The offset is not allowed to be greater than total members.");
        }
        Collection tutorBeans = DAOFactory.getMemberGroupDAO().getBeans_limit(groupID, offset, postsPerPage);

        request.setAttribute("TutorBeans", tutorBeans);
        request.setAttribute("TotalTutors", new Integer(totalTutors));
        request.setAttribute("TutorGroupID", new Integer(groupID));
    }

    public void prepareAssignUserToTutor(HttpServletRequest request)
        throws DatabaseException, AssertionException, BadInputException, ObjectNotFoundException, AuthenticationException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        int tutorID = ParamUtil.getParameterInt(request, "tutorid");
        MemberBean tutorBean = DAOFactory.getMemberDAO().getMember_forPublic(tutorID);
        //warning: Must check if user is a tutor or not

        // for sort and order stuff
        String sort  = ParamUtil.getParameter(request, "sort");
        String order = ParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "MemberCreationDate";
        if (order.length()== 0) order = "DESC";

        // we continue
        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }
        // This function is used to specify how many member is avaiable(NO belongs to any tutor)
        int totalMembers = DAOFactory.getMemberTutorDAO().getNumberOfMembers();

        if (offset > totalMembers) {
            //@todo : localize me
            throw new BadInputException("The offset is not allowed to be greater than total members.");
        }

        //Collection memberRows = DAOFactory.getMemberDAO().getMembers_withSortSupport_limit(offset, postsPerPage, sort, order);

        // This function is used to specify all member is avaiable (No belongs to any tutor)
        Collection memberRows = DAOFactory.getMemberTutorDAO().getBeans(offset, postsPerPage);

        Collection memberRowsOfTutor = DAOFactory.getMemberTutorDAO().getMembers_inTutor(tutorID);

        request.setAttribute("MemberBeans", memberRows);
        request.setAttribute("TotalMembers", new Integer(totalMembers));
        request.setAttribute("MembersOfTutor", memberRowsOfTutor);
        request.setAttribute("TutorBean", tutorBean);
        request.setAttribute("offset", new Integer(offset));
    }

    public void prepareListUserToTutor(HttpServletRequest request)
        throws DatabaseException, AssertionException, BadInputException, ObjectNotFoundException, AuthenticationException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        int tutorID = ParamUtil.getParameterInt(request, "tutorid");
        MemberBean tutorBean = DAOFactory.getMemberDAO().getMember_forPublic(tutorID); //Wrong roi

        //warning: Must check if user is a tutor or not


        // for sort and order stuff
        String sort  = ParamUtil.getParameter(request, "sort");
        String order = ParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "MemberCreationDate";
        if (order.length()== 0) order = "DESC";

        // we continue
        //int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        int totalMembers = DAOFactory.getMemberTutorDAO().getNumberOfBeans_inTutor(tutorID);

        if (offset > totalMembers) {
            //@todo : localize me
            throw new BadInputException("The offset is not allowed to be greater than total members.");
        }

        //Collection memberRows = DAOFactory.getMemberDAO().getMembers_withSortSupport_limit(offset, postsPerPage, sort, order);

        // This function is used to specify all member is avaiable (No belongs to any tutor)
        //Collection memberRows = DAOFactory.getMemberTutorDAO().getBeans(offset, postsPerPage);

        Collection memberRowsOfTutor = DAOFactory.getMemberTutorDAO().getMembers_inTutor(tutorID);

        request.setAttribute("TotalMembers", new Integer(totalMembers));
        request.setAttribute("MembersOfTutor", memberRowsOfTutor);
        request.setAttribute("offset", new Integer(offset));
        request.setAttribute("TutorBean", tutorBean);
    }

    public void prepareListUserExpire_unused(HttpServletRequest request)
        throws DatabaseException, AssertionException, BadInputException, AuthenticationException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        //int tutorID = ParamUtil.getParameterInt(request, "tutorid");
        //MemberBean tutorBean = DAOFactory.getMemberDAO().getMember_forPublic(tutorID); //Wrong roi

        //warning: Must check if user is a tutor or not

        // for sort and order stuff
        String sort  = ParamUtil.getParameter(request, "sort");
        String order = ParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "MemberCreationDate";
        if (order.length()== 0) order = "DESC";

        // we continue
        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }
        Timestamp now = DateUtil.getCurrentGMTTimestampExpiredDay(MVNForumConfig.getUserTutorExpireSoonDate());
        int totalMembers = DAOFactory.getMemberTutorDAO().getNumberOfBeans_inExpire(now);

        if (offset > totalMembers) {
            //@todo : localize me
            throw new BadInputException("The offset is not allowed to be greater than total members.");
        }

        Collection memberRowsOfUser = DAOFactory.getMemberTutorDAO().getBeans_inExpire_limit(now, offset, postsPerPage);

        request.setAttribute("TotalMembers", new Integer(totalMembers));
        request.setAttribute("MembersOfUser", memberRowsOfUser);
        request.setAttribute("offset", new Integer(offset));
        //request.setAttribute("TutorBean", tutorBean);
    }

    public void updateMemberTutorProcess(HttpServletRequest request)
        throws DatabaseException, DuplicateKeyException, AssertionException, BadInputException,
        CreateException, ObjectNotFoundException, AuthenticationException, ForeignKeyNotFoundException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        String btnAssign   = ParamUtil.getParameter(request, "AssignButton");
        String btnUnAssign = ParamUtil.getParameter(request, "UnAssignButton");
        int tutorID        = ParamUtil.getParameterInt(request, "TutorID");

        String[] checkList = request.getParameterValues("selectedmember");
        int relationType   = 0;
        int relationOption = 0;
        int relationStatus = 0;

        if ("Assign".equals(btnAssign)) {
            String tutorName = ParamUtil.getParameter(request, "TutorName", true);
            Timestamp exprire  = DateUtil.getCurrentGMTTimestampExpiredDay(MVNForumConfig.getExpireDateTutor());
            Timestamp now      = DateUtil.getCurrentGMTTimestamp();
            for (int i = 0; (checkList != null) && (i < checkList.length); i++) {
                int memberID = Integer.parseInt(checkList[i]);
                log.debug("Process Assign for MemberID = " + memberID);
                MemberBean memberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
                DAOFactory.getMemberTutorDAO().create(memberID, memberBean.getMemberName(), tutorID, tutorName,
                        now, exprire, relationType, relationOption, relationStatus);
            }
            request.setAttribute("action", "assign");
        } else if ("UnAssign".equals(btnUnAssign)) {
            for (int i = 0; (checkList != null) && (i < checkList.length); i++) {
                int memberID = Integer.parseInt(checkList[i]);
                log.debug("Process UnAssign for MemberID = " + memberID);
                DAOFactory.getMemberTutorDAO().delete(memberID);
            }
            request.setAttribute("action", "unassign");
        }
    }
}


my book on functional programming

 

new blog posts

 

Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.