1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.service;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.kpme.core.accrualcategory.rule.service.AccrualCategoryRuleService;
20 import org.kuali.kpme.core.accrualcategory.service.AccrualCategoryService;
21 import org.kuali.kpme.core.assignment.service.AssignmentService;
22 import org.kuali.kpme.core.block.service.CalendarBlockService;
23 import org.kuali.kpme.core.calendar.entry.service.CalendarEntryService;
24 import org.kuali.kpme.core.calendar.service.CalendarService;
25 import org.kuali.kpme.core.department.service.DepartmentService;
26 import org.kuali.kpme.core.earncode.group.service.EarnCodeGroupService;
27 import org.kuali.kpme.core.earncode.security.service.EarnCodeSecurityService;
28 import org.kuali.kpme.core.earncode.service.EarnCodeService;
29 import org.kuali.kpme.core.institution.service.InstitutionService;
30 import org.kuali.kpme.core.job.service.JobService;
31 import org.kuali.kpme.core.leaveplan.service.LeavePlanService;
32 import org.kuali.kpme.core.location.service.LocationService;
33 import org.kuali.kpme.core.paygrade.service.PayGradeService;
34 import org.kuali.kpme.core.paystep.service.PayStepService;
35 import org.kuali.kpme.core.paytype.service.PayTypeService;
36 import org.kuali.kpme.core.position.service.PositionBaseService;
37 import org.kuali.kpme.core.principal.service.PrincipalHRAttributesService;
38 import org.kuali.kpme.core.salarygroup.service.SalaryGroupService;
39 import org.kuali.kpme.core.service.group.KPMEGroupService;
40 import org.kuali.kpme.core.service.notification.KPMENotificationService;
41 import org.kuali.kpme.core.service.permission.HRPermissionService;
42 import org.kuali.kpme.core.service.role.KPMERoleService;
43 import org.kuali.kpme.core.service.timezone.TimezoneService;
44 import org.kuali.kpme.core.task.service.TaskService;
45 import org.kuali.kpme.core.workarea.service.WorkAreaService;
46 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
47 import org.kuali.rice.core.impl.cache.DistributedCacheManagerDecorator;
48 import org.kuali.rice.krad.service.BusinessObjectService;
49 import org.springframework.beans.BeansException;
50 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
51 import org.springframework.context.ApplicationContext;
52 import org.springframework.context.ApplicationContextAware;
53 import org.springframework.transaction.PlatformTransactionManager;
54 import org.springframework.transaction.support.TransactionTemplate;
55
56 public class HrServiceLocator implements ApplicationContextAware {
57
58 public static String SPRING_BEANS = "classpath:org/kuai/kpme/core/config/CORESpringBeans.xml";
59 public static ApplicationContext CONTEXT;
60 private static final String HR_CALENDAR_BLOCK_SERVICE = "calendarBlockService";
61
62 public static final String HR_PAY_CALENDAR_SERVICE = "calendarService";
63 public static final String HR_PAY_CALENDAR_ENTRY_SERVICE = "calendarEntryService";
64 public static final String HR_SALARY_GROUP_SERVICE = "salaryGroupService";
65 public static final String HR_ACCRUAL_CATEGORY_SERVICE = "accrualCategoryService";
66 public static final String HR_ACCRUAL_CATEGORY_RULE_SERVICE = "accrualCategoryRuleService";
67 public static final String HR_TASK_SERVICE = "taskService";
68 public static final String HR_LOCATION_SERVICE = "locationService";
69 public static final String HR_PAY_GRADE_SERVICE = "payGradeService";
70 public static final String HR_PERSON_SERVICE = "tkPersonService";
71 public static final String HR_BATCH_JOB_SERVICE = "batchJobService";
72 public static final String HR_BATCH_JOB_ENTRY_SERVICE = "batchJobEntryService";
73 public static final String HR_POSITION_SERVICE = "positionBaseService";
74 public static final String HR_LEAVE_PLAN_SERVICE = "leavePlanService";
75 public static final String HR_PRINCIPAL_HR_ATTRIBUTES_SERVICE = "principalHRAttributesService";
76 public static final String HR_ASSIGNMENT_SERVICE = "assignmentService";
77 public static final String HR_JOB_SERVICE = "jobService";
78 public static final String HR_PAY_TYPE_SERVICE = "payTypeService";
79 public static final String HR_WORK_AREA_SERVICE = "workAreaService";
80 public static final String HR_DEPARTMENT_SERVICE = "departmentService";
81 public static final String HR_EARN_CODE = "earnCodeService";
82 public static final String HR_EARN_CODE_SECURITY = "earnCodeSecurityService";
83 public static final String HR_TIME_EARN_CODE_GROUP_SERVICE = "earnCodeGroupService";
84 public static final String HR_INSTITUTION_SERVICE = "institutionService";
85 public static final String HR_PAY_STEP_SERVICE = "payStepService";
86 public static final String TK_TIME_ZONE_SERVICE = "timezoneService";
87
88 public static final String HR_PERMISSION_SERVICE = "hrPermissionService";
89
90
91 public static final String KPME_DISTRIBUTED_CACHE_MANAGER = "kpmeDistributedCacheManager";
92 public static final String KPME_GROUP_SERVICE = "kpmeGroupService";
93 public static final String KPME_NOTIFICATION_SERVICE = "kpmeNotificationService";
94 public static final String KPME_ROLE_SERVICE = "kpmeRoleService";
95
96 public static Object getBean(String beanName) {
97 return CONTEXT.getBean(beanName);
98 }
99
100 public static PlatformTransactionManager getPlatformTransactionManager() {
101 return (PlatformTransactionManager)CONTEXT.getBean("transactionManager");
102 }
103
104 public static TransactionTemplate getTransactionTemplate() {
105 return new TransactionTemplate(getPlatformTransactionManager());
106 }
107
108 public static PayStepService getPayStepService() {
109 return (PayStepService) CONTEXT.getBean(HR_PAY_STEP_SERVICE);
110 }
111
112 public static InstitutionService getInstitutionService() {
113 return (InstitutionService) CONTEXT.getBean(HR_INSTITUTION_SERVICE);
114 }
115
116 public static TaskService getTaskService() {
117 return (TaskService) CONTEXT.getBean(HR_TASK_SERVICE);
118 }
119
120 public static SalaryGroupService getSalaryGroupService() {
121 return (SalaryGroupService) CONTEXT.getBean(HR_SALARY_GROUP_SERVICE);
122 }
123
124 public static DepartmentService getDepartmentService() {
125 return (DepartmentService) CONTEXT.getBean(HR_DEPARTMENT_SERVICE);
126 }
127
128 public static WorkAreaService getWorkAreaService() {
129 return (WorkAreaService)CONTEXT.getBean(HR_WORK_AREA_SERVICE);
130 }
131 public static AssignmentService getAssignmentService(){
132 return (AssignmentService)CONTEXT.getBean(HR_ASSIGNMENT_SERVICE);
133 }
134
135 public static JobService getJobService() {
136 return (JobService)CONTEXT.getBean(HR_JOB_SERVICE);
137 }
138
139 public static PayTypeService getPayTypeService() {
140 return (PayTypeService)CONTEXT.getBean(HR_PAY_TYPE_SERVICE);
141 }
142
143 public static EarnCodeSecurityService getEarnCodeSecurityService() {
144 return (EarnCodeSecurityService) CONTEXT.getBean(HR_EARN_CODE_SECURITY);
145 }
146
147 public static EarnCodeService getEarnCodeService() {
148 return (EarnCodeService) CONTEXT.getBean(HR_EARN_CODE);
149 }
150
151 public static EarnCodeGroupService getEarnCodeGroupService(){
152 return (EarnCodeGroupService) CONTEXT.getBean(HR_TIME_EARN_CODE_GROUP_SERVICE);
153 }
154
155 public static AccrualCategoryService getAccrualCategoryService() {
156 return (AccrualCategoryService)CONTEXT.getBean(HR_ACCRUAL_CATEGORY_SERVICE);
157 }
158
159 public static AccrualCategoryRuleService getAccrualCategoryRuleService() {
160 return (AccrualCategoryRuleService)CONTEXT.getBean(HR_ACCRUAL_CATEGORY_RULE_SERVICE);
161 }
162
163 public static LocationService getLocationService() {
164 return (LocationService)CONTEXT.getBean(HR_LOCATION_SERVICE);
165 }
166
167 public static PayGradeService getPayGradeService() {
168 return (PayGradeService)CONTEXT.getBean(HR_PAY_GRADE_SERVICE);
169 }
170
171 public static PositionBaseService getPositionService(){
172 return (PositionBaseService) CONTEXT.getBean(HR_POSITION_SERVICE);
173 }
174
175 public static LeavePlanService getLeavePlanService(){
176 return (LeavePlanService)CONTEXT.getBean(HR_LEAVE_PLAN_SERVICE);
177 }
178
179 public static PrincipalHRAttributesService getPrincipalHRAttributeService(){
180 return (PrincipalHRAttributesService)CONTEXT.getBean(HR_PRINCIPAL_HR_ATTRIBUTES_SERVICE);
181 }
182
183 public static CalendarService getCalendarService() {
184 return (CalendarService)CONTEXT.getBean(HR_PAY_CALENDAR_SERVICE);
185 }
186
187 public static CalendarEntryService getCalendarEntryService() {
188 return (CalendarEntryService)CONTEXT.getBean(HR_PAY_CALENDAR_ENTRY_SERVICE);
189 }
190
191 public static TimezoneService getTimezoneService(){
192 return (TimezoneService) CONTEXT.getBean(TK_TIME_ZONE_SERVICE);
193 }
194
195 public static DistributedCacheManagerDecorator getDistributedCacheManager() {
196 return (DistributedCacheManagerDecorator)CONTEXT.getBean(KPME_DISTRIBUTED_CACHE_MANAGER);
197 }
198
199 public static KPMEGroupService getKPMEGroupService() {
200 return (KPMEGroupService) CONTEXT.getBean(KPME_GROUP_SERVICE);
201 }
202
203 public static KPMENotificationService getKPMENotificationService() {
204 return (KPMENotificationService) CONTEXT.getBean(KPME_NOTIFICATION_SERVICE);
205 }
206
207 public static HRPermissionService getHRPermissionService() {
208 return (HRPermissionService) CONTEXT.getBean(HR_PERMISSION_SERVICE);
209 }
210
211 public static KPMERoleService getKPMERoleService() {
212 return (KPMERoleService) CONTEXT.getBean(KPME_ROLE_SERVICE);
213 }
214
215 @Override
216 public void setApplicationContext(ApplicationContext arg0)
217 throws BeansException {
218 CONTEXT = arg0;
219 }
220
221 public static CalendarBlockService getCalendarBlockService() {
222 return (CalendarBlockService) CONTEXT.getBean(HR_CALENDAR_BLOCK_SERVICE );
223 }
224
225
226
227
228
229
230
231
232
233 @SuppressWarnings("unchecked")
234 public static <T> T getService(final String serviceName) {
235
236 if (StringUtils.isBlank(serviceName)) {
237 throw new IllegalArgumentException("the service name is blank.");
238 }
239
240 try {
241 return (T) CONTEXT.getBean(serviceName);
242 } catch (NoSuchBeanDefinitionException e) {
243
244 return (T) GlobalResourceLoader.<T>getService(serviceName);
245 } catch (Exception ex) {
246
247 return (T)GlobalResourceLoader.<T>getService(serviceName);
248 }
249 }
250
251 }