1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.document.calendar;
17
18 import java.io.Serializable;
19 import java.util.LinkedHashMap;
20 import java.util.LinkedList;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.joda.time.LocalDate;
25 import org.kuali.kpme.core.api.document.calendar.CalendarDocumentContract;
26 import org.kuali.kpme.core.assignment.Assignment;
27 import org.kuali.kpme.core.assignment.AssignmentDescriptionKey;
28 import org.kuali.kpme.core.calendar.entry.CalendarEntry;
29 import org.kuali.kpme.core.service.HrServiceLocator;
30 import org.kuali.kpme.core.util.TKUtils;
31
32 public abstract class CalendarDocument implements Serializable, CalendarDocumentContract{
33 private static final long serialVersionUID = 6074564807962995821L;
34 protected CalendarDocumentHeader documentHeader;
35 protected List<Assignment> assignments = new LinkedList<Assignment>();
36 protected CalendarEntry calendarEntry = null;
37 protected LocalDate asOfDate;
38 protected String calendarType;
39
40 public abstract CalendarDocumentHeader getDocumentHeader();
41
42 public abstract List<Assignment> getAssignments();
43
44 public abstract CalendarEntry getCalendarEntry();
45
46 public abstract LocalDate getAsOfDate();
47
48 public String getDocumentId() {
49 if(documentHeader != null)
50 return documentHeader.getDocumentId();
51 else
52 return null;
53 }
54
55 public String getPrincipalId() {
56 if(documentHeader != null)
57 return documentHeader.getPrincipalId();
58 else
59 return null;
60 }
61
62 public String getCalendarType() {
63 return calendarType;
64 }
65
66 public void setCalendarType(String calendarType) {
67 this.calendarType = calendarType;
68 }
69
70 public Map<String, String> getAssignmentDescriptions() {
71 Map<String, String> assignmentDescriptions = new LinkedHashMap<String, String>();
72 for (Assignment assignment : assignments) {
73 assignmentDescriptions.putAll(TKUtils.formatAssignmentDescription(assignment));
74 }
75 return assignmentDescriptions;
76 }
77
78 public Assignment getAssignment(AssignmentDescriptionKey assignmentDescriptionKey) {
79
80 for (Assignment assignment : assignments) {
81 if (assignment.getJobNumber().compareTo(assignmentDescriptionKey.getJobNumber()) == 0 &&
82 assignment.getWorkArea().compareTo(assignmentDescriptionKey.getWorkArea()) == 0 &&
83 assignment.getTask().compareTo(assignmentDescriptionKey.getTask()) == 0) {
84 return assignment;
85 }
86 }
87
88
89 Assignment foundAssign = HrServiceLocator.getAssignmentService().getAssignmentForTargetPrincipal(assignmentDescriptionKey, calendarEntry.getBeginPeriodFullDateTime().toLocalDate());
90 if (foundAssign != null) {
91 return foundAssign;
92 }
93 else
94 return null;
95 }
96
97 }