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.hr.job.service;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.hr.job.Job;
20  import org.kuali.hr.job.dao.JobDao;
21  import org.kuali.hr.time.paytype.PayType;
22  import org.kuali.hr.time.service.base.TkServiceLocator;
23  import org.kuali.rice.kim.api.identity.Person;
24  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25  
26  import java.math.BigDecimal;
27  import java.util.*;
28  
29  /**
30   * Represents an implementation of {@link JobService}.
31   */
32  public class JobServiceImpl implements JobService {
33  
34      private JobDao jobDao;
35  
36      @Override
37      public void saveOrUpdate(Job job) {
38          jobDao.saveOrUpdate(job);
39      }
40  
41      @Override
42      public void saveOrUpdate(List<Job> jobList) {
43          jobDao.saveOrUpdate(jobList);
44      }
45  
46      public void setJobDao(JobDao jobDao) {
47          this.jobDao = jobDao;
48      }
49  
50      @Override
51      public List<Job> getJobs(String principalId, Date asOfDate) {
52          List<Job> jobs = jobDao.getJobs(principalId, asOfDate);
53  
54          for (Job job : jobs) {
55              PayType payType = TkServiceLocator.getPayTypeService().getPayType(
56                      job.getHrPayType(), asOfDate);
57              job.setPayTypeObj(payType);
58          }
59  
60          return jobs;
61      }
62  
63      @Override
64      public Job getJob(String principalId, Long jobNumber, Date asOfDate) {
65          return getJob(principalId, jobNumber, asOfDate, true);
66      }
67  
68      public Job getPrimaryJob(String principalId, Date payPeriodEndDate) {
69          return jobDao.getPrimaryJob(principalId, payPeriodEndDate);
70      }
71  
72      @Override
73      public Job getJob(String principalId, Long jobNumber, Date asOfDate,
74                        boolean chkDetails) {
75          Job job = jobDao.getJob(principalId, jobNumber, asOfDate);
76          if (job == null && chkDetails) {
77              return null;
78              //throw new RuntimeException("No job for principal : " + principalId
79              //        + " Job Number: " + jobNumber);
80          }
81          if (chkDetails) {
82              String hrPayType = job.getHrPayType();
83              if (StringUtils.isBlank(hrPayType)) {
84                  throw new RuntimeException("No pay type for this job!");
85              }
86              PayType payType = TkServiceLocator.getPayTypeService().getPayType(
87                      hrPayType, asOfDate);
88              if (payType == null)
89                  throw new RuntimeException("No paytypes defined for this job!");
90              job.setPayTypeObj(payType);
91          }
92          return job;
93      }
94  
95      @Override
96      public List<Job> getActiveJobsForPosition(String positionNbr, Date asOfDate) {
97          return jobDao.getActiveJobsForPosition(positionNbr, asOfDate);
98      }
99  
100     @Override
101     public List<Job> getActiveJobsForPayType(String hrPayType, Date asOfDate) {
102         return jobDao.getActiveJobsForPayType(hrPayType, asOfDate);
103     }
104 
105     @Override
106     public Job getJob(String hrJobId) {
107         return jobDao.getJob(hrJobId);
108     }
109 
110     @Override
111     public Job getMaxJob(String principalId) {
112         return jobDao.getMaxJob(principalId);
113     }
114 
115     @Override
116     public List<Job> getJobs(String principalId, String firstName, String lastName, String jobNumber,
117                              String dept, String positionNbr, String payType,
118                              java.sql.Date fromEffdt, java.sql.Date toEffdt, String active, String showHistory) {
119 
120         if (StringUtils.isNotEmpty(firstName) || StringUtils.isNotEmpty(lastName)) {
121             Map<String, String> fields = new HashMap<String, String>();
122             fields.put("firstName", firstName);
123             fields.put("lastName", lastName);
124             List<Person> people = KimApiServiceLocator.getPersonService().findPeople(fields);
125 
126             List<Job> jobs = new ArrayList<Job>();
127             for (Person p : people) {
128                 List<Job> jobsForPerson = jobDao.getJobs(p.getPrincipalId(), jobNumber, dept, positionNbr, payType, fromEffdt, toEffdt, active, showHistory);
129                 jobs.addAll(jobsForPerson);
130             }
131 
132             return jobs;
133         }
134 
135         return jobDao.getJobs(principalId, jobNumber, dept, positionNbr, payType, fromEffdt, toEffdt, active, showHistory);
136     }
137     
138     public int getJobCount(String principalId, Long jobNumber, String dept) {
139     	return jobDao.getJobCount(principalId, jobNumber, dept);
140     }
141     
142     @Override
143     public List<Job> getActiveLeaveJobs(String principalId, Date asOfDate) {
144     	return jobDao.getActiveLeaveJobs(principalId, asOfDate);
145     }
146     
147     @Override
148     public BigDecimal getFteSumForJobs(List<Job> jobs) {
149     	BigDecimal fteSum = new BigDecimal(0);
150     	for(Job aJob : jobs) {
151     		fteSum = fteSum.add(aJob.getFte());
152     	}
153     	return fteSum;
154     	
155     }
156     
157 	@Override
158 	public BigDecimal getFteSumForAllActiveLeaveEligibleJobs(String principalId, Date asOfDate) {
159 		BigDecimal fteSum = new BigDecimal(0);
160 		List<Job> lmEligibleJobs = jobDao.getActiveLeaveJobs(principalId, asOfDate);
161 		for(Job job : lmEligibleJobs) {
162 			fteSum = fteSum.add(job.getFte());
163 		}
164 		return fteSum;
165 	}
166     
167     @Override
168     public BigDecimal getStandardHoursSumForJobs(List<Job> jobs) {
169     	BigDecimal hoursSum = new BigDecimal(0);
170     	for(Job aJob : jobs) {
171     		hoursSum = hoursSum.add(aJob.getStandardHours());
172     	}
173     	return hoursSum;
174     }
175    
176     @Override
177     public List<Job> getAllActiveLeaveJobs(String principalId, Date asOfDate) {
178     	return jobDao.getAllActiveLeaveJobs(principalId, asOfDate);
179     }
180     
181     public List<Job> getInactiveLeaveJobs(Long jobNumber, Date startDate, Date endDate) {
182     	return jobDao.getInactiveLeaveJobs(jobNumber, startDate, endDate);
183     }
184     
185     @Override
186     public List<Job> getAllInActiveLeaveJobsInRange(String principalId, Date startDate, Date endDate) {
187     	return jobDao.getAllInActiveLeaveJobsInRange(principalId, startDate, endDate);
188     }
189     
190     @Override
191     public Job getMaxTimestampJob(String principalId) {
192     	return jobDao.getMaxTimestampJob(principalId);
193     }
194     
195 }