View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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.rice.kew.impl.action;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
20  import org.kuali.rice.kew.actions.BlanketApproveAction;
21  import org.kuali.rice.kew.actiontaken.ActionTakenValue;
22  import org.kuali.rice.kew.api.KewApiServiceLocator;
23  import org.kuali.rice.kew.api.WorkflowRuntimeException;
24  import org.kuali.rice.kew.api.document.DocumentOrchestrationQueue;
25  import org.kuali.rice.kew.api.document.DocumentProcessingOptions;
26  import org.kuali.rice.kew.api.document.OrchestrationConfig;
27  import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
28  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
29  import org.kuali.rice.kew.service.KEWServiceLocator;
30  import org.kuali.rice.kim.api.identity.principal.Principal;
31  
32  /**
33   * References implementation of the {@code DocumentOrchestrationQueue}.
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public class DocumentOrchestrationQueueImpl implements DocumentOrchestrationQueue {
38  	
39  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentOrchestrationQueueImpl.class);
40  
41      @Override
42      public void orchestrateDocument(String documentId, String principalId, OrchestrationConfig orchestrationConfig,
43              DocumentProcessingOptions documentProcessingOptions) {
44          if (StringUtils.isBlank(principalId)) {
45              throw new RiceIllegalArgumentException("principalId is null or blank");
46          }
47  
48          if (StringUtils.isBlank(documentId)) {
49              throw new RiceIllegalArgumentException("documentId is null");
50          }
51  
52          if (orchestrationConfig == null) {
53              throw new RiceIllegalArgumentException("orchestrationConfig is null");
54          }
55          if (documentProcessingOptions == null) {
56              documentProcessingOptions = DocumentProcessingOptions.createDefault();
57          }
58  
59          LOG.info("Performing document orchestration on documentId=" + documentId);
60          KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId);
61          DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId);
62  		ActionTakenValue actionTaken = KEWServiceLocator.getActionTakenService().findByActionTakenId(orchestrationConfig.getActionTakenId());
63  		Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId);
64  		BlanketApproveAction blanketApprove = new BlanketApproveAction(document, principal, "", orchestrationConfig.getNodeNames());
65  		try {
66  			blanketApprove.performDeferredBlanketApproveWork(actionTaken, documentProcessingOptions);
67  		} catch (Exception e) {
68              if (e instanceof RuntimeException) {
69                  throw (RuntimeException)e;
70              }
71  			throw new WorkflowRuntimeException(e);
72  		}
73  		if (documentProcessingOptions.isIndexSearchAttributes()) {
74              DocumentAttributeIndexingQueue queue = KewApiServiceLocator.getDocumentAttributeIndexingQueue(document.getDocumentType().getApplicationId());
75              queue.indexDocument(documentId);
76  		}
77          LOG.info("Document orchestration complete against documentId=" + documentId);
78      }
79  
80  }