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.module.bc.util; 017 018 import java.util.HashMap; 019 import java.util.Map; 020 import java.util.Properties; 021 022 import org.apache.commons.lang.StringUtils; 023 import org.apache.struts.action.ActionMapping; 024 import org.kuali.kfs.module.bc.BCConstants; 025 import org.kuali.kfs.module.bc.document.web.struts.BudgetExpansionForm; 026 import org.kuali.kfs.sys.KFSConstants; 027 import org.kuali.kfs.sys.KFSPropertyConstants; 028 import org.kuali.kfs.sys.context.SpringContext; 029 import org.kuali.rice.kns.service.KualiConfigurationService; 030 import org.kuali.rice.kns.util.GlobalVariables; 031 import org.kuali.rice.kns.util.KNSConstants; 032 import org.kuali.rice.kns.util.UrlFactory; 033 import org.kuali.rice.kns.web.struts.form.KualiForm; 034 035 /** 036 * Provides helper methods for building URLs to various budget actions. 037 */ 038 public class BudgetUrlUtil { 039 040 /** 041 * Builds url for temp list action. 042 * 043 * @param mapping struts action mapping 044 * @param form BudgetExpansionForm 045 * @param tempListMode mode for temp list action 046 * @param tempListLookupClass class name to lookup 047 * @param additionalParameters appended to the url or replace default 048 * @return string url 049 */ 050 public static String buildTempListLookupUrl(ActionMapping mapping, BudgetExpansionForm form, Integer tempListMode, String tempListLookupClass, Map<String, String> additionalParameters) { 051 Map<String, String> parameters = new HashMap<String, String>(); 052 053 parameters.put(KNSConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObject(form, BCConstants.FORMKEY_PREFIX)); 054 parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, tempListLookupClass); 055 parameters.put(KFSConstants.HIDE_LOOKUP_RETURN_LINK, "true"); 056 parameters.put(KFSConstants.SUPPRESS_ACTIONS, "false"); 057 parameters.put(BCConstants.SHOW_INITIAL_RESULTS, "true"); 058 parameters.put(BCConstants.TempListLookupMode.TEMP_LIST_LOOKUP_MODE, Integer.toString(tempListMode)); 059 060 if (additionalParameters != null) { 061 for (String parameterKey : additionalParameters.keySet()) { 062 parameters.put(parameterKey, additionalParameters.get(parameterKey)); 063 } 064 } 065 066 return buildBudgetUrl(mapping, form, BCConstants.ORG_TEMP_LIST_LOOKUP, parameters); 067 } 068 069 /** 070 * Builds a budget URL setting default parameters. 071 * 072 * @param mapping struts action mapping 073 * @param form BudgetExpansionForm 074 * @param actionPath url path for requested action 075 * @param additionalParameters appended to the url or replace default 076 * @return string url 077 */ 078 public static String buildBudgetUrl(ActionMapping mapping, BudgetExpansionForm form, String actionPath, Map<String, String> additionalParameters) { 079 Properties parameters = new Properties(); 080 parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.START_METHOD); 081 parameters.put(BCConstants.RETURN_FORM_KEY, GlobalVariables.getUserSession().addObject(form, BCConstants.FORMKEY_PREFIX)); 082 083 String basePath = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSConstants.APPLICATION_URL_KEY); 084 parameters.put(KFSConstants.BACK_LOCATION, basePath + mapping.getPath() + ".do"); 085 parameters.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, form.getUniversityFiscalYear().toString()); 086 parameters.put(KFSPropertyConstants.KUALI_USER_PERSON_UNIVERSAL_IDENTIFIER, GlobalVariables.getUserSession().getPerson().getPrincipalId()); 087 088 if (StringUtils.isNotEmpty(((KualiForm) form).getAnchor())) { 089 parameters.put(BCConstants.RETURN_ANCHOR, ((KualiForm) form).getAnchor()); 090 } 091 092 if (additionalParameters != null) { 093 for (String parameterKey : additionalParameters.keySet()) { 094 parameters.put(parameterKey, additionalParameters.get(parameterKey)); 095 } 096 } 097 098 return UrlFactory.parameterizeUrl(basePath + "/" + actionPath, parameters); 099 } 100 } 101