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.core.document.calendar.CalendarDocumentContract;
024    import org.kuali.hr.job.Job;
025    import org.kuali.hr.time.assignment.Assignment;
026    import org.kuali.hr.time.calendar.CalendarEntries;
027    import org.kuali.hr.time.timeblock.TimeBlock;
028    import org.kuali.hr.time.timesummary.TimeSummary;
029    import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
030    
031    
032    public class TimesheetDocument implements CalendarDocumentContract {
033    
034            public static final String TIMESHEET_DOCUMENT_TYPE = "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 calendarEntry = 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        @Override
049            public TimesheetDocumentHeader getDocumentHeader() {
050                    return documentHeader;
051            }
052    
053            public void setDocumentHeader(TimesheetDocumentHeader documentHeader) {
054                    this.documentHeader = documentHeader;
055            }
056    
057        @Override
058            public List<Assignment> getAssignments() {
059                    return assignments;
060            }
061    
062            public void setAssignments(List<Assignment> assignments) {
063                    this.assignments = assignments;
064            }
065    
066            public List<Job> getJobs() {
067                    return jobs;
068            }
069    
070            public void setJobs(List<Job> jobs) {
071                    this.jobs = jobs;
072                    jobNumberToJobMap.clear();
073                    if(jobs!=null){
074                            for(Job job : jobs){
075                                    jobNumberToJobMap.put(job.getJobNumber(), job);
076                            }
077                    }
078            }
079    
080            public List<TimeBlock> getTimeBlocks() {
081                    return timeBlocks;
082            }
083    
084            public void setTimeBlocks(List<TimeBlock> timeBlocks) {
085                    this.timeBlocks = timeBlocks;
086            }
087    
088        @Override
089            public CalendarEntries getCalendarEntry() {
090                    return calendarEntry;
091            }
092    
093            public void setCalendarEntry(CalendarEntries calendarEntry) {
094                    this.calendarEntry = calendarEntry;
095            }
096    
097            public void setTimeSummary(TimeSummary timeSummary) {
098                    this.timeSummary = timeSummary;
099            }
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    }