1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.assignment;
17
18 import java.util.LinkedList;
19 import java.util.List;
20
21 import org.apache.commons.lang.builder.EqualsBuilder;
22 import org.apache.commons.lang.builder.HashCodeBuilder;
23 import org.joda.time.LocalDate;
24 import org.kuali.kpme.core.api.assignment.AssignmentContract;
25 import org.kuali.kpme.core.assignment.account.AssignmentAccount;
26 import org.kuali.kpme.core.block.CalendarBlockPermissions;
27 import org.kuali.kpme.core.bo.HrBusinessObject;
28 import org.kuali.kpme.core.job.Job;
29 import org.kuali.kpme.core.service.HrServiceLocator;
30 import org.kuali.kpme.core.task.Task;
31 import org.kuali.kpme.core.util.HrConstants;
32 import org.kuali.kpme.core.util.TKUtils;
33 import org.kuali.kpme.core.workarea.WorkArea;
34 import org.kuali.rice.kim.api.identity.Person;
35 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36
37 import com.google.common.collect.ImmutableList;
38
39 public class Assignment extends HrBusinessObject implements AssignmentContract {
40
41 private static final long serialVersionUID = 6347435053054442195L;
42
43 public static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
44 .add("jobNumber")
45 .add("workArea")
46 .add("task")
47 .add("principalId")
48 .build();
49
50 public static final ImmutableList<String> CACHE_FLUSH = new ImmutableList.Builder<String>()
51 .add(Assignment.CACHE_NAME)
52 .add(CalendarBlockPermissions.CACHE_NAME)
53 .build();
54 public static final String CACHE_NAME = HrConstants.CacheNamespace.NAMESPACE_PREFIX + "Assignment";
55
56 private String tkAssignmentId;
57 private String principalId;
58 private Long jobNumber;
59 private String hrJobId;
60 private transient Job job;
61 private Long workArea;
62
63 private Long task;
64 private String dept;
65
66 private transient WorkArea workAreaObj;
67 private Boolean history;
68 private String assignmentKey;
69
70 private transient Person principal;
71
72 private transient Task taskObj;
73
74 private String calGroup;
75
76 private List<AssignmentAccount> assignmentAccounts = new LinkedList<AssignmentAccount>();
77
78 public List<AssignmentAccount> getAssignmentAccounts() {
79 return assignmentAccounts;
80 }
81
82 public void setAssignmentAccounts(List<AssignmentAccount> assignmentAccounts) {
83 this.assignmentAccounts = assignmentAccounts;
84 }
85
86 public String getPrincipalId() {
87 return principalId;
88 }
89
90 public void setPrincipalId(String principalId) {
91 this.principalId = principalId;
92 this.setPrincipal(KimApiServiceLocator.getPersonService().getPerson(this.principalId));
93 }
94
95 public String getName() {
96 if (principal == null) {
97 principal = KimApiServiceLocator.getPersonService().getPerson(this.principalId);
98 }
99 return (principal != null) ? principal.getName() : "";
100 }
101
102 public Job getJob() {
103 if(job == null && this.getJobNumber() != null) {
104 this.setJob(HrServiceLocator.getJobService().getJob(this.getPrincipalId(), this.getJobNumber(), this.getEffectiveLocalDate()));
105 }
106 return job;
107 }
108
109 public void setJob(Job job) {
110 this.job = job;
111 }
112
113 public Long getJobNumber() {
114 return jobNumber;
115 }
116
117 public void setJobNumber(Long jobNumber) {
118 this.jobNumber = jobNumber;
119 }
120
121 public String getHrJobId() {
122 return hrJobId;
123 }
124
125 public void setHrJobId(String hrJobId) {
126 this.hrJobId = hrJobId;
127 }
128
129
130
131
132
133
134
135 public String getClockText() {
136 StringBuilder sb = new StringBuilder("example assignment clock text");
137
138 return sb.toString();
139 }
140
141 public String getTkAssignmentId() {
142 return tkAssignmentId;
143
144 }
145 public void setTkAssignmentId(String tkAssignmentId) {
146 this.tkAssignmentId = tkAssignmentId;
147 }
148
149 public void setWorkArea(Long workArea) {
150 this.workArea = workArea;
151 }
152
153 public void setTask(Long task) {
154 this.task = task;
155 }
156
157 public String getDept() {
158 if(this.getJobNumber()!= null) {
159 if(this.getJob() == null || !this.getJobNumber().equals(this.getJob().getJobNumber())) {
160 if(this.getEffectiveDate()!=null){
161 this.setJob(HrServiceLocator.getJobService().getJob(this.getPrincipalId(), this.getJobNumber(), this.getEffectiveLocalDate(), false));
162 }else{
163 this.setJob(HrServiceLocator.getJobService().getJob(this.getPrincipalId(), this.getJobNumber(), LocalDate.now(), false));
164 }
165 }
166 setDept((this.getJob() != null) ? this.getJob().getDept() : "");
167 }
168 return dept;
169 }
170
171 public void setDept(String dept) {
172 this.dept = dept;
173 }
174
175 public WorkArea getWorkAreaObj() {
176 if(workAreaObj == null && workArea != null) {
177 this.setWorkAreaObj(HrServiceLocator.getWorkAreaService().getWorkArea(this.getWorkArea(), this.getEffectiveLocalDate()));
178 }
179 return workAreaObj;
180 }
181
182 public void setWorkAreaObj(WorkArea workAreaObj) {
183 this.workAreaObj = workAreaObj;
184 }
185
186 public Long getWorkArea() {
187 return workArea;
188 }
189
190 public Long getTask() {
191 if(task == null) {
192 return Long.valueOf(0);
193 }
194 return task;
195 }
196
197 public String getAssignmentDescription() {
198 return TKUtils.getAssignmentString(getPrincipalId(), getJobNumber(), getWorkArea(), getTask(), getEffectiveLocalDate());
199 }
200
201 public Person getPrincipal() {
202 return principal;
203 }
204
205 public void setPrincipal(Person principal) {
206 this.principal = principal;
207 }
208
209 public Task getTaskObj() {
210 return taskObj;
211 }
212
213 public void setTaskObj(Task taskObj) {
214 this.taskObj = taskObj;
215 }
216
217
218
219
220
221
222
223
224 public Boolean getHistory() {
225 return history;
226 }
227 public void setHistory(Boolean history) {
228 this.history = history;
229 }
230
231 @Override
232 public String getUniqueKey() {
233 String jobKey = getPrincipalId()+"_"+getJobNumber()+"_"+getWorkArea()+"_"+
234 (getTask() != null ? getTask().toString() : "");
235 return jobKey;
236
237 }
238
239 @Override
240 public String getId() {
241 return getTkAssignmentId();
242 }
243
244 @Override
245 public void setId(String id) {
246 setTkAssignmentId(id);
247 }
248
249 @Override
250 public boolean equals(Object obj) {
251 if (obj == null)
252 return false;
253 if (obj == this)
254 return true;
255 if (obj.getClass() != getClass())
256 return false;
257
258 Assignment rhs = (Assignment)obj;
259 return new EqualsBuilder().append(principalId, rhs.principalId).append(jobNumber, rhs.jobNumber)
260 .append(workArea, rhs.workArea).append(task, rhs.task).isEquals();
261 }
262
263 @Override
264 public int hashCode() {
265 return new HashCodeBuilder(17, 781).append(principalId).append(jobNumber).append(workArea).append(task).toHashCode();
266 }
267
268 public String getCalGroup() {
269 return calGroup;
270 }
271
272 public void setCalGroup(String calGroup) {
273 this.calGroup = calGroup;
274 }
275
276 public String getAssignmentKey() {
277 return new AssignmentDescriptionKey(this).toAssignmentKeyString();
278 }
279 }