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