View Javadoc

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