View Javadoc

1   /**
2    * Copyright 2005-2012 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.messaging;
17  
18  import javax.xml.namespace.QName;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.rice.kew.api.action.RolePokerQueue;
22  import org.kuali.rice.kew.api.document.DocumentOrchestrationQueue;
23  import org.kuali.rice.kew.api.document.DocumentRefreshQueue;
24  import org.kuali.rice.kew.api.action.ActionInvocationQueue;
25  import org.kuali.rice.kew.api.KewApiConstants;
26  import org.kuali.rice.kew.api.document.DocumentProcessingQueue;
27  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
28  import org.kuali.rice.kew.service.KEWServiceLocator;
29  import org.kuali.rice.ksb.api.KsbApiServiceLocator;
30  
31  /**
32   * Utility class for accessing names of common asynchronous services.
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class MessageServiceNames {
37  
38  	private static final QName DOCUMENT_PROCESSING_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "documentProcessingQueue");
39  
40  	private static final QName DOCUMENT_ORCHESTRATION_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "documentOrchestrationQueue");
41  
42  	private static final QName DOCUMENT_REFRESH_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "documentRefreshQueue");
43  
44  	private static final QName ROLE_POKER_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "rolePokerQueue");
45  
46      private static final QName ACTION_INVOCATION_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "actionInvocationQueue");
47  
48  	private static QName getQName(String baseServiceName, DocumentRouteHeaderValue document) {
49  		if (document != null) {
50  			return new QName(document.getDocumentType().getApplicationId(), baseServiceName);
51  		}
52  		return new QName(baseServiceName);
53  	}
54  
55      public static DocumentProcessingQueue getDocumentProcessingQueue(DocumentRouteHeaderValue document) {
56          return (DocumentProcessingQueue)getServiceAsynchronously(DOCUMENT_PROCESSING_QUEUE, document);
57      }
58  
59  	public static ActionInvocationQueue getActionInvocationProcessorService(DocumentRouteHeaderValue document) {
60  		return (ActionInvocationQueue) getServiceAsynchronously(ACTION_INVOCATION_QUEUE, document);
61  	}
62  
63  	public static DocumentOrchestrationQueue getDocumentOrchestrationQueue(DocumentRouteHeaderValue document) {
64  		return (DocumentOrchestrationQueue) getServiceAsynchronously(DOCUMENT_ORCHESTRATION_QUEUE, document);
65  	}
66  
67      public static RolePokerQueue getRolePokerQueue(String documentId) {
68  		return (RolePokerQueue) getServiceAsynchronously(ROLE_POKER_QUEUE, documentId);
69  	}
70  	
71  	public static DocumentRefreshQueue getDocumentRequeuerService(String applicationId, String documentId, long waitTime) {
72  		if (waitTime > 0) {
73  			return (DocumentRefreshQueue) getDelayedServiceAsynchronously(DOCUMENT_REFRESH_QUEUE, documentId, waitTime);
74  		}
75  		return (DocumentRefreshQueue) getServiceAsynchronously(DOCUMENT_REFRESH_QUEUE, documentId, applicationId);
76  	}
77  
78  	public static Object getServiceAsynchronously(QName serviceName, DocumentRouteHeaderValue document) {
79          String applicationId = document.getDocumentType().getApplicationId();
80  		return getServiceAsynchronously(serviceName, getDocId(document), applicationId);
81  	}
82  
83      public static Object getServiceAsynchronously(QName serviceName, String documentId) {
84          String applicationId = null;
85          if (StringUtils.isNotBlank(documentId)) {
86              applicationId = KEWServiceLocator.getRouteHeaderService().getApplicationIdByDocumentId(documentId);
87          }
88          return getServiceAsynchronously(serviceName, documentId, applicationId);
89  	}
90  
91  	public static Object getServiceAsynchronously(QName serviceName, String documentId, String applicationId) {
92  		return KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, applicationId, null, null, (documentId == null ? null : documentId.toString()), null);
93  	}
94  
95  	public static Object getDelayedServiceAsynchronously(QName serviceName, DocumentRouteHeaderValue document, long waitTime) {
96  		return getDelayedServiceAsynchronously(serviceName, getDocId(document), waitTime);
97  	}
98  
99  	public static Object getDelayedServiceAsynchronously(QName serviceName, String documentId, long waitTime) {
100 		return KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, null, (documentId == null ? null : documentId.toString()), null, waitTime);
101 	}
102 
103 	private static String getDocId(DocumentRouteHeaderValue document) {
104 		return (document == null ? null : document.getDocumentId());
105 	}
106 
107 }