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.leave.timeoff.service;
17  
18  import org.apache.log4j.Logger;
19  import org.joda.time.LocalDate;
20  import org.kuali.kpme.core.api.assignment.Assignment;
21  import org.kuali.kpme.core.api.job.JobContract;
22  import org.kuali.kpme.core.api.namespace.KPMENamespace;
23  import org.kuali.kpme.core.api.permission.KPMEPermissionTemplate;
24  import org.kuali.kpme.core.role.KPMERoleMemberAttribute;
25  import org.kuali.kpme.core.service.HrServiceLocator;
26  import org.kuali.kpme.core.util.HrConstants;
27  import org.kuali.kpme.tklm.api.leave.timeoff.SystemScheduledTimeOffService;
28  import org.kuali.kpme.tklm.leave.timeoff.SystemScheduledTimeOff;
29  import org.kuali.kpme.tklm.leave.timeoff.dao.SystemScheduledTimeOffDao;
30  import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
31  import org.kuali.rice.kim.api.KimConstants;
32  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33  
34  import java.math.BigDecimal;
35  import java.util.ArrayList;
36  import java.util.HashMap;
37  import java.util.List;
38  import java.util.Map;
39  
40  public class SystemScheduledTimeOffServiceImpl implements SystemScheduledTimeOffService {
41  
42  	private static final Logger LOG = Logger.getLogger(SystemScheduledTimeOffServiceImpl.class);
43  	private SystemScheduledTimeOffDao systemScheduledTimeOffDao;
44  
45  	public SystemScheduledTimeOffDao getSystemScheduledTimeOffDao() {
46  		return systemScheduledTimeOffDao;
47  	}
48  
49  	public void setSystemScheduledTimeOffDao(
50  			SystemScheduledTimeOffDao systemScheduledTimeOffDao) {
51  		this.systemScheduledTimeOffDao = systemScheduledTimeOffDao;
52  	}
53  
54  	@Override
55  	public SystemScheduledTimeOff getSystemScheduledTimeOff(String lmSystemScheduledTimeOffId) {
56  		return getSystemScheduledTimeOffDao().getSystemScheduledTimeOff(lmSystemScheduledTimeOffId);
57  	}
58  
59  	@Override
60  	public List<SystemScheduledTimeOff> getSystemScheduledTimeOffForPayPeriod(
61  			String leavePlan, LocalDate startDate, LocalDate endDate) {
62  		return getSystemScheduledTimeOffDao().getSystemScheduledTimeOffForPayPeriod(leavePlan, startDate, endDate);
63  	}
64  
65  	@Override
66  	public SystemScheduledTimeOff getSystemScheduledTimeOffByDate(
67  			String leavePlan, LocalDate startDate) {
68  		return getSystemScheduledTimeOffDao().getSystemScheduledTimeOffByDate(leavePlan, startDate);
69  	}	
70  	/*@Override
71  	public Assignment getAssignmentToApplyHolidays(TimesheetDocument timesheetDocument, LocalDate payEndDate) {
72  		JobContract primaryJob = HrServiceLocator.getJobService().getPrimaryJob(timesheetDocument.getPrincipalId(), payEndDate);
73  		for(Assignment assign : timesheetDocument.getAssignmentMap()){
74  			if(assign.getJobNumber().equals(primaryJob.getJobNumber())){
75  				return assign;
76  			}
77  		}
78  		return null;
79  	}*/
80  
81      @Override
82      public BigDecimal calculateSysSchTimeOffHours(JobContract job, BigDecimal sstoHours) {
83          BigDecimal fte = job.getStandardHours().divide(new BigDecimal(40.0),HrConstants.BIG_DECIMAL_SCALE);
84          return fte.multiply(sstoHours).setScale(HrConstants.BIG_DECIMAL_SCALE);
85      }
86  
87      @Override
88      public List<SystemScheduledTimeOff> getSystemScheduledTimeOffs(String userPrincipalId, LocalDate fromEffdt, LocalDate toEffdt, String earnCode, LocalDate fromAccruedDate, LocalDate toAccruedDate, 
89      		LocalDate fromSchTimeOffDate, LocalDate toSchTimeOffDate, String premiumEarnCode, String active, String showHist) {
90      	List<SystemScheduledTimeOff> results = new ArrayList<SystemScheduledTimeOff>();
91          
92      	List<SystemScheduledTimeOff> systemScheduledTimeOffObjs = systemScheduledTimeOffDao.getSystemScheduledTimeOffs(fromEffdt, toEffdt, earnCode, fromAccruedDate, toAccruedDate, fromSchTimeOffDate, 
93          															toSchTimeOffDate, premiumEarnCode, active, showHist);
94      
95      	for (SystemScheduledTimeOff systemScheduledTimeOffObj : systemScheduledTimeOffObjs) {
96          	Map<String, String> roleQualification = new HashMap<String, String>();
97          	roleQualification.put(KimConstants.AttributeConstants.PRINCIPAL_ID, userPrincipalId);
98          	roleQualification.put(KPMERoleMemberAttribute.LOCATION.getRoleMemberAttributeName(), systemScheduledTimeOffObj.getLocation());
99          	
100         	if (!KimApiServiceLocator.getPermissionService().isPermissionDefinedByTemplate(KPMENamespace.KPME_WKFLW.getNamespaceCode(),
101     				KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>())
102     		  || KimApiServiceLocator.getPermissionService().isAuthorizedByTemplate(userPrincipalId, KPMENamespace.KPME_WKFLW.getNamespaceCode(),
103     				  KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), new HashMap<String, String>(), roleQualification)) {
104         		results.add(systemScheduledTimeOffObj);
105         	}
106     	}
107     	
108     	return results;
109     }
110     
111     @Override
112     public List<SystemScheduledTimeOff> getSystemScheduledTimeOffsForLeavePlan(LocalDate fromAccruedDate, LocalDate toAccruedDate, String leavePlan) {
113     	return systemScheduledTimeOffDao.getSystemScheduledTimeOffsForLeavePlan(fromAccruedDate, toAccruedDate, leavePlan);
114     }
115 
116 	@Override
117 	public String getSSTODescriptionForDate(String leavePlan,
118 			LocalDate localDate) {
119 		String description = "";
120 		SystemScheduledTimeOff ssto = systemScheduledTimeOffDao.getSystemScheduledTimeOffByDate(leavePlan, localDate);
121 		if(ssto != null)
122 			description = ssto.getDescr();
123 		return description;
124 	}
125 
126 }