📄 companymodule.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 CompanyModule { Logger logger = Logger.getLogger(CompanyModule.class); public static String PREFIX = "company."; public static String COMPANY_SHOW = "company.show"; public static String COMPANY_ADD_FORM = "company.add.form"; public static String COMPANY_ADD_AUTO = "company.add.auto"; public static String COMPANY_ADD_SUBMIT = "company.add.submit"; public static String COMPANY_EDIT_SUBMIT = "company.edit.submit"; public static String COMPANY_GET = "company.get"; public static String COMPANY_SEARCH = "company.search"; public static String COMPANY_EXISTS = "company.exists"; public static String COMPANY_DELETE = "company.delete"; public static String PARAM_COMPANY_ID = "id"; public static String PARAM_COMPANY_NAME = "name";/* public static String PARAM_COMPANY_ADDRESS = "address"; public static String PARAM_COMPANY_SUBURB = "suburb"; public static String PARAM_COMPANY_COUNTRY = "country"; public static String PARAM_COMPANY_STATE = "state"; public static String PARAM_COMPANY_POSTCODE = "postcode"; public static String PARAM_COMPANY_PHONE = "phone"; public static String PARAM_COMPANY_FAX = "fax";*/ public static String PARAM_COMPANY_ABN = "abn"; public static String PARAM_COMPANY_ACN = "acn"; public static String PARAM_COMPANY_URL = "url"; public static String PARAM_COMPANY_EMAIL = "email"; public static String PARAM_COMPANY_NOTES = "notes"; public static String PARAM_COMPANY_LOCATIONS = "locations"; public static String PARAM_COMPANY_OWNER = "record-owner"; public static String PARAM_COMPANY_SIZE = "company-size"; public static String PARAM_COMPANY_TYPE = "company-type"; public static String PARAM_COMPANY_AUTO_OWNER = "auto-owner"; private ContactDAO contactDAO = DAOFactory.getInstance().getContactDAO(); private CompanyDAO companyDAO = DAOFactory.getInstance().getCompanyDAO(); //private PermissionDAO permissionDAO = DAOFactory.getInstance().getPermissionDAO(); private LDAPDAO ldapDAO = LDAPDAOFactory.getInstance().getLDAPDAO(); //private PermissionModule pm = new PermissionModule(); public static SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm a"); /** Creates a new instance of CallModule */ public CompanyModule() { } public ServerResponse processCommand(ServerCommand command) throws Exception { String user = command.getUser(); ServerResponse sr = new ServerResponse(); if (command.getKey().equals(COMPANY_SHOW)) {// StringBuffer buf = new StringBuffer(); sr.addPart("companies", companyDAO.getCompanyList(user)); return sr; } else if (command.getKey().equals(COMPANY_GET)) { // Get single company String id = (String) command.getParameterValue(PARAM_COMPANY_ID); //Permission p = pm.getUserPermissionFor(Integer.parseInt(id), EntityType.COMPANY, user); //sr.addPart("permission", p); Company company = companyDAO.getCompany(Integer.parseInt(id)); sr.addPart("company", company); return sr; } else if (command.getKey().equals(COMPANY_EXISTS)) { // search for the company String name = (String) command.getParameterValue(PARAM_COMPANY_NAME); if (companyDAO.companyExists(name)) { sr.addPart("exists", "true"); return sr; } } else if (command.getKey().equals(COMPANY_SEARCH)) { // Perform company search Company company = new Company(); company.setCompanyName((String) command.getParameterValue(PARAM_COMPANY_NAME)); Location location = (Location) command.getParameterValue(PARAM_COMPANY_LOCATIONS); /* company.setSuburb((String) command.getParameterValue(PARAM_COMPANY_SUBURB)); company.setCountry((String) command.getParameterValue(PARAM_COMPANY_COUNTRY)); company.setState((String) command.getParameterValue(PARAM_COMPANY_STATE)); company.setPostcode((String) command.getParameterValue(PARAM_COMPANY_POSTCODE)); */ String typeCode = (String)command.getParameterValue(PARAM_COMPANY_TYPE); CompanyIdentifiersTypeCode type = (CompanyIdentifiersTypeCode) CompanyIdentifiersTypeCode.decode(typeCode, CompanyIdentifiersTypeCode.class); company.setCompanyType(type); ArrayList results = (ArrayList) companyDAO.searchCompany(company, location); StaffMember sm = ldapDAO.getUser(user); sr.addPart("user", sm); sr.addPart("results", results); return sr; } else if (command.getKey().equals(COMPANY_ADD_AUTO)) { // first check if it exists String name = (String) command.getParameterValue(PARAM_COMPANY_NAME); Company company = companyDAO.getCompany(name); if (company == null) { String owner = (String) command.getParameterValue(PARAM_COMPANY_AUTO_OWNER); if (owner == null) owner = user; company = new Company(); company.setCompanyName(name); company.setOwner(owner); company.setIncomplete(true); company.setCompanyType(CompanyIdentifiersTypeCode.OTHER); company.setLocations((ArrayList) command.getParameterValue(PARAM_COMPANY_LOCATIONS)); /*String phone = (String) command.getParameterValue(PARAM_COMPANY_PHONE); if (phone != null) company.setPhone(phone);*/ String notes = (String) command.getParameterValue(PARAM_COMPANY_NOTES); if (notes == null) notes = "(Automatically created company)"; company.setNotes(notes); companyDAO.insertCompany(company); //createDefaultCompanyPermissions(company.getCompanyID(), owner); } sr.addPart("company", company); return sr; } else if (command.getKey().equals(COMPANY_ADD_SUBMIT) || command.getKey().equals(COMPANY_EDIT_SUBMIT)) { // User is submitting a new call Company company = new Company();/* company.setPhone((String)command.getParameterValue(PARAM_COMPANY_PHONE)); company.setFax((String)command.getParameterValue(PARAM_COMPANY_FAX)); company.setAddress((String)command.getParameterValue(PARAM_COMPANY_ADDRESS)); company.setSuburb((String)command.getParameterValue(PARAM_COMPANY_SUBURB)); company.setCountry((String)command.getParameterValue(PARAM_COMPANY_COUNTRY)); company.setState((String)command.getParameterValue(PARAM_COMPANY_STATE)); company.setPostcode((String)command.getParameterValue(PARAM_COMPANY_POSTCODE));*/ company.setCompanyName((String)command.getParameterValue(PARAM_COMPANY_NAME)); company.setNotes((String)command.getParameterValue(PARAM_COMPANY_NOTES)); company.setABN((ArrayList)command.getParameterValue(PARAM_COMPANY_ABN)); company.setACN((ArrayList)command.getParameterValue(PARAM_COMPANY_ACN)); company.setURL((ArrayList)command.getParameterValue(PARAM_COMPANY_URL)); company.setEmail((ArrayList)command.getParameterValue(PARAM_COMPANY_EMAIL)); logger.debug(command.getParameterValue(PARAM_COMPANY_LOCATIONS)); company.setLocations((ArrayList)command.getParameterValue(PARAM_COMPANY_LOCATIONS)); String sizeCode = (String)command.getParameterValue(PARAM_COMPANY_SIZE); CompanySizeCode size = (CompanySizeCode) CompanySizeCode.decode(sizeCode, CompanySizeCode.class); company.setCompanySize(size); String typeCode = (String)command.getParameterValue(PARAM_COMPANY_TYPE); CompanyIdentifiersTypeCode type = (CompanyIdentifiersTypeCode) CompanyIdentifiersTypeCode.decode(typeCode, CompanyIdentifiersTypeCode.class); company.setCompanyType(type); company.setIncomplete(false); // any updating indicates that the company is not incomplete // Note that at this stage, you can't change the owner of a company // once it's been created if (command.getKey().equals(COMPANY_ADD_SUBMIT)){ company.setOwner(user); Company newCompany = companyDAO.insertCompany(company); //createDefaultCompanyPermissions(newCompany.getCompanyID(), user); company = newCompany; } else { company.setCompanyID(Integer.parseInt((String)command.getParameterValue(PARAM_COMPANY_ID))); companyDAO.updateCompany(company); } sr.addPart("company", company); return sr; } else if (command.getKey().equals(COMPANY_DELETE)) { int companyID = Integer.parseInt((String)command.getParameterValue(PARAM_COMPANY_ID)); //Permission p = pm.getUserPermissionFor(companyID, EntityType.COMPANY, user); //if (p.canDelete()) { StaffMember sm = ldapDAO.getUser(user); if (sm != null && sm.getPower() >= 3) { companyDAO.deleteCompany(companyID); return ServerResponse.ACKNOWLEDGE_OKAY; } else { return ServerResponse.PERMISSION_DENIED; } } return null; } /** * <p>Creates and adds the default permissions for a new Company. These are: * <ul> * <li>Full access for creator</li> * <li>Read access for creator's primary group</li> * <li>No access for 'everyone'</li> * </ul> * @param companyID The identifier of the newly created company * @param user Currently logged-in user public void createDefaultCompanyPermissions(int companyID, String user) { // Set the creator's permissions (full) Permission p = new Permission(); p.setEntityID(companyID); p.setEntityType(EntityType.COMPANY); 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); // Set the creator's primary group permissions (read only) String primaryGroup = ldapDAO.getPrimaryGroup(user); p.setID(primaryGroup); p.setPermissionType(PermissionType.PERMISSION_GROUP); p.setPermission(Permission.READ_PERMISSION, true); p.setPermission(Permission.WRITE_PERMISSION, false); p.setPermission(Permission.DELETE_PERMISSION, false); permissionDAO.insertPermission(p); } */ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -