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.document.web.struts;
017
018 import java.math.BigDecimal;
019 import java.util.List;
020 import java.util.Map;
021
022 import javax.servlet.http.HttpServletRequest;
023 import javax.servlet.http.HttpServletResponse;
024
025 import org.apache.struts.action.ActionForm;
026 import org.apache.struts.action.ActionForward;
027 import org.apache.struts.action.ActionMapping;
028 import org.kuali.kfs.module.bc.BCConstants;
029 import org.kuali.kfs.module.bc.BCKeyConstants;
030 import org.kuali.kfs.module.bc.BCPropertyConstants;
031 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionIntendedIncumbent;
032 import org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding;
033 import org.kuali.kfs.module.bc.service.BudgetConstructionIntendedIncumbentService;
034 import org.kuali.kfs.sys.KFSConstants;
035 import org.kuali.kfs.sys.KFSPropertyConstants;
036 import org.kuali.kfs.sys.context.SpringContext;
037 import org.kuali.rice.kns.service.BusinessObjectService;
038 import org.kuali.rice.kns.util.GlobalVariables;
039 import org.kuali.rice.kns.util.MessageList;
040 import org.kuali.rice.kns.util.MessageMap;
041
042 /**
043 * the struts action for the salary setting for incumbent
044 */
045 public class IncumbentSalarySettingAction extends DetailSalarySettingAction {
046 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(IncumbentSalarySettingAction.class);
047
048 private BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
049 private BudgetConstructionIntendedIncumbentService budgetConstructionIntendedIncumbentService = SpringContext.getBean(BudgetConstructionIntendedIncumbentService.class);
050
051 /**
052 * @see org.kuali.kfs.module.bc.document.web.struts.SalarySettingBaseAction#loadExpansionScreen(org.apache.struts.action.ActionMapping,
053 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
054 */
055 @Override
056 public ActionForward loadExpansionScreen(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
057 IncumbentSalarySettingForm incumbentSalarySettingForm = (IncumbentSalarySettingForm) form;
058 MessageMap errorMap;
059 if (incumbentSalarySettingForm.isBudgetByAccountMode()){
060 errorMap = incumbentSalarySettingForm.getCallBackErrors();
061 }
062 else {
063 errorMap = GlobalVariables.getMessageMap();
064 }
065
066 // update incumbent record if required
067 if (incumbentSalarySettingForm.isRefreshIncumbentBeforeSalarySetting()) {
068 budgetConstructionIntendedIncumbentService.refreshIncumbentFromExternal(incumbentSalarySettingForm.getEmplid());
069 }
070
071 // use the passed url parms to get the record from DB
072 Map<String, Object> fieldValues = incumbentSalarySettingForm.getKeyMapOfSalarySettingItem();
073 BudgetConstructionIntendedIncumbent budgetConstructionIntendedIncumbent = (BudgetConstructionIntendedIncumbent) businessObjectService.findByPrimaryKey(BudgetConstructionIntendedIncumbent.class, fieldValues);
074
075 if (budgetConstructionIntendedIncumbent == null) {
076 String emplid = (String) fieldValues.get(KFSPropertyConstants.EMPLID);
077
078 errorMap.putError(KFSConstants.GLOBAL_MESSAGES, BCKeyConstants.ERROR_INCUMBENT_NOT_FOUND, emplid);
079 if (incumbentSalarySettingForm.isBudgetByAccountMode()){
080 return this.returnToCaller(mapping, form, request, response);
081 }
082 else {
083 this.cleanupAnySessionForm(mapping, request);
084 return mapping.findForward(BCConstants.MAPPING_ORGANIZATION_SALARY_SETTING_RETURNING);
085 }
086 }
087
088 incumbentSalarySettingForm.setBudgetConstructionIntendedIncumbent(budgetConstructionIntendedIncumbent);
089 if (incumbentSalarySettingForm.isSingleAccountMode()) {
090 incumbentSalarySettingForm.pickAppointmentFundingsForSingleAccount();
091 }
092
093 // acquire position and funding locks for the associated funding lines
094 if (!incumbentSalarySettingForm.isViewOnlyEntry()) {
095 incumbentSalarySettingForm.postProcessBCAFLines();
096 incumbentSalarySettingForm.setNewBCAFLine(incumbentSalarySettingForm.createNewAppointmentFundingLine());
097
098 boolean accessModeUpdated = incumbentSalarySettingForm.updateAccessMode(errorMap);
099 if (!accessModeUpdated) {
100 if (incumbentSalarySettingForm.isBudgetByAccountMode()){
101 return this.returnToCaller(mapping, form, request, response);
102 }
103 else {
104 this.cleanupAnySessionForm(mapping, request);
105 return mapping.findForward(BCConstants.MAPPING_ORGANIZATION_SALARY_SETTING_RETURNING);
106 }
107 }
108
109 boolean gotLocks = incumbentSalarySettingForm.acquirePositionAndFundingLocks(errorMap);
110 if (!gotLocks) {
111 if (incumbentSalarySettingForm.isBudgetByAccountMode()){
112 return this.returnToCaller(mapping, form, request, response);
113 }
114 else {
115 this.cleanupAnySessionForm(mapping, request);
116 return mapping.findForward(BCConstants.MAPPING_ORGANIZATION_SALARY_SETTING_RETURNING);
117 }
118 }
119 }
120
121 return mapping.findForward(KFSConstants.MAPPING_BASIC);
122 }
123
124 /**
125 * @see org.kuali.kfs.module.bc.document.web.struts.DetailSalarySettingAction#save(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
126 */
127 @Override
128 public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
129
130 ActionForward saveAction = super.save(mapping, form, request, response);
131
132 IncumbentSalarySettingForm incumbentSalarySettingForm = (IncumbentSalarySettingForm) form;
133 this.sendWarnings(incumbentSalarySettingForm, GlobalVariables.getMessageList());
134
135 return saveAction;
136 }
137
138 /**
139 * send warning messsages back to the caller
140 *
141 * @param incumbentSalarySettingForm
142 * @param warnings
143 */
144 public void sendWarnings(IncumbentSalarySettingForm incumbentSalarySettingForm, MessageList warnings){
145 List<PendingBudgetConstructionAppointmentFunding> activeAppointmentFundings = incumbentSalarySettingForm.getActiveFundingLines();
146 if (activeAppointmentFundings == null || activeAppointmentFundings.isEmpty()) {
147 return;
148 }
149 BigDecimal requestedFteQuantityTotal = incumbentSalarySettingForm.getAppointmentRequestedFteQuantityTotal();
150
151 // check for an active line that is LWPA or LWPF
152 boolean hasFundingLineInvolvedLeaveWithoutPay = this.hasFundingLineInvolvedLeaveWithoutPay(activeAppointmentFundings);
153
154 if (!hasFundingLineInvolvedLeaveWithoutPay && requestedFteQuantityTotal.compareTo(BigDecimal.ONE) != 0) {
155 warnings.add(BCKeyConstants.WARNING_FTE_NOT_ONE);
156 }
157
158 }
159
160 /**
161 * @see org.kuali.kfs.module.bc.document.web.struts.SalarySettingBaseAction#getFundingAwareObjectName()
162 */
163 @Override
164 protected String getFundingAwareObjectName() {
165 return BCPropertyConstants.BUDGET_CONSTRUCTION_INTENDED_INCUMBENT;
166 }
167 }