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.businessobject.lookup;
017
018 import java.util.ArrayList;
019 import java.util.Iterator;
020 import java.util.List;
021 import java.util.Map;
022 import java.util.Properties;
023
024 import org.apache.commons.lang.StringUtils;
025 import org.kuali.kfs.module.bc.BCConstants;
026 import org.kuali.kfs.module.bc.BCPropertyConstants;
027 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionPosition;
028 import org.kuali.kfs.module.bc.util.BudgetParameterFinder;
029 import org.kuali.kfs.sys.KFSConstants;
030 import org.kuali.kfs.sys.KFSPropertyConstants;
031 import org.kuali.rice.kns.bo.BusinessObject;
032 import org.kuali.rice.kns.lookup.HtmlData;
033 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
034 import org.kuali.rice.kns.service.KualiConfigurationService;
035 import org.kuali.rice.kns.util.KNSConstants;
036 import org.kuali.rice.kns.util.UrlFactory;
037 import org.kuali.rice.kns.web.format.BooleanFormatter;
038
039 /**
040 * Lookupable helper service implementation for the position lookup..
041 */
042 public class PositionLookupableHelperServiceImpl extends SelectLookupableHelperServiceImpl {
043 public KualiConfigurationService kualiConfigurationService;
044
045 /**
046 * @see org.kuali.rice.kns.lookup.LookupableHelperService#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, java.util.List, java.util.List pkNames)
047 */
048 @Override
049 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
050 Map requestParameters = super.getParameters();
051 if (requestParameters.containsKey(BCConstants.SHOW_SALARY_BY_POSITION_ACTION)) {
052 String[] requestParm = (String[]) requestParameters.get(BCConstants.SHOW_SALARY_BY_POSITION_ACTION);
053 Boolean showSalaryByPosition = (Boolean) (new BooleanFormatter()).convertFromPresentationFormat(requestParm[0]);
054 if (!showSalaryByPosition) {
055 return getPositionCustomActionUrls(businessObject, pkNames);
056 }
057 }
058 else {
059 return getPositionCustomActionUrls(businessObject, pkNames);
060 }
061 return getSalarySettingByPositionUrls(businessObject);
062 }
063
064
065 /**
066 * Checks system parameter to determine if the position table is maintained by an external system or internally. If internally
067 * they calls super to display the edit and copy links. If external then returns the refresh button source.
068 *
069 * @param businessObject business object for result row
070 * @return String holding the action column contents
071 */
072 private List<HtmlData> getPositionCustomActionUrls(BusinessObject businessObject, List pkNames) {
073 BudgetConstructionPosition position = (BudgetConstructionPosition) businessObject;
074
075 boolean payrollPositionFeed = BudgetParameterFinder.getPayrollPositionFeedIndicator();
076 if (!payrollPositionFeed) {
077 return super.getCustomActionUrls(businessObject, pkNames);
078 }
079 return super.getEmptyActionUrls();
080 }
081
082 /***
083 *
084 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getActionUrlHref(org.kuali.rice.kns.bo.BusinessObject, java.lang.String, java.util.List)
085 */
086 @Override
087 protected String getActionUrlHref(BusinessObject businessObject, String methodToCall, List pkNames){
088 String href = super.getActionUrlHref(businessObject, methodToCall, pkNames);
089 href = StringUtils.replace(href, KFSConstants.MAINTENANCE_ACTION,
090 KFSConstants.RICE_PATH_PREFIX + KFSConstants.MAINTENANCE_ACTION);
091 return href;
092 }
093
094 /**
095 * Override to check system parameter for determining if the position data is feed from Payroll or maintained in the KFS.
096 *
097 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#allowsMaintenanceNewOrCopyAction()
098 */
099 @Override
100 public boolean allowsMaintenanceNewOrCopyAction() {
101 boolean payrollPositionFeed = BudgetParameterFinder.getPayrollPositionFeedIndicator();
102 if (payrollPositionFeed) {
103 return false;
104 }
105
106 return true;
107 }
108
109 private Properties getSalarySettingByPositionParameters(BusinessObject businessObject){
110 BudgetConstructionPosition position = (BudgetConstructionPosition) businessObject;
111
112 Properties parameters = new Properties();
113 parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, BCConstants.POSITION_SALARY_SETTING_METHOD);
114
115 parameters.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, position.getUniversityFiscalYear().toString());
116 parameters.put(BCPropertyConstants.POSITION_NUMBER, position.getPositionNumber());
117
118 Map requestParameters = super.getParameters();
119 boolean linkToNewWindow = true;
120 if (requestParameters.containsKey(BCPropertyConstants.ADD_LINE)) {
121 String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.ADD_LINE);
122 parameters.put(BCPropertyConstants.ADD_LINE, requestParm[0]);
123 Boolean addNewFunding = (Boolean) (new BooleanFormatter()).convertFromPresentationFormat(requestParm[0]);
124 if (addNewFunding) {
125 linkToNewWindow = false;
126 }
127 }
128 else {
129 parameters.put(BCPropertyConstants.ADD_LINE, "false");
130 }
131
132 if (requestParameters.containsKey(KNSConstants.DOC_FORM_KEY)) {
133 String[] requestParm = (String[]) requestParameters.get(KNSConstants.DOC_FORM_KEY);
134 parameters.put(BCConstants.RETURN_FORM_KEY, requestParm[0]);
135 }
136 else if (requestParameters.containsKey(KFSConstants.FORM_KEY)) {
137 String[] requestParm = (String[]) requestParameters.get(KFSConstants.FORM_KEY);
138 parameters.put(BCConstants.RETURN_FORM_KEY, requestParm[0]);
139 }
140
141 if (requestParameters.containsKey(KFSConstants.BACK_LOCATION)) {
142 String[] requestParm = (String[]) requestParameters.get(KFSConstants.BACK_LOCATION);
143 parameters.put(KFSConstants.BACK_LOCATION, requestParm[0]);
144 }
145
146 if (requestParameters.containsKey(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)) {
147 String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
148 parameters.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, requestParm[0]);
149 }
150
151 if (requestParameters.containsKey(KFSPropertyConstants.ACCOUNT_NUMBER)) {
152 String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.ACCOUNT_NUMBER);
153 parameters.put(KFSPropertyConstants.ACCOUNT_NUMBER, requestParm[0]);
154 }
155
156 if (requestParameters.containsKey(KFSPropertyConstants.SUB_ACCOUNT_NUMBER)) {
157 String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
158 parameters.put(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, requestParm[0]);
159 }
160
161 if (requestParameters.containsKey(KFSPropertyConstants.FINANCIAL_OBJECT_CODE)) {
162 String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
163 parameters.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, requestParm[0]);
164 }
165
166 if (requestParameters.containsKey(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE)) {
167 String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
168 parameters.put(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE, requestParm[0]);
169 }
170
171 if (requestParameters.containsKey(BCPropertyConstants.BUDGET_BY_ACCOUNT_MODE)) {
172 String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.BUDGET_BY_ACCOUNT_MODE);
173 parameters.put(BCPropertyConstants.BUDGET_BY_ACCOUNT_MODE, requestParm[0]);
174 }
175
176 if (requestParameters.containsKey(BCPropertyConstants.MAIN_WINDOW)) {
177 String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.MAIN_WINDOW);
178 parameters.put(BCPropertyConstants.MAIN_WINDOW, requestParm[0]);
179 }
180
181 if (requestParameters.containsKey(BCPropertyConstants.SINGLE_ACCOUNT_MODE)) {
182 String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.SINGLE_ACCOUNT_MODE);
183 parameters.put(BCPropertyConstants.SINGLE_ACCOUNT_MODE, requestParm[0]);
184 }
185 else {
186 parameters.put(BCPropertyConstants.SINGLE_ACCOUNT_MODE, "false");
187 }
188 parameters.put(BCConstants.REFRESH_POSITION_BEFORE_SALARY_SETTING, "false");
189 return parameters;
190 }
191
192 /**
193 * Builds URL to salary setting by Position setting parameters based on the caller request.
194 *
195 * @param businessObject business object for result row
196 * @return String holding the action column contents
197 */
198 public List<HtmlData> getSalarySettingByPositionUrls(BusinessObject businessObject) {
199 List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
200
201 Properties parameters = getSalarySettingByPositionParameters(businessObject);
202 String href = UrlFactory.parameterizeUrl(BCConstants.POSITION_SALARY_SETTING_ACTION, parameters);
203 AnchorHtmlData urlData1 =
204 new AnchorHtmlData(href, BCConstants.POSITION_SALARY_SETTING_METHOD, "Posn Salset");
205
206 Map requestParameters = super.getParameters();
207
208 boolean linkToNewWindow = true;
209 if (requestParameters.containsKey(BCPropertyConstants.ADD_LINE)) {
210 String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.ADD_LINE);
211 Boolean addNewFunding = (Boolean) (new BooleanFormatter()).convertFromPresentationFormat(requestParm[0]);
212 if (addNewFunding) {
213 linkToNewWindow = false;
214 }
215 }
216 if (linkToNewWindow) {
217 urlData1.setTarget(KFSConstants.NEW_WINDOW_URL_TARGET);
218 }
219
220 anchorHtmlDataList.add(urlData1);
221
222 // now add refresh url if feed from payroll is on
223 boolean payrollPositionFeed = BudgetParameterFinder.getPayrollPositionFeedIndicator();
224 String url2 = "";
225 if (payrollPositionFeed) {
226 parameters.put(BCConstants.REFRESH_POSITION_BEFORE_SALARY_SETTING, "true");
227 href = UrlFactory.parameterizeUrl(BCConstants.POSITION_SALARY_SETTING_ACTION, parameters);
228 AnchorHtmlData urlData2 =
229 new AnchorHtmlData(href, BCConstants.POSITION_SALARY_SETTING_METHOD, "Posn Salset w/sync");
230
231 if (linkToNewWindow) {
232 urlData2.setTarget(KFSConstants.NEW_WINDOW_URL_TARGET);
233 }
234
235 anchorHtmlDataList.add(urlData2);
236 anchorHtmlDataList.get(anchorHtmlDataList.lastIndexOf(urlData2)).setPrependDisplayText("<br />");
237 }
238
239 return anchorHtmlDataList;
240 }
241
242 /**
243 * Sets the kualiConfigurationService attribute value.
244 *
245 * @param kualiConfigurationService The kualiConfigurationService to set.
246 */
247 public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) {
248 this.kualiConfigurationService = kualiConfigurationService;
249 }
250
251 }