View Javadoc
1   /*
2    * Copyright 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.sys.service.impl;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.apache.struts.action.ActionForward;
25  import org.apache.struts.action.ActionMapping;
26  import org.kuali.ole.sys.businessobject.ElectronicPaymentClaim;
27  import org.kuali.ole.sys.service.ElectronicFundTransferActionHelper;
28  import org.kuali.ole.sys.service.ElectronicPaymentClaimingService;
29  import org.kuali.ole.sys.web.struts.ElectronicFundTransferForm;
30  import org.kuali.rice.kim.api.identity.Person;
31  import org.kuali.rice.kns.lookup.LookupResultsService;
32  import org.kuali.rice.kns.service.DataDictionaryService;
33  import org.kuali.rice.krad.exception.AuthorizationException;
34  import org.kuali.rice.krad.util.GlobalVariables;
35  
36  /**
37   * Represents a web action that occurs when a user returns a bunch of selected claims and redirects to the electronic funds transfer "claimng" page
38   */
39  public class ElectronicFundTransferRefreshActionHelper implements ElectronicFundTransferActionHelper {
40      private ElectronicPaymentClaimingService electronicPaymentClaimingService;
41      private DataDictionaryService ddService;
42      protected LookupResultsService lookupResultsService;
43      
44      protected static final String BASIC_FORWARD = "basic";
45      protected static final String ACTION_NAME = "claim";
46      protected static final String PORTAL_FORWARD = "portal";
47  
48      /**
49       * @see org.kuali.ole.sys.service.ElectronicFundTransferActionHelper#performAction(org.kuali.rice.kns.web.struts.form.KualiForm, org.apache.struts.action.ActionMapping)
50       */
51      public ActionForward performAction(ElectronicFundTransferForm form, ActionMapping mapping, Map params, String basePath) {
52          // is the current user able to claim electronic funds?
53          Person currentUser = GlobalVariables.getUserSession().getPerson();
54          if (!form.hasAvailableClaimingDocumentStrategies()) {
55              throw new AuthorizationException(currentUser.getPrincipalName(), ElectronicFundTransferRefreshActionHelper.ACTION_NAME, ddService.getDataDictionary().getBusinessObjectEntry(ElectronicPaymentClaim.class.getName()).getObjectLabel());
56          }
57          // does the current user have claimed funds waiting for them?
58          String lookupResultsSequenceNumber = null;
59          if (params.get("lookupResultsSequenceNumber") != null) {
60              lookupResultsSequenceNumber = ((String[])params.get("lookupResultsSequenceNumber"))[0];
61          }
62          if (StringUtils.isBlank(lookupResultsSequenceNumber)) {
63              return mapping.findForward(PORTAL_FORWARD);
64          }
65          List<ElectronicPaymentClaim> claims = getClaimedPayments(currentUser, lookupResultsSequenceNumber);
66          if (claims.size() == 0) {
67              return mapping.findForward(PORTAL_FORWARD);
68          }
69          // if so, load their currently claimed electronic funds to the form
70          form.setClaims(claims);
71          // and redirect
72          return mapping.findForward(BASIC_FORWARD);
73      }
74      
75      /**
76       * Gets the selected electronic payment claim records from the LookupResults service
77       * @param currentUser the claiming user
78       * @param lookupResultsSequenceNumber the parameter for the lookup results sequence number
79       * @return a list of claims
80       */
81      protected List<ElectronicPaymentClaim> getClaimedPayments(Person currentUser, String lookupResultsSequenceNumber) {
82          List<ElectronicPaymentClaim> claims = new ArrayList<ElectronicPaymentClaim>();
83          try {
84              Collection selectedClaims = lookupResultsService.retrieveSelectedResultBOs(lookupResultsSequenceNumber, ElectronicPaymentClaim.class, currentUser.getPrincipalId());
85              for (Object claimAsObj : selectedClaims) {
86                  ElectronicPaymentClaim claim = (ElectronicPaymentClaim) claimAsObj;
87                  if (!claim.getPaymentClaimStatusCode().equals(ElectronicPaymentClaim.ClaimStatusCodes.CLAIMED) && StringUtils.isBlank(claim.getReferenceFinancialDocumentNumber())) {
88                      claims.add(claim);
89                  }
90              }
91          }
92          catch (Exception e) {
93              throw new RuntimeException(e);
94          }        
95          return claims;
96      }
97      
98      /**
99       * Sets the electronicPaymentClaimingService attribute value.
100      * @param electronicPaymentClaimingService The electronicPaymentClaimingService to set.
101      */
102     public void setElectronicPaymentClaimingService(ElectronicPaymentClaimingService electronicPaymentClaimingService) {
103         this.electronicPaymentClaimingService = electronicPaymentClaimingService;
104     }
105     
106     /**
107      * Sets the ddService attribute value.
108      * @param ddService The ddService to set.
109      */
110     public void setDataDictonaryService(DataDictionaryService ddService) {
111         this.ddService = ddService;
112     }
113 
114     /**
115      * Sets the lookupResultsService attribute value.
116      * @param lookupResultsService The lookupResultsService to set.
117      */
118     public void setLookupResultsService(LookupResultsService lookupResultsService) {
119         this.lookupResultsService = lookupResultsService;
120     }
121     
122     
123 }
124