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 com.sfs.Formatter; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Calendar; import java.util.StringTokenizer; import org.apache.commons.lang.StringUtils; import com.sfs.whichdoctor.formatter.OutputFormatter; /** * The Class RotationBean. * * @author David Harrison 30th May 2003 */ public class RotationBean extends WhichDoctorCoreBean { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** The Constant MILLISECONDS. */ private static final int MILLISECONDS = 1000; /** The Constant SECONDS. */ private static final int SECONDS = 60; /** The Constant MINUTES. */ private static final int MINUTES = 60; /** The Constant HOURS. */ private static final int HOURS = 24; /** The Constant DAYS. */ private static final int DAYS = 30; /** The Constant WORKING_DAYS_CONSTANT. */ private static final double WORKING_DAYS_CONSTANT = 0.7142857; /** The person id. */ private int personId; /** The person. */ private PersonBean person; /** The rotation type. */ private String rotationType; /** The rotation type abbreviation. */ private String rotationTypeAbbreviation; /** The training class. */ private String trainingClass; /** The training type. */ private String trainingType; /** The training mapping. */ private String trainingMapping; /** The start date. */ private Date startDate; /** The end date. */ private Date endDate; /** The year. */ private int year; /** The leave days. */ private int leaveDays; /** The training time. */ private double trainingTime; /** The organisation1 id. */ private int organisation1Id; /** The organisation2 id. */ private int organisation2Id; /** The organisation1. */ private OrganisationBean organisation1; /** The organisation2. */ private OrganisationBean organisation2; /** The organisation1 name. */ private String organisation1Name; /** The organisation2 name. */ private String organisation2Name; /** The organisation1 type. */ private String organisation1Type; /** The organisation1 type mapping. */ private String organisation1TypeMapping; /** The organisation2 type. */ private String organisation2Type; /** The organisation2 type mapping. */ private String organisation2TypeMapping; /** The supervisors. */ private Collection<SupervisorBean> supervisors; /** The reports. */ private Collection<ReportBean> reports; /** The accreditation. */ private Collection<AccreditationBean> accreditation; /** The assessment. */ private Collection<AssessmentBean> assessment; /** The online tools. */ private Collection<OnlineToolBean> onlineTools; /** The person search. */ private PersonBean personSearch; /** The people guids. */ private Collection<Integer> peopleGUIDs; /** The summary types. */ private Collection<String> summaryTypes; /** The summary status. */ private String summaryStatus; /** The committee name. */ private String committeeName; /** * Sets the person id. * * @param personIdVal the new person id */ public final void setPersonId(final int personIdVal) { this.personId = personIdVal; } /** * Gets the person id. * * @return the person id */ public final int getPersonId() { return this.personId; } /** * Sets the person. * * @param personRef the new person */ public final void setPerson(final PersonBean personRef) { this.person = personRef; } /** * Gets the person. * * @return the person */ public final PersonBean getPerson() { return this.person; } /** * Sets the rotation type. * * @param rotationTypeVal the new type */ public final void setRotationType(final String rotationTypeVal) { this.rotationType = rotationTypeVal; } /** * Gets the rotation type. * * @return the rotation type */ public final String getRotationType() { return this.rotationType; } /** * Gets the rotation type abbreviation. * * @return the rotationTypeAbbreviation */ public final String getRotationTypeAbbreviation() { return this.rotationTypeAbbreviation; } /** * Sets the rotation type abbreviation. * * @param typeAbbreviationVal the new rotation type abbreviation */ public final void setRotationTypeAbbreviation(final String typeAbbreviationVal) { this.rotationTypeAbbreviation = typeAbbreviationVal; } /** * Sets the training class. * * @param trainingClassVal the new training class */ public final void setTrainingClass(final String trainingClassVal) { this.trainingClass = trainingClassVal; } /** * Gets the training class. * * @return the training class */ public final String getTrainingClass() { if (this.trainingClass == null) { this.trainingClass = ""; } return this.trainingClass; } /** * Sets the training type. * * @param trainingTypeVal the new training type */ public final void setTrainingType(final String trainingTypeVal) { this.trainingType = trainingTypeVal; } /** * Gets the training type. * * @return the training type */ public final String getTrainingType() { if (this.trainingType == null) { this.trainingType = ""; } return this.trainingType; } /** * Sets the training mapping. * * @param trainingMappingVal the new training mapping */ public final void setTrainingMapping(final String trainingMappingVal) { this.trainingMapping = trainingMappingVal; } /** * Gets the training mapping. * * @return the training mapping */ public final String getTrainingMapping() { if (this.trainingMapping == null) { this.trainingMapping = ""; } return this.trainingMapping; } /** * Sets the start date. * * @param startDateVal the new start date */ public final void setStartDate(final Date startDateVal) { if (startDateVal != null) { this.startDate = new Date(startDateVal.getTime()); } } /** * 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) { if (endDateVal != null) { this.endDate = new Date(endDateVal.getTime()); } } /** * Gets the end date. * * @return the end date */ public final Date getEndDate() { return this.endDate; } /** * Sets the year. * * @param yearVal the new year value */ public final void setYear(final int yearVal) { this.year = yearVal; } /** * Gets the year. * * @return the year */ public final int getYear() { return this.year; } /** * Sets the leave days. * * @param leaveDaysVal the new leave days */ public final void setLeaveDays(final int leaveDaysVal) { this.leaveDays = leaveDaysVal; } /** * Gets the leave days. * * @return the leave days */ public final int getLeaveDays() { return this.leaveDays; } /** * Sets the training time. * * @param trainingTimeVal the new training time */ public final void setTrainingTime(final double trainingTimeVal) { this.trainingTime = trainingTimeVal; } /** * Gets the training time. * * @return the training time */ public final double getTrainingTime() { return this.trainingTime; } /** * Gets the total days. * * @return the total days */ public final int getTotalDays() { int totalDays = 0; // End date - start date to get total months..... if (this.startDate != null && this.endDate != null) { Calendar start = Calendar.getInstance(); start.setTime(this.startDate); Calendar end = Calendar.getInstance(); end.setTime(this.endDate); final long fiscalDays = (end.getTimeInMillis() - start.getTimeInMillis()) / (MILLISECONDS * SECONDS * MINUTES * HOURS); final double workingDays = fiscalDays * WORKING_DAYS_CONSTANT; totalDays = (int) Formatter.round((workingDays * this.trainingTime), 0); } return totalDays; } /** * Gets the total months. * * @return the total months */ public final double getTotalMonths() { double totalMonths = 0.0; // End date - start date to get total months..... if (this.startDate != null && this.endDate != null) { Calendar start = Calendar.getInstance(); start.setTime(this.startDate); Calendar end = Calendar.getInstance(); end.setTime(this.endDate); final long fiscalDays = (end.getTimeInMillis() - start.getTimeInMillis()) / (MILLISECONDS * SECONDS * MINUTES * HOURS); final double totalDays = fiscalDays * this.trainingTime; totalMonths = Formatter.round(totalDays / DAYS, 1); } return totalMonths; } /** * Sets the organisation1 id. * * @param organisation1IdVal the new organisation1 id */ public final void setOrganisation1Id(final int organisation1IdVal) { this.organisation1Id = organisation1IdVal; } /** * Gets the organisation1 id. * * @return the organisation1 id */ public final int getOrganisation1Id() { return this.organisation1Id; } /** * Sets the organisation2 id. * * @param organisation2IdVal the new organisation2 id */ public final void setOrganisation2Id(final int organisation2IdVal) { this.organisation2Id = organisation2IdVal; } /** * Gets the organisation2 id. * * @return the organisation2 id */ public final int getOrganisation2Id() { return this.organisation2Id; } /** * Sets the organisation1 type. * * @param organisation1TypeVal the new organisation1 type */ public final void setOrganisation1Type(final String organisation1TypeVal) { this.organisation1Type = organisation1TypeVal; } /** * Gets the organisation1 type. * * @return the organisation1 type */ public final String getOrganisation1Type() { return this.organisation1Type; } /** * Sets the organisation1 type. * * @param organisation1TypeVal the new organisation1 type */ public final void setOrganisation1TypeMapping(final String organisation1TypeVal) { this.organisation1TypeMapping = organisation1TypeVal; } /** * Gets the organisation1 type mapping. * * @return the organisation1 type mapping */ public final String getOrganisation1TypeMapping() { return this.organisation1TypeMapping; } /** * Sets the organisation2 type. * * @param organisation2TypeVal the new organisation2 type */ public final void setOrganisation2Type(final String organisation2TypeVal) { this.organisation2Type = organisation2TypeVal; } /** * Gets the organisation2 type. * * @return the organisation2 type */ public final String getOrganisation2Type() { return this.organisation2Type; } /** * Sets the organisation2 type. * * @param organisation2TypeVal the new organisation1 type */ public final void setOrganisation2TypeMapping(final String organisation2TypeVal) { this.organisation2TypeMapping = organisation2TypeVal; } /** * Gets the organisation2 type mapping. * * @return the organisation2 type mapping */ public final String getOrganisation2TypeMapping() { return this.organisation2TypeMapping; } /** * Sets the organisation1. * * @param organisation1Ref the new organisation1 */ public final void setOrganisation1(final OrganisationBean organisation1Ref) { this.organisation1 = organisation1Ref; } /** * Gets the organisation1. * * @return the organisation1 */ public final OrganisationBean getOrganisation1() { if (this.organisation1 != null) { this.organisation1.getGUID(); } return this.organisation1; } /** * Sets the organisation2. * * @param organisation2Ref the new organisation2 */ public final void setOrganisation2(final OrganisationBean organisation2Ref) { this.organisation2 = organisation2Ref; } /** * Gets the organisation2. * * @return the organisation2 */ public final OrganisationBean getOrganisation2() { if (this.organisation2 != null) { this.organisation2.getGUID(); } return this.organisation2; } /** * Sets the organisation1 name. * * @param organisationName the new organisation1 name */ public final void setOrganisation1Name(final String organisationName) { this.organisation1Name = organisationName; } /** * Gets the organisation1 name. * * @return the organisation1 name */ public final String getOrganisation1Name() { String organisationName = ""; if (this.organisation1Name != null) { if (this.organisation1Name.compareTo("") != 0) { organisationName = this.organisation1Name; } } // If organisation1 is not null return the name of the organisation if (this.organisation1 != null) { organisationName = this.organisation1.getName(); } return organisationName; } /** * Sets the organisation2 name. * * @param organisationName the new organisation2 name */ public final void setOrganisation2Name(final String organisationName) { this.organisation2Name = organisationName; } /** * Gets the organisation2 name. * * @return the organisation2 name */ public final String getOrganisation2Name() { String organisationName = ""; if (this.organisation2Name != null) { if (this.organisation2Name.compareTo("") != 0) { organisationName = this.organisation2Name; } } // If organisation2 is not null return the name of the organisation if (this.organisation2 != null) { organisationName = this.organisation2.getName(); } return organisationName; } /** * Sets the supervisors. * * @param supervisorsVal the new supervisors */ public final void setSupervisors(final Collection<SupervisorBean> supervisorsVal) { this.supervisors = supervisorsVal; } /** * Gets the supervisors. * * @return the supervisors */ public final Collection<SupervisorBean> getSupervisors() { if (this.supervisors == null) { this.supervisors = new ArrayList<SupervisorBean>(); } return this.supervisors; } /** * Gets the supervisor. * * @param id the id * * @return the supervisor */ public final SupervisorBean getSupervisor(final int id) { SupervisorBean supervisor = null; int arrayId = id - 1; ArrayList<SupervisorBean> aySupervisors = (ArrayList<SupervisorBean>) this.getSupervisors(); if (aySupervisors.size() > arrayId) { supervisor = (SupervisorBean) aySupervisors.get(arrayId); } return supervisor; } /** * Adds the supervisor. * * @param supervisor the supervisor */ public final void addSupervisor(final SupervisorBean supervisor) { Collection<SupervisorBean> clSupervisors = getSupervisors(); clSupervisors.add(supervisor); setSupervisors(clSupervisors); } /** * Sets the reports. * * @param reportsVal the new reports */ public final void setReports(final Collection<ReportBean> reportsVal) { this.reports = reportsVal; } /** * Gets the reports. * * @return the reports */ public final Collection<ReportBean> getReports() { if (this.reports == null) { this.reports = new ArrayList<ReportBean>(); } return this.reports; } /** * Gets the excess. * * @return the excess */ public final boolean getExcess() { boolean excess = false; if (StringUtils.contains(getTrainingClass(), "ontinuing") || this.getInterruption()) { excess = true; } return excess; } /** * Gets the interruption. * * @return the interruption value */ public final boolean getInterruption() { boolean interruption = false; if (StringUtils.contains(getTrainingClass(), "nterrupt")) { interruption = true; } return interruption; } /** * Sets the accreditation. * * @param accreditationVal the new accreditation */ public final void setAccreditation(final Collection<AccreditationBean> accreditationVal) { this.accreditation = accreditationVal; } /** * Gets the accreditation. * * @return the accreditation */ public final Collection<AccreditationBean> getAccreditation() { return this.accreditation; } /** * Sets the online tools. * * @param onlineToolsVal the new online tools */ public final void setOnlineTools(final Collection<OnlineToolBean> onlineToolsVal) { this.onlineTools = onlineToolsVal; } /** * Gets the online tools. * * @return the online tools */ public final Collection<OnlineToolBean> getOnlineTools() { if (this.onlineTools == null) { this.onlineTools = new ArrayList<OnlineToolBean>(); } return this.onlineTools; } /** * Sets the assessment. * * @param assessmentVal the new assessment */ public final void setAssessment(final Collection<AssessmentBean> assessmentVal) { this.assessment = assessmentVal; } /** * Gets the assessment. * * @return the assessment */ public final Collection<AssessmentBean> getAssessment() { return this.assessment; } /** * Gets the assessment name. * * @return the assessment name */ public final String getAssessmentName() { final StringBuffer asssessmentName = new StringBuffer(); if (this.getAssessment() != null) { for (AssessmentBean assessment : this.getAssessment()) { if (StringUtils.isNotBlank(assessment.getCommitteeSpecialty())) { if (asssessmentName.length() > 0) { asssessmentName.append(" and "); } asssessmentName.append(assessment.getCommitteeSpecialty()); } } } return asssessmentName.toString(); } /** * Sets the person search. * * @param personSearchRef the new person search */ public final void setPersonSearch(final PersonBean personSearchRef) { this.personSearch = personSearchRef; } /** * Gets the person search. * * @return the person search */ public final PersonBean getPersonSearch() { return this.personSearch; } /** * Sets the people guids. * Used when performing a search for rotations based on a list of people GUID values. * * @param peopleGUIDsVal the new people gui ds */ public final void setPeopleGUIDs(final Collection<Integer> peopleGUIDsVal) { this.peopleGUIDs = peopleGUIDsVal; } /** * Gets the people gui ds. * * @return the people gui ds */ public final Collection<Integer> getPeopleGUIDs() { return this.peopleGUIDs; } /** * Sets the summary types which are used by the training summary. * * @param summaryTypesVal the new summary types */ public final void setSummaryTypes(final Collection<String> summaryTypesVal) { this.summaryTypes = summaryTypesVal; } /** * Gets the summary types. * * @return the summary types */ public final Collection<String> getSummaryTypes() { return this.summaryTypes; } /** * Sets the summary status for a specific committee for a training summary. * * @param summaryStatusVal the new summary status */ public final void setSummaryStatus(final String summaryStatusVal) { this.summaryStatus = summaryStatusVal; } /** * Gets the summary status. * * @return the summary status */ public final String getSummaryStatus() { return this.summaryStatus; } /** * Sets the committee name. * * @param committeeNameVal the new committee name */ public final void setCommitteeName(final String committeeNameVal) { this.committeeName = committeeNameVal; } /** * Gets the committee name. * * @return the committee name */ public final String getCommitteeName() { return this.committeeName; } /** * Gets the committee name acronym. * * @return the committee name acronym */ public final String getCommitteeNameAcronym() { StringBuffer acronym = new StringBuffer(); if (this.committeeName != null) { StringTokenizer st = new StringTokenizer(this.committeeName, " "); while (st.hasMoreTokens()) { String word = st.nextToken(); acronym.append(word.substring(0, 1).toUpperCase()); acronym.append("."); } } return acronym.toString(); } /** * Gets the email addresses count. * * @return the email addresses count */ public final int getEmailAddressesCount() { int emailAddressCount = 0; if (this.person != null) { if (person.getFirstEmailAddress() != null) { emailAddressCount++; } } if (this.supervisors != null) { for (SupervisorBean supervisor : this.supervisors) { if (supervisor.getPerson() != null) { if (supervisor.getPerson().getFirstEmailAddress() != null) { emailAddressCount++; } } } } return emailAddressCount; } /** * Gets the email addresses. * * @param preferences the application preferences * @return the email addresses */ public final String getEmailAddresses(final PreferencesBean preferences) { StringBuffer emailAddresses = new StringBuffer(); String divider = ", "; if (StringUtils.equalsIgnoreCase(preferences.getOption("email", "client"), "Outlook")) { divider = "; "; } if (this.person != null) { if (person.getFirstEmailAddress() != null) { if (emailAddresses.length() > 0) { emailAddresses.append(divider); } emailAddresses.append(person.getFirstEmailAddress().getEmail()); } } if (this.supervisors != null) { for (SupervisorBean supervisor : this.supervisors) { if (supervisor.getPerson() != null) { if (supervisor.getPerson().getFirstEmailAddress() != null) { if (emailAddresses.length() > 0) { emailAddresses.append(divider); } emailAddresses.append(supervisor.getPerson().getFirstEmailAddress().getEmail()); } } } } return emailAddresses.toString(); } /** * Gets the no email addresses count. * * @return the no email addresses count */ public final int getNoEmailAddressesCount() { int noEmailAddressesCount = 0; if (this.person != null) { if (person.getFirstEmailAddress() == null) { noEmailAddressesCount++; } } if (this.supervisors != null) { for (SupervisorBean supervisor : this.supervisors) { if (supervisor.getPerson() != null) { if (supervisor.getPerson().getFirstEmailAddress() == null) { noEmailAddressesCount++; } } } } return noEmailAddressesCount; } /** * Gets the no email addresses. * * @return the no email addresses */ public final String getNoEmailAddresses() { StringBuffer noEmailAddresses = new StringBuffer(); if (this.person != null) { if (person.getFirstEmailAddress() == null) { if (noEmailAddresses.length() > 0) { noEmailAddresses.append(", "); } noEmailAddresses.append(OutputFormatter.toFormattedName(person)); } } if (this.supervisors != null) { for (SupervisorBean supervisor : this.supervisors) { if (supervisor.getPerson() != null) { if (supervisor.getPerson().getFirstEmailAddress() == null) { if (noEmailAddresses.length() > 0) { noEmailAddresses.append(", "); } noEmailAddresses.append(OutputFormatter.toFormattedName(supervisor.getPerson())); } } } } return noEmailAddresses.toString(); } /** * Gets the order index. * * @return the order index */ public final String getOrderIndex() { StringBuffer sb = new StringBuffer(); if (this.getPerson() != null) { sb.append(this.getPerson().getLastName()); sb.append(" "); sb.append(this.getPerson().getPreferredName()); } sb.append("_"); sb.append(this.getGUID()); return sb.toString(); } }