View Javadoc
1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.coa.businessobject;
17  
18  import java.sql.Date;
19  import java.util.Arrays;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.sys.OLEPropertyConstants;
23  import org.kuali.ole.sys.ObjectUtil;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
26  import org.kuali.rice.core.api.util.type.KualiDecimal;
27  import org.kuali.rice.kew.api.doctype.DocumentTypeService;
28  import org.kuali.rice.kew.doctype.bo.DocumentType;
29  import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
30  import org.kuali.rice.kim.api.identity.Person;
31  import org.kuali.rice.kim.api.identity.PersonService;
32  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
33  
34  /**
35   * 
36   */
37  public class AccountDelegate extends PersistableBusinessObjectBase implements MutableInactivatable {
38  
39      private static final long serialVersionUID = 6883162275377881235L;
40  
41      /**
42       * Default no-arg constructor.
43       */
44      public AccountDelegate() {
45      }
46  
47      private String chartOfAccountsCode;
48      private String accountNumber;
49      private String financialDocumentTypeCode;
50      private String accountDelegateSystemId;
51      private KualiDecimal finDocApprovalFromThisAmt;
52      private boolean accountsDelegatePrmrtIndicator;
53      private boolean active;
54      private Date accountDelegateStartDate;
55      private KualiDecimal finDocApprovalToThisAmount;
56  
57      private Chart chart;
58      private Account account;
59      private transient DocumentTypeEBO financialSystemDocumentTypeCode;
60      private Person accountDelegate;
61  
62      /**
63       * Gets the accountNumber attribute.
64       * 
65       * @return Returns the accountNumber.
66       */
67      public String getAccountNumber() {
68          return accountNumber;
69      }
70  
71      /**
72       * Sets the accountNumber attribute value.
73       * 
74       * @param accountNumber The accountNumber to set.
75       */
76      public void setAccountNumber(String accountNumber) {
77          this.accountNumber = accountNumber;
78      }
79  
80      /**
81       * Gets the chartOfAccountsCode attribute.
82       * 
83       * @return Returns the chartOfAccountsCode.
84       */
85      public String getChartOfAccountsCode() {
86          return chartOfAccountsCode;
87      }
88  
89      /**
90       * Sets the chartOfAccountsCode attribute value.
91       * 
92       * @param chartOfAccountsCode The chartOfAccountsCode to set.
93       */
94      public void setChartOfAccountsCode(String chartOfAccountsCode) {
95          this.chartOfAccountsCode = chartOfAccountsCode;
96      }
97  
98      /**
99       * Gets the financialDocumentTypeCode attribute.
100      * 
101      * @return Returns the financialDocumentTypeCode
102      */
103     public String getFinancialDocumentTypeCode() {
104         return financialDocumentTypeCode;
105     }
106 
107     /**
108      * Sets the financialDocumentTypeCode attribute.
109      * 
110      * @param financialDocumentTypeCode The financialDocumentTypeCode to set.
111      */
112     public void setFinancialDocumentTypeCode(String financialDocumentTypeCode) {
113         this.financialDocumentTypeCode = financialDocumentTypeCode;
114     }
115 
116     /**
117      * Gets the accountDelegateSystemId attribute.
118      * 
119      * @return Returns the accountDelegateSystemId.
120      */
121     public String getAccountDelegateSystemId() {
122         return accountDelegateSystemId;
123     }
124 
125     /**
126      * Sets the accountDelegateSystemId attribute value.
127      * 
128      * @param accountDelegateSystemId The accountDelegateSystemId to set.
129      */
130     public void setAccountDelegateSystemId(String accountDelegateSystemId) {
131         this.accountDelegateSystemId = accountDelegateSystemId;
132     }
133 
134     /**
135      * Gets the finDocApprovalFromThisAmt attribute.
136      * 
137      * @return Returns the finDocApprovalFromThisAmt
138      */
139     public KualiDecimal getFinDocApprovalFromThisAmt() {
140         return finDocApprovalFromThisAmt;
141     }
142 
143     /**
144      * Sets the finDocApprovalFromThisAmt attribute.
145      * 
146      * @param finDocApprovalFromThisAmt The finDocApprovalFromThisAmt to set.
147      */
148     public void setFinDocApprovalFromThisAmt(KualiDecimal finDocApprovalFromThisAmt) {
149         this.finDocApprovalFromThisAmt = finDocApprovalFromThisAmt;
150     }
151 
152     /**
153      * Gets the accountsDelegatePrmrtIndicator attribute.
154      * 
155      * @return Returns the accountsDelegatePrmrtIndicator
156      */
157     public boolean isAccountsDelegatePrmrtIndicator() {
158         return accountsDelegatePrmrtIndicator;
159     }
160 
161     /**
162      * Sets the accountsDelegatePrmrtIndicator attribute.
163      * 
164      * @param accountsDelegatePrmrtIndicator The accountsDelegatePrmrtIndicator to set.
165      * @deprecated
166      */
167     public void setAccountsDelegatePrmrtIndicator(boolean accountsDelegatePrmrtIndicator) {
168         this.accountsDelegatePrmrtIndicator = accountsDelegatePrmrtIndicator;
169     }
170 
171     /**
172      * Gets the active attribute.
173      * 
174      * @return Returns the active
175      */
176     @Override
177     public boolean isActive() {
178         return active;
179     }
180 
181     /**
182      * Sets the active attribute.
183      * 
184      * @param active The active to set.
185      * @deprecated
186      */
187     public void setActive(boolean active) {
188         this.active = active;
189     }
190 
191     /**
192      * Gets the accountDelegateStartDate attribute.
193      * 
194      * @return Returns the accountDelegateStartDate
195      */
196     public Date getAccountDelegateStartDate() {
197         return accountDelegateStartDate;
198     }
199 
200     /**
201      * Sets the accountDelegateStartDate attribute.
202      * 
203      * @param accountDelegateStartDate The accountDelegateStartDate to set.
204      */
205     public void setAccountDelegateStartDate(Date accountDelegateStartDate) {
206         this.accountDelegateStartDate = accountDelegateStartDate;
207     }
208 
209     /**
210      * Gets the finDocApprovalToThisAmount attribute.
211      * 
212      * @return Returns the finDocApprovalToThisAmount
213      */
214     public KualiDecimal getFinDocApprovalToThisAmount() {
215         return finDocApprovalToThisAmount;
216     }
217 
218     /**
219      * Sets the finDocApprovalToThisAmount attribute.
220      * 
221      * @param finDocApprovalToThisAmount The finDocApprovalToThisAmount to set.
222      */
223     public void setFinDocApprovalToThisAmount(KualiDecimal finDocApprovalToThisAmount) {
224         this.finDocApprovalToThisAmount = finDocApprovalToThisAmount;
225     }
226 
227     /**
228      * Gets the account attribute.
229      * 
230      * @return Returns the account
231      */
232     public Account getAccount() {
233         return account;
234     }
235 
236     /**
237      * Sets the account attribute.
238      * 
239      * @param account The account to set.
240      * @deprecated
241      */
242     public void setAccount(Account account) {
243         this.account = account;
244     }
245 
246     /**
247      * Gets the financialSystemDocumentTypeCode attribute. 
248      * @return Returns the financialSystemDocumentTypeCode.
249      */
250     public DocumentTypeEBO getFinancialSystemDocumentTypeCode() {
251         if ( StringUtils.isBlank( financialDocumentTypeCode ) ) {
252             financialSystemDocumentTypeCode = null;
253         } else {
254             if ( financialSystemDocumentTypeCode == null || !StringUtils.equals(financialDocumentTypeCode, financialSystemDocumentTypeCode.getName() ) ) {
255                 org.kuali.rice.kew.api.doctype.DocumentType temp = SpringContext.getBean(DocumentTypeService.class).getDocumentTypeByName(financialDocumentTypeCode);
256                 if ( temp != null ) {
257                     financialSystemDocumentTypeCode = DocumentType.from( temp );
258                 } else {
259                     financialSystemDocumentTypeCode = null;
260                 }
261             }
262         }
263         return financialSystemDocumentTypeCode;
264     }
265 
266     public Person getAccountDelegate() {
267         accountDelegate = SpringContext.getBean(PersonService.class).updatePersonIfNecessary(accountDelegateSystemId, accountDelegate);
268         return accountDelegate;
269     }
270 
271     /**
272      * Sets the accountDelegate attribute value.
273      * 
274      * @param accountDelegate The accountDelegate to set.
275      */
276     public void setAccountDelegate(Person accountDelegate) {
277         this.accountDelegate = accountDelegate;
278     }
279 
280     /**
281      * This method (a hack by any other name...) returns a string so that an Account Delegate can have a link to view its own
282      * inquiry page after a look up
283      * 
284      * @return the String "View Account Delegate"
285      */
286     public String getAccountDelegateViewer() {
287         return "View Account Delegate";
288     }
289 
290     /**
291      * Gets the chart attribute.
292      * 
293      * @return Returns the chart.
294      */
295     public Chart getChart() {
296         return chart;
297     }
298 
299     /**
300      * Sets the chart attribute value.
301      * 
302      * @param chart The chart to set.
303      */
304     public void setChart(Chart chart) {
305         this.chart = chart;
306     }
307 
308     /**
309      * @see java.lang.Object#equals(java.lang.Object)
310      */
311     @Override
312     public boolean equals(Object obj) {
313         if (obj != null) {
314             if (this.getClass().equals(obj.getClass())) {
315                 AccountDelegate other = (AccountDelegate) obj;
316                 if (StringUtils.equalsIgnoreCase(this.chartOfAccountsCode, other.chartOfAccountsCode)) {
317                     if (StringUtils.equalsIgnoreCase(this.accountNumber, other.accountNumber)) {
318                         if (StringUtils.equalsIgnoreCase(this.financialDocumentTypeCode, other.financialDocumentTypeCode)) {
319                             if (StringUtils.equalsIgnoreCase(this.accountDelegateSystemId, other.accountDelegateSystemId)) {
320                                 return true;
321                             }
322                         }
323                     }
324                 }
325             }
326         }
327         return false;
328     }
329 
330     /**
331      * @see java.lang.Object#hashCode()
332      */
333     @Override
334     public int hashCode() {
335         return ObjectUtil.generateHashCode(this, Arrays.asList(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, OLEPropertyConstants.ACCOUNT_NUMBER,"financialDocumentTypeCode", "accountDelegateSystemId" ));
336     }
337 
338 }
339