View Javadoc

1   /**
2    * Copyright 2004-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.kpme.tklm.time.service;
17  //import org.kuali.hr.time.paytype.service.PayTypeService;
18  //import org.kuali.hr.time.permission.service.TKPermissionService;
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.kpme.tklm.common.BatchJobService;
21  import org.kuali.kpme.tklm.time.approval.service.TimeApproveService;
22  import org.kuali.kpme.tklm.time.clocklog.service.ClockLogService;
23  import org.kuali.kpme.tklm.time.docsearch.TkSearchableAttributeService;
24  import org.kuali.kpme.tklm.time.missedpunch.service.MissedPunchService;
25  import org.kuali.kpme.tklm.time.rules.TkRuleControllerService;
26  import org.kuali.kpme.tklm.time.rules.clocklocation.service.ClockLocationRuleService;
27  import org.kuali.kpme.tklm.time.rules.graceperiod.service.GracePeriodService;
28  import org.kuali.kpme.tklm.time.rules.lunch.department.service.DepartmentLunchRuleService;
29  import org.kuali.kpme.tklm.time.rules.lunch.sys.service.SystemLunchRuleService;
30  import org.kuali.kpme.tklm.time.rules.overtime.daily.service.DailyOvertimeRuleService;
31  import org.kuali.kpme.tklm.time.rules.overtime.weekly.service.WeeklyOvertimeRuleService;
32  import org.kuali.kpme.tklm.time.rules.shiftdifferential.service.ShiftDifferentialRuleService;
33  import org.kuali.kpme.tklm.time.rules.timecollection.service.TimeCollectionRuleService;
34  import org.kuali.kpme.tklm.time.service.permission.TKPermissionService;
35  import org.kuali.kpme.tklm.time.timeblock.service.TimeBlockHistoryDetailService;
36  import org.kuali.kpme.tklm.time.timeblock.service.TimeBlockHistoryService;
37  import org.kuali.kpme.tklm.time.timeblock.service.TimeBlockService;
38  import org.kuali.kpme.tklm.time.timehourdetail.service.TimeHourDetailService;
39  import org.kuali.kpme.tklm.time.timesheet.service.TimesheetService;
40  import org.kuali.kpme.tklm.time.timesummary.service.TimeSummaryService;
41  import org.kuali.kpme.tklm.time.user.pref.service.UserPreferenceService;
42  import org.kuali.kpme.tklm.time.workflow.service.TimesheetDocumentHeaderService;
43  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
44  import org.springframework.beans.BeansException;
45  import org.springframework.beans.factory.NoSuchBeanDefinitionException;
46  import org.springframework.context.ApplicationContext;
47  import org.springframework.context.ApplicationContextAware;
48  import org.springframework.jdbc.core.JdbcTemplate;
49  import org.springmodules.orm.ojb.PersistenceBrokerTemplate;
50  
51  public class TkServiceLocator implements ApplicationContextAware {
52  	public static String SPRING_BEANS = "classpath:org/kuali/kpme/tklm/config/TKLMSpringBeans.xml";
53  	private static ApplicationContext CONTEXT;
54  	public static final String HR_BATCH_JOB_SERVICE = "batchJobService";
55  	public static final String TK_CLOCK_LOG_SERVICE = "clockLogService";
56  	public static final String TK_TIME_BLOCK_SERVICE = "timeBlockService";
57  	public static final String TK_TIME_BLOCK_HISTORY_SERVICE = "timeBlockHistoryService";
58  	public static final String TK_TIME_BLOCK_HISTORY_DETAIL_SERVICE = "timeBlockHistoryDetailService";
59  	public static final String TK_PERSISTENCE_BROKER_TEMPLATE = "tkPersistenceBrokerTemplate";
60  	public static final String TK_CACHE_MANAGER_SERVICE = "cacheManager";
61  	public static final String TK_TIMESHEET_SERVICE = "timesheetService";
62  	public static final String TK_TIMESHEET_DOCUMENT_HEADER_SERVICE = "timesheetDocumentHeaderService";
63  	public static final String TK_TIME_COLLECTION_RULE_SERVICE = "timeCollectionRuleService";
64  	public static final String TK_TIME_SUMMARY_SERVICE = "timeSummaryService";
65  	public static final String TK_TIME_EARN_CODE_GROUP_SERVICE = "earnCodeGroupService";
66  	public static final String TK_TIME_HOUR_DETAIL_SERVICE= "timeHourDetailService";
67  	public static final String TK_DAILY_OVERTIME_RULE_SERVICE = "dailyOvertimeRuleService";
68  	public static final String TK_WEEKLY_OVERTIME_RULE_SERVICE = "weeklyOvertimeRuleService";
69  	public static final String TK_SHIFT_DIFFERENTIAL_RULE_SERVICE = "shiftDifferentialRuleService";
70  	public static final String TK_CLOCK_LOCATION_RULE_SERVICE = "clockLocationService";
71  	public static final String TK_GRACE_PERIOD_SERVICE = "gracePeriodService";
72  	public static final String TK_SYSTEM_LUNCH_RULE_SERVICE = "systemLunchRuleService";
73  	public static final String TK_DEPT_LUNCH_RULE_SERVICE = "deptLunchRuleService";
74  	public static final String TK_PRINCIPAL_CALENDAR_SERVICE = "principalCalendarService";
75  	public static final String TK_USER_PREF_SERVICE = "userPrefService";
76  	public static final String TK_TIME_OFF_ACCRUAL_SERVICE = "timeOffAccrualService";
77      public static final String TK_APPROVE_SERVICE = "timeApproveService";
78      public static final String TK_MISSED_PUNCH_SERVICE = "missedPunchService";
79      public static final String TK_WARNINGS_SERVICE = "tkWarningService";
80      public static final String TK_SEARCH_ATTR_SERVICE = "tkSearchableAttributeService";
81  
82      public static final String TK_PERMISSION_SERVICE = "tkPermissionService";
83      public static final String TK_ROLE_SERVICE = "tkRoleService";
84      
85      public static MissedPunchService getMissedPunchService() {
86          return (MissedPunchService) CONTEXT.getBean(TK_MISSED_PUNCH_SERVICE);
87      }
88      
89  	public static BatchJobService getBatchJobService(){
90  		return (BatchJobService)CONTEXT.getBean(HR_BATCH_JOB_SERVICE );
91  	}
92  
93  	public static ShiftDifferentialRuleService getShiftDifferentialRuleService() {
94  		return (ShiftDifferentialRuleService) CONTEXT.getBean(TK_SHIFT_DIFFERENTIAL_RULE_SERVICE);
95  	}
96  
97  	public static WeeklyOvertimeRuleService getWeeklyOvertimeRuleService() {
98  		return (WeeklyOvertimeRuleService) CONTEXT.getBean(TK_WEEKLY_OVERTIME_RULE_SERVICE);
99  	}
100 
101 	public static DailyOvertimeRuleService getDailyOvertimeRuleService() {
102 		return (DailyOvertimeRuleService) CONTEXT.getBean(TK_DAILY_OVERTIME_RULE_SERVICE);
103 	}
104 	
105 	public static TimesheetDocumentHeaderService getTimesheetDocumentHeaderService() {
106 		return (TimesheetDocumentHeaderService) CONTEXT.getBean(TK_TIMESHEET_DOCUMENT_HEADER_SERVICE);
107 	}
108 
109 	public static TimesheetService getTimesheetService() {
110 		return (TimesheetService) CONTEXT.getBean(TK_TIMESHEET_SERVICE);
111 	}
112 
113 	public static ClockLogService getClockLogService(){
114 	    return (ClockLogService)CONTEXT.getBean(TK_CLOCK_LOG_SERVICE);
115 	}
116 
117 	public static TimeBlockService getTimeBlockService(){
118 		return (TimeBlockService)CONTEXT.getBean(TK_TIME_BLOCK_SERVICE);
119 	}
120 
121 	public static TimeBlockHistoryService getTimeBlockHistoryService(){
122 		return (TimeBlockHistoryService)CONTEXT.getBean(TK_TIME_BLOCK_HISTORY_SERVICE);
123 	}
124 	
125 	public static TimeBlockHistoryDetailService getTimeBlockHistoryDetailService(){
126 		return (TimeBlockHistoryDetailService)CONTEXT.getBean(TK_TIME_BLOCK_HISTORY_DETAIL_SERVICE);
127 	}
128 
129 	public static PersistenceBrokerTemplate getTkPersistenceBrokerTemplate() {
130 	    return (PersistenceBrokerTemplate) CONTEXT.getBean(TK_PERSISTENCE_BROKER_TEMPLATE);
131 	}
132 
133 	public static TkRuleControllerService getTkRuleControllerService(){
134 		return (TkRuleControllerService) CONTEXT.getBean("tkRuleControllerService");
135 	}
136 
137 	public static TimeCollectionRuleService getTimeCollectionRuleService() {
138 		return (TimeCollectionRuleService) CONTEXT.getBean(TK_TIME_COLLECTION_RULE_SERVICE);
139 	}
140 
141 	public static TimeSummaryService getTimeSummaryService(){
142 		return (TimeSummaryService) CONTEXT.getBean(TK_TIME_SUMMARY_SERVICE);
143 	}
144 
145 	public static TimeHourDetailService getTimeHourDetailService(){
146 		return (TimeHourDetailService) CONTEXT.getBean(TK_TIME_HOUR_DETAIL_SERVICE);
147 	}
148 
149 	public static ClockLocationRuleService getClockLocationRuleService(){
150 		return (ClockLocationRuleService) CONTEXT.getBean(TK_CLOCK_LOCATION_RULE_SERVICE);
151 	}
152 
153 	public static GracePeriodService getGracePeriodService(){
154 		return (GracePeriodService) CONTEXT.getBean(TK_GRACE_PERIOD_SERVICE);
155 	}
156 
157 	public static SystemLunchRuleService getSystemLunchRuleService(){
158 		return (SystemLunchRuleService) CONTEXT.getBean(TK_SYSTEM_LUNCH_RULE_SERVICE);
159 	}
160 
161 	public static DepartmentLunchRuleService getDepartmentLunchRuleService(){
162 		return (DepartmentLunchRuleService) CONTEXT.getBean(TK_DEPT_LUNCH_RULE_SERVICE);
163 	}
164 
165 	public static UserPreferenceService getUserPreferenceService(){
166 		return (UserPreferenceService) CONTEXT.getBean(TK_USER_PREF_SERVICE);
167 	}
168 
169 	public static TimeApproveService getTimeApproveService(){
170 		return (TimeApproveService)CONTEXT.getBean(TK_APPROVE_SERVICE);
171 	}
172 
173 	public static TkSearchableAttributeService getTkSearchableAttributeService(){
174 		return (TkSearchableAttributeService) CONTEXT.getBean(TK_SEARCH_ATTR_SERVICE);
175 	}
176     
177     public static TKPermissionService getTKPermissionService() {
178     	return (TKPermissionService) CONTEXT.getBean(TK_PERMISSION_SERVICE);
179     }
180 	
181 	@Override
182 	public void setApplicationContext(ApplicationContext arg0) throws BeansException {
183 	    CONTEXT = arg0;
184 	}
185 	
186 
187     /**
188      * This is for the approval only
189      */
190     public static JdbcTemplate getTkJdbcTemplate() {
191 		return (JdbcTemplate) CONTEXT.getBean("tkJdbcTemplate");
192 	}
193     
194     public static JdbcTemplate getRiceJdbcTemplate() {
195 		return (JdbcTemplate) CONTEXT.getBean("riceJdbcTemplate");
196 	}
197 
198     /**
199      * Lookups a service by name.
200      *
201      * @param serviceName name of the Interface class of the service you want
202      * @param <T> the type of service you want.
203      * @return the service
204      * @throws IllegalArgumentException if the service name is blank.
205      */
206     @SuppressWarnings("unchecked")
207     public static <T> T getService(final String serviceName) {
208 
209         if (StringUtils.isBlank(serviceName)) {
210             throw new IllegalArgumentException("the service name is blank.");
211         }
212 
213         try {
214             return (T) CONTEXT.getBean(serviceName);
215         } catch (NoSuchBeanDefinitionException e) {
216             // If we don't find this service locally, look for it in the Rice context
217             return (T) GlobalResourceLoader.<T>getService(serviceName);
218         } catch (Exception ex) {
219             //ex.printStackTrace();
220             return (T)GlobalResourceLoader.<T>getService(serviceName);
221         }
222     }
223 
224 }