📄 contactmodule.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 ContactModule { Logger logger = Logger.getLogger(CompanyModule.class); public static String PREFIX = "contact."; public static String CONTACT_SHOW = "contact.show"; public static String CONTACT_ADD_FORM = "contact.add.form"; public static String CONTACT_ADD_SUBMIT = "contact.add.submit"; public static String CONTACT_EDIT_SUBMIT = "contact.edit.submit"; public static String CONTACT_GET = "contact.get"; public static String CONTACT_DELETE = "contact.delete"; public static String CONTACT_SEARCH_SUBMIT = "contact.search.submit"; public static String PARAM_CONTACT_ID = "id"; public static String PARAM_CONTACT_COMPANY = "company"; public static String PARAM_CONTACT_COMPANY_ID = "company-id"; public static String PARAM_CONTACT_LOCATION = "location"; public static String PARAM_CONTACT_FIRST_NAME = "first-name"; public static String PARAM_CONTACT_LAST_NAME = "last-name"; public static String PARAM_CONTACT_GENDER = "gender"; public static String PARAM_CONTACT_BIRTHDATE = "birthdate"; public static String PARAM_CONTACT_HOME_PHONE = "home-phone"; public static String PARAM_CONTACT_HOME_FAX = "home-fax"; public static String PARAM_CONTACT_WORK_PHONE = "work-phone"; public static String PARAM_CONTACT_WORK_OTHER_PHONE = "work-other-phone"; public static String PARAM_CONTACT_WORK_FAX = "work-fax"; public static String PARAM_CONTACT_WORK_MOBILE = "work-mobile"; public static String PARAM_CONTACT_HOME_ADDRESS = "home-address"; public static String PARAM_CONTACT_HOME_SUBURB = "home-suburb"; public static String PARAM_CONTACT_HOME_STATE = "home-state"; public static String PARAM_CONTACT_HOME_POSTCODE = "home-postcode"; public static String PARAM_CONTACT_HOME_COUNTRY = "home-country"; public static String PARAM_CONTACT_WORK_ADDRESS = "work-address"; public static String PARAM_CONTACT_WORK_SUBURB = "work-suburb"; public static String PARAM_CONTACT_WORK_STATE = "work-state"; public static String PARAM_CONTACT_WORK_POSTCODE = "work-postcode"; public static String PARAM_CONTACT_WORK_COUNTRY = "work-country"; public static String PARAM_CONTACT_NOTES = "notes"; // lubo: added contact identifier public static String PARAM_CONTACT_IDENTIFIER = "role"; public static String PARAM_CONTACT_EMAIL = "email"; public static String PARAM_CONTACT_WWW = "www"; // lubo: added extra fields public static String PARAM_CONTACT_TITLE = "title"; public static String PARAM_CONTACT_POSITION = "position"; public static String PARAM_CONTACT_OTHER_PHONE = "other-phone"; private ContactDAO contactDAO = DAOFactory.getInstance().getContactDAO(); private CompanyDAO companyDAO = DAOFactory.getInstance().getCompanyDAO(); private NotesDAO notesDAO = DAOFactory.getInstance().getNotesDAO(); 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 ContactModule() { } public ServerResponse processCommand(ServerCommand command) throws Exception { String user = command.getUser(); ServerResponse sr = new ServerResponse(); if (command.getKey().equals(CONTACT_SHOW)) { // lubo: get company id if present Integer companyID = (Integer)command.getParameterValue(PARAM_CONTACT_COMPANY_ID); ArrayList result = null; // lubo: check if we are filtering on company id if (companyID != null && companyID.intValue() > 0) { result = (ArrayList) contactDAO.getContactList(companyID.toString(),user); } else { result = (ArrayList) contactDAO.getContactList(String.valueOf(Company.ALL_COMPANIES.getCompanyID()),user); } sr.addPart("contacts", result); return sr; } else if (command.getKey().equals(CONTACT_GET)) { // Get single company String id = (String) command.getParameterValue(PARAM_CONTACT_ID); Permission p = pm.getUserPermissionFor(Integer.parseInt(id), EntityType.CONTACT, user); sr.addPart("permission", p); if (p.canRead()) { Contact contact = contactDAO.getContact(Integer.parseInt(id)); sr.addPart("contact", contact); if (contact.getCompanyID() > 0) { Company company = companyDAO.getCompany(contact.getCompanyID()); sr.addPart("company", company); } return sr; } else { return ServerResponse.PERMISSION_DENIED; } } else if (command.getKey().equals(CONTACT_ADD_FORM)) { // Prepare form data for Add (Log) Call sr.addPart("staff", ldapDAO.listUsers()); sr.addPart("date", new Date()); return sr; } else if (command.getKey().equals(CONTACT_ADD_SUBMIT) || command.getKey().equals(CONTACT_EDIT_SUBMIT) || (command.getKey().equals(ServerCommand.PARAM_FORM_SUBMIT) && (((String)command.getParameterValue(ServerCommand.PARAM_FORM_NAME)).equals(CONTACT_ADD_SUBMIT) || ((String)command.getParameterValue(ServerCommand.PARAM_FORM_NAME)).equals(CONTACT_EDIT_SUBMIT)))) { // User is submitting a new call Contact contact = new Contact(); String idStr = (String)command.getParameterValue(PARAM_CONTACT_COMPANY_ID); if (idStr != null) { int id = Integer.parseInt(idStr); contact.setCompanyID(id); //logger.debug("Set Company ID to: " + id); } else { contact.setCompanyID(Company.NO_COMPANY.getCompanyID()); } /*String dateString = (String)command.getParameterValue(PARAM_CONTACT_BIRTHDATE); if (dateString != null) { try { contact.setBirthDate(Contact.df.parse(dateString)); } catch (ParseException ex) { throw new RuntimeException("Error parsing date: " + dateString + " with format: " + df.toPattern(), ex); } }*/ contact.setBirthDate((String)command.getParameterValue(PARAM_CONTACT_BIRTHDATE)); contact.setFirstName((String)command.getParameterValue(PARAM_CONTACT_FIRST_NAME)); contact.setLastName((String)command.getParameterValue(PARAM_CONTACT_LAST_NAME)); contact.setGender((GenderCode) GenderCode.decode((String)command.getParameterValue(PARAM_CONTACT_GENDER), GenderCode.class)); Integer intLoc = (Integer)command.getParameterValue(PARAM_CONTACT_LOCATION); if (intLoc != null) contact.setLocationID(intLoc.intValue()); contact.setHomePhone((String)command.getParameterValue(PARAM_CONTACT_HOME_PHONE)); contact.setHomeFax((String)command.getParameterValue(PARAM_CONTACT_HOME_FAX)); contact.setHomeAddress((String)command.getParameterValue(PARAM_CONTACT_HOME_ADDRESS)); contact.setHomeSuburb((String)command.getParameterValue(PARAM_CONTACT_HOME_SUBURB)); contact.setHomeCountry((String)command.getParameterValue(PARAM_CONTACT_HOME_COUNTRY)); contact.setHomePostCode((String)command.getParameterValue(PARAM_CONTACT_HOME_POSTCODE)); contact.setHomeState((String)command.getParameterValue(PARAM_CONTACT_HOME_STATE)); contact.setWorkPhone((String)command.getParameterValue(PARAM_CONTACT_WORK_PHONE)); contact.setWorkOtherPhone((String)command.getParameterValue(PARAM_CONTACT_WORK_OTHER_PHONE)); contact.setWorkFax((String)command.getParameterValue(PARAM_CONTACT_WORK_FAX)); contact.setWorkMobile((String)command.getParameterValue(PARAM_CONTACT_WORK_MOBILE)); contact.setWorkAddress((String)command.getParameterValue(PARAM_CONTACT_WORK_ADDRESS)); contact.setWorkSuburb((String)command.getParameterValue(PARAM_CONTACT_WORK_SUBURB)); contact.setWorkCountry((String)command.getParameterValue(PARAM_CONTACT_WORK_COUNTRY)); contact.setWorkPostCode((String)command.getParameterValue(PARAM_CONTACT_WORK_POSTCODE)); contact.setWorkState((String)command.getParameterValue(PARAM_CONTACT_WORK_STATE)); contact.setNotes((String)command.getParameterValue(PARAM_CONTACT_NOTES)); // lubo: added contact identifier String roleCode = (String)command.getParameterValue(PARAM_CONTACT_IDENTIFIER); ContactIdentifiresTypeCode role = (ContactIdentifiresTypeCode) ContactIdentifiresTypeCode.decode(roleCode, ContactIdentifiresTypeCode.class); contact.setContactIdentifier(role); // lubo: email and www contact.setEmail((String)command.getParameterValue(PARAM_CONTACT_EMAIL)); contact.setWWW((String)command.getParameterValue(PARAM_CONTACT_WWW)); // lubo: extra fields contact.setOtherPhone((String)command.getParameterValue(PARAM_CONTACT_OTHER_PHONE)); contact.setPosition((String)command.getParameterValue(PARAM_CONTACT_POSITION)); contact.setTitle((String)command.getParameterValue(PARAM_CONTACT_TITLE)); // Note that at this stage, you can't change the owner of a contact // once it's been created if (command.getKey().equals(CONTACT_ADD_SUBMIT)){ contact.setOwner(user); Contact newContact = contactDAO.insertContact(contact); createDefaultContactPermissions(newContact.getContactID(), user); // tnichols - pass back the contact ID to the requestor sr.addPart("new-contact-id", new Integer(newContact.getContactID())); return sr; } else { contact.setContactID(Integer.parseInt((String)command.getParameterValue(PARAM_CONTACT_ID))); contactDAO.updateContact(contact); } } else if (command.getKey().toLowerCase().equals(CONTACT_SEARCH_SUBMIT)) { String firstName = (String)command.getParameterValue(PARAM_CONTACT_FIRST_NAME); String lastName = (String)command.getParameterValue(PARAM_CONTACT_LAST_NAME); String company = (String)command.getParameterValue(PARAM_CONTACT_COMPANY); Contact contact = new Contact(); contact.setFirstName(firstName); contact.setLastName(lastName); ArrayList contacts = (ArrayList) contactDAO.searchContacts(contact,user, company); sr.addPart("contacts", contacts); return sr; } else if (command.getKey().toLowerCase().equals(CONTACT_DELETE)) { String contactID = (String) command.getParameterValue(PARAM_CONTACT_ID); Permission p = pm.getUserPermissionFor(Integer.parseInt(contactID), EntityType.CONTACT, user); if (p.canDelete()) { contactDAO.deleteContact(Integer.parseInt(contactID)); return ServerResponse.ACKNOWLEDGE_OKAY; } else { return ServerResponse.PERMISSION_DENIED; } } return null; } /** * <p>Creates and adds the default permissions for a new Ccontact. 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 createDefaultContactPermissions(int contactID, String user) { StaffMember sm = ldapDAO.getUser(user); // Set the creator's permissions (full) Permission p = new Permission(); p.setEntityID(contactID); p.setEntityType(EntityType.CONTACT); p.setID(user); p.setPower(sm.getPower()); p.setLocation(sm.getLocation()); p.setDivision(sm.getDepartment()); p.setPermissionType(PermissionType.PERMISSION_USER); p.setPermission(Permission.READ_PERMISSION, true); p.setPermission(Permission.WRITE_PERMISSION, true); p.setPermission(Permission.DELETE_PERMISSION, true); p.setPermission(Permission.SECURITY_PERMISSION, true); permissionDAO.insertPermission(p); // Set the creator's primary group permissions (read only) p.setPermissionType(PermissionType.PERMISSION_GROUP); // location / division should be the same as previous p.setPower(0); p.setID(null); p.setPermission(Permission.READ_PERMISSION, true); p.setPermission(Permission.WRITE_PERMISSION, false); p.setPermission(Permission.DELETE_PERMISSION, false); p.setPermission(Permission.SECURITY_PERMISSION, false); permissionDAO.insertPermission(p); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -