001    /**
002     * Copyright 2004-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.hr.time.timesheet;
017    
018    import java.util.HashMap;
019    import java.util.LinkedList;
020    import java.util.List;
021    import java.util.Map;
022    
023    import org.kuali.hr.job.Job;
024    import org.kuali.hr.time.assignment.Assignment;
025    import org.kuali.hr.time.calendar.CalendarEntries;
026    import org.kuali.hr.time.timeblock.TimeBlock;
027    import org.kuali.hr.time.timesummary.TimeSummary;
028    import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
029    
030    
031    public class TimesheetDocument  {
032    
033            public static final String TIMESHEET_DOCUMENT_TYPE = "TimesheetDocument";
034    
035            private TimesheetDocumentHeader documentHeader;
036            private List<Assignment> assignments = new LinkedList<Assignment>();
037            private List<Job> jobs = new LinkedList<Job>();
038            private List<TimeBlock> timeBlocks = new LinkedList<TimeBlock>();
039            private CalendarEntries payCalendarEntry = null; // Was a Hidden NPE, now more exposed // new PayCalendarEntries();
040            private TimeSummary timeSummary = new TimeSummary();
041            private Map<Long, Job> jobNumberToJobMap = new HashMap<Long,Job>();
042    
043            public TimesheetDocument(TimesheetDocumentHeader documentHeader) {
044                    this.documentHeader = documentHeader;
045            }
046    
047            public TimesheetDocumentHeader getDocumentHeader() {
048                    return documentHeader;
049            }
050    
051            public void setDocumentHeader(TimesheetDocumentHeader documentHeader) {
052                    this.documentHeader = documentHeader;
053            }
054    
055            public List<Assignment> getAssignments() {
056                    return assignments;
057            }
058    
059            public void setAssignments(List<Assignment> assignments) {
060                    this.assignments = assignments;
061            }
062    
063            public List<Job> getJobs() {
064                    return jobs;
065            }
066    
067            public void setJobs(List<Job> jobs) {
068                    this.jobs = jobs;
069                    jobNumberToJobMap.clear();
070                    if(jobs!=null){
071                            for(Job job : jobs){
072                                    jobNumberToJobMap.put(job.getJobNumber(), job);
073                            }
074                    }
075            }
076    
077            public List<TimeBlock> getTimeBlocks() {
078                    return timeBlocks;
079            }
080    
081            public void setTimeBlocks(List<TimeBlock> timeBlocks) {
082                    this.timeBlocks = timeBlocks;
083            }
084    
085        public CalendarEntries getPayCalendarEntry() {
086                    return payCalendarEntry;
087            }
088    
089            public void setPayCalendarEntry(CalendarEntries payCalendarEntry) {
090                    this.payCalendarEntry = payCalendarEntry;
091            }
092    
093            public void setTimeSummary(TimeSummary timeSummary) {
094                    this.timeSummary = timeSummary;
095            }
096    
097            public TimeSummary getTimeSummary() {
098                    return timeSummary;
099            }
100    
101            public String getPrincipalId(){
102                    return getDocumentHeader().getPrincipalId();
103            }
104    
105            public Job getJob(Long jobNumber){
106                    return jobNumberToJobMap.get(jobNumber);
107            }
108    
109        public java.sql.Date getAsOfDate(){
110                    return new java.sql.Date(getPayCalendarEntry().getBeginPeriodDateTime().getTime());
111            }
112        
113        public java.sql.Date getDocEndDate(){
114                    return new java.sql.Date(getPayCalendarEntry().getEndPeriodDateTime().getTime());
115            }
116    
117            public String getDocumentId(){
118                    return this.getDocumentHeader().getDocumentId();
119            }
120    }