View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.tklm.leave.adjustment.web;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.joda.time.LocalDate;
20  import org.kuali.kpme.core.api.principal.PrincipalHRAttributes;
21  import org.kuali.kpme.core.bo.HrBusinessObject;
22  import org.kuali.kpme.core.bo.HrBusinessObjectMaintainableImpl;
23  import org.kuali.kpme.core.service.HrServiceLocator;
24  import org.kuali.kpme.core.util.HrConstants;
25  import org.kuali.kpme.core.util.HrContext;
26  import org.kuali.kpme.core.util.TKUtils;
27  import org.kuali.kpme.tklm.common.LMConstants;
28  import org.kuali.kpme.tklm.leave.adjustment.LeaveAdjustment;
29  import org.kuali.kpme.tklm.leave.block.LeaveBlockBo;
30  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
31  import org.kuali.rice.kns.document.MaintenanceDocument;
32  
33  import java.util.Map;
34  
35  public class LeaveAdjustmentMaintainableServiceImpl extends HrBusinessObjectMaintainableImpl{
36  
37  	private static final long serialVersionUID = 2500485054776792764L;
38  
39  	@Override
40  	public HrBusinessObject getObjectById(String id) {
41  		// TODO Auto-generated method stub
42  		return null;
43  	}
44  	
45  	@Override
46  	public void saveBusinessObject() {
47  		super.saveBusinessObject();
48  		
49  		// create leave block 
50  		LeaveAdjustment la = (LeaveAdjustment) this.getBusinessObject();
51  		LeaveBlockBo aLeaveBlock = new LeaveBlockBo();
52  		aLeaveBlock.setPrincipalId(la.getPrincipalId());
53  		aLeaveBlock.setLeaveDate(la.getEffectiveDate());
54  		aLeaveBlock.setEarnCode(la.getEarnCode());
55  		aLeaveBlock.setAccrualCategory(la.getAccrualCategory());
56  		aLeaveBlock.setDescription("Leave Adjustment");
57  		aLeaveBlock.setLeaveAmount(la.getAdjustmentAmount());	// can be negative or positive.  leave as is.
58  		aLeaveBlock.setAccrualGenerated(false);
59  		aLeaveBlock.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_ADJUSTMENT_MAINT);
60  		aLeaveBlock.setRequestStatus(HrConstants.REQUEST_STATUS.APPROVED);
61  		aLeaveBlock.setBlockId(0L);
62  		
63  		LmServiceLocator.getLeaveBlockService().saveLeaveBlock(LeaveBlockBo.to(aLeaveBlock), HrContext.getPrincipalId());
64  	}
65  	
66  	@SuppressWarnings("rawtypes")
67  	@Override
68  	public Map populateBusinessObject(Map<String, String> fieldValues,
69  			MaintenanceDocument maintenanceDocument, String methodToCall) {
70  		if (fieldValues.containsKey("principalId")
71  				&& StringUtils.isNotEmpty(fieldValues.get("principalId"))
72  				&& fieldValues.containsKey("effectiveDate")
73  				&& StringUtils.isNotEmpty(fieldValues.get("effectiveDate"))) {
74  			LocalDate effDate = TKUtils.formatDateString(fieldValues.get("effectiveDate"));
75  			PrincipalHRAttributes principalHRAttrObj = HrServiceLocator.getPrincipalHRAttributeService()
76  						.getPrincipalCalendar(fieldValues.get("principalId"), effDate);
77  			String lpString = (principalHRAttrObj != null) ? principalHRAttrObj.getLeavePlan() : "";
78  			fieldValues.put("leavePlan", lpString);
79  		}
80  		return super.populateBusinessObject(fieldValues, maintenanceDocument,
81  				methodToCall); 
82  	}
83  
84  
85  }