View Javadoc

1   /**
2    * Copyright 2005-2014 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.document;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
21  import org.kuali.rice.kew.api.WorkflowRuntimeException;
22  import org.kuali.rice.kew.api.document.DocumentProcessingOptions;
23  import org.kuali.rice.kew.api.document.DocumentProcessingQueue;
24  import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
25  import org.kuali.rice.kew.engine.OrchestrationConfig;
26  import org.kuali.rice.kew.engine.WorkflowEngine;
27  import org.kuali.rice.kew.engine.WorkflowEngineFactory;
28  
29  import javax.jws.WebParam;
30  import java.util.Collections;
31  
32  /**
33   * Reference implementation of the {@code DocumentProcessingQueue}.
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public class DocumentProcessingQueueImpl implements DocumentProcessingQueue {
38  
39      private static final Logger LOG = Logger.getLogger(DocumentProcessingQueueImpl.class);
40  
41      private WorkflowEngineFactory workflowEngineFactory;
42      private DocumentAttributeIndexingQueue documentAttributeIndexingQueue;
43  
44      @Override
45      public void process(@WebParam(name = "documentId") String documentId) {
46          processWithOptions(documentId, null);
47      }
48  
49      @Override
50      public void processWithOptions(@WebParam(name = "documentId") String documentId,
51              @WebParam(name = "options") DocumentProcessingOptions options) {
52          if (StringUtils.isBlank(documentId)) {
53              throw new RiceIllegalArgumentException("documentId was a null or blank value");
54          }
55          if (options == null) {
56              options = DocumentProcessingOptions.createDefault();
57          }
58          OrchestrationConfig config = new OrchestrationConfig(OrchestrationConfig.EngineCapability.STANDARD,
59                  Collections.<String>emptySet(), null, options.isSendNotifications(), options.isRunPostProcessor());
60          WorkflowEngine engine = getWorkflowEngineFactory().newEngine(config);
61          try {
62  			engine.process(documentId, null);
63  		} catch (Exception e) {
64  			LOG.error("Failed to process document through the workflow engine", e);
65              if (e instanceof RuntimeException) {
66                  throw (RuntimeException)e;
67              }
68  			throw new WorkflowRuntimeException(e);
69  		}
70          if (options.isIndexSearchAttributes()) {
71              getDocumentAttributeIndexingQueue().indexDocument(documentId);
72          }
73      }
74  
75      public WorkflowEngineFactory getWorkflowEngineFactory() {
76          return workflowEngineFactory;
77      }
78  
79      public void setWorkflowEngineFactory(WorkflowEngineFactory workflowEngineFactory) {
80          this.workflowEngineFactory = workflowEngineFactory;
81      }
82  
83      public DocumentAttributeIndexingQueue getDocumentAttributeIndexingQueue() {
84          return documentAttributeIndexingQueue;
85      }
86  
87      public void setDocumentAttributeIndexingQueue(DocumentAttributeIndexingQueue documentAttributeIndexingQueue) {
88          this.documentAttributeIndexingQueue = documentAttributeIndexingQueue;
89      }
90  
91  }