001/** 002 * Copyright 2005-2014 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 */ 016package org.kuali.rice.kew.service; 017 018import org.apache.log4j.Logger; 019import org.kuali.rice.core.api.config.module.RunMode; 020import org.kuali.rice.core.api.config.property.ConfigContext; 021import org.kuali.rice.core.api.encryption.EncryptionService; 022import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 023import org.kuali.rice.edl.framework.extract.ExtractService; 024import org.kuali.rice.kew.actionlist.service.ActionListService; 025import org.kuali.rice.kew.actionrequest.service.ActionRequestService; 026import org.kuali.rice.kew.actions.ActionRegistry; 027import org.kuali.rice.kew.actiontaken.service.ActionTakenService; 028import org.kuali.rice.kew.api.KewApiConstants; 029import org.kuali.rice.kew.batch.XmlPollerService; 030import org.kuali.rice.kew.docsearch.DocumentSearchCustomizationMediator; 031import org.kuali.rice.kew.docsearch.service.DocumentSearchService; 032import org.kuali.rice.kew.doctype.service.DocumentSecurityService; 033import org.kuali.rice.kew.doctype.service.DocumentTypePermissionService; 034import org.kuali.rice.kew.doctype.service.DocumentTypeService; 035import org.kuali.rice.kew.documentlink.service.DocumentLinkService; 036import org.kuali.rice.kew.engine.WorkflowEngineFactory; 037import org.kuali.rice.kew.engine.node.service.BranchService; 038import org.kuali.rice.kew.engine.node.service.RouteNodeService; 039import org.kuali.rice.kew.engine.simulation.SimulationWorkflowEngine; 040import org.kuali.rice.kew.exception.WorkflowDocumentExceptionRoutingService; 041import org.kuali.rice.kew.identity.service.IdentityHelperService; 042import org.kuali.rice.kew.impl.document.WorkflowDocumentPrototype; 043import org.kuali.rice.kew.mail.service.ActionListEmailService; 044import org.kuali.rice.kew.mail.service.EmailContentService; 045import org.kuali.rice.kew.notes.service.NoteService; 046import org.kuali.rice.kew.notification.service.NotificationService; 047import org.kuali.rice.kew.responsibility.service.ResponsibilityIdService; 048import org.kuali.rice.kew.role.service.RoleService; 049import org.kuali.rice.kew.routeheader.service.RouteHeaderService; 050import org.kuali.rice.kew.routeheader.service.WorkflowDocumentService; 051import org.kuali.rice.kew.routemodule.service.RouteModuleService; 052import org.kuali.rice.kew.routemodule.service.RoutingReportService; 053import org.kuali.rice.kew.rule.WorkflowRuleAttributeMediator; 054import org.kuali.rice.kew.rule.service.RuleAttributeService; 055import org.kuali.rice.kew.rule.service.RuleDelegationService; 056import org.kuali.rice.kew.rule.service.RuleServiceInternal; 057import org.kuali.rice.kew.rule.service.RuleTemplateService; 058import org.kuali.rice.kew.useroptions.UserOptionsService; 059import org.kuali.rice.kew.validation.RuleValidationAttributeResolver; 060import org.springframework.cache.CacheManager; 061import org.springframework.transaction.PlatformTransactionManager; 062 063import javax.persistence.EntityManagerFactory; 064import javax.sql.DataSource; 065import javax.transaction.TransactionManager; 066import javax.transaction.UserTransaction; 067import javax.xml.namespace.QName; 068 069 070/** 071 * Convenience class that holds service names and provide methods to acquire services. Defaults to 072 * GLR for actual service acquisition. Used to be responsible for loading and holding spring 073 * application context (when it was SpringServiceLocator) but those responsibilities have been 074 * moved to the SpringLoader. 075 * 076 * @author Kuali Rice Team (rice.collab@kuali.org) 077 * 078 */ 079public final class KEWServiceLocator { 080 081 private static final Logger LOG = Logger.getLogger(KEWServiceLocator.class); 082 083 public static final String KEW_RUN_MODE_PROPERTY = "kew.mode"; 084 085 public static final String DATASOURCE = "kewDataSource"; 086 087 public static final String QUICK_LINKS_SERVICE = "enQuickLinksService"; 088 089 public static final String DOCUMENT_SEARCH_SERVICE = "enDocumentSearchService"; 090 091 public static final String ACTION_TAKEN_SRV = "enActionTakenService"; 092 093 public static final String ACTION_REQUEST_SRV = "enActionRequestService"; 094 095 public static final String ACTION_LIST_SRV = "enActionListService"; 096 097 public static final String DOC_ROUTE_HEADER_SRV = "enDocumentRouteHeaderService"; 098 099 public static final String DOCUMENT_TYPE_GROUP_SERVICE = "enDocumentTypeGroupService"; 100 101 public static final String DOCUMENT_TYPE_SERVICE = "enDocumentTypeService"; 102 103 public static final String DOCUMENT_TYPE_PERMISSION_SERVICE = "enDocumentTypePermissionService"; 104 105 public static final String DOCUMENT_SECURITY_SERVICE = "enDocumentSecurityService"; 106 107 public static final String USER_OPTIONS_SRV = "enUserOptionsService"; 108 109 public static final String DOCUMENT_CHANGE_HISTORY_SRV = "enDocumentChangeHistoryService"; 110 111 public static final String DOCUMENT_VALUE_INDEX_SRV = "enDocumentValueIndexService"; 112 113 public static final String ROUTE_LEVEL_SERVICE = "enRouteLevelService"; 114 115 public static final String CONSTANTS_SERVICE = "enApplicationConstantsService"; 116 117 public static final String ROUTE_LOG_SERVICE = "enRouteLogService"; 118 119 public static final String RULE_TEMPLATE_SERVICE = "enRuleTemplateService"; 120 121 public static final String RULE_SERVICE = "enRuleServiceInternal"; 122 123 public static final String RULE_ATTRIBUTE_SERVICE = "enRuleAttributeService"; 124 125 public static final String RULE_TEMPLATE_ATTRIBUTE_SERVICE = "enRuleTemplateAttributeService"; 126 127 public static final String ROLE_SERVICE = "enRoleService"; 128 129 public static final String RESPONSIBILITY_ID_SERVICE = "enResponsibilityIdService"; 130 131 public static final String STATS_SERVICE = "enStatsService"; 132 133 public static final String ROUTE_MANAGER_QUEUE_SERVICE = "enRouteManagerQueueService"; 134 135 public static final String ROUTE_MANAGER_CONTROLLER = "enRouteManagerController"; 136 137 public static final String RULE_DELEGATION_SERVICE = "enRuleDelegationService"; 138 139 public static final String ROUTE_MANAGER_DRIVER = "enRouteManagerDriver"; 140 141 public static final String OPTIMISTIC_LOCK_FAILURE_SERVICE = "enOptimisticLockFailureService"; 142 143 public static final String NOTE_SERVICE = "enNoteService"; 144 145 public static final String ROUTING_REPORT_SERVICE = "enRoutingReportService"; 146 147 public static final String ROUTE_MODULE_SERVICE = "enRouteModuleService"; 148 149 public static final String EXCEPTION_ROUTING_SERVICE = "enExceptionRoutingService"; 150 151 public static final String ACTION_REGISTRY = "enActionRegistry"; 152 153 public static final String BRANCH_SERVICE = "enBranchService"; 154 155 public static final String WORKFLOW_MBEAN = "workflowMBean"; 156 157 public static final String JTA_TRANSACTION_MANAGER = "jtaTransactionManager"; 158 159 public static final String USER_TRANSACTION = "userTransaction"; 160 161 public static final String SCHEDULER = "enScheduler"; 162 163 public static final String DOCUMENT_LINK_SERVICE = "enDocumentLinkService"; 164 165 /** 166 * Polls for xml files on disk 167 */ 168 public static final String XML_POLLER_SERVICE = "enXmlPollerService"; 169 170 public static final String DB_TABLES_LOADER = "enDbTablesLoader"; 171 172 public static final String ROUTE_NODE_SERVICE = "enRouteNodeService"; 173 174 public static final String SIMULATION_ENGINE = "simulationEngine"; 175 176 public static final String WORKFLOW_ENGINE_FACTORY = "workflowEngineFactory"; 177 178 public static final String ACTION_LIST_EMAIL_SERVICE = "enActionListEmailService"; 179 180 public static final String EMAIL_CONTENT_SERVICE = "enEmailContentService"; 181 182 public static final String NOTIFICATION_SERVICE = "enNotificationService"; 183 184 public static final String TRANSACTION_MANAGER = "transactionManager"; 185 186 public static final String TRANSACTION_TEMPLATE = "transactionTemplate"; 187 188 public static final String WORKFLOW_DOCUMENT_SERVICE = "enWorkflowDocumentService"; 189 190 public static final String EXTENSION_SERVICE = "enExtensionService"; 191 192 public static final String TRANSFORMATION_SERVICE = "enTransformationService"; 193 194 public static final String REMOVE_REPLACE_DOCUMENT_SERVICE = "enRemoveReplaceDocumentService"; 195 196 public static final String EXTRACT_SERVICE = "enExtractService"; 197 198 public static final String IDENTITY_HELPER_SERVICE = "kewIdentityHelperService"; 199 200 public static final String ENTITY_MANAGER_FACTORY = "kewEntityManagerFactory"; 201 202 public static final String MAILER = "mailer"; 203 204 public static final String WORKFLOW_DOCUMENT_PROTOTYPE = "rice.kew.workflowDocumentPrototype"; 205 206 public static final String DOCUMENT_SEARCH_CUSTOMIZATION_MEDIATOR = "rice.kew.documentSearchCustomizationMediator"; 207 208 public static final String RULE_VALIDATION_ATTRIBUTE_RESOLVER = "rice.kew.ruleValidationAttributeResolver"; 209 210 public static final String WORKFLOW_RULE_ATTRIBUTE_MEDIATOR = "rice.kew.workflowRuleAttributeMediator"; 211 212 public static final String LOCAL_CACHE_MANAGER = "kewLocalCacheManager"; 213 214 public static EntityManagerFactory getEntityManagerFactory() { 215 return (EntityManagerFactory) getService(ENTITY_MANAGER_FACTORY); 216 } 217 218 /** 219 * @param serviceName 220 * the name of the service bean 221 * @return the service 222 */ 223 public static <T> T getService(String serviceName) { 224 return KEWServiceLocator.<T>getBean(serviceName); 225 } 226 227 public static <T> T getBean(String serviceName) { 228 if ( LOG.isDebugEnabled() ) { 229 LOG.debug("Fetching service " + serviceName); 230 } 231 QName name = new QName(serviceName); 232 RunMode kewRunMode = RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KEW_RUN_MODE_PROPERTY)); 233 if (kewRunMode == RunMode.REMOTE || kewRunMode == RunMode.THIN) { 234 if (!serviceName.equals(WORKFLOW_DOCUMENT_PROTOTYPE)) { 235 name = new QName(KewApiConstants.Namespaces.KEW_NAMESPACE_2_0, serviceName); 236 } else { 237 name = new QName(serviceName); 238 } 239 } 240 return GlobalResourceLoader.getResourceLoader().<T>getService(name); 241 } 242 243 public static DocumentTypeService getDocumentTypeService() { 244 return (DocumentTypeService) getBean(DOCUMENT_TYPE_SERVICE); 245 } 246 247 public static DocumentTypePermissionService getDocumentTypePermissionService() { 248 return (DocumentTypePermissionService) getBean(DOCUMENT_TYPE_PERMISSION_SERVICE); 249 } 250 251 public static DocumentSecurityService getDocumentSecurityService() { 252 return (DocumentSecurityService) getBean(DOCUMENT_SECURITY_SERVICE); 253 } 254 255 256 public static ActionRequestService getActionRequestService() { 257 return (ActionRequestService) getBean(ACTION_REQUEST_SRV); 258 } 259 260 public static ActionTakenService getActionTakenService() { 261 return (ActionTakenService) getBean(ACTION_TAKEN_SRV); 262 } 263 264 public static ResponsibilityIdService getResponsibilityIdService() { 265 return (ResponsibilityIdService) getBean(RESPONSIBILITY_ID_SERVICE); 266 } 267 268 public static RouteHeaderService getRouteHeaderService() { 269 return (RouteHeaderService) getBean(DOC_ROUTE_HEADER_SRV); 270 } 271 272 public static RuleTemplateService getRuleTemplateService() { 273 return (RuleTemplateService) getBean(RULE_TEMPLATE_SERVICE); 274 } 275 276 public static RuleAttributeService getRuleAttributeService() { 277 return (RuleAttributeService) getBean(RULE_ATTRIBUTE_SERVICE); 278 } 279 280 public static WorkflowDocumentService getWorkflowDocumentService() { 281 return (WorkflowDocumentService) getBean(WORKFLOW_DOCUMENT_SERVICE); 282 } 283 284 public static RouteModuleService getRouteModuleService() { 285 return (RouteModuleService) getBean(ROUTE_MODULE_SERVICE); 286 } 287 288 public static RoleService getRoleService() { 289 return (RoleService) getBean(ROLE_SERVICE); 290 } 291 292 public static RuleServiceInternal getRuleService() { 293 return (RuleServiceInternal) getBean(RULE_SERVICE); 294 } 295 296 public static RuleDelegationService getRuleDelegationService() { 297 return (RuleDelegationService) getBean(RULE_DELEGATION_SERVICE); 298 } 299 300 public static RoutingReportService getRoutingReportService() { 301 return (RoutingReportService) getBean(ROUTING_REPORT_SERVICE); 302 } 303 304 public static XmlPollerService getXmlPollerService() { 305 return (XmlPollerService) getBean(XML_POLLER_SERVICE); 306 } 307 308 public static UserOptionsService getUserOptionsService() { 309 return (UserOptionsService) getBean(USER_OPTIONS_SRV); 310 } 311 312 public static ActionListService getActionListService() { 313 return (ActionListService) getBean(ACTION_LIST_SRV); 314 } 315 316 public static RouteNodeService getRouteNodeService() { 317 return (RouteNodeService) getBean(ROUTE_NODE_SERVICE); 318 } 319 320 public static SimulationWorkflowEngine getSimulationEngine() { 321 return (SimulationWorkflowEngine) getBean(SIMULATION_ENGINE); 322 } 323 324 public static WorkflowEngineFactory getWorkflowEngineFactory() { 325 return (WorkflowEngineFactory) getBean(WORKFLOW_ENGINE_FACTORY); 326 } 327 328 public static WorkflowDocumentExceptionRoutingService getExceptionRoutingService() { 329 return (WorkflowDocumentExceptionRoutingService) getBean(EXCEPTION_ROUTING_SERVICE); 330 } 331 332 public static ActionListEmailService getActionListEmailService() { 333 return (ActionListEmailService) getBean(KEWServiceLocator.ACTION_LIST_EMAIL_SERVICE); 334 } 335 336 public static EmailContentService getEmailContentService() { 337 return (EmailContentService) getBean(KEWServiceLocator.EMAIL_CONTENT_SERVICE); 338 } 339 340 public static NotificationService getNotificationService() { 341 return (NotificationService) getBean(KEWServiceLocator.NOTIFICATION_SERVICE); 342 } 343 344 public static TransactionManager getTransactionManager() { 345 return (TransactionManager) getBean(JTA_TRANSACTION_MANAGER); 346 } 347 348 public static UserTransaction getUserTransaction() { 349 return (UserTransaction) getBean(USER_TRANSACTION); 350 } 351 352 public static NoteService getNoteService() { 353 return (NoteService) getBean(NOTE_SERVICE); 354 } 355 356 public static ActionRegistry getActionRegistry() { 357 return (ActionRegistry) getBean(ACTION_REGISTRY); 358 } 359 360 public static BranchService getBranchService() { 361 return (BranchService) getBean(BRANCH_SERVICE); 362 } 363 364 public static DocumentSearchService getDocumentSearchService() { 365 return (DocumentSearchService) getBean(DOCUMENT_SEARCH_SERVICE); 366 } 367 368 public static ExtractService getExtractService() { 369 return (ExtractService) getBean(EXTRACT_SERVICE); 370 } 371 372 public static IdentityHelperService getIdentityHelperService() { 373 return (IdentityHelperService) getBean(IDENTITY_HELPER_SERVICE); 374 } 375 376 public static DocumentLinkService getDocumentLinkService(){ 377 return (DocumentLinkService) getBean(DOCUMENT_LINK_SERVICE); 378 } 379 380 /** 381 * For the following methods, we go directly to the SpringLoader because we do NOT want them to 382 * be wrapped in any sort of proxy. 383 */ 384 385 public static DataSource getDataSource() { 386 return (DataSource) getBean(DATASOURCE); 387 } 388 389 public static PlatformTransactionManager getPlatformTransactionManager() { 390 return (PlatformTransactionManager) getBean(TRANSACTION_MANAGER); 391 } 392 393 public static WorkflowDocumentPrototype getWorkflowDocumentPrototype() { 394 return getBean(WORKFLOW_DOCUMENT_PROTOTYPE); 395 } 396 397 public static DocumentSearchCustomizationMediator getDocumentSearchCustomizationMediator() { 398 return getBean(DOCUMENT_SEARCH_CUSTOMIZATION_MEDIATOR); 399 } 400 401 public static WorkflowRuleAttributeMediator getWorkflowRuleAttributeMediator() { 402 return getBean(WORKFLOW_RULE_ATTRIBUTE_MEDIATOR); 403 } 404 405 public static RuleValidationAttributeResolver getRuleValidationAttributeResolver() { 406 return getBean(RULE_VALIDATION_ATTRIBUTE_RESOLVER); 407 } 408 409 public static CacheManager getLocalCacheManager() { 410 return (CacheManager) getService(LOCAL_CACHE_MANAGER); 411 } 412}