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.api;
17  
18  import javax.xml.namespace.QName;
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.core.api.config.module.RunMode;
21  import org.kuali.rice.core.api.config.property.ConfigContext;
22  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
23  import org.kuali.rice.kew.api.action.ActionInvocationQueue;
24  import org.kuali.rice.kew.api.action.RolePokerQueue;
25  import org.kuali.rice.kew.api.action.WorkflowDocumentActionsService;
26  import org.kuali.rice.kew.api.actionlist.ActionListService;
27  import org.kuali.rice.kew.api.doctype.DocumentTypeService;
28  import org.kuali.rice.kew.api.document.DocumentOrchestrationQueue;
29  import org.kuali.rice.kew.api.document.DocumentProcessingQueue;
30  import org.kuali.rice.kew.api.document.DocumentRefreshQueue;
31  import org.kuali.rice.kew.api.document.WorkflowDocumentService;
32  import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
33  import org.kuali.rice.kew.api.extension.ExtensionRepositoryService;
34  import org.kuali.rice.kew.api.group.GroupMembershipChangeQueue;
35  import org.kuali.rice.kew.api.mail.ImmediateEmailReminderQueue;
36  import org.kuali.rice.kew.api.note.NoteService;
37  import org.kuali.rice.kew.api.peopleflow.PeopleFlowService;
38  import org.kuali.rice.kew.api.preferences.PreferencesService;
39  import org.kuali.rice.kew.api.repository.type.KewTypeRepositoryService;
40  import org.kuali.rice.kew.api.responsibility.ResponsibilityChangeQueue;
41  import org.kuali.rice.kew.api.rule.RuleService;
42  import org.kuali.rice.ksb.api.KsbApiServiceLocator;
43  
44  /**
45   * A static service locator which aids in locating the various services that
46   * form the Kuali Service Bus API.
47   */
48  public class KewApiServiceLocator {
49  
50      // Rice 2.0 - TODO - should these be using the QName versions instead?  How else will they be fetched in "remote" mode?
51  	public static final String WORKFLOW_DOCUMENT_ACTIONS_SERVICE = "rice.kew.workflowDocumentActionsService";
52  	public static final String WORKFLOW_DOCUMENT_SERVICE = "rice.kew.workflowDocumentService";
53      public static final String ACTION_LIST_SERVICE = "rice.kew.actionListService";
54  	public static final String DOCUMENT_TYPE_SERVICE = "rice.kew.documentTypeService";
55  	public static final String NOTE_SERVICE = "rice.kew.noteService";
56      public static final String EXTENSION_REPOSITORY_SERVICE = "rice.kew.extensionRepositoryService";
57      public static final String RULE_SERVICE = "rice.kew.ruleService";
58      public static final String KEW_TYPE_REPOSITORY_SERVICE = "rice.kew.kewTypeRepositoryService";
59      public static final String PEOPLE_FLOW_SERVICE = "rice.kew.peopleFlowService";
60      public static final String PREFERENCES_SERVICE = "rice.kew.preferencesService";
61      public static final String KEW_RUN_MODE_PROPERTY = "kew.mode";
62      public static final String STANDALONE_APPLICATION_ID = "standalone.application.id";
63      public static final QName DOCUMENT_ATTRIBUTE_INDEXING_QUEUE_NAME = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "documentAttributeIndexingQueue");
64      public static final QName GROUP_MEMBERSHIP_CHANGE_QUEUE_NAME = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "groupMembershipChangeQueue");
65      public static final QName IMMEDIATE_EMAIL_REMINDER_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "immediateEmailReminderQueue");
66      public static final QName RESPONSIBILITY_CHANGE_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "responsibilityChangeQueue");
67      public static final QName DOCUMENT_REFRESH_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "documentRefreshQueue");
68      public static final QName ROLE_POKER_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "rolePokerQueue");
69      public static final QName DOCUMENT_PROCESSING_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "documentProcessingQueue");
70      public static final QName DOCUMENT_ORCHESTRATION_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "documentOrchestrationQueue");
71      public static final QName ACTION_INVOCATION_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "actionInvocationQueue");
72  
73      static <T> T getService(String serviceName) {
74          return GlobalResourceLoader.<T>getService(serviceName);
75      }
76  
77      public static WorkflowDocumentActionsService getWorkflowDocumentActionsService() {
78          RunMode kewRunMode = RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KEW_RUN_MODE_PROPERTY));
79          if (kewRunMode == RunMode.REMOTE || kewRunMode == RunMode.THIN) {
80              String standaloneApplicationId = ConfigContext.getCurrentContextConfig().getProperty(STANDALONE_APPLICATION_ID);
81              return getWorkflowDocumentActionsService(standaloneApplicationId);
82          } else { 
83              return getService(WORKFLOW_DOCUMENT_ACTIONS_SERVICE);
84          }
85      }
86      
87      public static WorkflowDocumentActionsService getWorkflowDocumentActionsService(String applicationId){
88          if(!StringUtils.isEmpty(applicationId)){//Need to find out proper remote endpoint in this case
89              QName qN = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, KewApiConstants.ServiceNames.WORKFLOW_DOCUMENT_ACTIONS_SERVICE_SOAP);
90              //http://rice.kuali.org/kew/v2_0}workflowDocumentActionsService
91              return (WorkflowDocumentActionsService)KsbApiServiceLocator.getServiceBus().getService(qN, applicationId);
92          }else{//we can use the default internal service here since we dont have an applicationId
93              return getWorkflowDocumentActionsService();
94          }
95      }
96      
97      public static WorkflowDocumentService getWorkflowDocumentService() {
98          return getService(WORKFLOW_DOCUMENT_SERVICE);
99      }
100 
101     public static ActionListService getActionListService() {
102         return getService(ACTION_LIST_SERVICE);
103     }
104     
105     public static DocumentTypeService getDocumentTypeService() {
106         return getService(DOCUMENT_TYPE_SERVICE);
107     }
108     
109     public static NoteService getNoteService() {
110     	return getService(NOTE_SERVICE);
111     }
112 
113     public static RuleService getRuleService() {
114     	return getService(RULE_SERVICE);
115     }
116 
117     public static ExtensionRepositoryService getExtensionRepositoryService() {
118         return getService(EXTENSION_REPOSITORY_SERVICE);
119     }
120 
121     public static KewTypeRepositoryService getKewTypeRepositoryService() {
122         return getService(KEW_TYPE_REPOSITORY_SERVICE);
123     }
124 
125     public static PeopleFlowService getPeopleFlowService() {
126         return getService(PEOPLE_FLOW_SERVICE);
127     }
128 
129     public static DocumentAttributeIndexingQueue getDocumentAttributeIndexingQueue() {
130         return getDocumentAttributeIndexingQueue(null);
131     }
132 
133     /**
134      * For accessing common asynchronous services.
135      */
136 
137     public static DocumentAttributeIndexingQueue getDocumentAttributeIndexingQueue(String applicationId) {
138         return (DocumentAttributeIndexingQueue)KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(DOCUMENT_ATTRIBUTE_INDEXING_QUEUE_NAME, applicationId);
139     }
140     
141     public static GroupMembershipChangeQueue getGroupMembershipChangeQueue() {
142         return (GroupMembershipChangeQueue)KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(GROUP_MEMBERSHIP_CHANGE_QUEUE_NAME);
143     }
144 
145     public static ResponsibilityChangeQueue getResponsibilityChangeQueue() {
146         return (ResponsibilityChangeQueue)KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(
147                 RESPONSIBILITY_CHANGE_QUEUE);
148     }
149     
150     public static ImmediateEmailReminderQueue getImmediateEmailReminderQueue() {
151         return KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(IMMEDIATE_EMAIL_REMINDER_QUEUE);
152     }
153 
154     public static PreferencesService getPreferencesService() {
155         return getService(PREFERENCES_SERVICE);
156     }
157 
158     public static DocumentProcessingQueue getDocumentProcessingQueue(String documentId, String applicationId) {
159         return (DocumentProcessingQueue)getServiceAsynchronously(DOCUMENT_PROCESSING_QUEUE, documentId, applicationId);
160     }
161 
162     public static ActionInvocationQueue getActionInvocationProcessorService(String documentId, String applicationId) {
163         return (ActionInvocationQueue) getServiceAsynchronously(ACTION_INVOCATION_QUEUE, documentId, applicationId);
164     }
165 
166     public static DocumentOrchestrationQueue getDocumentOrchestrationQueue(String documentId, String applicationId) {
167         return (DocumentOrchestrationQueue) getServiceAsynchronously(DOCUMENT_ORCHESTRATION_QUEUE, documentId, applicationId);
168     }
169 
170     public static RolePokerQueue getRolePokerQueue(String documentId, String applicationId) {
171         return (RolePokerQueue) getServiceAsynchronously(ROLE_POKER_QUEUE, documentId, applicationId);
172     }
173 
174     public static DocumentRefreshQueue getDocumentRequeuerService(String applicationId, String documentId, long waitTime) {
175         if (waitTime > 0) {
176             return (DocumentRefreshQueue) getDelayedServiceAsynchronously(DOCUMENT_REFRESH_QUEUE, documentId, waitTime, applicationId);
177         }
178         return (DocumentRefreshQueue) getServiceAsynchronously(DOCUMENT_REFRESH_QUEUE, documentId, applicationId);
179     }
180 
181     private static Object getDelayedServiceAsynchronously(QName serviceName, String documentId, long waitTime, String applicationId) {
182         return KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, applicationId, null, (documentId == null ? null : documentId.toString()), null, waitTime);
183     }
184 
185     private static Object getServiceAsynchronously(QName serviceName, String documentId, String applicationId) {
186         return KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, applicationId, null, null, (documentId == null ? null : documentId.toString()), null);
187     }
188 }