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.time.timesheet;
17  
18  import java.util.HashMap;
19  import java.util.LinkedList;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.kuali.hr.core.document.calendar.CalendarDocumentContract;
24  import org.kuali.hr.job.Job;
25  import org.kuali.hr.time.assignment.Assignment;
26  import org.kuali.hr.time.calendar.CalendarEntries;
27  import org.kuali.hr.time.timeblock.TimeBlock;
28  import org.kuali.hr.time.timesummary.TimeSummary;
29  import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
30  
31  
32  public class TimesheetDocument implements CalendarDocumentContract {
33  
34  	public static final String TIMESHEET_DOCUMENT_TYPE = "TimesheetDocument";
35  
36  	private TimesheetDocumentHeader documentHeader;
37  	private List<Assignment> assignments = new LinkedList<Assignment>();
38  	private List<Job> jobs = new LinkedList<Job>();
39  	private List<TimeBlock> timeBlocks = new LinkedList<TimeBlock>();
40  	private CalendarEntries calendarEntry = null; // Was a Hidden NPE, now more exposed // new PayCalendarEntries();
41  	private TimeSummary timeSummary = new TimeSummary();
42  	private Map<Long, Job> jobNumberToJobMap = new HashMap<Long,Job>();
43  
44  	public TimesheetDocument(TimesheetDocumentHeader documentHeader) {
45  		this.documentHeader = documentHeader;
46  	}
47  
48      @Override
49  	public TimesheetDocumentHeader getDocumentHeader() {
50  		return documentHeader;
51  	}
52  
53  	public void setDocumentHeader(TimesheetDocumentHeader documentHeader) {
54  		this.documentHeader = documentHeader;
55  	}
56  
57      @Override
58  	public List<Assignment> getAssignments() {
59  		return assignments;
60  	}
61  
62  	public void setAssignments(List<Assignment> assignments) {
63  		this.assignments = assignments;
64  	}
65  
66  	public List<Job> getJobs() {
67  		return jobs;
68  	}
69  
70  	public void setJobs(List<Job> jobs) {
71  		this.jobs = jobs;
72  		jobNumberToJobMap.clear();
73  		if(jobs!=null){
74  			for(Job job : jobs){
75  				jobNumberToJobMap.put(job.getJobNumber(), job);
76  			}
77  		}
78  	}
79  
80  	public List<TimeBlock> getTimeBlocks() {
81  		return timeBlocks;
82  	}
83  
84  	public void setTimeBlocks(List<TimeBlock> timeBlocks) {
85  		this.timeBlocks = timeBlocks;
86  	}
87  
88      @Override
89  	public CalendarEntries getCalendarEntry() {
90  		return calendarEntry;
91  	}
92  
93  	public void setCalendarEntry(CalendarEntries calendarEntry) {
94  		this.calendarEntry = calendarEntry;
95  	}
96  
97  	public void setTimeSummary(TimeSummary timeSummary) {
98  		this.timeSummary = timeSummary;
99  	}
100 
101 	public TimeSummary getTimeSummary() {
102 		return timeSummary;
103 	}
104 
105 	public String getPrincipalId(){
106 		return getDocumentHeader().getPrincipalId();
107 	}
108 
109 	public Job getJob(Long jobNumber){
110 		return jobNumberToJobMap.get(jobNumber);
111 	}
112 
113     @Override
114 	public java.sql.Date getAsOfDate(){
115 		return new java.sql.Date(getCalendarEntry().getBeginPeriodDateTime().getTime());
116 	}
117     
118     public java.sql.Date getDocEndDate(){
119 		return new java.sql.Date(getCalendarEntry().getEndPeriodDateTime().getTime());
120 	}
121 
122 	public String getDocumentId(){
123 		return this.getDocumentHeader().getDocumentId();
124 	}
125 }