001    /**
002     * Copyright 2004-2012 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            public static final String TIMESHEET_DOCUMENT_TITLE = "TimesheetDocument";
035    
036            private TimesheetDocumentHeader documentHeader;
037            private List<Assignment> assignments = new LinkedList<Assignment>();
038            private List<Job> jobs = new LinkedList<Job>();
039            private List<TimeBlock> timeBlocks = new LinkedList<TimeBlock>();
040            private CalendarEntries payCalendarEntry = null; // Was a Hidden NPE, now more exposed // new PayCalendarEntries();
041            private TimeSummary timeSummary = new TimeSummary();
042            private Map<Long, Job> jobNumberToJobMap = new HashMap<Long,Job>();
043    
044            public TimesheetDocument(TimesheetDocumentHeader documentHeader) {
045                    this.documentHeader = documentHeader;
046            }
047    
048            public TimesheetDocumentHeader getDocumentHeader() {
049                    return documentHeader;
050            }
051    
052            public void setDocumentHeader(TimesheetDocumentHeader documentHeader) {
053                    this.documentHeader = documentHeader;
054            }
055    
056            public List<Assignment> getAssignments() {
057                    return assignments;
058            }
059    
060            public void setAssignments(List<Assignment> assignments) {
061                    this.assignments = assignments;
062            }
063    
064            public List<Job> getJobs() {
065                    return jobs;
066            }
067    
068            public void setJobs(List<Job> jobs) {
069                    this.jobs = jobs;
070                    jobNumberToJobMap.clear();
071                    if(jobs!=null){
072                            for(Job job : jobs){
073                                    jobNumberToJobMap.put(job.getJobNumber(), job);
074                            }
075                    }
076            }
077    
078            public List<TimeBlock> getTimeBlocks() {
079                    return timeBlocks;
080            }
081    
082            public void setTimeBlocks(List<TimeBlock> timeBlocks) {
083                    this.timeBlocks = timeBlocks;
084            }
085    
086        public CalendarEntries getPayCalendarEntry() {
087                    return payCalendarEntry;
088            }
089    
090            public void setPayCalendarEntry(CalendarEntries payCalendarEntry) {
091                    this.payCalendarEntry = payCalendarEntry;
092            }
093    
094            public void setTimeSummary(TimeSummary timeSummary) {
095                    this.timeSummary = timeSummary;
096            }
097    
098            public TimeSummary getTimeSummary() {
099                    return timeSummary;
100            }
101    
102            public String getPrincipalId(){
103                    return getDocumentHeader().getPrincipalId();
104            }
105    
106            public Job getJob(Long jobNumber){
107                    return jobNumberToJobMap.get(jobNumber);
108            }
109    
110        public java.sql.Date getAsOfDate(){
111                    return new java.sql.Date(getPayCalendarEntry().getBeginPeriodDateTime().getTime());
112            }
113    
114            public String getDocumentId(){
115                    return this.getDocumentHeader().getDocumentId();
116            }
117    }