1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.businessobject;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.coa.businessobject.Chart;
20 import org.kuali.ole.coa.businessobject.Organization;
21 import org.kuali.ole.coa.service.ChartService;
22 import org.kuali.ole.coa.service.OrganizationService;
23 import org.kuali.ole.sys.context.SpringContext;
24
25 public class ChartOrgHolderImpl implements ChartOrgHolder {
26
27 protected String chartOfAccountsCode;
28 protected String organizationCode;
29
30 protected Chart chartOfAccounts;
31 protected Organization organization;
32
33 protected static transient OrganizationService organizationService;
34 protected static transient ChartService chartService;
35
36 public ChartOrgHolderImpl() {}
37
38 public ChartOrgHolderImpl( String chartOfAccountsCode, String organizationCode ) {
39 this.chartOfAccountsCode = chartOfAccountsCode;
40 this.organizationCode = organizationCode;
41 }
42
43 public ChartOrgHolderImpl( Organization org ) {
44 this.chartOfAccountsCode = org.getChartOfAccountsCode();
45 this.organizationCode = org.getOrganizationCode();
46 this.organization = org;
47 }
48
49 public String getChartOfAccountsCode() {
50 return chartOfAccountsCode;
51 }
52
53
54 public String getOrganizationCode() {
55 return organizationCode;
56 }
57
58 public Chart getChartOfAccounts() {
59 if ( chartOfAccounts == null && StringUtils.isNotBlank(chartOfAccountsCode) ) {
60 chartOfAccounts = getChartService().getByPrimaryId(chartOfAccountsCode);
61 }
62 return chartOfAccounts;
63 }
64
65 public Organization getOrganization() {
66 if ( organization == null && StringUtils.isNotBlank(chartOfAccountsCode) && StringUtils.isNotBlank(organizationCode) ) {
67 organization = getOrganizationService().getByPrimaryId(chartOfAccountsCode, organizationCode);
68 }
69 return organization;
70 }
71
72 private static OrganizationService getOrganizationService() {
73 if ( organizationService == null ) {
74 organizationService = SpringContext.getBean(OrganizationService.class);
75 }
76 return organizationService;
77 }
78
79 private static ChartService getChartService() {
80 if ( chartService == null ) {
81 chartService = SpringContext.getBean(ChartService.class);
82 }
83 return chartService;
84 }
85
86
87 public void setChartOfAccountsCode(String chartOfAccountsCode) {
88 this.chartOfAccountsCode = chartOfAccountsCode;
89 }
90
91
92 public void setOrganizationCode(String organizationCode) {
93 this.organizationCode = organizationCode;
94 }
95
96 @Override
97 public boolean equals(Object obj) {
98 if ( obj == null || !(obj instanceof ChartOrgHolder) ) {
99 return false;
100 }
101 return StringUtils.equals( chartOfAccountsCode, ((ChartOrgHolder)obj).getChartOfAccountsCode() )
102 && StringUtils.equals( organizationCode, ((ChartOrgHolder)obj).getOrganizationCode() );
103 }
104
105 @Override
106 public int hashCode() {
107 return String.valueOf(chartOfAccountsCode).hashCode() + String.valueOf(organizationCode).hashCode();
108 }
109
110 @Override
111 public String toString() {
112 return String.valueOf(chartOfAccountsCode) + "-" + String.valueOf(organizationCode);
113 }
114 }