001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.sys.web.struts;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import org.apache.commons.lang.StringUtils;
022 import org.kuali.kfs.sys.KFSConstants;
023 import org.kuali.kfs.sys.KFSKeyConstants;
024 import org.kuali.kfs.sys.businessobject.ElectronicPaymentClaim;
025 import org.kuali.kfs.sys.context.SpringContext;
026 import org.kuali.kfs.sys.service.ElectronicPaymentClaimingDocumentGenerationStrategy;
027 import org.kuali.kfs.sys.service.ElectronicPaymentClaimingService;
028 import org.kuali.rice.kim.bo.Person;
029 import org.kuali.rice.kns.util.GlobalVariables;
030 import org.kuali.rice.kns.web.struts.form.KualiForm;
031
032 public class ElectronicFundTransferForm extends KualiForm {
033 private List<ElectronicPaymentClaim> claims;
034 private List<ElectronicPaymentClaimingDocumentGenerationStrategy> availableClaimingDocumentStrategies;
035 private List<ElectronicPaymentClaimClaimedHelper> claimedByCheckboxHelpers;
036 private String chosenElectronicPaymentClaimingDocumentCode;
037 private String hasDocumentation;
038
039 /**
040 * Constructs a ElectronicFundTransferForm
041 */
042 public ElectronicFundTransferForm() {
043 claims = new ArrayList<ElectronicPaymentClaim>();
044 claimedByCheckboxHelpers = new ArrayList<ElectronicPaymentClaimClaimedHelper>();
045 }
046
047 /**
048 * Gets the availableClaimingDocumentStrategies attribute.
049 * @return Returns the availableClaimingDocumentStrategies.
050 */
051 public List<ElectronicPaymentClaimingDocumentGenerationStrategy> getAvailableClaimingDocumentStrategies() {
052 return availableClaimingDocumentStrategies;
053 }
054 /**
055 * Sets the availableClaimingDocumentStrategies attribute value.
056 * @param availableClaimingDocumentStrategies The availableClaimingDocumentStrategies to set.
057 */
058 public void setAvailableClaimingDocumentStrategies(List<ElectronicPaymentClaimingDocumentGenerationStrategy> availableClaimingDocuments) {
059 this.availableClaimingDocumentStrategies = availableClaimingDocuments;
060 }
061
062 public boolean hasAvailableClaimingDocumentStrategies() {
063 return availableClaimingDocumentStrategies !=null && !availableClaimingDocumentStrategies.isEmpty();
064 }
065 /**
066 * Gets the chosenElectronicPaymentClaimingDocumentCode attribute.
067 * @return Returns the chosenElectronicPaymentClaimingDocumentCode.
068 */
069 public String getChosenElectronicPaymentClaimingDocumentCode() {
070 return chosenElectronicPaymentClaimingDocumentCode;
071 }
072 /**
073 * Sets the chosenElectronicPaymentClaimingDocumentCode attribute value.
074 * @param chosenElectronicPaymentClaimingDocumentCode The chosenElectronicPaymentClaimingDocumentCode to set.
075 */
076 public void setChosenElectronicPaymentClaimingDocumentCode(String chosenElectronicPaymentClaimingDocumentCode) {
077 this.chosenElectronicPaymentClaimingDocumentCode = chosenElectronicPaymentClaimingDocumentCode;
078 }
079 /**
080 * Gets the claims attribute.
081 * @return Returns the claims.
082 */
083 public List<ElectronicPaymentClaim> getClaims() {
084 return claims;
085 }
086 /**
087 * Returns the claim at the specified index in the list of claims.
088 * @param i index of the claim to return
089 * @return the claim at the index
090 */
091 public ElectronicPaymentClaim getClaim(int i) {
092 while (claims.size() <= i) {
093 claims.add(new ElectronicPaymentClaim());
094 }
095 return claims.get(i);
096 }
097 /**
098 * Puts an ElectronicPaymentClaim record in the claims array at a specified point
099 * @param claim the claim to add
100 * @param i the index in the list to add the record at
101 */
102 public void setClaim(ElectronicPaymentClaim claim, int i) {
103 while (claims.size() <= i) {
104 claims.add(new ElectronicPaymentClaim());
105 }
106 claims.add(i, claim);
107 }
108 /**
109 * Sets the claims attribute value.
110 * @param claims The claims to set.
111 */
112 public void setClaims(List<ElectronicPaymentClaim> claims) {
113 this.claims = claims;
114 }
115
116 /**
117 * Gets the hasDocumentation attribute.
118 * @return Returns the hasDocumentation.
119 */
120 public String getHasDocumentation() {
121 return hasDocumentation;
122 }
123
124 /**
125 * Sets the hasDocumentation attribute value.
126 * @param hasDocumentation The hasDocumentation to set.
127 */
128 public void setHasDocumentation(String hasDocumentation) {
129 this.hasDocumentation = hasDocumentation;
130 }
131
132 /**
133 * Returns a boolean whether the user has stated that documentation exists for the claims about to be made or not
134 * @return true if has documentation, false otherwise
135 */
136 public boolean isProperlyDocumented() {
137 return StringUtils.isNotBlank(this.hasDocumentation) && this.hasDocumentation.equals("Yep");
138 }
139
140 /**
141 * Returns whether the current user has administrative powers for Electronic Funds Transfer or not
142 * @return true if administrative powers exist, false otherwise
143 */
144 public boolean isAllowElectronicFundsTransferAdministration() {
145 Person currentUser = GlobalVariables.getUserSession().getPerson();
146
147 return SpringContext.getBean(ElectronicPaymentClaimingService.class).isAuthorizedForClaimingElectronicPayment(currentUser, null);
148 }
149
150 /**
151 * @return the key to the EFT documentation message
152 */
153 public String getDocumentationMessageKey() {
154 return KFSKeyConstants.ElectronicPaymentClaim.MESSAGE_EFT_CLAIMING_DOCUMENTATION;
155 }
156
157 /**
158 * @return the key to the EFT document choice message
159 */
160 public String getDocumentChoiceMessageKey() {
161 return KFSKeyConstants.ElectronicPaymentClaim.MESSAGE_EFT_DOCUMENT_CHOICE;
162 }
163
164 /**
165 * @return the key to the EFT "previously claimed" message for the table header
166 */
167 public String getPreviouslyClaimedHeaderKey() {
168 return KFSKeyConstants.ElectronicPaymentClaim.MESSAGE_EFT_PREVIOUSLY_CLAIMED_HEADER;
169 }
170
171 /**
172 * @return the key to the EFT "claiming document number" message for the table header
173 */
174 public String getClaimingDocumentNumberHeaderKey() {
175 return KFSKeyConstants.ElectronicPaymentClaim.MESSAGE_EFT_CLAIMING_DOCUMENT_NUMBER_HEADER;
176 }
177
178 /**
179 * Gets the claimedByCheckboxHelpers attribute.
180 * @return Returns the claimedByCheckboxHelpers.
181 */
182 public List<ElectronicPaymentClaimClaimedHelper> getClaimedByCheckboxHelpers() {
183 return claimedByCheckboxHelpers;
184 }
185
186 /**
187 * Sets the claimedByCheckboxHelpers attribute value.
188 * @param claimedByCheckboxHelpers The claimedByCheckboxHelpers to set.
189 */
190 public void setClaimedByCheckboxHelpers(List<ElectronicPaymentClaimClaimedHelper> claimedByCheckboxHelpers) {
191 this.claimedByCheckboxHelpers = claimedByCheckboxHelpers;
192 }
193
194 /**
195 * Sets the claimedHelper at the given index
196 * @param claimedHelper the claimedCheckboxHelper to set
197 * @param index where in the list it belongs
198 */
199 public void setClaimedByCheckboxHelper(ElectronicPaymentClaimClaimedHelper claimedHelper, int index) {
200 while (claimedByCheckboxHelpers.size() <= index) {
201 claimedByCheckboxHelpers.add(new ElectronicPaymentClaimClaimedHelper());
202 }
203 claimedByCheckboxHelpers.set(index, claimedHelper);
204 }
205
206 /**
207 * @param index location in the list of ElectronicPaymentClaimClaimedHelpers to return the helper at
208 * @return the ElectronicPaymentClaimClaimedHelper at the given location
209 */
210 public ElectronicPaymentClaimClaimedHelper getClaimedByCheckboxHelper(int index) {
211 while (claimedByCheckboxHelpers.size() <= index) {
212 claimedByCheckboxHelpers.add(new ElectronicPaymentClaimClaimedHelper());
213 }
214 return claimedByCheckboxHelpers.get(index);
215 }
216 }
217