1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.batch;
17
18 import org.kuali.ole.coa.businessobject.Account;
19 import org.kuali.ole.select.OleSelectNotificationConstant;
20 import org.kuali.ole.select.service.OleAccountService;
21 import org.kuali.ole.select.service.OleNotifyService;
22 import org.kuali.ole.select.service.impl.OleNotifyServiceImpl;
23 import org.kuali.ole.sys.OLEConstants;
24 import org.kuali.ole.sys.batch.AbstractStep;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.rice.core.api.config.property.ConfigurationService;
27 import org.kuali.rice.core.api.datetime.DateTimeService;
28 import org.kuali.rice.kew.api.exception.WorkflowException;
29 import org.kuali.rice.kns.document.MaintenanceDocument;
30 import org.kuali.rice.krad.UserSession;
31 import org.kuali.rice.krad.rules.rule.event.RouteDocumentEvent;
32 import org.kuali.rice.krad.service.DocumentService;
33 import org.kuali.rice.krad.service.impl.DocumentServiceImpl;
34 import org.kuali.rice.krad.util.GlobalVariables;
35 import org.kuali.rice.krad.util.ObjectUtils;
36
37 import java.util.*;
38
39 public class OleAccountTemporaryRestrictedStep extends AbstractStep {
40
41
42
43
44 @Override
45 public boolean execute(String jobName, Date jobRunDate) throws InterruptedException {
46
47 boolean notify = false;
48 List<Account> TempRestrictedAccountDetails = SpringContext.getBean(OleAccountService.class).getTemporaryRestrictedAccounts();
49 Map fiscalOfficerMap = new HashMap();
50
51 Date currenDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
52 OleNotifyService service = SpringContext.getBean(OleNotifyServiceImpl.class);
53 ConfigurationService kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
54
55 for (Account TRestrictedAccount : TempRestrictedAccountDetails) {
56 String fiscalOfficerPrincipalName = TRestrictedAccount.getAccountFiscalOfficerUser().getPrincipalName();
57 Date tempRestrictedAccountStatusDate = TRestrictedAccount.getAccountRestrictedStatusDate();
58 if (tempRestrictedAccountStatusDate.compareTo(currenDate) < 0) {
59 notify = true;
60 List<String> user = new ArrayList<String>();
61 user.add(fiscalOfficerPrincipalName);
62 try {
63 service.notify(user, "Account Restricted Status Date for the Following Temporary Restricted AccountNumber : " + TRestrictedAccount.getAccountNumber() + " is equal to currentDate. You can update AccountRestrictedStatusCode or can extend AccountRestrictedStatusDate ");
64 } catch (WorkflowException ex) {
65
66 throw new RuntimeException(ex);
67 }
68
69 try {
70
71 GlobalVariables.setUserSession(new UserSession(kualiConfigurationService.getPropertyValueAsString(OleSelectNotificationConstant.ACCOUNT_DOCUMENT_INTIATOR)));
72 GlobalVariables.getUserSession().getPrincipalName();
73 editAccountTemporaryRestrictedRecordDocument(TRestrictedAccount);
74 } catch (Exception ex) {
75
76 throw new RuntimeException(ex);
77 }
78 }
79 }
80 return notify;
81
82 }
83
84
85 public void editAccountTemporaryRestrictedRecordDocument(Account TRestrictedAccount) throws Exception {
86
87 MaintenanceDocument accountMaintDoc = null;
88
89 Account newAccountRecord = new Account();
90 try {
91
92 org.kuali.rice.krad.service.BusinessObjectService businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
93
94 DocumentService documentService = new DocumentServiceImpl();
95 accountMaintDoc = (MaintenanceDocument) documentService.getNewDocument(OLEConstants.DocumentTypeAttributes.ACCOUNTING_DOCUMENT_TYPE_NAME);
96 accountMaintDoc.getDocumentHeader().setDocumentDescription(OleSelectNotificationConstant.OLE_ACCOUNT_TEMP_RESTRICTED_EDIT_DOCUMENT_DESCRIPTION);
97 accountMaintDoc.getOldMaintainableObject().setBusinessObject(TRestrictedAccount);
98 newAccountRecord = (Account) ObjectUtils.deepCopy(TRestrictedAccount);
99 accountMaintDoc.getNewMaintainableObject().setBusinessObject(newAccountRecord);
100 accountMaintDoc.getNewMaintainableObject().setMaintenanceAction(OLEConstants.MAINTENANCE_EDIT_ACTION);
101 accountMaintDoc.getNewMaintainableObject().setDocumentNumber(accountMaintDoc.getDocumentNumber());
102 accountMaintDoc.validateBusinessRules(new RouteDocumentEvent(accountMaintDoc));
103 documentService.routeDocument(accountMaintDoc, null, null);
104
105 } catch (WorkflowException ex) {
106 throw new RuntimeException(ex);
107 }
108 }
109
110 }
111