View Javadoc

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