View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.web.struts;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.kfs.sys.KFSKeyConstants;
26  import org.kuali.kfs.sys.businessobject.ElectronicPaymentClaim;
27  import org.kuali.kfs.sys.context.SpringContext;
28  import org.kuali.kfs.sys.service.ElectronicPaymentClaimingDocumentGenerationStrategy;
29  import org.kuali.kfs.sys.service.ElectronicPaymentClaimingService;
30  import org.kuali.rice.kim.api.identity.Person;
31  import org.kuali.rice.kns.web.struts.form.KualiForm;
32  import org.kuali.rice.krad.util.GlobalVariables;
33  
34  public class ElectronicFundTransferForm extends KualiForm {
35      private List<ElectronicPaymentClaim> claims;
36      private List<ElectronicPaymentClaimingDocumentGenerationStrategy> availableClaimingDocumentStrategies;
37      private List<ElectronicPaymentClaimClaimedHelper> claimedByCheckboxHelpers;
38      private String chosenElectronicPaymentClaimingDocumentCode;
39      private String hasDocumentation;
40      
41      /**
42       * Constructs a ElectronicFundTransferForm
43       */
44      public ElectronicFundTransferForm() {
45          claims = new ArrayList<ElectronicPaymentClaim>();
46          claimedByCheckboxHelpers = new ArrayList<ElectronicPaymentClaimClaimedHelper>();
47      }
48      
49      /**
50       * Gets the availableClaimingDocumentStrategies attribute. 
51       * @return Returns the availableClaimingDocumentStrategies.
52       */
53      public List<ElectronicPaymentClaimingDocumentGenerationStrategy> getAvailableClaimingDocumentStrategies() {
54          return availableClaimingDocumentStrategies;
55      }
56      /**
57       * Sets the availableClaimingDocumentStrategies attribute value.
58       * @param availableClaimingDocumentStrategies The availableClaimingDocumentStrategies to set.
59       */
60      public void setAvailableClaimingDocumentStrategies(List<ElectronicPaymentClaimingDocumentGenerationStrategy> availableClaimingDocuments) {
61          this.availableClaimingDocumentStrategies = availableClaimingDocuments;
62      }
63      
64      public boolean hasAvailableClaimingDocumentStrategies() {
65          return availableClaimingDocumentStrategies !=null && !availableClaimingDocumentStrategies.isEmpty();
66      }
67      /**
68       * Gets the chosenElectronicPaymentClaimingDocumentCode attribute. 
69       * @return Returns the chosenElectronicPaymentClaimingDocumentCode.
70       */
71      public String getChosenElectronicPaymentClaimingDocumentCode() {
72          return chosenElectronicPaymentClaimingDocumentCode;
73      }
74      /**
75       * Sets the chosenElectronicPaymentClaimingDocumentCode attribute value.
76       * @param chosenElectronicPaymentClaimingDocumentCode The chosenElectronicPaymentClaimingDocumentCode to set.
77       */
78      public void setChosenElectronicPaymentClaimingDocumentCode(String chosenElectronicPaymentClaimingDocumentCode) {
79          this.chosenElectronicPaymentClaimingDocumentCode = chosenElectronicPaymentClaimingDocumentCode;
80      }
81      /**
82       * Gets the claims attribute. 
83       * @return Returns the claims.
84       */
85      public List<ElectronicPaymentClaim> getClaims() {
86          return claims;
87      }
88      /**
89       * Returns the claim at the specified index in the list of claims.
90       * @param i index of the claim to return
91       * @return the claim at the index
92       */
93      public ElectronicPaymentClaim getClaim(int i) {
94          while (claims.size() <= i) {
95              claims.add(new ElectronicPaymentClaim());
96          }
97          return claims.get(i);
98      }
99      /**
100      * Puts an ElectronicPaymentClaim record in the claims array at a specified point
101      * @param claim the claim to add
102      * @param i the index in the list to add the record at
103      */
104     public void setClaim(ElectronicPaymentClaim claim, int i) {
105         while (claims.size() <= i) {
106             claims.add(new ElectronicPaymentClaim());
107         }
108         claims.add(i, claim);
109     }
110     /**
111      * Sets the claims attribute value.
112      * @param claims The claims to set.
113      */
114     public void setClaims(List<ElectronicPaymentClaim> claims) {
115         this.claims = claims;
116     }
117 
118     /**
119      * Gets the hasDocumentation attribute. 
120      * @return Returns the hasDocumentation.
121      */
122     public String getHasDocumentation() {
123         return hasDocumentation;
124     }
125 
126     /**
127      * Sets the hasDocumentation attribute value.
128      * @param hasDocumentation The hasDocumentation to set.
129      */
130     public void setHasDocumentation(String hasDocumentation) {
131         this.hasDocumentation = hasDocumentation;
132     }
133     
134     /**
135      * Returns a boolean whether the user has stated that documentation exists for the claims about to be made or not
136      * @return true if has documentation, false otherwise
137      */
138     public boolean isProperlyDocumented() {
139         return StringUtils.isNotBlank(this.hasDocumentation) && this.hasDocumentation.equals("Yep");
140     }
141     
142     /**
143      * Returns whether the current user has administrative powers for Electronic Funds Transfer or not
144      * @return true if administrative powers exist, false otherwise
145      */
146     public boolean isAllowElectronicFundsTransferAdministration() {
147         Person currentUser = GlobalVariables.getUserSession().getPerson();        
148         
149         return SpringContext.getBean(ElectronicPaymentClaimingService.class).isAuthorizedForClaimingElectronicPayment(currentUser, null);
150     }
151     
152     /**
153      * @return the key to the EFT documentation message
154      */
155     public String getDocumentationMessageKey() {
156         return KFSKeyConstants.ElectronicPaymentClaim.MESSAGE_EFT_CLAIMING_DOCUMENTATION;
157     }
158     
159     /**
160      * @return the key to the EFT document choice message
161      */
162     public String getDocumentChoiceMessageKey() {
163         return KFSKeyConstants.ElectronicPaymentClaim.MESSAGE_EFT_DOCUMENT_CHOICE;
164     }
165     
166     /**
167      * @return the key to the EFT "previously claimed" message for the table header
168      */
169     public String getPreviouslyClaimedHeaderKey() {
170         return KFSKeyConstants.ElectronicPaymentClaim.MESSAGE_EFT_PREVIOUSLY_CLAIMED_HEADER;
171     }
172     
173     /**
174      * @return the key to the EFT "claiming document number" message for the table header
175      */
176     public String getClaimingDocumentNumberHeaderKey() {
177         return KFSKeyConstants.ElectronicPaymentClaim.MESSAGE_EFT_CLAIMING_DOCUMENT_NUMBER_HEADER;
178     }
179 
180     /**
181      * Gets the claimedByCheckboxHelpers attribute. 
182      * @return Returns the claimedByCheckboxHelpers.
183      */
184     public List<ElectronicPaymentClaimClaimedHelper> getClaimedByCheckboxHelpers() {
185         return claimedByCheckboxHelpers;
186     }
187 
188     /**
189      * Sets the claimedByCheckboxHelpers attribute value.
190      * @param claimedByCheckboxHelpers The claimedByCheckboxHelpers to set.
191      */
192     public void setClaimedByCheckboxHelpers(List<ElectronicPaymentClaimClaimedHelper> claimedByCheckboxHelpers) {
193         this.claimedByCheckboxHelpers = claimedByCheckboxHelpers;
194     }
195     
196     /**
197      * Sets the claimedHelper at the given index
198      * @param claimedHelper the claimedCheckboxHelper to set
199      * @param index where in the list it belongs
200      */
201     public void setClaimedByCheckboxHelper(ElectronicPaymentClaimClaimedHelper claimedHelper, int index) {
202         while (claimedByCheckboxHelpers.size() <= index) {
203             claimedByCheckboxHelpers.add(new ElectronicPaymentClaimClaimedHelper());
204         }
205         claimedByCheckboxHelpers.set(index, claimedHelper);
206     }
207     
208     /**
209      * @param index location in the list of ElectronicPaymentClaimClaimedHelpers to return the helper at
210      * @return the ElectronicPaymentClaimClaimedHelper at the given location
211      */
212     public ElectronicPaymentClaimClaimedHelper getClaimedByCheckboxHelper(int index) {
213         while (claimedByCheckboxHelpers.size() <= index) {
214             claimedByCheckboxHelpers.add(new ElectronicPaymentClaimClaimedHelper());
215         }
216         return claimedByCheckboxHelpers.get(index);
217     }
218 }
219