View Javadoc
1   /*
2    * Copyright 2012 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.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       * @see org.kuali.ole.sys.batch.Step#execute(java.lang.String, java.util.Date)
43       */
44      @Override
45      public boolean execute(String jobName, Date jobRunDate) throws InterruptedException {
46          // TODO Auto-generated method stub
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                      // TODO Auto-generated catch block
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                      // TODO Auto-generated catch block
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