001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.sys.businessobject; 017 018 import java.util.LinkedHashMap; 019 import java.util.List; 020 021 import org.kuali.kfs.coa.businessobject.Chart; 022 import org.kuali.kfs.coa.businessobject.Organization; 023 import org.kuali.kfs.coa.service.ChartService; 024 import org.kuali.kfs.coa.service.OrganizationService; 025 import org.kuali.kfs.sys.context.SpringContext; 026 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; 027 import org.kuali.rice.kns.util.TypedArrayList; 028 029 public class ChartOrgHolderImpl implements ChartOrgHolder { 030 031 protected String chartOfAccountsCode; 032 protected String organizationCode; 033 034 protected Chart chartOfAccounts; 035 protected Organization organization; 036 037 protected static transient OrganizationService organizationService; 038 protected static transient ChartService chartService; 039 040 public ChartOrgHolderImpl() { 041 // TODO Auto-generated constructor stub 042 } 043 044 public ChartOrgHolderImpl( String chartOfAccountsCode, String organizationCode ) { 045 this.chartOfAccountsCode = chartOfAccountsCode; 046 this.organizationCode = organizationCode; 047 } 048 049 public String getChartOfAccountsCode() { 050 return chartOfAccountsCode; 051 } 052 053 054 public String getOrganizationCode() { 055 return organizationCode; 056 } 057 058 public Chart getChartOfAccounts() { 059 if ( chartOfAccounts == null ) { 060 chartOfAccounts = getChartService().getByPrimaryId(chartOfAccountsCode); 061 } 062 return chartOfAccounts; 063 } 064 065 public Organization getOrganization() { 066 if ( organization == null ) { 067 organization = getOrganizationService().getByPrimaryId(chartOfAccountsCode, organizationCode); 068 } 069 return organization; 070 } 071 072 private static OrganizationService getOrganizationService() { 073 if ( organizationService == null ) { 074 organizationService = SpringContext.getBean(OrganizationService.class); 075 } 076 return organizationService; 077 } 078 079 private static ChartService getChartService() { 080 if ( chartService == null ) { 081 chartService = SpringContext.getBean(ChartService.class); 082 } 083 return chartService; 084 } 085 086 087 public void setChartOfAccountsCode(String chartOfAccountsCode) { 088 this.chartOfAccountsCode = chartOfAccountsCode; 089 } 090 091 092 public void setOrganizationCode(String organizationCode) { 093 this.organizationCode = organizationCode; 094 } 095 096 @Override 097 public boolean equals(Object obj) { 098 if ( !(obj instanceof ChartOrgHolder) ) { 099 return false; 100 } 101 return chartOfAccountsCode.equals(((ChartOrgHolder)obj).getChartOfAccountsCode()) 102 && organizationCode.equals(((ChartOrgHolder)obj).getOrganizationCode()); 103 } 104 105 @Override 106 public int hashCode() { 107 return chartOfAccountsCode.hashCode() + organizationCode.hashCode(); 108 } 109 }