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.io.Serializable; 019 import java.util.HashMap; 020 import java.util.LinkedList; 021 import java.util.List; 022 import java.util.Map; 023 024 import org.kuali.hr.core.document.calendar.CalendarDocumentContract; 025 import org.kuali.hr.job.Job; 026 import org.kuali.hr.time.assignment.Assignment; 027 import org.kuali.hr.time.calendar.CalendarEntries; 028 import org.kuali.hr.time.timeblock.TimeBlock; 029 import org.kuali.hr.time.timesummary.TimeSummary; 030 import org.kuali.hr.time.workflow.TimesheetDocumentHeader; 031 032 033 public class TimesheetDocument implements CalendarDocumentContract, Serializable { 034 035 public static final String TIMESHEET_DOCUMENT_TYPE = "TimesheetDocument"; 036 037 private TimesheetDocumentHeader documentHeader; 038 private List<Assignment> assignments = new LinkedList<Assignment>(); 039 private List<Job> jobs = new LinkedList<Job>(); 040 private List<TimeBlock> timeBlocks = new LinkedList<TimeBlock>(); 041 private CalendarEntries calendarEntry = null; // Was a Hidden NPE, now more exposed // new PayCalendarEntries(); 042 private TimeSummary timeSummary = new TimeSummary(); 043 private Map<Long, Job> jobNumberToJobMap = new HashMap<Long,Job>(); 044 045 public TimesheetDocument(TimesheetDocumentHeader documentHeader) { 046 this.documentHeader = documentHeader; 047 } 048 049 @Override 050 public TimesheetDocumentHeader getDocumentHeader() { 051 return documentHeader; 052 } 053 054 public void setDocumentHeader(TimesheetDocumentHeader documentHeader) { 055 this.documentHeader = documentHeader; 056 } 057 058 @Override 059 public List<Assignment> getAssignments() { 060 return assignments; 061 } 062 063 public void setAssignments(List<Assignment> assignments) { 064 this.assignments = assignments; 065 } 066 067 public List<Job> getJobs() { 068 return jobs; 069 } 070 071 public void setJobs(List<Job> jobs) { 072 this.jobs = jobs; 073 jobNumberToJobMap.clear(); 074 if(jobs!=null){ 075 for(Job job : jobs){ 076 jobNumberToJobMap.put(job.getJobNumber(), job); 077 } 078 } 079 } 080 081 public List<TimeBlock> getTimeBlocks() { 082 return timeBlocks; 083 } 084 085 public void setTimeBlocks(List<TimeBlock> timeBlocks) { 086 this.timeBlocks = timeBlocks; 087 } 088 089 @Override 090 public CalendarEntries getCalendarEntry() { 091 return calendarEntry; 092 } 093 094 public void setCalendarEntry(CalendarEntries calendarEntry) { 095 this.calendarEntry = calendarEntry; 096 } 097 098 public void setTimeSummary(TimeSummary timeSummary) { 099 this.timeSummary = timeSummary; 100 } 101 102 public TimeSummary getTimeSummary() { 103 return timeSummary; 104 } 105 106 public String getPrincipalId(){ 107 return getDocumentHeader().getPrincipalId(); 108 } 109 110 public Job getJob(Long jobNumber){ 111 return jobNumberToJobMap.get(jobNumber); 112 } 113 114 @Override 115 public java.sql.Date getAsOfDate(){ 116 return new java.sql.Date(getCalendarEntry().getBeginPeriodDateTime().getTime()); 117 } 118 119 public java.sql.Date getDocEndDate(){ 120 return new java.sql.Date(getCalendarEntry().getEndPeriodDateTime().getTime()); 121 } 122 123 public String getDocumentId(){ 124 return this.getDocumentHeader().getDocumentId(); 125 } 126 }