001: /*
002: * Copyright 2006-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.financial.bo;
017:
018: import org.apache.commons.lang.StringUtils;
019: import org.kuali.core.bo.user.KualiModuleUserBase;
020: import org.kuali.core.bo.user.UniversalUser;
021: import org.kuali.core.service.KualiModuleService;
022: import org.kuali.kfs.KFSPropertyConstants;
023: import org.kuali.kfs.context.SpringContext;
024: import org.kuali.module.chart.bo.Chart;
025: import org.kuali.module.chart.bo.ChartUser;
026: import org.kuali.module.chart.bo.Org;
027: import org.kuali.module.chart.service.ChartService;
028: import org.kuali.module.chart.service.OrganizationService;
029: import org.kuali.module.financial.service.FinancialUserService;
030:
031: /**
032: *
033: * This class is used to represent a financial user.
034: */
035: public class FinancialUser extends KualiModuleUserBase {
036:
037: public static final String MODULE_ID = "financial";
038:
039: private transient Chart chartOfAccounts;
040: private transient Org organization;
041: private transient Chart userChartOfAccounts;
042: private transient Org userOrganization;
043:
044: private static FinancialUserService financialUserService;
045: private static ChartService chartService;
046: private static OrganizationService organizationService;
047:
048: /**
049: *
050: * Constructs a FinancialUser.java.
051: * @param user
052: */
053: public FinancialUser(UniversalUser user) {
054: super (MODULE_ID, user);
055: if (financialUserService == null) {
056: chartService = SpringContext.getBean(ChartService.class);
057: organizationService = SpringContext
058: .getBean(OrganizationService.class);
059: financialUserService = (FinancialUserService) SpringContext
060: .getBean(KualiModuleService.class).getModule(
061: MODULE_ID).getModuleUserService();
062: }
063: }
064:
065: /**
066: *
067: * Constructs a FinancialUser.java.
068: */
069: public FinancialUser() {
070: this (null);
071: }
072:
073: /**
074: * Returns the active flag from the embedded ChartUser object.
075: *
076: * @see org.kuali.core.bo.user.KualiModuleUser#isActive()
077: */
078: public boolean isActive() {
079: if (getUniversalUser() == null)
080: return false;
081: String activeStatus = getUniversalUser().getModuleProperties(
082: ChartUser.MODULE_ID).get(KFSPropertyConstants.ACTIVE);
083: return activeStatus != null && activeStatus.equals("Y");
084: }
085:
086: /**
087: *
088: * @see org.kuali.core.bo.user.KualiModuleUserBase#isModified(org.kuali.core.bo.user.UniversalUser, org.kuali.core.bo.user.UniversalUser)
089: */
090: @Override
091: public boolean isModified(UniversalUser oldRecord,
092: UniversalUser newRecord) {
093: boolean isThisModuleUserForNewRecordActive = "Y"
094: .equals(newRecord.getModuleProperties(
095: ChartUser.MODULE_ID).get(
096: KFSPropertyConstants.ACTIVE));
097: return super .isModified(oldRecord, newRecord)
098: || (oldRecord == null && isThisModuleUserForNewRecordActive)
099: || (oldRecord != null && oldRecord.getModuleUser(
100: MODULE_ID).isActive() != isThisModuleUserForNewRecordActive);
101: }
102:
103: /**
104: *
105: * @see org.kuali.core.bo.user.KualiModuleUserBase#setActive(boolean)
106: */
107: @Override
108: public void setActive(boolean active) {
109: throw new UnsupportedOperationException(
110: "setActive is not supported on FinancialUser objects");
111: }
112:
113: /**
114: *
115: * This method...
116: * @return
117: */
118: public Chart getChartOfAccounts() {
119: return chartOfAccounts;
120: }
121:
122: /**
123: *
124: * This method...
125: * @param chartOfAccounts
126: */
127: public void setChartOfAccounts(Chart chartOfAccounts) {
128: this .chartOfAccounts = chartOfAccounts;
129: }
130:
131: /**
132: *
133: * This method...
134: * @return
135: */
136: public String getChartOfAccountsCode() {
137: if (getUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)
138: .equals("")) {
139: return financialUserService
140: .getDefaultChartOfAccountsCode(this );
141: }
142: return getUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
143: }
144:
145: /**
146: *
147: * This method...
148: * @return
149: */
150: public Org getOrganization() {
151: return organization;
152: }
153:
154: /**
155: *
156: * This method...
157: * @param organization
158: */
159: public void setOrganization(Org organization) {
160: this .organization = organization;
161: }
162:
163: /**
164: *
165: * This method...
166: * @return
167: */
168: public String getOrganizationCode() {
169: if (getUserProperty(KFSPropertyConstants.ORGANIZATION_CODE)
170: .equals("")) {
171: return financialUserService
172: .getDefaultOrganizationCode(this );
173: }
174: return getUserProperty(KFSPropertyConstants.ORGANIZATION_CODE);
175: }
176:
177: /**
178: *
179: * This method...
180: * @return
181: */
182: public String getUserChartOfAccountsCode() {
183: return getUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
184: }
185:
186: /**
187: *
188: * This method...
189: * @param chartOfAccountsCode
190: */
191: public void setUserChartOfAccountsCode(String chartOfAccountsCode) {
192: setUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
193: chartOfAccountsCode);
194: }
195:
196: /**
197: *
198: * This method...
199: * @return
200: */
201: public String getUserOrganizationCode() {
202: return getUserProperty(KFSPropertyConstants.ORGANIZATION_CODE);
203: }
204:
205: /**
206: *
207: * This method...
208: * @param organizationCode
209: */
210: public void setUserOrganizationCode(String organizationCode) {
211: setUserProperty(KFSPropertyConstants.ORGANIZATION_CODE,
212: organizationCode);
213: }
214:
215: /**
216: *
217: * This method...
218: * @return
219: */
220: public Chart getUserChartOfAccounts() {
221: if (userChartOfAccounts == null
222: || !userChartOfAccounts.getChartOfAccountsCode()
223: .equals(getUserChartOfAccountsCode())) {
224: refresh();
225: }
226: return userChartOfAccounts;
227: }
228:
229: /**
230: *
231: * This method...
232: * @param chartOfAccounts
233: */
234: public void setUserChartOfAccounts(Chart chartOfAccounts) {
235: this .userChartOfAccounts = chartOfAccounts;
236: }
237:
238: /**
239: *
240: * This method...
241: * @return
242: */
243: public Org getUserOrganization() {
244: if (userOrganization == null
245: || !userOrganization.getChartOfAccountsCode().equals(
246: getUserChartOfAccountsCode())
247: || !userOrganization.getOrganizationCode().equals(
248: getUserOrganizationCode())) {
249: refresh();
250: }
251: return userOrganization;
252: }
253:
254: /**
255: *
256: * This method...
257: * @param organization
258: */
259: public void setUserOrganization(Org organization) {
260: this .userOrganization = organization;
261: }
262:
263: /**
264: * Get the linked objects manually since this object is not directly persistable.
265: * Mimics the refresh method on OJB persistable objects.
266: *
267: * TODO: replace me when BO MetaData can handle this
268: */
269: public void refresh() {
270: if (StringUtils.isNotEmpty(getChartOfAccountsCode())) {
271: if (chartOfAccounts == null
272: || !chartOfAccounts.getChartOfAccountsCode()
273: .equals(getChartOfAccountsCode())) {
274: chartOfAccounts = chartService
275: .getByPrimaryId(getChartOfAccountsCode()
276: .toUpperCase());
277: }
278: } else {
279: chartOfAccounts = null;
280: }
281: if (StringUtils.isNotEmpty(getOrganizationCode())) {
282: if (organization == null
283: || !organization.getChartOfAccountsCode().equals(
284: getChartOfAccountsCode())
285: || !organization.getOrganizationCode().equals(
286: getOrganizationCode())) {
287: organization = organizationService.getByPrimaryId(
288: getChartOfAccountsCode().toUpperCase(),
289: getOrganizationCode().toUpperCase());
290: }
291: } else {
292: organization = null;
293: }
294: if (StringUtils.isNotEmpty(getUserChartOfAccountsCode())) {
295: if (userChartOfAccounts == null
296: || !userChartOfAccounts.getChartOfAccountsCode()
297: .equals(getUserChartOfAccountsCode())) {
298: userChartOfAccounts = chartService
299: .getByPrimaryId(getUserChartOfAccountsCode()
300: .toUpperCase());
301: }
302: } else {
303: userChartOfAccounts = null;
304: }
305: if (StringUtils.isNotEmpty(getUserOrganizationCode())) {
306: if (userOrganization == null
307: || !userOrganization.getChartOfAccountsCode()
308: .equals(getUserChartOfAccountsCode())
309: || !userOrganization.getOrganizationCode().equals(
310: getUserOrganizationCode())) {
311: userOrganization = organizationService.getByPrimaryId(
312: getUserChartOfAccountsCode().toUpperCase(),
313: getUserOrganizationCode().toUpperCase());
314: }
315: } else {
316: userOrganization = null;
317: }
318: }
319:
320: }
|