Java tutorial
/******************************************************************************* * Copyright (c) 2009 David Harrison. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl-3.0.html * * Contributors: * David Harrison - initial API and implementation ******************************************************************************/ package com.sfs.whichdoctor.beans; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashMap; import org.apache.commons.lang.StringUtils; import com.sfs.Formatter; import com.sfs.beans.UserBean; /** * The Class BulkContactBean. * * @author David Harrison */ public class BulkContactBean implements java.io.Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** The id. */ private int id; /** The reference id. */ private int referenceId; /** The type. */ private String type; /** The object type. */ private String objectType; /** The secondary type. */ private String secondaryType; /** The reference gui ds. */ private HashMap<Integer, Integer> referenceGUIDs = new HashMap<Integer, Integer>(); /** The contact type. */ private String contactType; /** The contact class. */ private String contactClass; /** The start date. */ private Date startDate; /** The end date. */ private Date endDate; /** Holds the person objects *. */ private HashMap<Integer, PersonBean> people = new HashMap<Integer, PersonBean>(); /** Holds the organisation objects *. */ private HashMap<Integer, OrganisationBean> organisations = new HashMap<Integer, OrganisationBean>(); /** Holds references to the GUIDs for the person and organisation objects *. */ private Collection<Integer> personGUIDsReceiving = new ArrayList<Integer>(); /** The person gui ds not receiving. */ private Collection<Integer> personGUIDsNotReceiving = new ArrayList<Integer>(); /** The organisation gui ds receiving. */ private Collection<Integer> organisationGUIDsReceiving = new ArrayList<Integer>(); /** The organisation gui ds not receiving. */ private Collection<Integer> organisationGUIDsNotReceiving = new ArrayList<Integer>(); /** The created user. */ private UserBean createdUser; /** The created date. */ private Date createdDate; /** The created by. */ private String createdBy; /** * Sets the id. * * @param idVal the new id */ public final void setId(final int idVal) { this.id = idVal; } /** * Gets the id. * * @return the id */ public final int getId() { return this.id; } /** * Sets the reference id. * * @param referenceIdVal the new reference id */ public final void setReferenceId(final int referenceIdVal) { this.referenceId = referenceIdVal; } /** * Gets the reference id. * * @return the reference id */ public final int getReferenceId() { return this.referenceId; } /** * Sets the type. * * @param typeVal the new type */ public final void setType(final String typeVal) { this.type = typeVal; } /** * Gets the type. * * @return the type */ public final String getType() { return this.type; } /** * Sets the object type. * * @param objectTypeVal the new object type */ public final void setObjectType(final String objectTypeVal) { String strObjectType = objectTypeVal; if (objectTypeVal != null) { if (StringUtils.equalsIgnoreCase(objectTypeVal, "Members")) { strObjectType = "people"; } if (StringUtils.equalsIgnoreCase(objectTypeVal, "Invoices")) { strObjectType = "debits"; } } this.objectType = strObjectType.toLowerCase(); } /** * Gets the object type. * * @return the object type */ public final String getObjectType() { return this.objectType; } /** * Sets the secondary type. * * @param secondaryTypeVal the new secondary type */ public final void setSecondaryType(final String secondaryTypeVal) { this.secondaryType = secondaryTypeVal; } /** * Gets the secondary type. * * @return the secondary type */ public final String getSecondaryType() { return this.secondaryType; } /** * Sets the start date. * * @param startDateVal the new start date */ public final void setStartDate(final Date startDateVal) { this.startDate = startDateVal; } /** * Gets the start date. * * @return the start date */ public final Date getStartDate() { return this.startDate; } /** * Sets the end date. * * @param endDateVal the new end date */ public final void setEndDate(final Date endDateVal) { this.endDate = endDateVal; } /** * Gets the end date. * * @return the end date */ public final Date getEndDate() { return this.endDate; } /** * Gets the web object type. * * @return the web object type */ public final String getWebObjectType() { String webObjectType = ""; if (this.objectType != null) { if (StringUtils.equalsIgnoreCase(this.objectType, "people") || StringUtils.equalsIgnoreCase(this.objectType, "rotations")) { webObjectType = "person"; } else { if (this.objectType.length() > 0) { webObjectType = this.objectType.substring(0, this.objectType.length() - 1); } } } return webObjectType; } /** * Gets the action title. * * @return the action title */ public final String getActionTitle() { String title = "Return to " + getType().toLowerCase(); if (StringUtils.equalsIgnoreCase(getType(), "ledger") || StringUtils.equalsIgnoreCase(getType(), "ageddebtors")) { title = "Return to finance report"; } return title; } /** * Gets the action url. * * @param preferences the preferences * * @return the action url */ public final String getActionUrl(final PreferencesBean preferences) { String url = ""; if (StringUtils.equalsIgnoreCase(getType(), "export")) { url = preferences.buildUrl("save", getObjectType().toLowerCase() + "_export", "existing", getReferenceId(), "Type=" + getSecondaryType()); } if (StringUtils.equalsIgnoreCase(getType(), "search")) { url = preferences.buildUrl("read", getObjectType().toLowerCase() + "_search", "search"); } if (StringUtils.equalsIgnoreCase(getType(), "group")) { url = preferences.buildUrl("read", "groups", "guid", getReferenceId(), "StartDate=" + Formatter.conventionalDate(getStartDate()) + "&EndDate=" + Formatter.conventionalDate(getEndDate())); } if (StringUtils.equalsIgnoreCase(getType(), "ledger")) { url = preferences.buildUrl("read", "ledger", "search"); } if (StringUtils.equalsIgnoreCase(getType(), "ageddebtors")) { url = preferences.buildUrl("read", "ledger", "search"); } return url; } /** * Sets the reference gui ds. * * @param collectionGUIDs the new reference gui ds */ public final void setReferenceGUIDs(final Collection<Integer> collectionGUIDs) { for (int referenceGUID : collectionGUIDs) { this.referenceGUIDs.put(referenceGUID, referenceGUID); } } /** * Gets the reference gui ds. * * @return the reference gui ds */ public final Collection<Integer> getReferenceGUIDs() { Collection<Integer> collectionGUIDs = new ArrayList<Integer>(); for (Integer referenceGUID : this.referenceGUIDs.keySet()) { collectionGUIDs.add(referenceGUID); } return collectionGUIDs; } /** * Adds the reference guid. * * @param referenceGUID the reference guid */ public final void addReferenceGUID(final int referenceGUID) { if (!this.referenceGUIDs.containsKey(referenceGUID)) { this.referenceGUIDs.put(referenceGUID, referenceGUID); } } /** * Sets the contact type. * * @param contactTypeVal the new contact type */ public final void setContactType(final String contactTypeVal) { this.contactType = contactTypeVal; } /** * Gets the contact type. * * @return the contact type */ public final String getContactType() { return this.contactType; } /** * Sets the contact class. * * @param contactClassVal the new contact class */ public final void setContactClass(final String contactClassVal) { this.contactClass = contactClassVal; } /** * Gets the contact class. * * @return the contact class */ public final String getContactClass() { return this.contactClass; } /** * Sets the people. * * @param peopleRef the people */ public final void setPeople(final HashMap<Integer, PersonBean> peopleRef) { this.people = peopleRef; } /** * Gets the people. * * @return the people */ public final HashMap<Integer, PersonBean> getPeople() { if (this.people == null) { this.people = new HashMap<Integer, PersonBean>(); } return this.people; } /** * Adds the person. * * @param person the person */ public final void addPerson(final PersonBean person) { if (this.people == null) { this.people = new HashMap<Integer, PersonBean>(); } if (!this.people.containsKey(person.getGUID())) { this.people.put(person.getGUID(), person); if (person.getFirstEmailAddress() != null) { if (person.getFirstEmailAddress().getRequestNoMail() || person.getFirstEmailAddress().getReturnedMail()) { this.personGUIDsNotReceiving.add(person.getGUID()); } else { this.personGUIDsReceiving.add(person.getGUID()); } } else { this.personGUIDsNotReceiving.add(person.getGUID()); } } } /** * Gets the person. * * @param guid the guid * * @return the person */ public final PersonBean getPerson(final int guid) { PersonBean person = null; if (containsPerson(guid)) { person = getPeople().get(guid); } return person; } /** * Contains person. * * @param personGUID the person guid * * @return true, if successful */ public final boolean containsPerson(final int personGUID) { return this.getPeople().containsKey(personGUID); } /** * Gets the people gui ds. * * @return the people gui ds */ public final Collection<Integer> getPeopleGUIDs() { Collection<Integer> peopleGUIDs = new ArrayList<Integer>(); for (Integer personGUID : getPeople().keySet()) { peopleGUIDs.add(personGUID); } return peopleGUIDs; } /** * Sets the organisations. * * @param organisationsRef the organisations */ public final void setOrganisations(final HashMap<Integer, OrganisationBean> organisationsRef) { this.organisations = organisationsRef; } /** * Gets the organisations. * * @return the organisations */ public final HashMap<Integer, OrganisationBean> getOrganisations() { return this.organisations; } /** * Adds the organisation. * * @param organisation the organisation */ public final void addOrganisation(final OrganisationBean organisation) { if (this.organisations == null) { this.organisations = new HashMap<Integer, OrganisationBean>(); } if (!this.organisations.containsKey(organisation.getGUID())) { this.organisations.put(organisation.getGUID(), organisation); if (organisation.getFirstEmailAddress() != null) { if (organisation.getFirstEmailAddress().getRequestNoMail() || organisation.getFirstEmailAddress().getReturnedMail()) { this.organisationGUIDsNotReceiving.add(organisation.getGUID()); } else { this.organisationGUIDsReceiving.add(organisation.getGUID()); } } else { this.organisationGUIDsNotReceiving.add(organisation.getGUID()); } } } /** * Gets the organisation. * * @param guid the guid * * @return the organisation */ public final OrganisationBean getOrganisation(final int guid) { OrganisationBean organisation = null; if (containsOrganisation(guid)) { organisation = getOrganisations().get(guid); } return organisation; } /** * Contains organisation. * * @param organisationGUID the organisation guid * * @return true, if successful */ public final boolean containsOrganisation(final int organisationGUID) { return this.getOrganisations().containsKey(organisationGUID); } /** * Gets the organisation gui ds. * * @return the organisation gui ds */ public final Collection<Integer> getOrganisationGUIDs() { Collection<Integer> organisationGUIDs = new ArrayList<Integer>(); for (Integer organisationGUID : getOrganisations().keySet()) { organisationGUIDs.add(organisationGUID); } return organisationGUIDs; } /** * Sets the person gui ds receiving. * * @param personGUIDsReceivingRef the new person gui ds receiving */ public final void setPersonGUIDsReceiving(final Collection<Integer> personGUIDsReceivingRef) { this.personGUIDsReceiving = personGUIDsReceivingRef; } /** * Gets the person gui ds receiving. * * @return the person gui ds receiving */ public final Collection<Integer> getPersonGUIDsReceiving() { return this.personGUIDsReceiving; } /** * Sets the person gui ds not receiving. * * @param personGUIDsNotReceivingRef the new person gui ds not receiving */ public final void setPersonGUIDsNotReceiving(final Collection<Integer> personGUIDsNotReceivingRef) { this.personGUIDsNotReceiving = personGUIDsNotReceivingRef; } /** * Gets the person gui ds not receiving. * * @return the person gui ds not receiving */ public final Collection<Integer> getPersonGUIDsNotReceiving() { return this.personGUIDsNotReceiving; } /** * Gets the people receiving count. * * @return the people receiving count */ public final int getPeopleReceivingCount() { int peopleReceivingCount = 0; if (this.personGUIDsReceiving != null) { peopleReceivingCount = this.personGUIDsReceiving.size(); } return peopleReceivingCount; } /** * Gets the people not receiving count. * * @return the people not receiving count */ public final int getPeopleNotReceivingCount() { int peopleNotReceivingCount = 0; if (this.personGUIDsNotReceiving != null) { peopleNotReceivingCount = this.personGUIDsNotReceiving.size(); } return peopleNotReceivingCount; } /** * Sets the organisation gui ds receiving. * * @param organisationGUIDsReceivingRef the new organisation guids receiving */ public final void setOrganisationGUIDsReceiving(final Collection<Integer> organisationGUIDsReceivingRef) { this.organisationGUIDsReceiving = organisationGUIDsReceivingRef; } /** * Gets the organisation gui ds receiving. * * @return the organisation gui ds receiving */ public final Collection<Integer> getOrganisationGUIDsReceiving() { return this.organisationGUIDsReceiving; } /** * Sets the organisation gui ds not receiving. * * @param organisationGUIDsNotReceivingRef the new organisation guids not * receiving */ public final void setOrganisationGUIDsNotReceiving(final Collection<Integer> organisationGUIDsNotReceivingRef) { this.organisationGUIDsNotReceiving = organisationGUIDsNotReceivingRef; } /** * Gets the organisation gui ds not receiving. * * @return the organisation gui ds not receiving */ public final Collection<Integer> getOrganisationGUIDsNotReceiving() { return this.organisationGUIDsNotReceiving; } /** * Gets the organisations receiving count. * * @return the organisations receiving count */ public final int getOrganisationsReceivingCount() { int organisationsReceivingCount = 0; if (this.organisationGUIDsReceiving != null) { organisationsReceivingCount = this.organisationGUIDsReceiving.size(); } return organisationsReceivingCount; } /** * Gets the organisations not receiving count. * * @return the organisations not receiving count */ public final int getOrganisationsNotReceivingCount() { int organisationsNotReceivingCount = 0; if (this.organisationGUIDsNotReceiving != null) { organisationsNotReceivingCount = this.organisationGUIDsNotReceiving.size(); } return organisationsNotReceivingCount; } /** * Gets the receiving total count. * * @return the receiving total count */ public final int getReceivingTotalCount() { return getPeopleReceivingCount() + getOrganisationsReceivingCount(); } /** * Gets the not receiving total count. * * @return the not receiving total count */ public final int getNotReceivingTotalCount() { return getPeopleNotReceivingCount() + getOrganisationsNotReceivingCount(); } /** * Sets the created user. * * @param createdUserRef the new created user */ public final void setCreatedUser(final UserBean createdUserRef) { this.createdUser = createdUserRef; } /** * Gets the created user. * * @return the created user */ public final UserBean getCreatedUser() { return this.createdUser; } /** * Sets the created date. * * @param createdDateVal the new created date */ public final void setCreatedDate(final Date createdDateVal) { this.createdDate = createdDateVal; } /** * Gets the created date. * * @return the created date */ public final Date getCreatedDate() { return this.createdDate; } /** * Sets the created by. * * @param createdByVal the new created by */ public final void setCreatedBy(final String createdByVal) { this.createdBy = createdByVal; } /** * Gets the created by. * * @return the created by */ public final String getCreatedBy() { return this.createdBy; } /** * Gets the receiving email list. * * @param user the user * @param preferences the application preferences * @return the receiving email list */ public final String getReceivingEmailList(final UserBean user, final PreferencesBean preferences) { StringBuffer receivingEmailList = new StringBuffer(); String divider = ", "; if (StringUtils.equalsIgnoreCase(preferences.getOption("email", "client"), "Outlook")) { divider = "; "; } if (user != null && StringUtils.isNotBlank(user.getEmail())) { receivingEmailList.append(user.getEmail()); receivingEmailList.append(divider); } if (this.personGUIDsReceiving != null) { for (Integer guid : personGUIDsReceiving) { PersonBean person = getPerson(guid); if (person != null) { receivingEmailList.append(person.getFirstEmailAddress().getEmail()); receivingEmailList.append(divider); } } } if (this.organisationGUIDsReceiving != null) { for (Integer guid : organisationGUIDsReceiving) { OrganisationBean organisation = getOrganisation(guid); if (organisation != null) { receivingEmailList.append(organisation.getFirstEmailAddress().getEmail()); receivingEmailList.append(divider); } } } return receivingEmailList.toString(); } /** * Clear results. */ public final void clearResults() { this.personGUIDsReceiving = new ArrayList<Integer>(); this.personGUIDsNotReceiving = new ArrayList<Integer>(); this.organisationGUIDsReceiving = new ArrayList<Integer>(); this.organisationGUIDsNotReceiving = new ArrayList<Integer>(); this.people = new HashMap<Integer, PersonBean>(); this.organisations = new HashMap<Integer, OrganisationBean>(); } /** * Clones the bulk contact bean. */ @Override public BulkContactBean clone() { BulkContactBean contact = new BulkContactBean(); contact.setId(this.id); contact.setReferenceId(this.referenceId); contact.setType(this.type); contact.setObjectType(this.objectType); contact.setSecondaryType(this.secondaryType); contact.setReferenceGUIDs(this.getReferenceGUIDs()); contact.setContactType(this.contactType); contact.setContactClass(this.contactClass); contact.setStartDate(this.getStartDate()); contact.setEndDate(this.getEndDate()); contact.setPeople(this.getPeople()); contact.setPersonGUIDsReceiving(this.getPersonGUIDsReceiving()); contact.setPersonGUIDsNotReceiving(this.getPersonGUIDsNotReceiving()); contact.setOrganisations(this.getOrganisations()); contact.setOrganisationGUIDsReceiving(this.getOrganisationGUIDsReceiving()); contact.setOrganisationGUIDsNotReceiving(this.getOrganisationGUIDsNotReceiving()); contact.setCreatedUser(this.createdUser); contact.setCreatedDate(this.getCreatedDate()); contact.setCreatedBy(this.createdBy); return contact; } }