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.purap.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.kfs.KFSPropertyConstants;
022: import org.kuali.kfs.context.SpringContext;
023: import org.kuali.module.chart.bo.Chart;
024: import org.kuali.module.chart.bo.ChartUser;
025: import org.kuali.module.chart.bo.Org;
026: import org.kuali.module.chart.service.ChartService;
027: import org.kuali.module.chart.service.ChartUserService;
028: import org.kuali.module.chart.service.OrganizationService;
029:
030: /**
031: * PurapUser business Object.
032: */
033: public class PurapUser extends KualiModuleUserBase {
034: public static final String MODULE_ID = "purap";
035: private transient Chart chartOfAccounts;
036: private transient Org organization;
037: private transient Chart userChartOfAccounts;
038: private transient Org userOrganization;
039:
040: public PurapUser() {
041: this (null);
042: }
043:
044: public PurapUser(UniversalUser user) {
045: super (MODULE_ID, user);
046: }
047:
048: /**
049: * @see org.kuali.core.bo.user.KualiModuleUserBase#isActive()
050: */
051: @Override
052: public boolean isActive() {
053: return isActiveFacultyStaffAffiliate();
054: }
055:
056: public Chart getChartOfAccounts() {
057: refresh();
058: return chartOfAccounts;
059: }
060:
061: public void setChartOfAccounts(Chart chartOfAccounts) {
062: this .chartOfAccounts = chartOfAccounts;
063: }
064:
065: public String getChartOfAccountsCode() {
066: if (StringUtils
067: .isNotEmpty(getUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE))) {
068: return getUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
069: }
070: if (getUniversalUser().getModuleUser(ChartUser.MODULE_ID) != null)
071: return ((ChartUser) getUniversalUser().getModuleUser(
072: ChartUser.MODULE_ID)).getChartOfAccountsCode();
073: return SpringContext.getBean(ChartUserService.class)
074: .getDefaultChartCode(getUniversalUser());
075: }
076:
077: public Org getOrganization() {
078: refresh();
079: return organization;
080: }
081:
082: public void setOrganization(Org organization) {
083: this .organization = organization;
084: }
085:
086: public String getOrganizationCode() {
087: if (StringUtils
088: .isNotEmpty(getUserProperty(KFSPropertyConstants.ORGANIZATION_CODE)))
089: return getUserProperty(KFSPropertyConstants.ORGANIZATION_CODE);
090: if (getUniversalUser().getModuleUser(ChartUser.MODULE_ID) != null)
091: return ((ChartUser) getUniversalUser().getModuleUser(
092: ChartUser.MODULE_ID)).getOrganizationCode();
093: return SpringContext.getBean(ChartUserService.class)
094: .getDefaultOrganizationCode(getUniversalUser());
095: }
096:
097: public String getUserChartOfAccountsCode() {
098: return getUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
099: }
100:
101: public void setUserChartOfAccountsCode(String chartOfAccountsCode) {
102: setUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
103: chartOfAccountsCode);
104: }
105:
106: public String getUserOrganizationCode() {
107: return getUserProperty(KFSPropertyConstants.ORGANIZATION_CODE);
108: }
109:
110: public void setUserOrganizationCode(String organizationCode) {
111: setUserProperty(KFSPropertyConstants.ORGANIZATION_CODE,
112: organizationCode);
113: }
114:
115: public Chart getUserChartOfAccounts() {
116: if (userChartOfAccounts == null
117: || !userChartOfAccounts.getChartOfAccountsCode()
118: .equals(getUserChartOfAccountsCode())) {
119: refresh();
120: }
121: return userChartOfAccounts;
122: }
123:
124: public void setUserChartOfAccounts(Chart chartOfAccounts) {
125: this .userChartOfAccounts = chartOfAccounts;
126: }
127:
128: public Org getUserOrganization() {
129: if (userOrganization == null
130: || !userOrganization.getChartOfAccountsCode().equals(
131: getUserChartOfAccountsCode())
132: || !userOrganization.getOrganizationCode().equals(
133: getUserOrganizationCode())) {
134: refresh();
135: }
136: return userOrganization;
137: }
138:
139: public void setUserOrganization(Org organization) {
140: this .userOrganization = organization;
141: }
142:
143: /**
144: * Get the linked objects manually since this object is not directly persistable. Mimics the refresh method on OJB persistable
145: * objects.
146: */
147: public void refresh() {
148: if (StringUtils.isNotEmpty(getChartOfAccountsCode())) {
149: if (chartOfAccounts == null
150: || !chartOfAccounts.getChartOfAccountsCode()
151: .equals(getChartOfAccountsCode())) {
152: chartOfAccounts = SpringContext.getBean(
153: ChartService.class).getByPrimaryId(
154: getChartOfAccountsCode().toUpperCase());
155: }
156: } else {
157: chartOfAccounts = null;
158: }
159: if (StringUtils.isNotEmpty(getOrganizationCode())) {
160: if (organization == null
161: || !organization.getChartOfAccountsCode().equals(
162: getChartOfAccountsCode())
163: || !organization.getOrganizationCode().equals(
164: getOrganizationCode())) {
165: organization = SpringContext.getBean(
166: OrganizationService.class).getByPrimaryId(
167: getChartOfAccountsCode().toUpperCase(),
168: getOrganizationCode().toUpperCase());
169: }
170: } else {
171: organization = null;
172: }
173: }
174:
175: }
|