001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.api;
017
018 import javax.xml.namespace.QName;
019 import org.apache.commons.lang.StringUtils;
020 import org.kuali.rice.core.api.config.module.RunMode;
021 import org.kuali.rice.core.api.config.property.ConfigContext;
022 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
023 import org.kuali.rice.kew.api.action.WorkflowDocumentActionsService;
024 import org.kuali.rice.kew.api.actionlist.ActionListService;
025 import org.kuali.rice.kew.api.doctype.DocumentTypeService;
026 import org.kuali.rice.kew.api.document.WorkflowDocumentService;
027 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
028 import org.kuali.rice.kew.api.extension.ExtensionRepositoryService;
029 import org.kuali.rice.kew.api.group.GroupMembershipChangeQueue;
030 import org.kuali.rice.kew.api.mail.ImmediateEmailReminderQueue;
031 import org.kuali.rice.kew.api.note.NoteService;
032 import org.kuali.rice.kew.api.peopleflow.PeopleFlowService;
033 import org.kuali.rice.kew.api.preferences.PreferencesService;
034 import org.kuali.rice.kew.api.repository.type.KewTypeRepositoryService;
035 import org.kuali.rice.kew.api.responsibility.ResponsibilityChangeQueue;
036 import org.kuali.rice.kew.api.rule.RuleService;
037 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
038
039 /**
040 * A static service locator which aids in locating the various services that
041 * form the Kuali Service Bus API.
042 */
043 public class KewApiServiceLocator {
044
045 // Rice 2.0 - TODO - should these be using the QName versions instead? How else will they be fetched in "remote" mode?
046 public static final String WORKFLOW_DOCUMENT_ACTIONS_SERVICE = "rice.kew.workflowDocumentActionsService";
047 public static final String WORKFLOW_DOCUMENT_SERVICE = "rice.kew.workflowDocumentService";
048 public static final String ACTION_LIST_SERVICE = "rice.kew.actionListService";
049 public static final String DOCUMENT_TYPE_SERVICE = "rice.kew.documentTypeService";
050 public static final String NOTE_SERVICE = "rice.kew.noteService";
051 public static final String EXTENSION_REPOSITORY_SERVICE = "rice.kew.extensionRepositoryService";
052 public static final String RULE_SERVICE = "rice.kew.ruleService";
053 public static final String KEW_TYPE_REPOSITORY_SERVICE = "rice.kew.kewTypeRepositoryService";
054 public static final String PEOPLE_FLOW_SERVICE = "rice.kew.peopleFlowService";
055 public static final String PREFERENCES_SERVICE = "rice.kew.preferencesService";
056 public static final String KEW_RUN_MODE_PROPERTY = "kew.mode";
057 public static final String STANDALONE_APPLICATION_ID = "standalone.application.id";
058 public static final QName DOCUMENT_ATTRIBUTE_INDEXING_QUEUE_NAME = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "documentAttributeIndexingQueue");
059 public static final QName GROUP_MEMBERSHIP_CHANGE_QUEUE_NAME = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "groupMembershipChangeQueue");
060 public static final QName IMMEDIATE_EMAIL_REMINDER_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "immediateEmailReminderQueue");
061 public static final QName RESPONSIBILITY_CHANGE_QUEUE = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, "responsibilityChangeQueue");
062
063 static <T> T getService(String serviceName) {
064 return GlobalResourceLoader.<T>getService(serviceName);
065 }
066
067 public static WorkflowDocumentActionsService getWorkflowDocumentActionsService() {
068 RunMode kewRunMode = RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KEW_RUN_MODE_PROPERTY));
069 if (kewRunMode == RunMode.REMOTE || kewRunMode == RunMode.THIN) {
070 String standaloneApplicationId = ConfigContext.getCurrentContextConfig().getProperty(STANDALONE_APPLICATION_ID);
071 return getWorkflowDocumentActionsService(standaloneApplicationId);
072 } else {
073 return getService(WORKFLOW_DOCUMENT_ACTIONS_SERVICE);
074 }
075 }
076
077 public static WorkflowDocumentActionsService getWorkflowDocumentActionsService(String applicationId){
078 if(!StringUtils.isEmpty(applicationId)){//Need to find out proper remote endpoint in this case
079 QName qN = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, KewApiConstants.ServiceNames.WORKFLOW_DOCUMENT_ACTIONS_SERVICE_SOAP);
080 //http://rice.kuali.org/kew/v2_0}workflowDocumentActionsService
081 return (WorkflowDocumentActionsService)KsbApiServiceLocator.getServiceBus().getService(qN, applicationId);
082 }else{//we can use the default internal service here since we dont have an applicationId
083 return getWorkflowDocumentActionsService();
084 }
085 }
086
087 public static WorkflowDocumentService getWorkflowDocumentService() {
088 return getService(WORKFLOW_DOCUMENT_SERVICE);
089 }
090
091 public static ActionListService getActionListService() {
092 return getService(ACTION_LIST_SERVICE);
093 }
094
095 public static DocumentTypeService getDocumentTypeService() {
096 return getService(DOCUMENT_TYPE_SERVICE);
097 }
098
099 public static NoteService getNoteService() {
100 return getService(NOTE_SERVICE);
101 }
102
103 public static RuleService getRuleService() {
104 return getService(RULE_SERVICE);
105 }
106
107 public static ExtensionRepositoryService getExtensionRepositoryService() {
108 return getService(EXTENSION_REPOSITORY_SERVICE);
109 }
110
111 public static KewTypeRepositoryService getKewTypeRepositoryService() {
112 return getService(KEW_TYPE_REPOSITORY_SERVICE);
113 }
114
115 public static PeopleFlowService getPeopleFlowService() {
116 return getService(PEOPLE_FLOW_SERVICE);
117 }
118
119 public static DocumentAttributeIndexingQueue getDocumentAttributeIndexingQueue() {
120 return getDocumentAttributeIndexingQueue(null);
121 }
122
123 public static DocumentAttributeIndexingQueue getDocumentAttributeIndexingQueue(String applicationId) {
124 return (DocumentAttributeIndexingQueue)KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(DOCUMENT_ATTRIBUTE_INDEXING_QUEUE_NAME, applicationId);
125 }
126
127 public static GroupMembershipChangeQueue getGroupMembershipChangeQueue() {
128 return (GroupMembershipChangeQueue)KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(GROUP_MEMBERSHIP_CHANGE_QUEUE_NAME);
129 }
130
131 public static ResponsibilityChangeQueue getResponsibilityChangeQueue() {
132 return (ResponsibilityChangeQueue)KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(
133 RESPONSIBILITY_CHANGE_QUEUE);
134 }
135
136 public static ImmediateEmailReminderQueue getImmediateEmailReminderQueue() {
137 return KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(IMMEDIATE_EMAIL_REMINDER_QUEUE);
138 }
139
140 public static PreferencesService getPreferencesService() {
141 return getService(PREFERENCES_SERVICE);
142 }
143 }