001/*
002 * Copyright 2008 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 */
016package org.kuali.ole.sys.service.impl;
017
018import java.util.Map;
019import java.util.Properties;
020
021import org.apache.struts.action.ActionForward;
022import org.apache.struts.action.ActionMapping;
023import org.kuali.ole.sys.businessobject.ElectronicPaymentClaim;
024import org.kuali.ole.sys.service.ElectronicFundTransferActionHelper;
025import org.kuali.ole.sys.service.ElectronicPaymentClaimingService;
026import org.kuali.ole.sys.web.struts.ElectronicFundTransferForm;
027import org.kuali.rice.krad.util.KRADConstants;
028import org.kuali.rice.krad.util.UrlFactory;
029
030/**
031 * An action for Electronic Fund Transfer that simply redirects to either the claiming or non-claiming lookup.
032 */
033public class ElectronicFundTransferStartActionHelper implements ElectronicFundTransferActionHelper {
034    private ElectronicPaymentClaimingService electronicPaymentClaimingService;
035
036    /**
037     * @see org.kuali.ole.sys.service.ElectronicFundTransferActionHelper#performAction(org.kuali.ole.sys.web.struts.ElectronicFundTransferForm, org.apache.struts.action.ActionMapping, java.util.Map)
038     */
039    public ActionForward performAction(ElectronicFundTransferForm form, ActionMapping mapping, Map parameterMap, String basePath) {
040        return new ActionForward((form.hasAvailableClaimingDocumentStrategies() ? getClaimingLookupUrl(form, basePath) : getNonClaimingLookupUrl(form, basePath) ), true);
041    }
042    
043    /**
044     * @return URL for non-claiming EFT search
045     */
046    protected String getNonClaimingLookupUrl(ElectronicFundTransferForm form, String basePath) {        
047        Properties props = getCommonLookupProperties(form);
048        props.put(KRADConstants.HIDE_LOOKUP_RETURN_LINK, Boolean.toString(true));
049        props.put(KRADConstants.RETURN_LOCATION_PARAMETER, basePath + "/" + getNonClaimingReturnLocation());
050        props.put(KRADConstants.BACK_LOCATION, basePath + "/" + getNonClaimingReturnLocation());
051        return UrlFactory.parameterizeUrl(basePath + "/kr/" + KRADConstants.LOOKUP_ACTION, props);
052    }
053    
054    /**
055     * @return URL for claiming EFT search
056     */
057    protected String getClaimingLookupUrl(ElectronicFundTransferForm form, String basePath) {
058        Properties props = getCommonLookupProperties(form);
059        props.put(KRADConstants.MULTIPLE_VALUE, Boolean.toString(true));
060        props.put(KRADConstants.LOOKUP_ANCHOR, KRADConstants.ANCHOR_TOP_OF_FORM);
061        props.put(KRADConstants.LOOKED_UP_COLLECTION_NAME, "claims");
062        props.put(KRADConstants.RETURN_LOCATION_PARAMETER, basePath + "/" + getClaimingReturnLocation());
063        props.put(KRADConstants.BACK_LOCATION, basePath + "/" + getClaimingReturnLocation());
064        return UrlFactory.parameterizeUrl(basePath + "/kr/" + KRADConstants.MULTIPLE_VALUE_LOOKUP_ACTION, props);
065    }
066    
067    /**
068     * @return a set of Properties common to both claiming and non-claiming lookup
069     */
070    protected Properties getCommonLookupProperties(ElectronicFundTransferForm form) {
071        Properties props = new Properties();
072        props.put(KRADConstants.SUPPRESS_ACTIONS, Boolean.toString(true));
073        props.put(KRADConstants.DOC_FORM_KEY, "88888888");
074        props.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, ElectronicPaymentClaim.class.getName());
075        props.put(KRADConstants.METHOD_TO_CALL_ATTRIBUTE, "start");
076        return props;
077    }
078    
079    /**
080     * @return the location where the search should return to for claiming
081     */
082    protected String getClaimingReturnLocation() {
083        return "electronicFundTransfer.do";
084    }
085    
086    /**
087     * @return the location where the search should return to for non-claiming - ie, the portal!
088     */
089    protected String getNonClaimingReturnLocation() {
090        return "portal.do";
091    }
092    
093    /**
094     * Sets the electronicPaymentClaimingService attribute value.
095     * @param electronicPaymentClaimingService The electronicPaymentClaimingService to set.
096     */
097    public void setElectronicPaymentClaimingService(ElectronicPaymentClaimingService electronicPaymentClaimingService) {
098        this.electronicPaymentClaimingService = electronicPaymentClaimingService;
099    }
100    
101}
102