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  package org.kuali.ole.pdp.businessobject;
17  
18  import java.util.LinkedHashMap;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.pdp.PdpPropertyConstants;
23  import org.kuali.ole.pdp.PdpConstants.PayeeIdTypeCodes;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.ole.vnd.businessobject.VendorDetail;
26  import org.kuali.ole.vnd.document.service.VendorService;
27  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
28  import org.kuali.rice.core.api.util.type.KualiInteger;
29  import org.kuali.rice.kim.api.identity.Person;
30  import org.kuali.rice.kim.api.identity.PersonService;
31  import org.kuali.rice.kim.api.identity.entity.EntityDefault;
32  import org.kuali.rice.kim.api.identity.principal.Principal;
33  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
34  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
35  import org.kuali.rice.krad.util.ObjectUtils;
36  
37  public class PayeeACHAccount extends PersistableBusinessObjectBase implements MutableInactivatable {
38  
39      private KualiInteger achAccountGeneratedIdentifier;
40      private String bankRoutingNumber;
41      private String bankAccountNumber;
42      private String payeeIdNumber;
43      private String payeeName;
44      private String payeeEmailAddress;
45      private String payeeIdentifierTypeCode;
46      private String achTransactionType;
47      private String bankAccountTypeCode;
48      private boolean active;
49  
50      private ACHBank bankRouting;
51      private ACHTransactionType transactionType;
52      private ACHPayee achPayee;
53  
54      /**
55       * Default constructor.
56       */
57      public PayeeACHAccount() {
58  
59      }
60  
61      /**
62       * Gets the achAccountGeneratedIdentifier attribute.
63       * 
64       * @return Returns the achAccountGeneratedIdentifier
65       */
66      public KualiInteger getAchAccountGeneratedIdentifier() {
67          return achAccountGeneratedIdentifier;
68      }
69  
70      /**
71       * Sets the achAccountGeneratedIdentifier attribute.
72       * 
73       * @param achAccountGeneratedIdentifier The achAccountGeneratedIdentifier to set.
74       */
75      public void setAchAccountGeneratedIdentifier(KualiInteger achAccountGeneratedIdentifier) {
76          this.achAccountGeneratedIdentifier = achAccountGeneratedIdentifier;
77      }
78  
79  
80      /**
81       * Gets the bankRoutingNumber attribute.
82       * 
83       * @return Returns the bankRoutingNumber
84       */
85      public String getBankRoutingNumber() {
86          return bankRoutingNumber;
87      }
88  
89      /**
90       * Sets the bankRoutingNumber attribute.
91       * 
92       * @param bankRoutingNumber The bankRoutingNumber to set.
93       */
94      public void setBankRoutingNumber(String bankRoutingNumber) {
95          this.bankRoutingNumber = bankRoutingNumber;
96      }
97  
98  
99      /**
100      * Gets the bankAccountNumber attribute.
101      * 
102      * @return Returns the bankAccountNumber
103      */
104     public String getBankAccountNumber() {
105         return bankAccountNumber;
106     }
107 
108     /**
109      * Sets the bankAccountNumber attribute.
110      * 
111      * @param bankAccountNumber The bankAccountNumber to set.
112      */
113     public void setBankAccountNumber(String bankAccountNumber) {
114         this.bankAccountNumber = bankAccountNumber;
115     }
116 
117     /**
118      * Gets the payee's name from KIM or Vendor data, if the payee type is Employee, Entity or Vendor;
119      * otherwise returns the stored field value.
120      * 
121      * @return Returns the payee name
122      */
123     public String getPayeeName() {
124         // for Employee, retrieves from Person table by employee ID
125         if (StringUtils.equalsIgnoreCase(payeeIdentifierTypeCode, PayeeIdTypeCodes.EMPLOYEE)) {
126             Person person = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(payeeIdNumber);
127             if (ObjectUtils.isNotNull(person)) {
128                 return person.getName();
129             }
130         }
131         // for Entity, retrieve from Entity table by entity ID
132         else if (StringUtils.equalsIgnoreCase(payeeIdentifierTypeCode, PayeeIdTypeCodes.ENTITY)) {
133             if(ObjectUtils.isNotNull(payeeIdNumber)) {
134                 EntityDefault entity = KimApiServiceLocator.getIdentityService().getEntityDefault(payeeIdNumber);
135                 if (ObjectUtils.isNotNull(entity) && ObjectUtils.isNotNull(entity.getName())) {
136                     return entity.getName().getCompositeName();
137                 }
138             }
139         }
140         // for Vendor, retrieves from Vendor table by vendor number
141         else if (StringUtils.equalsIgnoreCase(payeeIdentifierTypeCode, PayeeIdTypeCodes.VENDOR_ID)) {
142             VendorDetail vendor = SpringContext.getBean(VendorService.class).getVendorDetail(payeeIdNumber);
143             if (ObjectUtils.isNotNull(vendor)) {
144                 return vendor.getVendorName();
145             }
146         }
147 
148         // otherwise return field value
149         return payeeName;
150     }
151 
152     /**
153      * Sets the payeeName attribute.
154      * 
155      * @param payeeName The payeeName to set.
156      */
157     public void setPayeeName(String payeeName) {
158         this.payeeName = payeeName;
159     }
160 
161     /**
162      * Gets the payee's email address from KIM data if the payee type is Employee or Entity;
163      * otherwise, returns the stored field value.
164      * 
165      * @return Returns the payeeEmailAddress
166      */
167     public String getPayeeEmailAddress() {
168         // for Employee, retrieve from Person table by employee ID
169         if (StringUtils.equalsIgnoreCase(payeeIdentifierTypeCode, PayeeIdTypeCodes.EMPLOYEE)) {
170             Person person = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(payeeIdNumber);
171             if (ObjectUtils.isNotNull(person)) {
172                 return person.getEmailAddress();
173             }
174         }
175         // for Entity, retrieve from Entity table by entity ID then from Person table
176         else if (StringUtils.equalsIgnoreCase(payeeIdentifierTypeCode, PayeeIdTypeCodes.ENTITY)) {
177             if(ObjectUtils.isNotNull(payeeIdNumber)) {
178                 EntityDefault entity = KimApiServiceLocator.getIdentityService().getEntityDefault(payeeIdNumber);
179                 if (ObjectUtils.isNotNull(entity)) {
180                     List<Principal> principals = entity.getPrincipals();
181                     if (principals.size() > 0 && ObjectUtils.isNotNull(principals.get(0))) {
182                         String principalId = principals.get(0).getPrincipalId();
183                         Person person = SpringContext.getBean(PersonService.class).getPerson(principalId);
184                         if (ObjectUtils.isNotNull(person)) {
185                             return person.getEmailAddress();
186                         }
187                     }
188                 }
189             }
190         }
191 
192         // otherwise returns the field value
193         return payeeEmailAddress;
194     }
195 
196     /**
197      * Sets the payeeEmailAddress attribute if the payee is not Employee or Entity.
198      * 
199      * @param payeeEmailAddress The payeeEmailAddress to set.
200      */
201     public void setPayeeEmailAddress(String payeeEmailAddress) {
202         this.payeeEmailAddress = payeeEmailAddress;
203     }
204 
205     /**
206      * Gets the payeeIdentifierTypeCode attribute.
207      * 
208      * @return Returns the payeeIdentifierTypeCode
209      */
210     public String getPayeeIdentifierTypeCode() {
211         return payeeIdentifierTypeCode;
212     }
213 
214     /**
215      * Sets the payeeIdentifierTypeCode attribute.
216      * 
217      * @param payeeIdentifierTypeCode The payeeIdentifierTypeCode to set.
218      */
219     public void setPayeeIdentifierTypeCode(String payeeIdentifierTypeCode) {
220         this.payeeIdentifierTypeCode = payeeIdentifierTypeCode;
221     }
222 
223     /**
224      * Gets the achTransactionType attribute.
225      * 
226      * @return Returns the achTransactionType.
227      */
228     public String getAchTransactionType() {
229         return achTransactionType;
230     }
231 
232     /**
233      * Sets the achTransactionType attribute value.
234      * 
235      * @param achTransactionType The achTransactionType to set.
236      */
237     public void setAchTransactionType(String achTransactionType) {
238         this.achTransactionType = achTransactionType;
239     }
240 
241     /**
242      * Gets the transactionType attribute.
243      * 
244      * @return Returns the transactionType.
245      */
246     public ACHTransactionType getTransactionType() {
247         return transactionType;
248     }
249 
250     /**
251      * Sets the transactionType attribute value.
252      * 
253      * @param transactionType The transactionType to set.
254      */
255     public void setTransactionType(ACHTransactionType transactionType) {
256         this.transactionType = transactionType;
257     }
258 
259     /**
260      * Gets the active attribute.
261      * 
262      * @return Returns the active
263      */
264     @Override
265     public boolean isActive() {
266         return active;
267     }
268 
269     /**
270      * Sets the active attribute.
271      * 
272      * @param active The active to set.
273      */
274     @Override
275     public void setActive(boolean active) {
276         this.active = active;
277     }
278 
279     /**
280      * Gets the bankAccountTypeCode attribute.
281      * 
282      * @return Returns the bankAccountTypeCode.
283      */
284     public String getBankAccountTypeCode() {
285         return bankAccountTypeCode;
286     }
287 
288     /**
289      * Sets the bankAccountTypeCode attribute value.
290      * 
291      * @param bankAccountTypeCode The bankAccountTypeCode to set.
292      */
293     public void setBankAccountTypeCode(String bankAccountTypeCode) {
294         this.bankAccountTypeCode = bankAccountTypeCode;
295     }
296 
297     /**
298      * Gets the bankRouting attribute.
299      * 
300      * @return Returns the bankRouting.
301      */
302     public ACHBank getBankRouting() {
303         return bankRouting;
304     }
305 
306     /**
307      * Sets the bankRouting attribute value.
308      * 
309      * @param bankRouting The bankRouting to set.
310      * @deprecated
311      */
312     @Deprecated
313     public void setBankRouting(ACHBank bankRouting) {
314         this.bankRouting = bankRouting;
315     }
316 
317 
318     /**
319      * Gets the payeeIdNumber attribute.
320      * 
321      * @return Returns the payeeIdNumber.
322      */
323     public String getPayeeIdNumber() {
324         return payeeIdNumber;
325     }
326 
327     /**
328      * Sets the payeeIdNumber attribute value.
329      * 
330      * @param payeeIdNumber The payeeIdNumber to set.
331      */
332     public void setPayeeIdNumber(String payeeIdNumber) {
333         this.payeeIdNumber = payeeIdNumber;
334     }
335 
336 
337     /**
338      * Gets the achPayee attribute.
339      * 
340      * @return Returns the achPayee.
341      */
342     public ACHPayee getAchPayee() {
343         return achPayee;
344     }
345 
346     /**
347      * Sets the achPayee attribute value.
348      * 
349      * @param achPayee The achPayee to set.
350      */
351     public void setAchPayee(ACHPayee achPayee) {
352         this.achPayee = achPayee;
353     }
354 
355     /**
356      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
357      */
358     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
359         LinkedHashMap m = new LinkedHashMap();
360         if (this.achAccountGeneratedIdentifier != null) {
361             m.put(PdpPropertyConstants.ACH_ACCOUNT_GENERATED_IDENTIFIER, this.achAccountGeneratedIdentifier.toString());
362         }
363         return m;
364     }
365 }