1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.assignment;
17
18 import java.sql.Date;
19 import java.sql.Timestamp;
20 import java.util.LinkedList;
21 import java.util.List;
22
23 import org.apache.commons.lang.builder.EqualsBuilder;
24 import org.apache.commons.lang.builder.HashCodeBuilder;
25 import org.kuali.hr.core.KPMEConstants;
26 import org.kuali.hr.job.Job;
27 import org.kuali.hr.time.HrBusinessObject;
28 import org.kuali.hr.time.collection.rule.TimeCollectionRule;
29 import org.kuali.hr.time.dept.lunch.DeptLunchRule;
30 import org.kuali.hr.time.service.base.TkServiceLocator;
31 import org.kuali.hr.time.task.Task;
32 import org.kuali.hr.time.util.TKUtils;
33 import org.kuali.hr.time.workarea.WorkArea;
34 import org.kuali.rice.kim.api.identity.Person;
35 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36
37 public class Assignment extends HrBusinessObject {
38 public static final String CACHE_NAME = KPMEConstants.APPLICATION_NAMESPACE_CODE + "/" + "Assignment";
39
40
41
42 private static final long serialVersionUID = -3408305833805778653L;
43
44 private String tkAssignmentId;
45 private String principalId;
46 private Long jobNumber;
47 private String hrJobId;
48 private Job job;
49 private Long workArea;
50
51 private Long task;
52 private String dept;
53 private TimeCollectionRule timeCollectionRule;
54 private DeptLunchRule deptLunchRule;
55 private WorkArea workAreaObj;
56 private Boolean history;
57 private String assignmentKey;
58
59 private Person principal;
60
61 private Task taskObj;
62
63 private String calGroup;
64
65 private List<AssignmentAccount> assignmentAccounts = new LinkedList<AssignmentAccount>();
66
67 public List<AssignmentAccount> getAssignmentAccounts() {
68 return assignmentAccounts;
69 }
70
71 public void setAssignmentAccounts(List<AssignmentAccount> assignmentAccounts) {
72 this.assignmentAccounts = assignmentAccounts;
73 }
74
75 public Assignment(){}
76
77 public Assignment(String principalId, Long jobNumber, Date effectiveDate,
78 String earnCode, Long workAreaId, Long taskId) {
79 this.principalId = principalId;
80 this.jobNumber = jobNumber;
81 this.effectiveDate = effectiveDate;
82 this.workArea = workAreaId;
83 this.task = taskId;
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(TkServiceLocator.getJobService().getJob(this.getPrincipalId(), this.getJobNumber(), this.getEffectiveDate()));
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 public Date getEffectiveDate() {
130 return effectiveDate;
131 }
132
133 public void setEffectiveDate(Date effectiveDate) {
134 this.effectiveDate = effectiveDate;
135 }
136
137 public boolean isActive() {
138 return active;
139 }
140
141 public void setActive(boolean active) {
142 this.active = active;
143 }
144
145
146
147
148
149
150
151 public String getClockText() {
152 StringBuilder sb = new StringBuilder("example assignment clock text");
153
154 return sb.toString();
155 }
156
157 public String getTkAssignmentId() {
158 return tkAssignmentId;
159
160 }
161 public void setTkAssignmentId(String tkAssignmentId) {
162 this.tkAssignmentId = tkAssignmentId;
163 }
164
165 public Timestamp getTimestamp() {
166 return timestamp;
167 }
168
169 public void setTimestamp(Timestamp timestamp) {
170 this.timestamp = timestamp;
171 }
172
173 public void setWorkArea(Long workArea) {
174 this.workArea = workArea;
175 }
176
177 public void setTask(Long task) {
178 this.task = task;
179 }
180
181 public String getDept() {
182 if(this.getJobNumber()!= null) {
183 if(this.getJob() == null || !this.getJobNumber().equals(this.getJob().getJobNumber())) {
184 if(this.getEffectiveDate()!=null){
185 this.setJob(TkServiceLocator.getJobService().getJob(this.getPrincipalId(), this.getJobNumber(), this.getEffectiveDate(), false));
186 }else{
187 this.setJob(TkServiceLocator.getJobService().getJob(this.getPrincipalId(), this.getJobNumber(), TKUtils.getCurrentDate(), false));
188 }
189 }
190 setDept((this.getJob() != null) ? this.getJob().getDept() : "");
191 }
192 return dept;
193 }
194
195 public void setDept(String dept) {
196 this.dept = dept;
197 }
198
199 public WorkArea getWorkAreaObj() {
200 if(workAreaObj == null && workArea != null) {
201 this.setWorkAreaObj(TkServiceLocator.getWorkAreaService().getWorkArea(this.getWorkArea(), this.getEffectiveDate()));
202 }
203 return workAreaObj;
204 }
205
206 public void setWorkAreaObj(WorkArea workAreaObj) {
207 this.workAreaObj = workAreaObj;
208 }
209
210 public Long getWorkArea() {
211 return workArea;
212 }
213
214 public Long getTask() {
215 if(task == null) {
216 return new Long(0);
217 }
218 return task;
219 }
220
221 public void setTimeCollectionRule(TimeCollectionRule timeCollectionRule) {
222 this.timeCollectionRule = timeCollectionRule;
223 }
224
225 public TimeCollectionRule getTimeCollectionRule() {
226 return timeCollectionRule;
227 }
228
229 public boolean isSynchronous() {
230 return timeCollectionRule.isClockUserFl();
231 }
232
233 public DeptLunchRule getDeptLunchRule() {
234 return deptLunchRule;
235 }
236
237 public void setDeptLunchRule(DeptLunchRule deptLunchRule) {
238 this.deptLunchRule = deptLunchRule;
239 }
240
241 public String getAssignmentDescription() {
242 return TKUtils.getAssignmentString(this);
243 }
244
245 public Person getPrincipal() {
246 return principal;
247 }
248
249 public void setPrincipal(Person principal) {
250 this.principal = principal;
251 }
252
253 public Task getTaskObj() {
254 return taskObj;
255 }
256
257 public void setTaskObj(Task taskObj) {
258 this.taskObj = taskObj;
259 }
260
261
262
263
264
265
266
267
268 public Boolean getHistory() {
269 return history;
270 }
271 public void setHistory(Boolean history) {
272 this.history = history;
273 }
274
275 @Override
276 public String getUniqueKey() {
277 String jobKey = getPrincipalId()+"_"+getJobNumber()+"_"+getWorkArea()+"_"+
278 (getTask() != null ? getTask().toString() : "");
279 return jobKey;
280
281 }
282
283 @Override
284 public String getId() {
285 return getTkAssignmentId();
286 }
287
288 @Override
289 public void setId(String id) {
290 setTkAssignmentId(id);
291 }
292
293 @Override
294 public boolean equals(Object obj) {
295 if (obj == null)
296 return false;
297 if (obj == this)
298 return true;
299 if (obj.getClass() != getClass())
300 return false;
301
302 Assignment rhs = (Assignment)obj;
303 return new EqualsBuilder().append(principalId, rhs.principalId).append(jobNumber, rhs.jobNumber)
304 .append(workArea, rhs.workArea).append(task, rhs.task).isEquals();
305 }
306
307 @Override
308 public int hashCode() {
309 return new HashCodeBuilder(17, 781).append(principalId).append(jobNumber).append(workArea).append(task).toHashCode();
310 }
311
312 public String getCalGroup() {
313 return calGroup;
314 }
315
316 public void setCalGroup(String calGroup) {
317 this.calGroup = calGroup;
318 }
319
320 public String getAssignmentKey() {
321 return new AssignmentDescriptionKey(this).toAssignmentKeyString();
322 }
323 }