001 /**
002 * Copyright 2004-2013 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.hr.lm.leavedonation.service;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import org.kuali.hr.core.cache.CacheUtils;
022 import org.kuali.hr.lm.LMConstants;
023 import org.kuali.hr.lm.leaveblock.LeaveBlock;
024 import org.kuali.hr.lm.leavedonation.LeaveDonation;
025 import org.kuali.hr.time.HrBusinessObject;
026 import org.kuali.hr.time.service.base.TkServiceLocator;
027 import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
028
029 public class LeaveDonationMaintainableServiceImpl extends HrBusinessObjectMaintainableImpl {
030
031 private static final long serialVersionUID = -2969252116840795858L;
032
033 @Override
034 public HrBusinessObject getObjectById(String id) {
035 return TkServiceLocator.getLeaveDonationService().getLeaveDonation(id);
036 }
037
038 @Override
039 public void saveBusinessObject() {
040 super.saveBusinessObject();
041 //leave donation saved, clear cache before grabbing saved object
042 CacheUtils.flushCache(LeaveDonation.CACHE_NAME);
043
044 // create leave blocks for donor and recipient
045 LeaveDonation ld = (LeaveDonation) this.getBusinessObject();
046 List<LeaveBlock> lbList = new ArrayList<LeaveBlock>();
047 // donor leave block
048 LeaveBlock aLeaveBlock = new LeaveBlock();
049 aLeaveBlock.setPrincipalId(ld.getDonorsPrincipalID());
050 aLeaveBlock.setLeaveDate(ld.getEffectiveDate());
051 aLeaveBlock.setEarnCode(ld.getDonatedEarnCode());
052 aLeaveBlock.setAccrualCategory(ld.getDonatedAccrualCategory());
053 aLeaveBlock.setDescription(ld.getDescription());
054 aLeaveBlock.setLeaveAmount(ld.getAmountDonated().negate()); // usage
055 aLeaveBlock.setAccrualGenerated(false);
056 aLeaveBlock.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.DONATION_MAINT);
057 aLeaveBlock.setRequestStatus(LMConstants.REQUEST_STATUS.APPROVED);
058 aLeaveBlock.setBlockId(0L);
059 lbList.add(aLeaveBlock);
060
061 // recipient leave block
062 aLeaveBlock = new LeaveBlock();
063 aLeaveBlock.setPrincipalId(ld.getRecipientsPrincipalID());
064 aLeaveBlock.setLeaveDate(ld.getEffectiveDate());
065 aLeaveBlock.setEarnCode(ld.getRecipientsEarnCode());
066 aLeaveBlock.setAccrualCategory(ld.getRecipientsAccrualCategory());
067 aLeaveBlock.setDescription(ld.getDescription());
068 aLeaveBlock.setLeaveAmount(ld.getAmountReceived());
069 aLeaveBlock.setAccrualGenerated(false);
070 aLeaveBlock.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.DONATION_MAINT);
071 aLeaveBlock.setRequestStatus(LMConstants.REQUEST_STATUS.APPROVED);
072 aLeaveBlock.setBlockId(0L);
073 lbList.add(aLeaveBlock);
074
075 TkServiceLocator.getLeaveBlockService().saveLeaveBlocks(lbList);
076 }
077 }