⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callmodule.java

📁 发泄网! 发泄网! 发泄网! 发泄网! 发泄网! 发泄网! 发泄网! 发泄网!
💻 JAVA
字号:
    /* CRMS, customer relationship management system    Copyright (C) 2003  Service To Youth Council    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    (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, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    For further information contact the SYC ICT department on GPL@syc.net.au    98 Kermode Street    North Adelaide    South Australia    SA 5006     +61 (0)8 8367 0755    *//* * CallModule.java * * Created on 1 April 2003, 02:17 */package crms.module;import crms.*;import crms.dao.*;import crms.util.*;import crms.vo.*;import java.text.*;import java.util.*;import org.apache.log4j.Logger;/** * <p>This is the object responsible for handling the majority of the  * business logic related to handling calls.</p> * * @author  dmurphy */public class CallModule {        Logger logger = Logger.getLogger(CallModule.class);        public static String PREFIX = "calls.";    public static String CALLS_SHOW = "calls.show";    public static String CALLS_ADD_FORM = "calls.add.form";    public static String CALLS_ADD_SUBMIT = "calls.add.submit";    public static String CALL_EDIT_FORM = "calls.edit.form";    public static String CALL_EDIT_SUBMIT = "calls.edit.submit";    public static String CALL_SEARCH = "calls.search";    public static String CALL_DELETE = "calls.delete";        public static String PARAM_CALL_FOR = "for";    public static String PARAM_CALL_FROM = "from";    public static String PARAM_CALL_DATE = "date";    public static String PARAM_CALL_TIME = "time";    public static String PARAM_CALL_NUMBER = "number";    public static String PARAM_CALL_NOTE = "note";    public static String PARAM_CALL_FIRST_NAME = "firstName";    public static String PARAM_CALL_LAST_NAME = "lastName";    public static String PARAM_CALL_FLAGS = "flags";        public static String PARAM_CALL_SEARCH = "search";        public static String PARAM_CALL_ID = "call-id";    public static String PARAM_CALL_SHOW_ALL = "show-all";	public static String PARAM_COMPANY_ID = "company-id";        private CallDAO callDAO = DAOFactory.getInstance().getCallDAO();    private ContactDAO contactDAO = DAOFactory.getInstance().getContactDAO();	private CompanyDAO companyDAO = DAOFactory.getInstance().getCompanyDAO();    private LDAPDAO ldapDAO = LDAPDAOFactory.getInstance().getLDAPDAO();    private PermissionDAO permissionDAO = DAOFactory.getInstance().getPermissionDAO();        public static SimpleDateFormat df = new SimpleDateFormat("d MMMM, yyyy h:mm a");            PermissionModule pm = new PermissionModule();        /** Creates a new instance of CallModule */    public CallModule() {            }        public ServerResponse processCommand(ServerCommand command) throws Exception {                String user = command.getUser();        ServerResponse response = new ServerResponse();                if (command.getKey().equals(CALL_SEARCH)) {            CallSearch search = (CallSearch) command.getParameterValue(PARAM_CALL_SEARCH);			Integer companyID = (Integer)command.getParameterValue(PARAM_COMPANY_ID);            ArrayList callList = null;            			// check if we are filtering on company id				if (companyID != null && companyID.intValue() > 0) {				search.setCompanyID(companyID.intValue());			}									callList = (ArrayList) callDAO.searchCalls(search, user);                        logger.debug("Adding " + callList.size() + " calls to response.");            response.addPart("calls", callList);            return response;        }        else if (command.getKey().equals(CALLS_SHOW)) {                        boolean limit = (command.getParameterValue(PARAM_CALL_SHOW_ALL) == null);			Integer companyID = (Integer)command.getParameterValue(PARAM_COMPANY_ID);            ArrayList callList = null;            			// check if we are filtering on company id				if (companyID != null && companyID.intValue() > 0) {				callList = (ArrayList) callDAO.getCallListForCompany(companyID.intValue(), user,limit);			} else {				callList = (ArrayList) callDAO.getCallList(user,limit);			}            logger.debug("Adding " + callList.size() + " calls to response.");            response.addPart("calls", callList);                        ArrayList contacts = new ArrayList();            for (int i=0; i < callList.size(); i++) {                Call call = (Call) callList.get(i);                Contact contact = contactDAO.getContact(call.getContactID());                contacts.add(contact);            }            response.addPart("contacts", contacts);                        return response;        }        else if (command.getKey().equals(CALLS_ADD_FORM)) {                        // Prepare form data for Add (Log) Call            response.addPart("date", new Date());            return response;        }        else if (command.getKey().equals(CALLS_ADD_SUBMIT)) {                        // User is submitting a new call                        Call call = new Call();            call.setCreator(user);                        String date = (String) command.getParameterValue(PARAM_CALL_DATE);            String time = (String) command.getParameterValue(PARAM_CALL_TIME);                        Date newDate = df.parse(date + " " + time);                        call.setDate(newDate);            call.setNote((String)command.getParameterValue(PARAM_CALL_NOTE));            call.setNumber((String)command.getParameterValue(PARAM_CALL_NUMBER));            call.setOwner((String)command.getParameterValue(PARAM_CALL_FOR));            call.setOwnerHasRead(false);            call.setFromFirstName((String)command.getParameterValue(PARAM_CALL_FIRST_NAME));            call.setFromLastName((String)command.getParameterValue(PARAM_CALL_LAST_NAME));			call.setFlags( ((Integer)command.getParameterValue(PARAM_CALL_FLAGS)).intValue());            			if (command.getParameterValue(PARAM_COMPANY_ID) != null) {				Integer cID = (Integer)command.getParameterValue(PARAM_COMPANY_ID);				call.setCompanyID(cID.intValue());			}                        Call newCall = callDAO.createCall(call);                        // Create the default Call permissions for this call.            //createDefaultCallPermissions(newCall, user);			response.addPart("call", newCall);                        return response;                    }        else if (command.getKey().equals(CALL_EDIT_SUBMIT)) {                        // User is updating an existing call                        Call call = new Call();            call.setCreator(user);                        int callID = Integer.parseInt((String)command.getParameterValue(PARAM_CALL_ID));            String date = (String)command.getParameterValue(PARAM_CALL_DATE);            String time = (String)command.getParameterValue(PARAM_CALL_TIME);                                    Permission p = pm.getUserPermissionFor(callID, EntityType.CALL, user);                        if (!p.canWrite()) {                return ServerResponse.PERMISSION_DENIED;                }                        Date newDate = df.parse(date + " " + time);                        call.setCallID(callID);            call.setDate(newDate);//            call.setContactID(contactID);            call.setNote((String)command.getParameterValue(PARAM_CALL_NOTE));            call.setNumber((String)command.getParameterValue(PARAM_CALL_NUMBER));            call.setOwner((String)command.getParameterValue(PARAM_CALL_FOR));            //call.setOwnerHasRead(false);            call.setFromFirstName((String)command.getParameterValue(PARAM_CALL_FIRST_NAME));            call.setFromLastName((String)command.getParameterValue(PARAM_CALL_LAST_NAME));			call.setFlags( ((Integer)command.getParameterValue(PARAM_CALL_FLAGS)).intValue());                        if (command.getParameterValue(PARAM_COMPANY_ID) != null) {            	Integer cID = (Integer)command.getParameterValue(PARAM_COMPANY_ID);            	call.setCompanyID(cID.intValue());            }                        callDAO.updateCall(call);            return ServerResponse.ACKNOWLEDGE_OKAY;        }        else if (command.getKey().equals(CALL_EDIT_FORM)) {            String callID = (String) command.getParameterValue(PARAM_CALL_ID);            Integer companyID = (Integer) command.getParameterValue(PARAM_COMPANY_ID);                        //Permission p = pm.getUserPermissionFor(Integer.parseInt(callID), EntityType.CALL, user);            //response.addPart("permission", p);            //logger.debug("Added permission to response for call...");                        //if (p.canRead()) {                Call call = callDAO.getCall(callID, user);                if (!call.getOwnerHasRead()) {                    call.setOwnerHasRead(true);                    callDAO.updateCall(call);                }                            if (call.getOwner() != null) {                    StaffMember sm = ldapDAO.getUser(call.getOwner());					call.setOwnerObj(sm);                }                else {                    logger.debug("Call owner is null!");                }				if ( call.getCompanyID() > 0) {					Company company = companyDAO.getCompany(call.getCompanyID());					call.setCompany(company);				} else {					logger.debug("Company is null!");				}                response.addPart("call", call);            /*} else {                return ServerResponse.PERMISSION_DENIED;                        }*/                        return response;        }        else if (command.getKey().equals(CALL_DELETE)) {            String callID = (String) command.getParameterValue(PARAM_CALL_ID);            //Permission p = pm.getUserPermissionFor(Integer.parseInt(callID), EntityType.CALL, user);            //if (p.canDelete()) {                callDAO.deleteCall(Integer.parseInt(callID));                return ServerResponse.ACKNOWLEDGE_OKAY;            /*} else {                return ServerResponse.PERMISSION_DENIED;               }*/        }                return null;    }         /**     * <p>Creates and adds the default permissions for a new Call. These are:     *  <ul>     *      <li>Full access for creator</li>     *      <li>Full access for owner of call (callee)</li>     *  </ul>     * @param callID The identifier of the newly created call     * @param user Currently logged-in user     */        public void createDefaultCallPermissions(Call call, String user) {        // Set the creator's permissions (full)        Permission p = new Permission();        p.setEntityID(call.getCallID());        p.setEntityType(EntityType.CALL);        p.setID(user);        p.setPermissionType(PermissionType.PERMISSION_USER);        p.setPermission(Permission.READ_PERMISSION, true);        p.setPermission(Permission.WRITE_PERMISSION, true);        p.setPermission(Permission.DELETE_PERMISSION, true);        permissionDAO.insertPermission(p);                p.setID(call.getOwner());        permissionDAO.insertPermission(p);                        // Allow 'everyone' to have read access.//        p.setPermissionType(PermissionType.PERMISSION_ALL);//        p.setID(null);//        p.setPermission(Permission.READ_PERMISSION, true);//        p.setPermission(Permission.WRITE_PERMISSION, false);//        p.setPermission(Permission.DELETE_PERMISSION, false);//        permissionDAO.insertPermission(p);            }        public Call getCall(String id, String user) {        return callDAO.getCall(id, user);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -