View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.messaging;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.rice.kew.actionrequest.service.DocumentRequeuerService;
23  import org.kuali.rice.kew.actions.asyncservices.ActionInvocationService;
24  import org.kuali.rice.kew.actions.asyncservices.BlanketApproveProcessorService;
25  import org.kuali.rice.kew.actions.asyncservices.MoveDocumentService;
26  import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
27  import org.kuali.rice.kew.mail.service.ActionListImmediateEmailReminderService;
28  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
29  import org.kuali.rice.kew.rule.service.RuleCacheProcessor;
30  import org.kuali.rice.ksb.api.KsbApiServiceLocator;
31  import org.kuali.rice.ksb.messaging.service.KSBXMLService;
32  
33  
34  /**
35   * Utility class for accessing names of common asynchronous services.
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  public class MessageServiceNames {
40  
41  	public static final String DOCUMENT_ROUTING_SERVICE = "DocumentRoutingService";
42  
43  	public static final String ACTION_LIST_IMMEDIATE_REMINDER_SERVICE = "ImmediateEmailService";
44  
45  	public static final String BLANKET_APPROVE_PROCESSING_SERVICE = "BlanketApproveProcessorService";
46  
47  	public static final String DOCUMENT_REQUEUE_PROCESSING_SERVICE = "DocumentRequeueProcessorService";
48  
49  	public static final String WORKGROUP_MEMBERSHIP_CHANGE_SERVICE = "WorkgroupMembershipChangeService";
50  
51  	public static final String SERVICE_REMOVER_SERVICE = "RemoteClassRemoverService";
52  
53  	public static final String RULE_CACHE_PROCESSOR_SERVICE = "RuleCacheProcessorService";
54  
55  	public static final String ROLE_POKER = "RolePokerProcessorService";
56  
57  	public static final String MOVE_DOCUMENT_PROCESSOR = "MoveDocumentProcessor";
58  
59  	public static final String ACTION_INVOCATION_PROCESSOR = "ActionInvocationProcessor";
60  
61  	public static final String RESPONSIBILITY_CHANGE_SERVICE = "ResponsibilityChangeService";
62  
63  	private static QName getQName(String baseServiceName, DocumentRouteHeaderValue document) {
64  		if (document != null) {
65  			return new QName(document.getDocumentType().getApplicationId(), baseServiceName);
66  		}
67  		return new QName(baseServiceName);
68  	}
69  
70  	private static QName getQName(String baseServiceName, String applicationId) {
71  		if (!StringUtils.isEmpty(applicationId)) {
72  			return new QName(applicationId, baseServiceName);
73  		}
74  		return new QName(baseServiceName);
75  	}
76  
77  	public static KSBXMLService getRouteDocumentMessageService(DocumentRouteHeaderValue document) {
78  		return (KSBXMLService) getServiceAsynchronously(getQName(DOCUMENT_ROUTING_SERVICE, document), document);
79  	}
80  
81  	public static MoveDocumentService getMoveDocumentProcessorService(DocumentRouteHeaderValue document) {
82  		return (MoveDocumentService) getServiceAsynchronously(getQName(MOVE_DOCUMENT_PROCESSOR, document), document);
83  	}
84  
85  	public static ActionInvocationService getActionInvocationProcessorService(DocumentRouteHeaderValue document) {
86  		return (ActionInvocationService) getServiceAsynchronously(getQName(ACTION_INVOCATION_PROCESSOR, document), document);
87  	}
88  
89  	public static BlanketApproveProcessorService getBlanketApproveProcessorService(DocumentRouteHeaderValue document) {
90  		return (BlanketApproveProcessorService) getServiceAsynchronously(getQName(BLANKET_APPROVE_PROCESSING_SERVICE, document), document);
91  	}
92  
93  	public static ActionListImmediateEmailReminderService getImmediateEmailService() {
94  		return (ActionListImmediateEmailReminderService) getServiceAsynchronously(getQName(ACTION_LIST_IMMEDIATE_REMINDER_SERVICE, (DocumentRouteHeaderValue) null), (String)null);
95  	}
96  
97  	public static RuleCacheProcessor getRuleCacheProcessor() {
98  		return (RuleCacheProcessor) getServiceAsynchronously(new QName(MessageServiceNames.RULE_CACHE_PROCESSOR_SERVICE), (String)null);
99  	}
100 
101 	public static DocumentRequeuerService getDocumentRequeuerService(String applicationId, String documentId, long waitTime) {
102 		QName serviceName = getQName(DOCUMENT_REQUEUE_PROCESSING_SERVICE, applicationId);
103 		if (waitTime > 0) {
104 			return (DocumentRequeuerService) getDelayedServiceAsynchronously(serviceName, documentId, waitTime);
105 		}
106 		return (DocumentRequeuerService) getServiceAsynchronously(serviceName, documentId);
107 	}
108 
109 	public static Object getServiceAsynchronously(QName serviceName, DocumentRouteHeaderValue document) {
110 		return getServiceAsynchronously(serviceName, getDocId(document));
111 	}
112 
113 	public static Object getServiceAsynchronously(QName serviceName, String documentId) {
114 		return KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, null, null, (documentId == null ? null : documentId.toString()), null);
115 	}
116 
117 	public static Object getDelayedServiceAsynchronously(QName serviceName, DocumentRouteHeaderValue document, long waitTime) {
118 		return getDelayedServiceAsynchronously(serviceName, getDocId(document), waitTime);
119 	}
120 
121 	public static Object getDelayedServiceAsynchronously(QName serviceName, String documentId, long waitTime) {
122 		return KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, null, (documentId == null ? null : documentId.toString()), null, waitTime);
123 	}
124 
125 	private static String getDocId(DocumentRouteHeaderValue document) {
126 		return (document == null ? null : document.getDocumentId());
127 	}
128 
129 }