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