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.search.http; import com.sfs.DataFilter; import com.sfs.Formatter; import com.sfs.beans.ObjectTypeBean; import com.sfs.beans.UserBean; import com.sfs.whichdoctor.beans.AccreditationBean; import com.sfs.whichdoctor.beans.AddressBean; import com.sfs.whichdoctor.beans.EmailBean; import com.sfs.whichdoctor.beans.ExamBean; import com.sfs.whichdoctor.beans.ItemBean; import com.sfs.whichdoctor.beans.FinancialSummaryBean; import com.sfs.whichdoctor.beans.MembershipBean; import com.sfs.whichdoctor.beans.PersonBean; import com.sfs.whichdoctor.beans.QualificationBean; import com.sfs.whichdoctor.beans.RotationBean; import com.sfs.whichdoctor.beans.SearchBean; import com.sfs.whichdoctor.beans.SpecialtyBean; import com.sfs.whichdoctor.beans.WorkshopBean; import com.sfs.whichdoctor.dao.MembershipDAO; import com.sfs.whichdoctor.search.sql.PersonSqlHandler; import java.util.ArrayList; import java.util.Collection; import java.util.TreeMap; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; /** * The Class PersonInputHandler. * * @author David Harrison */ public class PersonInputHandler extends InputHandlerBase { /** The Constant MAX_ACCREDITATION. */ private static final int MAX_ACCREDITATION = 1000; private static final int MAX_ID = 999999999; /** The data logger. */ private static Logger dataLogger = Logger.getLogger(PersonInputHandler.class); /** The person sql handler. */ @Resource private PersonSqlHandler personSqlHandler; /** The membership dao. */ @Resource private MembershipDAO membershipDAO; /** * Process the incoming HttpRequest for search parameters. * * @param request the request * @param user the user * * @return the search bean */ public final SearchBean process(final HttpServletRequest request, final UserBean user) { SearchBean search = personSqlHandler.initiate(user); PersonBean searchCriteria = (PersonBean) search.getSearchCriteria(); PersonBean searchConstraints = (PersonBean) search.getSearchConstraints(); String firstName = DataFilter.getHtml(request.getParameter("firstName")); String lastName = DataFilter.getHtml(request.getParameter("lastName")); String strGender = DataFilter.getHtml(request.getParameter("gender")); /* Membership type fields */ String strMINA = DataFilter.getHtml(request.getParameter("minA")); String strMINB = DataFilter.getHtml(request.getParameter("minB")); String strGUIDList = DataFilter.getHtml(request.getParameter("guidList")); String strIncludeGUIDList = DataFilter.getHtml(request.getParameter("includeGUIDList")); String strIdentifierList = DataFilter.getHtml(request.getParameter("identifierList")); String strTrainingStatus = DataFilter.getHtml(request.getParameter("trainingStatus")); String strTrainingStatusDetail = DataFilter.getHtml(request.getParameter("trainingStatusDetail")); String strTrainingOrganisation = DataFilter.getHtml(request.getParameter("trainingOrganisation")); String strTrainingProgram = DataFilter.getHtml(request.getParameter("trainingProgram")); String trainingProgramYearA = DataFilter.getHtml(request.getParameter("trainingProgramYearA")); String trainingProgramYearB = DataFilter.getHtml(request.getParameter("trainingProgramYearB")); String strSpecialtyStatus = DataFilter.getHtml(request.getParameter("specialtyStatus")); String strOrganisation = DataFilter.getHtml(request.getParameter("organisation")); String strRegion = DataFilter.getHtml(request.getParameter("region")); String strAddressClass = DataFilter.getHtml(request.getParameter("addressClass")); String strAddressType = DataFilter.getHtml(request.getParameter("addressType")); String strCountry = DataFilter.getHtml(request.getParameter("country")); String strCity = DataFilter.getHtml(request.getParameter("city")); String strAddressReturnedMail = DataFilter.getHtml(request.getParameter("addressReturnedMail")); String strAddressRequestNoMail = DataFilter.getHtml(request.getParameter("addressRequestNoMail")); String strEmailType = DataFilter.getHtml(request.getParameter("emailType")); String strEmailReturnedMail = DataFilter.getHtml(request.getParameter("emailReturnedMail")); String strEmailRequestNoMail = DataFilter.getHtml(request.getParameter("emailRequestNoMail")); String strEmailQuestions = DataFilter.getHtml(request.getParameter("emailQuestions")); String strClosingBalanceA = DataFilter.getHtml(request.getParameter("closingBalanceA")); String strClosingBalanceB = DataFilter.getHtml(request.getParameter("closingBalanceB")); String strWorkshopType = DataFilter.getHtml(request.getParameter("workshopType")); String strWorkshopAttendance = DataFilter.getHtml(request.getParameter("workshopAttendance")); String strWorkshopYear = DataFilter.getHtml(request.getParameter("workshopYear")); String strAccreditationA = DataFilter.getHtml(request.getParameter("accreditationA")); String strAccreditationB = DataFilter.getHtml(request.getParameter("accreditationB")); String strAccreditationTotal = DataFilter.getHtml(request.getParameter("accreditationTotal")); String strAccreditationType = DataFilter.getHtml(request.getParameter("accreditationType")); String strAccreditationSpecialty = DataFilter.getHtml(request.getParameter("accreditationSpecialty")); String strExamType = DataFilter.getHtml(request.getParameter("examType")); String strExamStatus = ""; String strExamStatusLevel = ""; if (StringUtils.equals(strExamType, "Written Exam")) { strExamStatus = DataFilter.getHtml(request.getParameter("writtenExamStatus")); strExamStatusLevel = DataFilter.getHtml(request.getParameter("writtenExamStatusLevel")); } if (StringUtils.equals(strExamType, "Clinical Exam")) { strExamStatus = DataFilter.getHtml(request.getParameter("clinicalExamStatus")); strExamStatusLevel = DataFilter.getHtml(request.getParameter("clinicalExamStatusLevel")); } String strExamDateA = DataFilter.getHtml(request.getParameter("examDateA")); String strExamDateB = DataFilter.getHtml(request.getParameter("examDateB")); String strQualificationType = DataFilter.getHtml(request.getParameter("qualificationType")); String strQualificationSubType = DataFilter.getHtml(request.getParameter("qualificationSubType")); String strQualificationInstitution = DataFilter.getHtml(request.getParameter("qualificationInstitution")); String strQualificationCountry = DataFilter.getHtml(request.getParameter("qualificationCountry")); String strGraduatedA = DataFilter.getHtml(request.getParameter("graduatedA")); String strGraduatedB = DataFilter.getHtml(request.getParameter("graduatedB")); String strRotationGUID = DataFilter.getHtml(request.getParameter("rotationGUID")); String strCreatedA = DataFilter.getHtml(request.getParameter("createdA")); String strCreatedB = DataFilter.getHtml(request.getParameter("createdB")); String strUpdatedA = DataFilter.getHtml(request.getParameter("updatedA")); String strUpdatedB = DataFilter.getHtml(request.getParameter("updatedB")); // Set first and last name requirements if (StringUtils.isNotBlank(firstName)) { searchCriteria.setFirstName(firstName.trim()); } if (StringUtils.isNotBlank(lastName)) { searchCriteria.setLastName(lastName.trim()); } if (StringUtils.isNotBlank(strGender) && !StringUtils.equals(strGender, "Null")) { searchCriteria.setGender(strGender); } /* Tag searches */ searchCriteria.setTags(this.setTagArray(request, user)); // Add MIN number to criteria if successfully parsed to int try { int criteriaMIN = Integer.parseInt(strMINA); searchCriteria.setPersonIdentifier(criteriaMIN); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing MIN: " + nfe.getMessage()); } if (StringUtils.isNotBlank(strMINB)) { int constraintMIN = 0; try { constraintMIN = Integer.parseInt(strMINB); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing MIN contraint: " + nfe.getMessage()); } if (StringUtils.equals(strMINB, "+")) { constraintMIN = MAX_ID; } if (StringUtils.equals(strMINB, "-")) { constraintMIN = -1; } searchConstraints.setPersonIdentifier(constraintMIN); } if (StringUtils.isNotBlank(strGUIDList)) { // Parse the GUID list string into a collection of strings searchCriteria.setGUIDList(DataFilter.parseTextDataToCollection(strGUIDList)); } if (StringUtils.isNotBlank(strIncludeGUIDList)) { // Parse the GUID list string into a collection of strings searchCriteria.setIncludeGUIDList(DataFilter.parseTextDataToCollection(strIncludeGUIDList)); } if (StringUtils.isNotBlank(strIdentifierList)) { // Parse the identifier list string into a collection of strings searchCriteria.setIdentifierList(DataFilter.parseTextDataToCollection(strIdentifierList)); } if (strRegion != null) { if (strRegion.compareTo("Null") != 0) { searchCriteria.setRegion(strRegion); } } // Process the membership parameters Collection<MembershipBean> membershipDetailsCriteria = new ArrayList<MembershipBean>(); Collection<MembershipBean> membershipDetailsConstraints = new ArrayList<MembershipBean>(); ArrayList<MembershipBean> memDetailsCriteria = (ArrayList<MembershipBean>) searchCriteria .getMembershipDetails(); // Iterate through membership beans for (int a = 0; a < memDetailsCriteria.size(); a++) { MembershipBean membershipCriteria = memDetailsCriteria.get(a); MembershipBean[] result = null; if (StringUtils.equalsIgnoreCase(membershipCriteria.getMembershipClass(), "RACP") && StringUtils.equalsIgnoreCase(membershipCriteria.getMembershipType(), "")) { result = processRACPMembership(request); } if (StringUtils.equalsIgnoreCase(membershipCriteria.getMembershipClass(), "RACP") && StringUtils.equalsIgnoreCase(membershipCriteria.getMembershipType(), "Fellowship Details")) { result = processRACPFellowship(request); } if (StringUtils.equalsIgnoreCase(membershipCriteria.getMembershipClass(), "RACP") && StringUtils.equalsIgnoreCase(membershipCriteria.getMembershipType(), "Affiliation")) { result = processRACPAffiliation(request); } if (result != null) { MembershipBean criteria = result[0]; MembershipBean constraints = result[1]; if (criteria != null && constraints != null) { membershipDetailsCriteria.add(criteria); membershipDetailsConstraints.add(constraints); } } } // Add the membership detail arrays back to the search beans searchCriteria.setMembershipDetails(membershipDetailsCriteria); searchConstraints.setMembershipDetails(membershipDetailsConstraints); /* Check if accreditation was set */ AccreditationBean accredA = new AccreditationBean(); AccreditationBean accredB = new AccreditationBean(); if (StringUtils.isNotBlank(strAccreditationA)) { // Value submitted for A try { accredA.setWeeksCertified(Formatter.getWholeWeeks(Integer.parseInt(strAccreditationA))); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing accreditationA: " + nfe.getMessage()); } } if (StringUtils.isNotBlank(strAccreditationB)) { // Value submitted for B try { accredB.setWeeksCertified(Formatter.getWholeWeeks(Integer.parseInt(strAccreditationB))); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing accreditationB: " + nfe.getMessage()); } if (StringUtils.equals(strAccreditationB, "+")) { accredB.setWeeksCertified(MAX_ACCREDITATION); } if (StringUtils.equals(strAccreditationB, "-")) { accredB.setWeeksCertified(-1); } } if (accredB.getWeeksCertified() < accredA.getWeeksCertified()) { int tempValue = accredA.getWeeksCertified(); accredA.setWeeksCertified(accredB.getWeeksCertified()); accredB.setWeeksCertified(tempValue); } if (accredB.getWeeksCertified() == 0) { accredB.setWeeksCertified(accredA.getWeeksCertified()); } if (accredA.getWeeksCertified() == 0) { accredA.setWeeksCertified(accredB.getWeeksCertified()); } if (accredA.getWeeksCertified() != 0) { if (strAccreditationTotal != null) { accredA.setAbbreviation(strAccreditationTotal); } if (strAccreditationType != null) { if (strAccreditationType.compareTo("Null") != 0) { accredA.setAccreditationType(strAccreditationType); } } if (strAccreditationSpecialty != null) { if (strAccreditationSpecialty.compareTo("Null") != 0) { accredA.setSpecialtyType(strAccreditationSpecialty); } } TreeMap<String, AccreditationBean[]> accreditationSummary = new TreeMap<String, AccreditationBean[]>(); AccreditationBean[] summary = new AccreditationBean[] { accredA, accredB }; accreditationSummary.put("Accreditation", summary); searchCriteria.setTrainingSummary("Search", accreditationSummary); } if (!StringUtils.equalsIgnoreCase(strTrainingStatus, "Null")) { searchCriteria.setTrainingStatus(strTrainingStatus); } if (StringUtils.isNotBlank(strTrainingStatusDetail) && !StringUtils.equalsIgnoreCase(strTrainingStatusDetail, "Any")) { searchCriteria.setTrainingStatusDetail(strTrainingStatusDetail); } /* Check if specialty details were set */ boolean specialty = false; SpecialtyBean specialtyCriteria = new SpecialtyBean(); SpecialtyBean specialtyConstraints = new SpecialtyBean(); if (strTrainingOrganisation != null) { if (strTrainingOrganisation.compareTo("Null") != 0) { specialtyCriteria.setTrainingOrganisation(strTrainingOrganisation); specialty = true; } } if (strTrainingProgram != null) { if (strTrainingProgram.compareTo("Any") != 0) { specialtyCriteria.setTrainingProgram(strTrainingProgram); specialty = true; } } if (StringUtils.isNotBlank(trainingProgramYearA)) { int trainingProgramYear = 0; try { trainingProgramYear = Integer.parseInt(trainingProgramYearA); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing training year A: " + nfe.getMessage()); } if (StringUtils.equalsIgnoreCase(trainingProgramYearA, "+")) { trainingProgramYear = MAXIMUM_YEAR; } if (StringUtils.equalsIgnoreCase(trainingProgramYearA, "-")) { trainingProgramYear = MINIMUM_YEAR; } specialtyCriteria.setTrainingProgramYear(trainingProgramYear); } if (StringUtils.isNotBlank(trainingProgramYearB)) { int trainingProgramYear = 0; try { trainingProgramYear = Integer.parseInt(trainingProgramYearB); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing training program B: " + nfe.getMessage()); } if (StringUtils.equalsIgnoreCase(trainingProgramYearB, "+")) { trainingProgramYear = MAXIMUM_YEAR; } if (StringUtils.equalsIgnoreCase(trainingProgramYearB, "-")) { trainingProgramYear = MINIMUM_YEAR; } specialtyConstraints.setTrainingProgramYear(trainingProgramYear); } if (strSpecialtyStatus != null) { if (strSpecialtyStatus.compareTo("Null") != 0) { specialtyCriteria.setStatus(strSpecialtyStatus); specialty = true; } } if (specialty) { ArrayList<SpecialtyBean> spCriteria = new ArrayList<SpecialtyBean>(); ArrayList<SpecialtyBean> spConstraints = new ArrayList<SpecialtyBean>(); spCriteria.add(specialtyCriteria); spConstraints.add(specialtyConstraints); searchCriteria.setSpecialtyList(spCriteria); searchConstraints.setSpecialtyList(spConstraints); } // Check if address details have been submitted boolean address = false; AddressBean addressCriteria = new AddressBean(); AddressBean addressConstraints = new AddressBean(); // Address defaults addressCriteria.setReturnedMail(false); addressConstraints.setReturnedMail(true); addressCriteria.setRequestNoMail(false); addressConstraints.setRequestNoMail(true); // Set the address class and type - but don't set the address flag yet if (StringUtils.isNotBlank(strAddressClass)) { if (StringUtils.equalsIgnoreCase(strAddressClass, "Preferred")) { // Set the primary flag to true addressCriteria.setPrimary(true); addressConstraints.setPrimary(true); } else { // Set the address class addressCriteria.setContactClass(strAddressClass); } } if (StringUtils.isNotBlank(strAddressType)) { // Set the address type addressCriteria.setContactType(strAddressType); } // Set the address city if (StringUtils.isNotBlank(strCity)) { addressCriteria.setAddressField(strCity); address = true; } // Set the address country if (StringUtils.isNotBlank(strCountry)) { addressCriteria.setCountry(strCountry); address = true; } // Set the returned mail if (StringUtils.equals(strAddressReturnedMail, "true")) { addressCriteria.setReturnedMail(true); addressConstraints.setReturnedMail(true); address = true; } if (StringUtils.equals(strAddressReturnedMail, "false")) { addressCriteria.setReturnedMail(false); addressConstraints.setReturnedMail(false); address = true; } // Set the request mail if (StringUtils.equals(strAddressRequestNoMail, "true")) { addressCriteria.setRequestNoMail(true); addressConstraints.setRequestNoMail(true); address = true; } if (StringUtils.equals(strAddressRequestNoMail, "false")) { addressCriteria.setRequestNoMail(false); addressConstraints.setRequestNoMail(false); address = true; } if (address) { Collection<AddressBean> addresses = new ArrayList<AddressBean>(); Collection<AddressBean> addresses2 = new ArrayList<AddressBean>(); addresses.add(addressCriteria); addresses2.add(addressConstraints); searchCriteria.setAddress(addresses); searchConstraints.setAddress(addresses2); } // Check if Email details have been submitted boolean email = false; EmailBean emailCriteria = new EmailBean(); EmailBean emailConstraints = new EmailBean(); // Email defaults emailCriteria.setReturnedMail(true); emailConstraints.setReturnedMail(false); emailCriteria.setRequestNoMail(true); emailConstraints.setRequestNoMail(false); emailCriteria.setEmailQuestions(true); emailConstraints.setEmailQuestions(false); // Set the email type - but don't set the address flag yet if (StringUtils.isNotBlank(strEmailType)) { if (StringUtils.equalsIgnoreCase(strEmailType, "Preferred")) { // Set the primary flag to true emailCriteria.setPrimary(true); emailConstraints.setPrimary(true); } else { // Set the email type emailCriteria.setContactType(strEmailType); } } if (StringUtils.equals(strEmailReturnedMail, "true")) { emailCriteria.setReturnedMail(true); emailConstraints.setReturnedMail(true); email = true; } if (StringUtils.equals(strEmailReturnedMail, "false")) { emailCriteria.setReturnedMail(false); emailConstraints.setReturnedMail(false); email = true; } if (StringUtils.equals(strEmailRequestNoMail, "true")) { emailCriteria.setRequestNoMail(true); emailConstraints.setRequestNoMail(true); email = true; } if (StringUtils.equals(strEmailRequestNoMail, "false")) { emailCriteria.setRequestNoMail(false); emailConstraints.setRequestNoMail(false); email = true; } if (StringUtils.equals(strEmailQuestions, "true")) { emailCriteria.setEmailQuestions(true); emailConstraints.setEmailQuestions(true); email = true; } if (StringUtils.equals(strEmailQuestions, "false")) { emailCriteria.setEmailQuestions(false); emailConstraints.setEmailQuestions(false); email = true; } if (email) { Collection<EmailBean> emails = new ArrayList<EmailBean>(); Collection<EmailBean> emails2 = new ArrayList<EmailBean>(); emails.add(emailCriteria); emails2.add(emailConstraints); searchCriteria.setEmail(emails); searchConstraints.setEmail(emails2); } if (StringUtils.isNotBlank(strClosingBalanceA) && !StringUtils.equals(strClosingBalanceA, "Null")) { // Something has been defined for this field double closingBalanceA = 0; double closingBalanceB = 0; try { closingBalanceA = Double.parseDouble(strClosingBalanceA); } catch (NumberFormatException nfe) { closingBalanceA = 0; } try { closingBalanceB = Double.parseDouble(strClosingBalanceB); } catch (NumberFormatException nfe) { closingBalanceB = 0; } if (StringUtils.equals(strClosingBalanceB, "-")) { closingBalanceB = -100000000; } if (StringUtils.equals(strClosingBalanceB, "+")) { closingBalanceB = 100000000; } FinancialSummaryBean financialSummaryCriteria = new FinancialSummaryBean(); // This is a unique id to indicate the financial summary has been set financialSummaryCriteria.setId(1); financialSummaryCriteria.setClosingBalance(closingBalanceA); searchCriteria.setFinancialSummary(financialSummaryCriteria); if (closingBalanceB != 0) { FinancialSummaryBean financialSummaryConstraints = new FinancialSummaryBean(); financialSummaryConstraints.setClosingBalance(closingBalanceB); searchConstraints.setFinancialSummary(financialSummaryConstraints); } } if (StringUtils.isNotBlank(strOrganisation)) { TreeMap<String, ItemBean> employers = new TreeMap<String, ItemBean>(); ItemBean employer = new ItemBean(); employer.setName(strOrganisation); employers.put(strOrganisation, employer); searchCriteria.setEmployers(employers); } WorkshopBean workshopCriteria = new WorkshopBean(); WorkshopBean workshopConstraints = new WorkshopBean(); boolean workshopSearch = false; if (strWorkshopType != null) { if (strWorkshopType.compareTo("") != 0) { if (strWorkshopType.compareTo("Null") != 0) { workshopCriteria.setType(strWorkshopType); workshopSearch = true; } } } if (strWorkshopAttendance != null) { if (strWorkshopAttendance.compareTo("") != 0) { workshopCriteria.setMemo(strWorkshopAttendance); workshopSearch = true; } } if (strWorkshopYear != null) { if (strWorkshopYear.compareTo("") != 0) { try { String startDate = "1/1/" + strWorkshopYear; String endDate = "31/12/" + strWorkshopYear; workshopCriteria.setWorkshopDate(DataFilter.parseDate(startDate, false)); workshopConstraints.setWorkshopDate(DataFilter.parseDate(endDate, false)); workshopSearch = true; } catch (Exception e) { dataLogger.debug("Error setting workshop details: " + e.getMessage()); } } } if (workshopSearch) { ArrayList<WorkshopBean> workshops1 = new ArrayList<WorkshopBean>(); ArrayList<WorkshopBean> workshops2 = new ArrayList<WorkshopBean>(); workshops1.add(workshopCriteria); workshops2.add(workshopConstraints); searchCriteria.setWorkshops(workshops1); searchConstraints.setWorkshops(workshops2); } // Check if exam was set... boolean examSearch = false; ExamBean examCriteria = new ExamBean(); ExamBean examConstraint = new ExamBean(); if (strExamType != null) { if (strExamType.compareTo("") != 0 && strExamType.compareTo("Null") != 0) { examCriteria.setType(strExamType); examSearch = true; } } if (strExamStatus != null) { if (strExamStatus.compareTo("") != 0 && strExamStatus.compareTo("Null") != 0) { examCriteria.setStatus(strExamStatus); examSearch = true; } } if (strExamStatusLevel != null) { if (strExamStatusLevel.compareTo("") != 0 && strExamStatusLevel.compareTo("Any") != 0) { examCriteria.setStatusLevel(strExamStatusLevel); examSearch = true; } } if (strExamDateA != null) { if (strExamDateA.compareTo("") != 0) { examCriteria.setDateSat(DataFilter.parseDate(strExamDateA, false)); examSearch = true; } } if (strExamDateB != null) { if (strExamDateB.compareTo("") != 0) { examConstraint.setDateSat(DataFilter.parseDate(strExamDateB, false)); if (strExamDateB.compareTo("+") == 0) { /* All dates above Date A requested */ examConstraint.setDateSat(getMaximumDate()); } if (strExamDateB.compareTo("-") == 0) { /* Add dates below Date A requested */ examConstraint.setDateSat(getMinimumDate()); } } } if (examSearch) { Collection<ExamBean> exams1 = new ArrayList<ExamBean>(); Collection<ExamBean> exams2 = new ArrayList<ExamBean>(); exams1.add(examCriteria); exams2.add(examConstraint); searchCriteria.setExams(exams1); searchConstraints.setExams(exams2); } /* Check if qualification was set */ boolean qualificationSearch = false; QualificationBean qualificationCriteria = new QualificationBean(); QualificationBean qualificationConstraint = new QualificationBean(); if (strQualificationType != null) { if (strQualificationType.compareTo("") != 0 && strQualificationType.compareTo("Null") != 0) { qualificationCriteria.setQualificationType(strQualificationType); qualificationSearch = true; } } if (strQualificationSubType != null) { if (strQualificationSubType.compareTo("") != 0 && strQualificationSubType.compareTo("Any") != 0) { qualificationCriteria.setQualificationSubType(strQualificationSubType); qualificationSearch = true; } } if (strQualificationInstitution != null) { if (strQualificationInstitution.compareTo("") != 0) { qualificationCriteria.setInstitution(strQualificationInstitution); qualificationSearch = true; } } if (strQualificationCountry != null) { if (strQualificationCountry.compareTo("") != 0) { qualificationCriteria.setCountry(strQualificationCountry); qualificationSearch = true; } } if (strGraduatedA != null) { if (strGraduatedA.compareTo("") != 0) { try { qualificationCriteria.setYear(Integer.parseInt(strGraduatedA)); qualificationSearch = true; } catch (Exception e) { dataLogger.info("Error parsing graduated year A: " + e.getMessage()); } } } if (strGraduatedB != null) { try { qualificationConstraint.setYear(Integer.parseInt(strGraduatedB)); } catch (NumberFormatException nfe) { dataLogger.info("Error parsing graduated year B: " + nfe.getMessage()); } if (strGraduatedB.compareTo("+") == 0) { /* All qualifications above graduated A requested */ qualificationConstraint.setYear(MAXIMUM_YEAR); } if (strGraduatedB.compareTo("-") == 0) { /* Add qualifications below graduated A requested */ qualificationConstraint.setYear(MINIMUM_YEAR); } } if (qualificationSearch) { Collection<QualificationBean> qualifications1 = new ArrayList<QualificationBean>(); Collection<QualificationBean> qualifications2 = new ArrayList<QualificationBean>(); qualifications1.add(qualificationCriteria); qualifications2.add(qualificationConstraint); searchCriteria.setQualifications(qualifications1); searchConstraints.setQualifications(qualifications2); } // Rotation parameters if (strRotationGUID != null) { int guid = 0; try { guid = Integer.parseInt(strRotationGUID); } catch (NumberFormatException nfe) { guid = 0; } if (guid > 0) { RotationBean rotation = new RotationBean(); rotation.setGUID(guid); Collection<RotationBean> rotations = new ArrayList<RotationBean>(); rotations.add(rotation); searchCriteria.setRotations(rotations); } } if (strCreatedA != null) { if (strCreatedA.compareTo("") != 0) { searchCriteria.setCreatedDate(DataFilter.parseDate(strCreatedA, false)); } } if (strCreatedB != null) { if (strCreatedB.compareTo("") != 0) { searchConstraints.setCreatedDate(DataFilter.parseDate(strCreatedB, false)); if (strCreatedB.compareTo("+") == 0) { /* All dates above Date A requested */ searchConstraints.setCreatedDate(getMaximumDate()); } if (strCreatedB.compareTo("-") == 0) { /* Add dates below Date A requested */ searchConstraints.setCreatedDate(getMinimumDate()); } } } if (strUpdatedA != null) { if (strUpdatedA.compareTo("") != 0) { searchCriteria.setModifiedDate(DataFilter.parseDate(strUpdatedA, false)); } } if (strUpdatedB != null) { if (strUpdatedB.compareTo("") != 0) { searchConstraints.setModifiedDate(DataFilter.parseDate(strUpdatedB, false)); if (strUpdatedB.compareTo("+") == 0) { /* All dates above Date A requested */ searchConstraints.setModifiedDate(getMaximumDate()); } if (strUpdatedB.compareTo("-") == 0) { /* Add dates below Date A requested */ searchConstraints.setModifiedDate(getMinimumDate()); } } } search.setSearchCriteria(searchCriteria); search.setSearchConstraints(searchConstraints); return search; } /** * Return a standard search bean. * * @param user the user * * @return the search bean */ public final SearchBean process(final UserBean user) { SearchBean search = personSqlHandler.initiate(user); PersonBean searchCriteria = (PersonBean) search.getSearchCriteria(); search.setSearchCriteria(searchCriteria); return search; } /** * Process the RACP Membership search parameters. * * @param request the request * * @return the membership bean[] */ private MembershipBean[] processRACPMembership(final HttpServletRequest request) { MembershipBean criteria = membershipDAO.getInstance("RACP", ""); MembershipBean constraints = membershipDAO.getInstance("RACP", ""); String strCandidateA = DataFilter.getHtml(request.getParameter("candidateNumberA")); String strCandidateB = DataFilter.getHtml(request.getParameter("candidateNumberB")); String strDivision = DataFilter.getHtml(request.getParameter("division")); String strMemberClass = DataFilter.getHtml(request.getParameter("membershipClass")); String strMemberType = DataFilter.getHtml(request.getParameter("membershipType")); String strStatus = DataFilter.getHtml(request.getParameter("status")); String strTrainingType = DataFilter.getHtml(request.getParameter("trainingType")); String strSupervisorStatus = DataFilter.getHtml(request.getParameter("supervisorStatus")); String strFinancialExcemption = DataFilter.getHtml(request.getParameter("financialExcemption")); String strRegionRepresentative = DataFilter.getHtml(request.getParameter("regionRepresentative")); String strJoinedDateA = DataFilter.getHtml(request.getParameter("joinedDateA")); String strJoinedDateB = DataFilter.getHtml(request.getParameter("joinedDateB")); String strLeftDateA = DataFilter.getHtml(request.getParameter("leftDateA")); String strLeftDateB = DataFilter.getHtml(request.getParameter("leftDateB")); /* Add Candidate Number to criteria if successfully parsed to int */ try { int criteriaCN = Integer.parseInt(strCandidateA); criteria.setField("Candidate Number", new Integer(criteriaCN)); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing Candidate Number A: " + nfe.getMessage()); } if (strCandidateB != null) { int constraintCN = 0; try { constraintCN = Integer.parseInt(strCandidateB); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing Candidate Number B: " + nfe.getMessage()); } if (strCandidateB.compareTo("+") == 0) { constraintCN = MAX_ID; } if (strCandidateB.compareTo("-") == 0) { constraintCN = -1; } constraints.setField("Candidate Number", new Integer(constraintCN)); } if (strSupervisorStatus != null) { if (strSupervisorStatus.compareTo("Null") != 0) { criteria.setField("Supervisor Status", strSupervisorStatus); } } if (strDivision != null) { if (strDivision.compareTo("Null") != 0) { ObjectTypeBean object = new ObjectTypeBean(); object.setClassName(strDivision); object.setName(""); criteria.setField("Division", object); } } ObjectTypeBean membership = new ObjectTypeBean(); if (StringUtils.isNotBlank(strMemberClass) && !StringUtils.equalsIgnoreCase(strMemberClass, "Null")) { membership.setClassName(strMemberClass); if (StringUtils.isNotBlank(strMemberType) && !StringUtils.equalsIgnoreCase(strMemberType, "Any")) { membership.setName(strMemberType); } criteria.setField("Membership Type", membership); } if (StringUtils.isNotBlank(strStatus)) { if (!StringUtils.equalsIgnoreCase(strStatus, "Null")) { ObjectTypeBean object = new ObjectTypeBean(); object.setClassName(strStatus); criteria.setField("Status", object); } } if (strTrainingType != null) { if (strTrainingType.compareTo("") != 0 && strTrainingType.compareTo("Null") != 0) { ObjectTypeBean object = new ObjectTypeBean(); object.setClassName(strTrainingType); criteria.setField("Training Type", object); } } if (this.getFunctionality().isEnabled("Region Representatives") && StringUtils.isNotBlank(strRegionRepresentative) && !StringUtils.equals(strRegionRepresentative, "Null")) { final ObjectTypeBean object = new ObjectTypeBean(); object.setClassName(strRegionRepresentative); criteria.setField("Region Representative", object); } if (StringUtils.equalsIgnoreCase(strFinancialExcemption, "Yes")) { criteria.setField("Financial Excemption", "Yes"); } if (StringUtils.equalsIgnoreCase(strFinancialExcemption, "No")) { criteria.setField("Financial Excemption", "No"); } if (strJoinedDateA != null) { if (strJoinedDateA.compareTo("") != 0) { criteria.setJoinedDate(DataFilter.parseDate(strJoinedDateA, false)); } } if (strJoinedDateB != null) { if (strJoinedDateB.compareTo("") != 0) { constraints.setJoinedDate(DataFilter.parseDate(strJoinedDateB, false)); if (strJoinedDateB.compareTo("+") == 0) { // All dates above Date A requested constraints.setJoinedDate(getMaximumDate()); } if (strJoinedDateB.compareTo("-") == 0) { // Add dates below Date A requested constraints.setJoinedDate(getMinimumDate()); } } } if (strLeftDateA != null) { if (strLeftDateA.compareTo("") != 0) { criteria.setLeftDate(DataFilter.parseDate(strLeftDateA, false)); } } if (strLeftDateB != null) { if (strLeftDateB.compareTo("") != 0) { constraints.setLeftDate(DataFilter.parseDate(strLeftDateB, false)); if (strLeftDateB.compareTo("+") == 0) { // All dates above Date A requested constraints.setLeftDate(getMaximumDate()); } if (strLeftDateB.compareTo("-") == 0) { // Add dates below Date A requested constraints.setLeftDate(getMinimumDate()); } } } return new MembershipBean[] { criteria, constraints }; } /** * Process the RACP Fellowship search parameters. * * @param request the request * * @return the membership bean[] */ private MembershipBean[] processRACPFellowship(final HttpServletRequest request) { MembershipBean criteria = membershipDAO.getInstance("RACP", "Fellowship Details"); MembershipBean constraints = membershipDAO.getInstance("RACP", "Fellowship Details"); String strFRACPA = DataFilter.getHtml(request.getParameter("fracpA")); String strFRACPB = DataFilter.getHtml(request.getParameter("fracpB")); String strFellowshipDateA = DataFilter.getHtml(request.getParameter("fellowshipDateA")); String strFellowshipDateB = DataFilter.getHtml(request.getParameter("fellowshipDateB")); String strAdmittingSAC = DataFilter.getHtml(request.getParameter("admittingSAC")); String strAdmittingCountry = DataFilter.getHtml(request.getParameter("admittingCountry")); // Add FRACP number to criteria if successfully parsed to int try { int criteriaFRACP = Integer.parseInt(strFRACPA); criteria.setField("FRACP", new Integer(criteriaFRACP)); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing FRACP A: " + nfe.getMessage()); } if (strFRACPB != null) { int constraintFRACP = 0; try { constraintFRACP = Integer.parseInt(strFRACPB); } catch (NumberFormatException nfe) { dataLogger.debug("Error parsing FRACP B: " + nfe.getMessage()); } if (strFRACPB.compareTo("+") == 0) { constraintFRACP = MAX_ID; } if (strFRACPB.compareTo("-") == 0) { constraintFRACP = -1; } constraints.setField("FRACP", new Integer(constraintFRACP)); } if (strFellowshipDateA != null) { if (strFellowshipDateA.compareTo("") != 0) { criteria.setField("Fellowship Date", DataFilter.parseDate(strFellowshipDateA, false)); } } if (strFellowshipDateB != null) { if (strFellowshipDateB.compareTo("") != 0) { constraints.setField("Fellowship Date", DataFilter.parseDate(strFellowshipDateB, false)); if (strFellowshipDateB.compareTo("+") == 0) { // All dates above Date A requested constraints.setField("Fellowship Date", getMaximumDate()); } if (strFellowshipDateB.compareTo("-") == 0) { // Add dates below Date A requested constraints.setField("Fellowship Date", getMinimumDate()); } } } if (StringUtils.isNotBlank(strAdmittingSAC) && !StringUtils.equalsIgnoreCase(strAdmittingSAC, "Null")) { ObjectTypeBean object = new ObjectTypeBean(); object.setClassName(strAdmittingSAC); criteria.setField("Admitting SAC", object); } if (StringUtils.isNotBlank(strAdmittingCountry) && !StringUtils.equalsIgnoreCase(strAdmittingCountry, "Null")) { criteria.setField("Admitting Country", strAdmittingCountry); } return new MembershipBean[] { criteria, constraints }; } /** * Process the RACP affiliation search parameters. * * @param request the request * * @return the membership bean[] */ private MembershipBean[] processRACPAffiliation(final HttpServletRequest request) { MembershipBean criteria = membershipDAO.getInstance("RACP", "Affiliation"); MembershipBean constraints = membershipDAO.getInstance("RACP", "Affiliation"); String strAffiliationType = DataFilter.getHtml(request.getParameter("affiliationType")); String strAffiliationName = DataFilter.getHtml(request.getParameter("affiliationName")); if (StringUtils.isNotBlank(strAffiliationType) && !StringUtils.equalsIgnoreCase(strAffiliationType, "Null")) { ObjectTypeBean object = new ObjectTypeBean(); object.setClassName(strAffiliationType); if (StringUtils.isNotBlank(strAffiliationName) && !StringUtils.equalsIgnoreCase(strAffiliationName, "Any")) { object.setName(strAffiliationName); } criteria.setField("Affiliation", object); } return new MembershipBean[] { criteria, constraints }; } }