1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leavepayout.service;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.kuali.hr.lm.LMConstants;
20 import org.kuali.hr.lm.balancetransfer.BalanceTransfer;
21 import org.kuali.hr.lm.leavepayout.LeavePayout;
22 import org.kuali.hr.lm.leaveblock.LeaveBlock;
23 import org.kuali.hr.time.HrBusinessObject;
24 import org.kuali.hr.time.service.base.TkServiceLocator;
25 import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
26 import org.kuali.rice.kew.api.document.DocumentStatus;
27 import org.kuali.rice.kew.api.exception.WorkflowException;
28 import org.kuali.rice.kns.document.MaintenanceDocument;
29 import org.kuali.rice.krad.bo.DocumentHeader;
30 import org.kuali.rice.krad.service.DocumentService;
31 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
32 import org.kuali.rice.krad.util.ObjectUtils;
33
34 public class LeavePayoutMaintainableImpl extends
35 HrBusinessObjectMaintainableImpl {
36
37 private static final long serialVersionUID = 1L;
38
39 @Override
40 public void saveBusinessObject() {
41 LeavePayout bt = (LeavePayout) this.getBusinessObject();
42
43 LeavePayout existingBt = TkServiceLocator.getLeavePayoutService().getLeavePayoutById(bt.getId());
44
45 if(ObjectUtils.isNotNull(existingBt)) {
46 if(existingBt.getPayoutAmount().compareTo(bt.getPayoutAmount()) != 0) {
47
48 }
49 if(existingBt.getForfeitedAmount().compareTo(bt.getForfeitedAmount()) != 0) {
50
51 }
52
53 }
54 }
55
56 @Override
57 public HrBusinessObject getObjectById(String id) {
58
59 return TkServiceLocator.getLeavePayoutService().getLeavePayoutById(id);
60 }
61
62 @Override
63 public void doRouteStatusChange(DocumentHeader documentHeader) {
64
65 String documentId = documentHeader.getDocumentNumber();
66 LeavePayout payout = (LeavePayout)this.getDataObject();
67 DocumentService documentService = KRADServiceLocatorWeb.getDocumentService();
68
69 DocumentStatus newDocumentStatus = documentHeader.getWorkflowDocument().getStatus();
70 String routedByPrincipalId = documentHeader.getWorkflowDocument().getRoutedByPrincipalId();
71 if (DocumentStatus.ENROUTE.equals(newDocumentStatus)
72 && CollectionUtils.isEmpty(payout.getLeaveBlocks())) {
73
74 try {
75 MaintenanceDocument md = (MaintenanceDocument)KRADServiceLocatorWeb.getDocumentService().getByDocumentHeaderId(documentId);
76
77 payout = TkServiceLocator.getLeavePayoutService().payout(payout);
78 md.getNewMaintainableObject().setDataObject(payout);
79 documentService.saveDocument(md);
80 }
81 catch (WorkflowException e) {
82 LOG.error("caught exception while handling doRouteStatusChange -> documentService.getByDocumentHeaderId(" + documentHeader.getDocumentNumber() + "). ", e);
83 throw new RuntimeException("caught exception while handling doRouteStatusChange -> documentService.getByDocumentHeaderId(" + documentHeader.getDocumentNumber() + "). ", e);
84 }
85 } else if (DocumentStatus.DISAPPROVED.equals(newDocumentStatus)) {
86
87 for(LeaveBlock lb : payout.getLeaveBlocks()) {
88 if(ObjectUtils.isNotNull(lb)) {
89 lb.setRequestStatus(LMConstants.REQUEST_STATUS.DISAPPROVED);
90 TkServiceLocator.getLeaveBlockService().deleteLeaveBlock(lb.getLmLeaveBlockId(), routedByPrincipalId);
91 }
92 }
93
94 } else if (DocumentStatus.FINAL.equals(newDocumentStatus)) {
95
96 for(LeaveBlock lb : payout.getLeaveBlocks()) {
97 if(ObjectUtils.isNotNull(lb)) {
98 lb.setRequestStatus(LMConstants.REQUEST_STATUS.APPROVED);
99 TkServiceLocator.getLeaveBlockService().updateLeaveBlock(lb, routedByPrincipalId);
100 }
101 }
102 } else if (DocumentStatus.CANCELED.equals(newDocumentStatus)) {
103
104 for(LeaveBlock lb : payout.getLeaveBlocks()) {
105 if(ObjectUtils.isNotNull(lb)) {
106 lb.setRequestStatus(LMConstants.REQUEST_STATUS.DEFERRED);
107 TkServiceLocator.getLeaveBlockService().updateLeaveBlock(lb, routedByPrincipalId);
108 }
109 }
110 }
111 }
112
113 }