View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.bc.businessobject.lookup;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Properties;
25  
26  import org.apache.commons.lang.StringUtils;
27  import org.kuali.kfs.module.bc.BCConstants;
28  import org.kuali.kfs.module.bc.BCPropertyConstants;
29  import org.kuali.kfs.module.bc.businessobject.BudgetConstructionPosition;
30  import org.kuali.kfs.module.bc.util.BudgetParameterFinder;
31  import org.kuali.kfs.sys.KFSConstants;
32  import org.kuali.kfs.sys.KFSPropertyConstants;
33  import org.kuali.rice.core.api.config.property.ConfigurationService;
34  import org.kuali.rice.core.web.format.BooleanFormatter;
35  import org.kuali.rice.kns.lookup.HtmlData;
36  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
37  import org.kuali.rice.krad.bo.BusinessObject;
38  import org.kuali.rice.krad.util.KRADConstants;
39  import org.kuali.rice.krad.util.UrlFactory;
40  
41  /**
42   * Lookupable helper service implementation for the position lookup..
43   */
44  public class PositionLookupableHelperServiceImpl extends SelectLookupableHelperServiceImpl {
45      public ConfigurationService kualiConfigurationService;
46  
47      /**
48       * @see org.kuali.rice.kns.lookup.LookupableHelperService#getCustomActionUrls(org.kuali.rice.krad.bo.BusinessObject, java.util.List, java.util.List pkNames)
49       */
50      @Override
51      public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
52          Map requestParameters = super.getParameters();
53          if (requestParameters.containsKey(BCConstants.SHOW_SALARY_BY_POSITION_ACTION)) {
54              String[] requestParm = (String[]) requestParameters.get(BCConstants.SHOW_SALARY_BY_POSITION_ACTION);
55              Boolean showSalaryByPosition = (Boolean) (new BooleanFormatter()).convertFromPresentationFormat(requestParm[0]);
56              if (!showSalaryByPosition) {
57                  return getPositionCustomActionUrls(businessObject, pkNames);
58              }
59          }
60          else {
61              return getPositionCustomActionUrls(businessObject, pkNames);
62          }
63          return getSalarySettingByPositionUrls(businessObject);
64      }
65  
66  
67      /**
68       * Checks system parameter to determine if the position table is maintained by an external system or internally. If internally
69       * they calls super to display the edit and copy links. If external then returns the refresh button source.
70       *
71       * @param businessObject business object for result row
72       * @return String holding the action column contents
73       */
74      private List<HtmlData> getPositionCustomActionUrls(BusinessObject businessObject, List pkNames) {
75          BudgetConstructionPosition position = (BudgetConstructionPosition) businessObject;
76  
77          boolean payrollPositionFeed = BudgetParameterFinder.getPayrollPositionFeedIndicator();
78          if (!payrollPositionFeed) {
79              return super.getCustomActionUrls(businessObject, pkNames);
80          }
81          return super.getEmptyActionUrls();
82      }
83  
84      /***
85       *
86       * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getActionUrlHref(org.kuali.rice.krad.bo.BusinessObject, java.lang.String, java.util.List)
87       */
88      @Override
89      protected String getActionUrlHref(BusinessObject businessObject, String methodToCall, List pkNames){
90          String href = super.getActionUrlHref(businessObject, methodToCall, pkNames);
91          href = StringUtils.replace(href, KFSConstants.MAINTENANCE_ACTION,
92                  KFSConstants.RICE_PATH_PREFIX + KFSConstants.MAINTENANCE_ACTION);
93          return href;
94      }
95  
96      /**
97       * Override to check system parameter for determining if the position data is feed from Payroll or maintained in the KFS.
98       *
99       * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#allowsMaintenanceNewOrCopyAction()
100      */
101     @Override
102     public boolean allowsMaintenanceNewOrCopyAction() {
103         boolean payrollPositionFeed = BudgetParameterFinder.getPayrollPositionFeedIndicator();
104         if (payrollPositionFeed) {
105             return false;
106         }
107 
108         return true;
109     }
110 
111     private Properties getSalarySettingByPositionParameters(BusinessObject businessObject){
112         BudgetConstructionPosition position = (BudgetConstructionPosition) businessObject;
113 
114         Properties parameters = new Properties();
115         parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, BCConstants.POSITION_SALARY_SETTING_METHOD);
116 
117         parameters.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, position.getUniversityFiscalYear().toString());
118         parameters.put(BCPropertyConstants.POSITION_NUMBER, position.getPositionNumber());
119 
120         Map requestParameters = super.getParameters();
121         boolean linkToNewWindow = true;
122         if (requestParameters.containsKey(BCPropertyConstants.ADD_LINE)) {
123             String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.ADD_LINE);
124             parameters.put(BCPropertyConstants.ADD_LINE, requestParm[0]);
125             Boolean addNewFunding = (Boolean) (new BooleanFormatter()).convertFromPresentationFormat(requestParm[0]);
126             if (addNewFunding) {
127                 linkToNewWindow = false;
128             }
129         }
130         else {
131             parameters.put(BCPropertyConstants.ADD_LINE, "false");
132         }
133 
134         if (requestParameters.containsKey(KRADConstants.DOC_FORM_KEY)) {
135             String[] requestParm = (String[]) requestParameters.get(KRADConstants.DOC_FORM_KEY);
136             parameters.put(BCConstants.RETURN_FORM_KEY, requestParm[0]);
137         }
138         else  if (requestParameters.containsKey(KFSConstants.FORM_KEY)) {
139             String[] requestParm = (String[]) requestParameters.get(KFSConstants.FORM_KEY);
140             parameters.put(BCConstants.RETURN_FORM_KEY, requestParm[0]);
141         }
142 
143         if (requestParameters.containsKey(KFSConstants.BACK_LOCATION)) {
144             String[] requestParm = (String[]) requestParameters.get(KFSConstants.BACK_LOCATION);
145             parameters.put(KFSConstants.BACK_LOCATION, requestParm[0]);
146         }
147 
148         if (requestParameters.containsKey(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)) {
149             String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
150             parameters.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, requestParm[0]);
151         }
152 
153         if (requestParameters.containsKey(KFSPropertyConstants.ACCOUNT_NUMBER)) {
154             String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.ACCOUNT_NUMBER);
155             parameters.put(KFSPropertyConstants.ACCOUNT_NUMBER, requestParm[0]);
156         }
157 
158         if (requestParameters.containsKey(KFSPropertyConstants.SUB_ACCOUNT_NUMBER)) {
159             String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
160             parameters.put(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, requestParm[0]);
161         }
162 
163         if (requestParameters.containsKey(KFSPropertyConstants.FINANCIAL_OBJECT_CODE)) {
164             String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
165             parameters.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, requestParm[0]);
166         }
167 
168         if (requestParameters.containsKey(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE)) {
169             String[] requestParm = (String[]) requestParameters.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
170             parameters.put(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE, requestParm[0]);
171         }
172 
173         if (requestParameters.containsKey(BCPropertyConstants.BUDGET_BY_ACCOUNT_MODE)) {
174             String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.BUDGET_BY_ACCOUNT_MODE);
175             parameters.put(BCPropertyConstants.BUDGET_BY_ACCOUNT_MODE, requestParm[0]);
176         }
177 
178         if (requestParameters.containsKey(BCPropertyConstants.MAIN_WINDOW)) {
179             String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.MAIN_WINDOW);
180             parameters.put(BCPropertyConstants.MAIN_WINDOW, requestParm[0]);
181         }
182 
183         if (requestParameters.containsKey(BCPropertyConstants.SINGLE_ACCOUNT_MODE)) {
184             String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.SINGLE_ACCOUNT_MODE);
185             parameters.put(BCPropertyConstants.SINGLE_ACCOUNT_MODE, requestParm[0]);
186         }
187         else {
188             parameters.put(BCPropertyConstants.SINGLE_ACCOUNT_MODE, "false");
189         }
190         parameters.put(BCConstants.REFRESH_POSITION_BEFORE_SALARY_SETTING, "false");
191         return parameters;
192     }
193 
194     /**
195      * Builds URL to salary setting by Position setting parameters based on the caller request.
196      *
197      * @param businessObject business object for result row
198      * @return String holding the action column contents
199      */
200     public List<HtmlData> getSalarySettingByPositionUrls(BusinessObject businessObject) {
201         List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
202 
203         Properties parameters = getSalarySettingByPositionParameters(businessObject);
204         String href = UrlFactory.parameterizeUrl(BCConstants.POSITION_SALARY_SETTING_ACTION, parameters);
205         AnchorHtmlData urlData1 =
206             new AnchorHtmlData(href, BCConstants.POSITION_SALARY_SETTING_METHOD, "Posn Salset");
207 
208         Map requestParameters = super.getParameters();
209 
210         boolean linkToNewWindow = true;
211         if (requestParameters.containsKey(BCPropertyConstants.ADD_LINE)) {
212             String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.ADD_LINE);
213             Boolean addNewFunding = (Boolean) (new BooleanFormatter()).convertFromPresentationFormat(requestParm[0]);
214             if (addNewFunding) {
215                 linkToNewWindow = false;
216             }
217         }
218         if (linkToNewWindow) {
219             urlData1.setTarget(BCConstants.SECOND_WINDOW_TARGET_NAME);
220         }
221 
222         anchorHtmlDataList.add(urlData1);
223 
224         // now add refresh url if feed from payroll is on
225         boolean payrollPositionFeed = BudgetParameterFinder.getPayrollPositionFeedIndicator();
226         String url2 = "";
227         if (payrollPositionFeed) {
228             parameters.put(BCConstants.REFRESH_POSITION_BEFORE_SALARY_SETTING, "true");
229             href = UrlFactory.parameterizeUrl(BCConstants.POSITION_SALARY_SETTING_ACTION, parameters);
230             AnchorHtmlData urlData2 =
231                 new AnchorHtmlData(href, BCConstants.POSITION_SALARY_SETTING_METHOD, "Posn Salset w/sync");
232 
233             if (linkToNewWindow) {
234                 urlData2.setTarget(KFSConstants.NEW_WINDOW_URL_TARGET);
235             }
236 
237             anchorHtmlDataList.add(urlData2);
238             anchorHtmlDataList.get(anchorHtmlDataList.lastIndexOf(urlData2)).setPrependDisplayText("<br />");
239         }
240 
241         return anchorHtmlDataList;
242     }
243 
244     /**
245      * Sets the kualiConfigurationService attribute value.
246      *
247      * @param kualiConfigurationService The kualiConfigurationService to set.
248      */
249     public void setConfigurationService(ConfigurationService kualiConfigurationService) {
250         this.kualiConfigurationService = kualiConfigurationService;
251     }
252 
253 }