View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.lm.leaveadjustment.service;
17  
18  import java.util.Date;
19  import java.util.Map;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.hr.lm.LMConstants;
23  import org.kuali.hr.lm.leaveadjustment.LeaveAdjustment;
24  import org.kuali.hr.lm.leaveblock.LeaveBlock;
25  import org.kuali.hr.time.HrBusinessObject;
26  import org.kuali.hr.time.principal.PrincipalHRAttributes;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
29  import org.kuali.hr.time.util.TKContext;
30  import org.kuali.rice.kns.document.MaintenanceDocument;
31  
32  public class LeaveAdjustmentMaintainableServiceImpl extends HrBusinessObjectMaintainableImpl{
33  
34  	private static final long serialVersionUID = 2500485054776792764L;
35  
36  	@Override
37  	public HrBusinessObject getObjectById(String id) {
38  		// TODO Auto-generated method stub
39  		return null;
40  	}
41  	
42  	@Override
43  	public void saveBusinessObject() {
44  		super.saveBusinessObject();
45  		
46  		// create leave block 
47  		LeaveAdjustment la = (LeaveAdjustment) this.getBusinessObject();
48  		LeaveBlock aLeaveBlock = new LeaveBlock();
49  		aLeaveBlock.setPrincipalId(la.getPrincipalId());
50  		aLeaveBlock.setLeaveDate(la.getEffectiveDate());
51  		aLeaveBlock.setEarnCode(la.getEarnCode());
52  		aLeaveBlock.setAccrualCategory(la.getAccrualCategory());
53  		aLeaveBlock.setDescription("Leave Adjustment");
54  		aLeaveBlock.setLeaveAmount(la.getAdjustmentAmount());	// can be negative or positive.  leave as is.
55  		aLeaveBlock.setAccrualGenerated(false);
56  		aLeaveBlock.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_ADJUSTMENT_MAINT);
57  		aLeaveBlock.setRequestStatus(LMConstants.REQUEST_STATUS.APPROVED);
58  		aLeaveBlock.setBlockId(0L);
59  		
60  		TkServiceLocator.getLeaveBlockService().saveLeaveBlock(aLeaveBlock, TKContext.getPrincipalId());		
61  	}
62  	
63  	@SuppressWarnings("rawtypes")
64  	@Override
65  	public Map populateBusinessObject(Map<String, String> fieldValues,
66  			MaintenanceDocument maintenanceDocument, String methodToCall) {
67  		if (fieldValues.containsKey("principalId")
68  				&& StringUtils.isNotEmpty(fieldValues.get("principalId"))
69  				&& fieldValues.containsKey("effectiveDate")
70  				&& StringUtils.isNotEmpty(fieldValues.get("effectiveDate"))) {
71  			Date effDate = new Date(fieldValues.get("effectiveDate"));
72  			PrincipalHRAttributes principalHRAttrObj = TkServiceLocator.getPrincipalHRAttributeService()
73  						.getPrincipalCalendar(fieldValues.get("principalId"), effDate);
74  			String lpString = (principalHRAttrObj != null) ? principalHRAttrObj.getLeavePlan() : "";
75  			fieldValues.put("leavePlan", lpString);
76  		}
77  		return super.populateBusinessObject(fieldValues, maintenanceDocument,
78  				methodToCall); 
79  	}
80  
81  
82  }