View Javadoc
1   /*
2    * Copyright 2007 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  
17  package org.kuali.ole.coa.businessobject;
18  
19  import java.sql.Date;
20  import java.util.Arrays;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.ole.sys.OLEPropertyConstants;
24  import org.kuali.ole.sys.ObjectUtil;
25  import org.kuali.ole.sys.context.SpringContext;
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.GlobalBusinessObjectDetailBase;
33  
34  /**
35   * 
36   */
37  public class AccountDelegateGlobalDetail extends GlobalBusinessObjectDetailBase {
38  
39      private static final long serialVersionUID = -8089154029664644867L;
40  
41      private String accountDelegateUniversalId;
42      private String financialDocumentTypeCode;
43      private KualiDecimal approvalFromThisAmount;
44      private KualiDecimal approvalToThisAmount;
45      private boolean accountDelegatePrimaryRoutingIndicator;
46      private Date accountDelegateStartDate;
47  
48      private Person accountDelegate;
49      private transient DocumentTypeEBO financialSystemDocumentTypeCode;
50  
51      /**
52       * Default constructor.
53       */
54      public AccountDelegateGlobalDetail() {
55          super();
56      }
57  
58      public AccountDelegateGlobalDetail(AccountDelegateModelDetail model) {
59          accountDelegatePrimaryRoutingIndicator = model.getAccountDelegatePrimaryRoutingIndicator();
60          accountDelegateStartDate = model.getAccountDelegateStartDate();
61          accountDelegateUniversalId = model.getAccountDelegateUniversalId();
62          approvalFromThisAmount = model.getApprovalFromThisAmount();
63          approvalToThisAmount = model.getApprovalToThisAmount();
64          financialDocumentTypeCode = model.getFinancialDocumentTypeCode();
65      }
66  
67      /**
68       * Gets the financialSystemDocumentTypeCode attribute. 
69       * @return Returns the financialSystemDocumentTypeCode.
70       */
71      public DocumentTypeEBO getFinancialSystemDocumentTypeCode() {
72          if ( StringUtils.isBlank( financialDocumentTypeCode ) ) {
73              financialSystemDocumentTypeCode = null;
74          } else {
75              if ( financialSystemDocumentTypeCode == null || !StringUtils.equals(financialDocumentTypeCode, financialSystemDocumentTypeCode.getName() ) ) {
76                  org.kuali.rice.kew.api.doctype.DocumentType temp = SpringContext.getBean(DocumentTypeService.class).getDocumentTypeByName(financialDocumentTypeCode);
77                  if ( temp != null ) {
78                      financialSystemDocumentTypeCode = DocumentType.from( temp );
79                  } else {
80                      financialSystemDocumentTypeCode = null;
81                  }
82              }
83          }
84          return financialSystemDocumentTypeCode;
85      }
86  
87      /**
88       * Gets the accountDelegateUniversalId attribute.
89       * 
90       * @return Returns the accountDelegateUniversalId
91       */
92      public String getAccountDelegateUniversalId() {
93          return accountDelegateUniversalId;
94      }
95  
96      /**
97       * Sets the accountDelegateUniversalId attribute.
98       * 
99       * @param accountDelegateUniversalId The accountDelegateUniversalId to set.
100      */
101     public void setAccountDelegateUniversalId(String accountDelegateUniversalId) {
102         this.accountDelegateUniversalId = accountDelegateUniversalId;
103     }    
104     
105     /**
106      * Gets the financialDocumentTypeCode attribute.
107      * 
108      * @return Returns the financialDocumentTypeCode
109      */
110     public String getFinancialDocumentTypeCode() {
111         return financialDocumentTypeCode;
112     }
113 
114     /**
115      * Sets the financialDocumentTypeCode attribute.
116      * 
117      * @param financialDocumentTypeCode The financialDocumentTypeCode to set.
118      */
119     public void setFinancialDocumentTypeCode(String financialDocumentTypeCode) {
120         this.financialDocumentTypeCode = financialDocumentTypeCode;
121     }
122 
123 
124     /**
125      * Gets the approvalFromThisAmount attribute.
126      * 
127      * @return Returns the approvalFromThisAmount
128      */
129     public KualiDecimal getApprovalFromThisAmount() {
130         return approvalFromThisAmount;
131     }
132 
133     /**
134      * Sets the approvalFromThisAmount attribute.
135      * 
136      * @param approvalFromThisAmount The approvalFromThisAmount to set.
137      */
138     public void setApprovalFromThisAmount(KualiDecimal approvalFromThisAmount) {
139         this.approvalFromThisAmount = approvalFromThisAmount;
140     }
141 
142 
143     /**
144      * Gets the approvalToThisAmount attribute.
145      * 
146      * @return Returns the approvalToThisAmount
147      */
148     public KualiDecimal getApprovalToThisAmount() {
149         return approvalToThisAmount;
150     }
151 
152     /**
153      * Sets the approvalToThisAmount attribute.
154      * 
155      * @param approvalToThisAmount The approvalToThisAmount to set.
156      */
157     public void setApprovalToThisAmount(KualiDecimal approvalToThisAmount) {
158         this.approvalToThisAmount = approvalToThisAmount;
159     }
160 
161 
162     /**
163      * Gets the accountDelegatePrimaryRoutingIndicator attribute.
164      * 
165      * @return Returns the accountDelegatePrimaryRoutingIndicator
166      */
167     public boolean getAccountDelegatePrimaryRoutingIndicator() {
168         return accountDelegatePrimaryRoutingIndicator;
169     }
170 
171     /**
172      * Sets the accountDelegatePrimaryRoutingIndicator attribute.
173      * 
174      * @param accountDelegatePrimaryRoutingIndicator The accountDelegatePrimaryRoutingIndicator to set.
175      * @deprecated
176      */
177     public void setAccountDelegatePrimaryRoutingIndicator(boolean accountDelegatePrimaryRoutingIndicator) {
178         this.accountDelegatePrimaryRoutingIndicator = accountDelegatePrimaryRoutingIndicator;
179     }
180 
181 
182     /**
183      * Gets the accountDelegateStartDate attribute.
184      * 
185      * @return Returns the accountDelegateStartDate
186      */
187     public Date getAccountDelegateStartDate() {
188         return accountDelegateStartDate;
189     }
190 
191     /**
192      * Sets the accountDelegateStartDate attribute.
193      * 
194      * @param accountDelegateStartDate The accountDelegateStartDate to set.
195      */
196     public void setAccountDelegateStartDate(Date accountDelegateStartDate) {
197         this.accountDelegateStartDate = accountDelegateStartDate;
198     }
199 
200     public Person getAccountDelegate() {
201         accountDelegate = SpringContext.getBean(PersonService.class).updatePersonIfNecessary(accountDelegateUniversalId, accountDelegate);        
202         return accountDelegate;
203     }
204 
205     /**
206      * @param accountDelegate The accountDelegate to set.
207      * @deprecated
208      */
209     public void setAccountDelegate(Person accountDelegate) {
210         this.accountDelegate = accountDelegate;
211     }
212 
213     /**
214      * @see java.lang.Object#equals(java.lang.Object)
215      */
216     @Override
217     public boolean equals(Object obj) {
218         if (obj != null) {
219             if (this.getClass().equals(obj.getClass())) {
220                 AccountDelegateGlobalDetail other = (AccountDelegateGlobalDetail) obj;
221                 if (StringUtils.equalsIgnoreCase(getDocumentNumber(), other.getDocumentNumber())) {
222                     if (StringUtils.equalsIgnoreCase(this.financialDocumentTypeCode, other.financialDocumentTypeCode)) {
223                         if (this.accountDelegatePrimaryRoutingIndicator == other.accountDelegatePrimaryRoutingIndicator) {
224                             if (StringUtils.equalsIgnoreCase(this.accountDelegateUniversalId, other.accountDelegateUniversalId)) {
225                                 return true;
226                             }
227                         }
228                     }
229                 }
230             }
231         }
232         return false;
233     }
234 
235     /**
236      * @see java.lang.Object#hashCode()
237      */
238     @Override
239     public int hashCode() {
240         return ObjectUtil.generateHashCode(this, Arrays.asList(OLEPropertyConstants.DOCUMENT_NUMBER,"financialDocumentTypeCode", "accountDelegatePrimaryRoutingIndicator", "accountDelegateUniversalId" ));
241     }
242 
243 }
244