View Javadoc
1   package org.kuali.ole.sys.context;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.sys.batch.AbstractStep;
5   import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
6   import org.kuali.rice.coreservice.api.parameter.Parameter;
7   import org.kuali.rice.coreservice.api.parameter.ParameterKey;
8   import org.kuali.rice.coreservice.framework.parameter.ParameterService;
9   import org.kuali.rice.kew.api.KewApiServiceLocator;
10  import org.kuali.rice.kew.api.action.ActionItem;
11  import org.kuali.rice.kew.api.action.DocumentActionParameters;
12  import org.kuali.rice.kew.api.action.WorkflowDocumentActionsService;
13  import org.kuali.rice.kew.api.actionlist.ActionListService;
14  
15  import java.util.ArrayList;
16  import java.util.Date;
17  import java.util.Iterator;
18  import java.util.List;
19  
20  /**
21   * Created by pvsubrah on 10/28/14.
22   */
23  public class ActionListBatchProcessor extends AbstractStep {
24      private WorkflowDocumentActionsService workflowDocumentActionsService;
25      private ActionListService actionListService;
26      private ParameterService parameterService;
27  
28      @Override
29      public boolean execute(String jobName, Date jobRunDate) throws InterruptedException {
30          ParameterKey principalIdParameterKey = ParameterKey.create(OLEConstants.APPL_ID_OLE, OLEConstants.SYS_NMSPC, OLEConstants.BATCH_CMPNT, "ACTN_LIST_BATCH_PRNPL_NM");
31          Parameter principalId = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(principalIdParameterKey);
32          String principal = principalId.getValue();
33  
34  
35          ParameterKey requestCodeParameterKey = ParameterKey.create(OLEConstants.APPL_ID_OLE, OLEConstants.SYS_NMSPC, OLEConstants.BATCH_CMPNT,"ACTN_LIST_BATCH_RQST_CD");
36          Parameter requestCode = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(requestCodeParameterKey);
37          String request = requestCode.getValue();
38  
39          ParameterKey docTypeParameterKey = ParameterKey.create(OLEConstants.APPL_ID_OLE, OLEConstants.SYS_NMSPC, OLEConstants.BATCH_CMPNT,"ACTN_LIST_BATCH_DOC_TYP_CD");
40          Parameter docTypeCode = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(docTypeParameterKey);
41  
42          List<ActionItem> actionItems = getActionListService().getActionItemsForPrincipal(principal);
43          List<String> docIds = new ArrayList<String>();
44          List<ActionItem> filteredActionItems = new ArrayList<ActionItem>();
45  
46          if(docTypeCode.getValue().equals("*")){
47              filteredActionItems = actionItems;
48          } else {
49              for (Iterator<ActionItem> iterator = actionItems.iterator(); iterator.hasNext(); ) {
50                  ActionItem actionItem = iterator.next();
51                  if(docTypeCode.getValue().equals(actionItem.getDocName())){
52                      filteredActionItems.add(actionItem);
53                  }
54              }
55          }
56  
57          for (Iterator<ActionItem> iterator = filteredActionItems.iterator(); iterator.hasNext(); ) {
58              ActionItem actionItem = iterator.next();
59              if(actionItem.getActionRequestCd().equals(requestCode.getValue())){
60                  docIds.add(actionItem.getDocumentId());
61              }
62          }
63  
64          switch (request){
65              case "A":
66                  approve(docIds, principal);
67              case "K":
68                  acknowledge(docIds, principal);
69              case "F":
70                  fyi(docIds, principal);
71              case "C":
72                  complete(docIds, principal);
73          }
74          return true;
75      }
76  
77      private void complete(List<String> docIds, String principal) {
78          for (Iterator<String> iterator = docIds.iterator(); iterator.hasNext(); ) {
79              String docId = iterator.next();
80              getWorkflowDocumentActionsService().complete(DocumentActionParameters.create(docId, principal));
81          }
82      }
83  
84      private void fyi(List<String> docIds, String principal) {
85          for (Iterator<String> iterator = docIds.iterator(); iterator.hasNext(); ) {
86              String docId = iterator.next();
87              getWorkflowDocumentActionsService().clearFyi(DocumentActionParameters.create(docId, principal));
88          }
89      }
90  
91      private void acknowledge(List<String> docIds, String principal) {
92          for (Iterator<String> iterator = docIds.iterator(); iterator.hasNext(); ) {
93              String docId = iterator.next();
94              getWorkflowDocumentActionsService().acknowledge(DocumentActionParameters.create(docId, principal));
95          }
96      }
97  
98      private void approve(List<String> docIds, String principal) {
99          for (Iterator<String> iterator = docIds.iterator(); iterator.hasNext(); ) {
100             String docId = iterator.next();
101             getWorkflowDocumentActionsService().approve(DocumentActionParameters.create(docId, principal));
102         }
103     }
104 
105     private WorkflowDocumentActionsService getWorkflowDocumentActionsService() {
106         if (null == workflowDocumentActionsService) {
107             workflowDocumentActionsService = KewApiServiceLocator.getWorkflowDocumentActionsService();
108         }
109         return workflowDocumentActionsService;
110     }
111 
112     public org.kuali.rice.kew.api.actionlist.ActionListService getActionListService() {
113         if (null == actionListService) {
114             actionListService = KewApiServiceLocator.getActionListService();
115         }
116         return actionListService;
117     }
118 
119     @Override
120     public ParameterService getParameterService() {
121         if(null == parameterService){
122             parameterService = (ParameterService) SpringContext.getService("parameterService");
123         }
124         return parameterService;
125     }
126 }