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.leavedonation.service;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.hr.core.cache.CacheUtils;
22  import org.kuali.hr.lm.LMConstants;
23  import org.kuali.hr.lm.leaveblock.LeaveBlock;
24  import org.kuali.hr.lm.leavedonation.LeaveDonation;
25  import org.kuali.hr.time.HrBusinessObject;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
28  
29  public class LeaveDonationMaintainableServiceImpl extends HrBusinessObjectMaintainableImpl {
30  
31  	private static final long serialVersionUID = -2969252116840795858L;
32  
33  	@Override
34  	public HrBusinessObject getObjectById(String id) {
35  		return TkServiceLocator.getLeaveDonationService().getLeaveDonation(id);
36  	}
37  	
38  	@Override
39  	public void saveBusinessObject() {
40  		super.saveBusinessObject();
41  		//leave donation saved, clear cache before grabbing saved object
42          CacheUtils.flushCache(LeaveDonation.CACHE_NAME);
43  
44  		// create leave blocks for donor and recipient
45  		LeaveDonation ld = (LeaveDonation) this.getBusinessObject();
46  		List<LeaveBlock> lbList = new ArrayList<LeaveBlock>();
47  		// donor leave block
48  		LeaveBlock aLeaveBlock = new LeaveBlock();
49  		aLeaveBlock.setPrincipalId(ld.getDonorsPrincipalID());
50  		aLeaveBlock.setLeaveDate(ld.getEffectiveDate());
51  		aLeaveBlock.setEarnCode(ld.getDonatedEarnCode());
52  		aLeaveBlock.setAccrualCategory(ld.getDonatedAccrualCategory());
53  		aLeaveBlock.setDescription(ld.getDescription());
54  		aLeaveBlock.setLeaveAmount(ld.getAmountDonated().negate());	// usage
55  		aLeaveBlock.setAccrualGenerated(false);
56  		aLeaveBlock.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.DONATION_MAINT);
57  		aLeaveBlock.setRequestStatus(LMConstants.REQUEST_STATUS.APPROVED);
58  		aLeaveBlock.setBlockId(0L);
59  		lbList.add(aLeaveBlock);
60  		
61  		// recipient leave block
62  		aLeaveBlock = new LeaveBlock();
63  		aLeaveBlock.setPrincipalId(ld.getRecipientsPrincipalID());
64  		aLeaveBlock.setLeaveDate(ld.getEffectiveDate());
65  		aLeaveBlock.setEarnCode(ld.getRecipientsEarnCode());
66  		aLeaveBlock.setAccrualCategory(ld.getRecipientsAccrualCategory());
67  		aLeaveBlock.setDescription(ld.getDescription());
68  		aLeaveBlock.setLeaveAmount(ld.getAmountReceived());
69  		aLeaveBlock.setAccrualGenerated(false);
70  		aLeaveBlock.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.DONATION_MAINT);
71  		aLeaveBlock.setRequestStatus(LMConstants.REQUEST_STATUS.APPROVED);
72  		aLeaveBlock.setBlockId(0L);
73  		lbList.add(aLeaveBlock);
74  		
75  		TkServiceLocator.getLeaveBlockService().saveLeaveBlocks(lbList);
76  	}
77  }