/*
* Copyright 2006-2007 The Kuali Foundation.
*
* Licensed under the Educational Community License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.opensource.org/licenses/ecl1.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kuali.module.purap.bo;
import org.apache.commons.lang.StringUtils;
import org.kuali.core.bo.user.KualiModuleUserBase;
import org.kuali.core.bo.user.UniversalUser;
import org.kuali.kfs.KFSPropertyConstants;
import org.kuali.kfs.context.SpringContext;
import org.kuali.module.chart.bo.Chart;
import org.kuali.module.chart.bo.ChartUser;
import org.kuali.module.chart.bo.Org;
import org.kuali.module.chart.service.ChartService;
import org.kuali.module.chart.service.ChartUserService;
import org.kuali.module.chart.service.OrganizationService;
/**
* PurapUser business Object.
*/
public class PurapUser extends KualiModuleUserBase {
public static final String MODULE_ID = "purap";
private transient Chart chartOfAccounts;
private transient Org organization;
private transient Chart userChartOfAccounts;
private transient Org userOrganization;
public PurapUser() {
this(null);
}
public PurapUser(UniversalUser user) {
super(MODULE_ID, user);
}
/**
* @see org.kuali.core.bo.user.KualiModuleUserBase#isActive()
*/
@Override
public boolean isActive() {
return isActiveFacultyStaffAffiliate();
}
public Chart getChartOfAccounts() {
refresh();
return chartOfAccounts;
}
public void setChartOfAccounts(Chart chartOfAccounts) {
this.chartOfAccounts = chartOfAccounts;
}
public String getChartOfAccountsCode() {
if (StringUtils.isNotEmpty(getUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE))) {
return getUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
}
if (getUniversalUser().getModuleUser(ChartUser.MODULE_ID) != null)
return ((ChartUser) getUniversalUser().getModuleUser(ChartUser.MODULE_ID)).getChartOfAccountsCode();
return SpringContext.getBean(ChartUserService.class).getDefaultChartCode(getUniversalUser());
}
public Org getOrganization() {
refresh();
return organization;
}
public void setOrganization(Org organization) {
this.organization = organization;
}
public String getOrganizationCode() {
if (StringUtils.isNotEmpty(getUserProperty(KFSPropertyConstants.ORGANIZATION_CODE)))
return getUserProperty(KFSPropertyConstants.ORGANIZATION_CODE);
if (getUniversalUser().getModuleUser(ChartUser.MODULE_ID) != null)
return ((ChartUser) getUniversalUser().getModuleUser(ChartUser.MODULE_ID)).getOrganizationCode();
return SpringContext.getBean(ChartUserService.class).getDefaultOrganizationCode(getUniversalUser());
}
public String getUserChartOfAccountsCode() {
return getUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
}
public void setUserChartOfAccountsCode(String chartOfAccountsCode) {
setUserProperty(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
}
public String getUserOrganizationCode() {
return getUserProperty(KFSPropertyConstants.ORGANIZATION_CODE);
}
public void setUserOrganizationCode(String organizationCode) {
setUserProperty(KFSPropertyConstants.ORGANIZATION_CODE, organizationCode);
}
public Chart getUserChartOfAccounts() {
if (userChartOfAccounts == null || !userChartOfAccounts.getChartOfAccountsCode().equals(getUserChartOfAccountsCode())) {
refresh();
}
return userChartOfAccounts;
}
public void setUserChartOfAccounts(Chart chartOfAccounts) {
this.userChartOfAccounts = chartOfAccounts;
}
public Org getUserOrganization() {
if (userOrganization == null || !userOrganization.getChartOfAccountsCode().equals(getUserChartOfAccountsCode()) || !userOrganization.getOrganizationCode().equals(getUserOrganizationCode())) {
refresh();
}
return userOrganization;
}
public void setUserOrganization(Org organization) {
this.userOrganization = organization;
}
/**
* Get the linked objects manually since this object is not directly persistable. Mimics the refresh method on OJB persistable
* objects.
*/
public void refresh() {
if (StringUtils.isNotEmpty(getChartOfAccountsCode())) {
if (chartOfAccounts == null || !chartOfAccounts.getChartOfAccountsCode().equals(getChartOfAccountsCode())) {
chartOfAccounts = SpringContext.getBean(ChartService.class).getByPrimaryId(getChartOfAccountsCode().toUpperCase());
}
}
else {
chartOfAccounts = null;
}
if (StringUtils.isNotEmpty(getOrganizationCode())) {
if (organization == null || !organization.getChartOfAccountsCode().equals(getChartOfAccountsCode()) || !organization.getOrganizationCode().equals(getOrganizationCode())) {
organization = SpringContext.getBean(OrganizationService.class).getByPrimaryId(getChartOfAccountsCode().toUpperCase(), getOrganizationCode().toUpperCase());
}
}
else {
organization = null;
}
}
}
|