001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.kra.bo;
017:
018: import java.util.LinkedHashMap;
019:
020: import org.kuali.core.bo.user.UniversalUser;
021: import org.kuali.core.exceptions.UserNotFoundException;
022: import org.kuali.core.service.UniversalUserService;
023: import org.kuali.kfs.KFSPropertyConstants;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.module.chart.bo.ChartUser;
026: import org.kuali.module.chart.service.ChartUserService;
027:
028: /**
029: * This class represents an ad-hoc person.
030: */
031: public class AdhocPerson extends AbstractAdhoc {
032:
033: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
034: .getLogger(AdhocPerson.class);
035:
036: private String personUniversalIdentifier;
037: private String personUserIdentifier;
038: private String name;
039: private UniversalUser user;
040:
041: public AdhocPerson() {
042: super ();
043: }
044:
045: public AdhocPerson(String documentNumber,
046: String personUniversalIdentifier) {
047: this ();
048: this .setDocumentNumber(documentNumber);
049: this .personUniversalIdentifier = personUniversalIdentifier;
050: }
051:
052: /**
053: * Gets the personUniversalIdentifier attribute.
054: *
055: * @return Returns the personUniversalIdentifier.
056: */
057: public String getPersonUniversalIdentifier() {
058: return personUniversalIdentifier;
059: }
060:
061: /**
062: * Sets the personUniversalIdentifier attribute value.
063: *
064: * @param personUniversalIdentifier The personUniversalIdentifier to set.
065: */
066: public void setPersonUniversalIdentifier(
067: String personUniversalIdentifier) {
068: this .personUniversalIdentifier = personUniversalIdentifier;
069: }
070:
071: /**
072: * Gets the user attribute.
073: *
074: * @return Returns the user.
075: */
076: public UniversalUser getUser() {
077: user = SpringContext.getBean(UniversalUserService.class)
078: .updateUniversalUserIfNecessary(
079: personUniversalIdentifier, user);
080: return user;
081: }
082:
083: /**
084: * Sets the user attribute value.
085: *
086: * @param user The user to set.
087: * @deprecated Should not be set. User should be retrieved from SpringContext each time. See getUser() above.
088: */
089: public void setUser(UniversalUser user) {
090: this .user = user;
091: }
092:
093: public String getPrimaryDepartmentCode() {
094: String org = "";
095: if (user == null || user.getPersonUserIdentifier() == null) {
096: user = null;
097: try {
098: user = SpringContext
099: .getBean(UniversalUserService.class)
100: .getUniversalUser(
101: getPersonUniversalIdentifier());
102: } catch (UserNotFoundException ex) {
103: // do nothing, leave user as null
104: }
105: }
106: if (user == null) {
107: return "";
108: }
109: if (this .user.getModuleUser(ChartUser.MODULE_ID) != null) {
110: org = ((ChartUser) this .user
111: .getModuleUser(ChartUser.MODULE_ID))
112: .getOrganizationCode();
113: } else {
114: org = SpringContext.getBean(ChartUserService.class)
115: .getDefaultOrganizationCode(this .user);
116: }
117: return org;
118: }
119:
120: /**
121: * This method retrieves the associated user id from the UniversalUser attribute.
122: *
123: * @return The user id of the associated user.
124: */
125: public String getPersonUserIdentifier() {
126: if (user == null || user.getPersonUserIdentifier() == null) {
127: user = null;
128: try {
129: user = SpringContext
130: .getBean(UniversalUserService.class)
131: .getUniversalUser(
132: getPersonUniversalIdentifier());
133: } catch (UserNotFoundException ex) {
134: // do nothing, leave user as null
135: }
136: }
137: if (user == null) {
138: return "";
139: }
140: return user.getPersonUserIdentifier();
141: }
142:
143: /**
144: * This method has no function and is only here to satisfy Struts.
145: *
146: * @param userIdentifier User id to be passed in.
147: */
148: public void setPersonUserIdentifier(String userIdentifier) {
149: // do nothing, the getter will handle this
150: }
151:
152: /**
153: * This method retrieves the associated user name from the UniversalUser attribute.
154: *
155: * @return The user name in the format of LAST, FIRST
156: */
157: public String getName() {
158: if (user == null || user.getPersonName() == null) {
159: user = null;
160: try {
161: user = SpringContext
162: .getBean(UniversalUserService.class)
163: .getUniversalUser(
164: getPersonUniversalIdentifier());
165: } catch (UserNotFoundException ex) {
166: // do nothing, leave UU as null
167: }
168: }
169: if (user == null) {
170: return "";
171: }
172: return user.getPersonName();
173: }
174:
175: /**
176: * This method has no function and is only here to satisfy Struts.
177: *
178: * @param name The name of the user.
179: */
180: public void setName(String name) {
181: // do nothing, the getter will handle this
182: }
183:
184: /**
185: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
186: */
187: protected LinkedHashMap toStringMapper() {
188: LinkedHashMap m = new LinkedHashMap();
189: m.put(KFSPropertyConstants.DOCUMENT_NUMBER, this
190: .getDocumentNumber());
191: m.put("personUniversalIdentifier",
192: this.personUniversalIdentifier);
193: return m;
194: }
195: }
|