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.document.service.OleSelectDocumentService;
21 import org.kuali.ole.select.service.OleAccountService;
22 import org.kuali.ole.select.service.OleNotifyService;
23 import org.kuali.ole.select.service.impl.OleNotifyServiceImpl;
24 import org.kuali.ole.sys.OLEConstants;
25 import org.kuali.ole.sys.batch.AbstractStep;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.rice.core.api.config.property.ConfigurationService;
28 import org.kuali.rice.core.api.datetime.DateTimeService;
29 import org.kuali.rice.kew.api.exception.WorkflowException;
30 import org.kuali.rice.kns.document.MaintenanceDocument;
31 import org.kuali.rice.krad.UserSession;
32 import org.kuali.rice.krad.rules.rule.event.RouteDocumentEvent;
33 import org.kuali.rice.krad.service.DocumentService;
34 import org.kuali.rice.krad.service.impl.DocumentServiceImpl;
35 import org.kuali.rice.krad.util.GlobalVariables;
36 import org.kuali.rice.krad.util.ObjectUtils;
37
38 import java.util.*;
39
40 public class OleAccountTemporaryRestrictedStep extends AbstractStep {
41
42
43
44
45
46 private OleSelectDocumentService oleSelectDocumentService;
47
48 @Override
49 public boolean execute(String jobName, Date jobRunDate) throws InterruptedException {
50
51 boolean notify = false;
52 List<Account> TempRestrictedAccountDetails = SpringContext.getBean(OleAccountService.class).getTemporaryRestrictedAccounts();
53 Map fiscalOfficerMap = new HashMap();
54
55 Date currenDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
56 OleNotifyService service = SpringContext.getBean(OleNotifyServiceImpl.class);
57 ConfigurationService kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
58
59 for (Account TRestrictedAccount : TempRestrictedAccountDetails) {
60 String fiscalOfficerPrincipalName = TRestrictedAccount.getAccountFiscalOfficerUser().getPrincipalName();
61 Date tempRestrictedAccountStatusDate = TRestrictedAccount.getAccountRestrictedStatusDate();
62 if (tempRestrictedAccountStatusDate.compareTo(currenDate) < 0) {
63 notify = true;
64 List<String> user = new ArrayList<String>();
65 user.add(fiscalOfficerPrincipalName);
66 try {
67 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 ");
68 } catch (WorkflowException ex) {
69
70 throw new RuntimeException(ex);
71 }
72
73 try {
74
75 GlobalVariables.setUserSession(new UserSession(kualiConfigurationService.getPropertyValueAsString(getOleSelectDocumentService().getSelectParameterValue(OleSelectNotificationConstant.ACCOUNT_DOCUMENT_INTIATOR))));
76 GlobalVariables.getUserSession().getPrincipalName();
77 editAccountTemporaryRestrictedRecordDocument(TRestrictedAccount);
78 } catch (Exception ex) {
79
80 throw new RuntimeException(ex);
81 }
82 }
83 }
84 return notify;
85
86 }
87
88
89 public void editAccountTemporaryRestrictedRecordDocument(Account TRestrictedAccount) throws Exception {
90
91 MaintenanceDocument accountMaintDoc = null;
92
93 Account newAccountRecord = new Account();
94 try {
95
96 org.kuali.rice.krad.service.BusinessObjectService businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
97
98 DocumentService documentService = new DocumentServiceImpl();
99 accountMaintDoc = (MaintenanceDocument) documentService.getNewDocument(OLEConstants.DocumentTypeAttributes.ACCOUNTING_DOCUMENT_TYPE_NAME);
100 accountMaintDoc.getDocumentHeader().setDocumentDescription(OleSelectNotificationConstant.OLE_ACCOUNT_TEMP_RESTRICTED_EDIT_DOCUMENT_DESCRIPTION);
101 accountMaintDoc.getOldMaintainableObject().setBusinessObject(TRestrictedAccount);
102 newAccountRecord = (Account) ObjectUtils.deepCopy(TRestrictedAccount);
103 accountMaintDoc.getNewMaintainableObject().setBusinessObject(newAccountRecord);
104 accountMaintDoc.getNewMaintainableObject().setMaintenanceAction(OLEConstants.MAINTENANCE_EDIT_ACTION);
105 accountMaintDoc.getNewMaintainableObject().setDocumentNumber(accountMaintDoc.getDocumentNumber());
106 accountMaintDoc.validateBusinessRules(new RouteDocumentEvent(accountMaintDoc));
107 documentService.routeDocument(accountMaintDoc, null, null);
108
109 } catch (WorkflowException ex) {
110 throw new RuntimeException(ex);
111 }
112 }
113
114 public OleSelectDocumentService getOleSelectDocumentService() {
115 if(oleSelectDocumentService == null){
116 oleSelectDocumentService = SpringContext.getBean(OleSelectDocumentService.class);
117 }
118 return oleSelectDocumentService;
119 }
120
121 public void setOleSelectDocumentService(OleSelectDocumentService oleSelectDocumentService) {
122 this.oleSelectDocumentService = oleSelectDocumentService;
123 }
124
125 }
126