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.coa.businessobject.lookup;
017    
018    import java.util.List;
019    import java.util.Map;
020    import java.util.Properties;
021    
022    import org.kuali.kfs.coa.businessobject.AccountDelegateGlobal;
023    import org.kuali.kfs.sys.KFSConstants;
024    import org.kuali.rice.kns.authorization.BusinessObjectRestrictions;
025    import org.kuali.rice.kns.bo.BusinessObject;
026    import org.kuali.rice.kns.lookup.HtmlData;
027    import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
028    import org.kuali.rice.kns.util.UrlFactory;
029    import org.kuali.rice.kns.web.struts.form.LookupForm;
030    
031    /**
032     * This class overrides the getBackLocation, getReturnUrl, setFieldConversions and getActionUrls for
033     * {@link OrganizationRoutingModelName}
034     */
035    public class OrganizationRoutingModelNameLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
036        private boolean initializingDelegate = true;
037    
038        /**
039         * Overrides the base implementation to always return to {@link KFSConstants.MAINTENANCE_ACTION}
040         *
041         * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getBackLocation()
042         */
043        @Override
044        public String getBackLocation() {
045            // it doesn't really matter what the backLocation is set to; we're
046            // always going to return to the maintenance screen
047            return KFSConstants.MAINTENANCE_ACTION;
048        }
049    
050        /**
051         * Overrides the base implementation to add in new parameters to the return url
052         * <ul>
053         * <li>{@link KFSConstants.DISPATCH_REQUEST_PARAMETER}</li>
054         * <li>{@link KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE}</li>
055         * <li>{@link KFSConstants.OVERRIDE_KEYS}</li>
056         * </ul>
057         * {@link KFSConstants.DISPATCH_REQUEST_PARAMETER}
058         *
059         * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getReturnUrl(org.kuali.rice.kns.bo.BusinessObject, java.util.Map,
060         *      java.lang.String)
061         */
062        @Override
063        public HtmlData getReturnUrl(BusinessObject businessObject, LookupForm lookupForm, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions) {
064            Properties parameters = getParameters(businessObject, lookupForm.getFieldConversions(), lookupForm.getLookupableImplServiceName(), returnKeys);
065            parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.MAINTENANCE_NEWWITHEXISTING_ACTION);
066            parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, AccountDelegateGlobal.class.getName());
067            parameters.put(KFSConstants.OVERRIDE_KEYS, "modelName" + KFSConstants.FIELD_CONVERSIONS_SEPERATOR + "modelChartOfAccountsCode" + KFSConstants.FIELD_CONVERSIONS_SEPERATOR + "modelOrganizationCode");
068            setBackLocation(KFSConstants.MAINTENANCE_ACTION);
069            return getReturnAnchorHtmlData(businessObject, parameters, lookupForm, returnKeys, businessObjectRestrictions);
070        }
071    
072        /**
073         * Overrides base implementation to determine whether or not we are dealing with looking up the model or editing it
074         *
075         * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#setFieldConversions(java.util.Map)
076         */
077        @Override
078        public void setFieldConversions(Map fieldConversions) {
079            super.setFieldConversions(fieldConversions);
080            if (fieldConversions == null || fieldConversions.size() == 0) {
081                // if we don't have any field conversions, then we must be
082                // actually dealing with the model, instead of looking up the model
083                // in order to initalize a new global account delegate
084                //
085                // yeah, it's a hack...but at least a semi-clever hack
086                initializingDelegate = false;
087            }
088        }
089    
090        /**
091         * Overrides base implementation to remove the action urls if we are initializing the delegate model
092         *
093         * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, java.util.List)
094         */
095        @Override
096        public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
097            if (!initializingDelegate) {
098                return super.getCustomActionUrls(businessObject, pkNames);
099            }
100            else {
101                return super.getEmptyActionUrls();
102            }
103        }
104    }