/** * Copyright © 2001, 2002 The JA-SIG Collaborative. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the JA-SIG Collaborative * (http://www.jasig.org/)." * * THIS SOFTWARE IS PROVIDED BY THE JA-SIG COLLABORATIVE "AS IS" AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JA-SIG COLLABORATIVE OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * */ package org.jasig.portal; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import org.jasig.portal.UserInstitution; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jasig.portal.utils.IPortalDocument; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * Describes a graduate school applicant. * @author rtwigg@uccs.edu */ public class Applicant implements IBasicEntity { private static final Log log = LogFactory.getLog(Applicant.class); private static long zeroSeconds = 0; private String ID; private String userName; private String passwd; private String passwdMask; private String lastName; private String firstName; private String email; private int status; private Hashtable userInstitutions; private static int nextuiID; /** * Constructs an applicant. */ public Applicant() { this.ID = ""; this.userName = ""; this.passwd = ""; this.passwdMask = ""; this.lastName = ""; this.firstName = ""; this.email = ""; this.status = 0; this.userInstitutions = new Hashtable(); this.nextuiID = 0; } /** * Constructs an applicant. * @param userName the user name */ public Applicant(String userName) { this.ID=""; this.userName = userName; this.passwd = ""; this.passwdMask = ""; this.lastName = ""; this.firstName = ""; this.email = ""; this.status = 0; this.userInstitutions = new Hashtable(); this.nextuiID = 0; } // Accessor methods public String getID() { return ID; } public String getUserName() { return userName; } public String getPasswd() { return passwd; } public String getPasswdMask() { return passwdMask; } public String getLastName() { return lastName; } public String getFirstName() { return firstName; } public String getEmail () { return email; } public int getStatus() { return status; } public int getNextuiID() { return ++nextuiID; } public Object getUserInstitution(String uiID) { return userInstitutions.get(uiID); } public UserInstitution[] getUserInstitution() { if (userInstitutions != null) { Iterator iter = userInstitutions.values().iterator(); if (iter.hasNext()) { return (UserInstitution[])userInstitutions.values().toArray(new UserInstitution[0]); } } return null; } public UserInstitution[] getUserInstitutions() { if (userInstitutions != null) { Iterator iter = userInstitutions.values().iterator(); if (iter.hasNext()) { return (UserInstitution[])userInstitutions.values().toArray(new UserInstitution[0]); } } return null; } // Modifier methods public void setID (String ID) { this.ID = ID; } public void setUserName (String userName) { this.userName = userName; } public void setPasswd (String passwd) { this.passwd = passwd; } public void setPasswdMask (String passwd) { passwdMask=""; for (int i=0; i < passwd.length(); i++) { this.passwdMask = passwdMask + "*"; } } public void setLastName (String lastName) { this.lastName = lastName; } public void setFirstName (String firstName) { this.firstName = firstName; } public void setEmail (String email) { this.email = email; } public void setStatus (int status) { this.status = status; } public void clearUserInstitutions() { this.userInstitutions.clear(); } /** * Implementation required by IBasicEntity interface. * @return EntityIdentifier */ public EntityIdentifier getEntityIdentifier() { return new EntityIdentifier(userName, Applicant.class); } /** * Adds an institution to this applicant */ public void addInstitution(UserInstitution ui) { userInstitutions.put(ui.getID(), ui); } /** * Removes an institution from this applicant * @param institutionName the institution to remove */ public void removeInstitution(UserInstitution userInstitution) { removeInstitution(userInstitution.getID()); } /** * Removes an institution from this applicant * @param uiID the user institution Id */ public void removeInstitution(String uiID) { userInstitutions.remove(uiID); } public Object getInstitution(String uiID) { return userInstitutions.get(uiID); } /** * Return an XML representation of an institution */ private final void addInstitutionElements(Document doc, Element applicantE) { if (userInstitutions != null) { Iterator iter = userInstitutions.values().iterator(); while (iter.hasNext()) { UserInstitution ui = (UserInstitution)iter.next(); Element userInstitutionE = ui.getDocument(doc); userInstitutionE = (Element)doc.importNode(userInstitutionE, true); applicantE.appendChild(userInstitutionE); } } } /** * Return an xml representation of this applicant */ public Element getDocument(Document doc) { Element applicant = doc.createElement("applicant"); if (doc instanceof IPortalDocument) { ((IPortalDocument)doc).putIdentifier(userName, applicant); } else { StringBuffer msg = new StringBuffer(128); msg.append("Applicant::getDocument() : "); msg.append("Document does not implement IPortalDocument, "); msg.append("so element caching cannot be performed."); log.error( msg.toString()); } applicant.setAttribute("ID", ID); applicant.setAttribute("userName", userName + ""); applicant.setAttribute("passwd", passwd); applicant.setAttribute("passwdMask", passwdMask); applicant.setAttribute("firstName", firstName + ""); applicant.setAttribute("lastName", lastName + ""); applicant.setAttribute("email", email + ""); applicant.setAttribute("status", status + ""); addInstitutionElements(doc, applicant); return applicant; } public void setFromXML(Element applicantE) { setUserName(applicantE.getAttribute("userName")); setPasswd(applicantE.getAttribute("passwd")); setFirstName(applicantE.getAttribute("firstName")); setLastName(applicantE.getAttribute("lastName")); setEmail(applicantE.getAttribute("email")); setStatus(Integer.parseInt(applicantE.getAttribute("status"))); // Now set user institutions clearUserInstitutions(); NodeList appChildren = applicantE.getChildNodes(); if (appChildren != null) { for (int i = 0; i < appChildren.getLength(); i++) { if (appChildren.item(i).getNodeName().equals("userInstitution")) { Element userInstitutionE = (Element)appChildren.item(i); NamedNodeMap userInstitutionAtts = userInstitutionE.getAttributes(); UserInstitution ui = new UserInstitution(); for (int j = 0; j < userInstitutionAtts.getLength(); j++) { Node uiAtt = userInstitutionAtts.item(j); String uiAttName = uiAtt.getNodeName(); String uiAttValue = uiAtt.getNodeValue(); if (uiAttName.equals("ID")) { ui.setID(uiAttValue); } else if (uiAttName.equals("institutionName")) { ui.setInstitutionName(uiAttValue); } else if (uiAttName.equals("major")) { ui.setMajor(uiAttValue); } else if (uiAttName.equals("degree")) { ui.setDegree(uiAttValue); } else if (uiAttName.equals("GPA")) { ui.setGPA(uiAttValue); } else if (uiAttName.equals("transcriptStatus")) { ui.setTranscriptStatus(uiAttValue); } } addInstitution(ui); } } } } }