1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.api.assignment;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.joda.time.DateTime;
21 import org.joda.time.LocalDate;
22 import org.kuali.kpme.core.api.KPMEConstants;
23 import org.kuali.kpme.core.api.assignment.account.AssignmentAccount;
24 import org.kuali.kpme.core.api.assignment.account.AssignmentAccountContract;
25 import org.kuali.kpme.core.api.groupkey.HrGroupKey;
26 import org.kuali.kpme.core.api.job.Job;
27 import org.kuali.kpme.core.api.task.Task;
28 import org.kuali.kpme.core.api.workarea.WorkArea;
29 import org.kuali.rice.core.api.CoreConstants;
30 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
31 import org.kuali.rice.core.api.mo.ModelBuilder;
32 import org.kuali.rice.core.api.mo.ModelObjectUtils;
33 import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
34 import org.kuali.rice.core.api.util.jaxb.LocalDateAdapter;
35 import org.w3c.dom.Element;
36
37 import javax.xml.bind.annotation.*;
38 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
39 import java.io.Serializable;
40 import java.util.Collection;
41 import java.util.Collections;
42 import java.util.List;
43
44 @XmlRootElement(name = Assignment.Constants.ROOT_ELEMENT_NAME)
45 @XmlAccessorType(XmlAccessType.NONE)
46 @XmlType(name = Assignment.Constants.TYPE_NAME, propOrder = {
47 Assignment.Elements.NAME,
48 Assignment.Elements.ASSIGNMENT_ACCOUNTS,
49 Assignment.Elements.PRINCIPAL_ID,
50 KPMEConstants.CommonElements.GROUP_KEY_CODE,
51 KPMEConstants.CommonElements.GROUP_KEY,
52 Assignment.Elements.JOB,
53 Assignment.Elements.JOB_NUMBER,
54 Assignment.Elements.CLOCK_TEXT,
55 Assignment.Elements.TK_ASSIGNMENT_ID,
56 Assignment.Elements.DEPT,
57 Assignment.Elements.WORK_AREA_OBJ,
58 Assignment.Elements.WORK_AREA,
59 Assignment.Elements.TASK,
60 Assignment.Elements.TASK_OBJ,
61 Assignment.Elements.CAL_GROUP,
62 Assignment.Elements.ASSIGNMENT_KEY,
63 Assignment.Elements.PRIMARY_ASSIGN,
64 Assignment.Elements.ASSIGNMENT_DESCRIPTION,
65 Assignment.Elements.ACTIVE,
66 Assignment.Elements.ID,
67 Assignment.Elements.EFFECTIVE_LOCAL_DATE,
68 Assignment.Elements.CREATE_TIME,
69 Assignment.Elements.USER_PRINCIPAL_ID,
70 CoreConstants.CommonElements.VERSION_NUMBER,
71 CoreConstants.CommonElements.OBJECT_ID,
72 CoreConstants.CommonElements.FUTURE_ELEMENTS
73 })
74 public final class Assignment
75 extends AbstractDataTransferObject
76 implements AssignmentContract
77 {
78
79 private static final long serialVersionUID = -8869596129477285844L;
80 @XmlElement(name = Elements.NAME, required = false)
81 private final String name;
82 @XmlElementWrapper(name = Elements.ASSIGNMENT_ACCOUNTS, required = false)
83 @XmlElement(name = Elements.ASSIGNMENT_ACCOUNT, required = false)
84 private final List<AssignmentAccount> assignmentAccounts;
85 @XmlElement(name = Elements.PRINCIPAL_ID, required = true)
86 private final String principalId;
87
88 @XmlElement(name = KPMEConstants.CommonElements.GROUP_KEY_CODE, required = true)
89 private final String groupKeyCode;
90 @XmlElement(name = KPMEConstants.CommonElements.GROUP_KEY, required = false)
91 private final HrGroupKey groupKey;
92
93 @XmlElement(name = Elements.JOB, required = false)
94 private final Job job;
95 @XmlElement(name = Elements.JOB_NUMBER, required = false)
96 private final Long jobNumber;
97 @XmlElement(name = Elements.CLOCK_TEXT, required = false)
98 private final String clockText;
99 @XmlElement(name = Elements.TK_ASSIGNMENT_ID, required = false)
100 private final String tkAssignmentId;
101 @XmlElement(name = Elements.DEPT, required = false)
102 private final String dept;
103 @XmlElement(name = Elements.WORK_AREA_OBJ, required = false)
104 private final WorkArea workAreaObj;
105 @XmlElement(name = Elements.WORK_AREA, required = false)
106 private final Long workArea;
107 @XmlElement(name = Elements.TASK, required = false)
108 private final Long task;
109 @XmlElement(name = Elements.TASK_OBJ, required = false)
110 private final Task taskObj;
111 @XmlElement(name = Elements.CAL_GROUP, required = false)
112 private final String calGroup;
113 @XmlElement(name = Elements.ASSIGNMENT_KEY, required = false)
114 private final String assignmentKey;
115 @XmlElement(name = Elements.PRIMARY_ASSIGN, required = false)
116 private final boolean primaryAssign;
117 @XmlElement(name = Elements.ASSIGNMENT_DESCRIPTION, required = false)
118 private final String assignmentDescription;
119 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
120 private final Long versionNumber;
121 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
122 private final String objectId;
123 @XmlElement(name = Elements.ACTIVE, required = false)
124 private final boolean active;
125 @XmlElement(name = Elements.ID, required = false)
126 private final String id;
127 @XmlElement(name = Elements.EFFECTIVE_LOCAL_DATE, required = false)
128 @XmlJavaTypeAdapter(LocalDateAdapter.class)
129 private final LocalDate effectiveLocalDate;
130 @XmlElement(name = Elements.CREATE_TIME, required = false)
131 @XmlJavaTypeAdapter(DateTimeAdapter.class)
132 private final DateTime createTime;
133 @XmlElement(name = Elements.USER_PRINCIPAL_ID, required = false)
134 private final String userPrincipalId;
135 @SuppressWarnings("unused")
136 @XmlAnyElement
137 private final Collection<Element> _futureElements = null;
138
139
140
141
142
143 private Assignment() {
144 this.name = null;
145 this.assignmentAccounts = null;
146 this.principalId = null;
147
148 this.groupKeyCode = null;
149 this.groupKey = null;
150
151 this.job = null;
152 this.jobNumber = null;
153 this.clockText = null;
154 this.tkAssignmentId = null;
155 this.dept = null;
156 this.workAreaObj = null;
157 this.workArea = null;
158 this.task = null;
159 this.taskObj = null;
160 this.calGroup = null;
161 this.assignmentKey = null;
162 this.primaryAssign = false;
163 this.assignmentDescription = null;
164 this.versionNumber = null;
165 this.objectId = null;
166 this.active = false;
167 this.id = null;
168 this.effectiveLocalDate = null;
169 this.createTime = null;
170 this.userPrincipalId = null;
171
172 }
173
174 private Assignment(Builder builder) {
175 this.name = builder.getName();
176 this.assignmentAccounts = CollectionUtils.isEmpty(builder.getAssignmentAccounts()) ? Collections.<AssignmentAccount>emptyList() : ModelObjectUtils.<AssignmentAccount>buildImmutableCopy(builder.getAssignmentAccounts());
177 this.principalId = builder.getPrincipalId();
178
179 this.groupKeyCode = builder.getGroupKeyCode();
180 this.groupKey = builder.getGroupKey() == null ? null : builder.getGroupKey().build();
181
182 this.job = builder.getJob() == null ? null : builder.getJob().build();
183 this.jobNumber = builder.getJobNumber();
184 this.clockText = builder.getClockText();
185 this.tkAssignmentId = builder.getTkAssignmentId();
186 this.dept = builder.getDept();
187 this.workAreaObj = builder.getWorkAreaObj() == null ? null : builder.getWorkAreaObj().build();
188 this.workArea = builder.getWorkArea();
189 this.task = builder.getTask();
190 this.taskObj = builder.getTaskObj() == null ? null : builder.getTaskObj().build();
191 this.calGroup = builder.getCalGroup();
192 this.assignmentKey = builder.getAssignmentKey();
193 this.primaryAssign = builder.isPrimaryAssign();
194 this.assignmentDescription = builder.getAssignmentDescription();
195 this.versionNumber = builder.getVersionNumber();
196 this.objectId = builder.getObjectId();
197 this.active = builder.isActive();
198 this.id = builder.getId();
199 this.effectiveLocalDate = builder.getEffectiveLocalDate();
200 this.createTime = builder.getCreateTime();
201 this.userPrincipalId = builder.getUserPrincipalId();
202 }
203
204 @Override
205 public String getName() {
206 return this.name;
207 }
208
209 @Override
210 public List<AssignmentAccount> getAssignmentAccounts() {
211 return this.assignmentAccounts;
212 }
213
214 @Override
215 public String getPrincipalId() {
216 return this.principalId;
217 }
218
219 @Override
220 public String getGroupKeyCode() {
221 return this.groupKeyCode;
222 }
223
224 @Override
225 public Job getJob() {
226 return this.job;
227 }
228
229 @Override
230 public Long getJobNumber() {
231 return this.jobNumber;
232 }
233
234 @Override
235 public String getClockText() {
236 return this.clockText;
237 }
238
239 @Override
240 public String getTkAssignmentId() {
241 return this.tkAssignmentId;
242 }
243
244 @Override
245 public String getDept() {
246 return this.dept;
247 }
248
249 @Override
250 public WorkArea getWorkAreaObj() {
251 return this.workAreaObj;
252 }
253
254 @Override
255 public Long getWorkArea() {
256 return this.workArea;
257 }
258
259 @Override
260 public Long getTask() {
261 return this.task;
262 }
263
264 @Override
265 public Task getTaskObj() {
266 return this.taskObj;
267 }
268
269 @Override
270 public HrGroupKey getGroupKey() {
271 return this.groupKey;
272 }
273
274 @Override
275 public String getCalGroup() {
276 return this.calGroup;
277 }
278
279 @Override
280 public String getAssignmentKey() {
281 return this.assignmentKey;
282 }
283
284 @Override
285 public boolean isPrimaryAssign() {
286 return this.primaryAssign;
287 }
288
289 @Override
290 public String getAssignmentDescription() {
291 return this.assignmentDescription;
292 }
293
294 @Override
295 public Long getVersionNumber() {
296 return this.versionNumber;
297 }
298
299 @Override
300 public String getObjectId() {
301 return this.objectId;
302 }
303
304 @Override
305 public boolean isActive() {
306 return this.active;
307 }
308
309 @Override
310 public String getId() {
311 return this.id;
312 }
313
314 @Override
315 public LocalDate getEffectiveLocalDate() {
316 return this.effectiveLocalDate;
317 }
318
319 @Override
320 public DateTime getCreateTime() {
321 return this.createTime;
322 }
323
324 @Override
325 public String getUserPrincipalId() {
326 return this.userPrincipalId;
327 }
328
329
330
331
332
333
334 public final static class Builder
335 implements Serializable, AssignmentContract, ModelBuilder
336 {
337
338 private static final long serialVersionUID = 4303332490877015437L;
339 private String name;
340 private List<AssignmentAccount.Builder> assignmentAccounts;
341 private String principalId;
342
343 private String groupKeyCode;
344 private HrGroupKey.Builder groupKey;
345
346 private Job.Builder job;
347 private Long jobNumber;
348 private String clockText;
349 private String tkAssignmentId;
350 private String dept;
351 private WorkArea.Builder workAreaObj;
352 private Long workArea;
353 private Long task;
354 private Task.Builder taskObj;
355 private String calGroup;
356 private String assignmentKey;
357 private boolean primaryAssign;
358 private String assignmentDescription;
359 private Long versionNumber;
360 private String objectId;
361 private boolean active;
362 private String id;
363 private LocalDate effectiveLocalDate;
364 private DateTime createTime;
365 private String userPrincipalId;
366 private static final ModelObjectUtils.Transformer<AssignmentAccountContract, AssignmentAccount.Builder> toAssignmentAccountBuilder =
367 new ModelObjectUtils.Transformer<AssignmentAccountContract, AssignmentAccount.Builder>() {
368 public AssignmentAccount.Builder transform(AssignmentAccountContract input) {
369 return AssignmentAccount.Builder.create(input);
370 }
371 };
372 private Builder(String principalId, String groupKeyCode, Long workArea, Long jobNumber, Long task) {
373 setPrincipalId(principalId);
374 setGroupKeyCode(groupKeyCode);
375 setWorkArea(workArea);
376 setJobNumber(jobNumber);
377 setTask(task);
378 }
379
380 public static Builder create(String principalId, String groupKeyCode, Long workArea, Long jobNumber, Long task) {
381 return new Builder(principalId, groupKeyCode, workArea, jobNumber, task);
382 }
383
384 public static Builder create(AssignmentContract contract) {
385 if (contract == null) {
386 throw new IllegalArgumentException("contract was null");
387 }
388 Builder builder = create(contract.getPrincipalId(), contract.getGroupKeyCode(), contract.getWorkArea(), contract.getJobNumber(), contract.getTask());
389 builder.setName(contract.getName());
390 if (CollectionUtils.isEmpty(contract.getAssignmentAccounts())) {
391 builder.setAssignmentAccounts(Collections.<AssignmentAccount.Builder>emptyList());
392 } else {
393 builder.setAssignmentAccounts(ModelObjectUtils.transform(contract.getAssignmentAccounts(), toAssignmentAccountBuilder));
394 }
395 builder.setJob(contract.getJob() == null ? null : Job.Builder.create(contract.getJob()));
396 builder.setClockText(contract.getClockText());
397 builder.setTkAssignmentId(contract.getTkAssignmentId());
398 builder.setDept(contract.getDept());
399 builder.setWorkAreaObj(contract.getWorkAreaObj() == null ? null : WorkArea.Builder.create(contract.getWorkAreaObj()));
400 builder.setTaskObj(contract.getTaskObj() == null ? null : Task.Builder.create(contract.getTaskObj()));
401 builder.setGroupKey(contract.getGroupKey() == null ? null : HrGroupKey.Builder.create(contract.getGroupKey()));
402 builder.setCalGroup(contract.getCalGroup());
403 builder.setAssignmentKey(contract.getAssignmentKey());
404 builder.setPrimaryAssign(contract.isPrimaryAssign());
405 builder.setAssignmentDescription(contract.getAssignmentDescription());
406 builder.setVersionNumber(contract.getVersionNumber());
407 builder.setObjectId(contract.getObjectId());
408 builder.setActive(contract.isActive());
409 builder.setId(contract.getId());
410 builder.setEffectiveLocalDate(contract.getEffectiveLocalDate());
411 builder.setCreateTime(contract.getCreateTime());
412 builder.setUserPrincipalId(contract.getUserPrincipalId());
413 return builder;
414 }
415
416 public Assignment build() {
417 return new Assignment(this);
418 }
419
420 @Override
421 public String getName() {
422 return this.name;
423 }
424
425 @Override
426 public List<AssignmentAccount.Builder> getAssignmentAccounts() {
427 return this.assignmentAccounts;
428 }
429
430 @Override
431 public String getPrincipalId() {
432 return this.principalId;
433 }
434
435 @Override
436 public Job.Builder getJob() {
437 return this.job;
438 }
439
440 @Override
441 public Long getJobNumber() {
442 return this.jobNumber;
443 }
444
445 @Override
446 public String getClockText() {
447 return this.clockText;
448 }
449
450 @Override
451 public String getTkAssignmentId() {
452 return this.tkAssignmentId;
453 }
454
455 @Override
456 public String getDept() {
457 return this.dept;
458 }
459
460 @Override
461 public WorkArea.Builder getWorkAreaObj() {
462 return this.workAreaObj;
463 }
464
465 @Override
466 public Long getWorkArea() {
467 return this.workArea;
468 }
469
470 @Override
471 public Long getTask() {
472 return this.task;
473 }
474
475 @Override
476 public Task.Builder getTaskObj() {
477 return this.taskObj;
478 }
479
480 @Override
481 public String getCalGroup() {
482 return this.calGroup;
483 }
484
485 @Override
486 public String getAssignmentKey() {
487 return this.assignmentKey;
488 }
489
490 @Override
491 public boolean isPrimaryAssign() {
492 return this.primaryAssign;
493 }
494
495 @Override
496 public String getAssignmentDescription() {
497 return this.assignmentDescription;
498 }
499
500 @Override
501 public Long getVersionNumber() {
502 return this.versionNumber;
503 }
504
505 @Override
506 public String getObjectId() {
507 return this.objectId;
508 }
509
510 @Override
511 public boolean isActive() {
512 return this.active;
513 }
514
515 @Override
516 public String getId() {
517 return this.id;
518 }
519
520 @Override
521 public LocalDate getEffectiveLocalDate() {
522 return this.effectiveLocalDate;
523 }
524
525 @Override
526 public DateTime getCreateTime() {
527 return this.createTime;
528 }
529
530 @Override
531 public String getUserPrincipalId() {
532 return this.userPrincipalId;
533 }
534
535 @Override
536 public String getGroupKeyCode() {
537 return groupKeyCode;
538 }
539
540 public void setGroupKeyCode(String groupKeyCode) {
541 this.groupKeyCode = groupKeyCode;
542 }
543
544 @Override
545 public HrGroupKey.Builder getGroupKey() {
546 return groupKey;
547 }
548
549 public void setGroupKey(HrGroupKey.Builder groupKey) {
550 this.groupKey = groupKey;
551 }
552
553 public void setName(String name) {
554 this.name = name;
555 }
556
557 public void setAssignmentAccounts(List<AssignmentAccount.Builder> assignmentAccounts) {
558 this.assignmentAccounts = assignmentAccounts;
559 }
560
561 public void setPrincipalId(String principalId) {
562 if (StringUtils.isBlank(principalId)) {
563 throw new IllegalArgumentException("principalId is blank");
564 }
565 this.principalId = principalId;
566 }
567
568 public void setJob(Job.Builder job) {
569 this.job = job;
570 }
571
572 public void setJobNumber(Long jobNumber) {
573 if (jobNumber == null) {
574 throw new IllegalArgumentException("jobNumber is null");
575 }
576 this.jobNumber = jobNumber;
577 }
578
579 public void setClockText(String clockText) {
580 this.clockText = clockText;
581 }
582
583 public void setTkAssignmentId(String tkAssignmentId) {
584 this.tkAssignmentId = tkAssignmentId;
585 }
586
587 public void setDept(String dept) {
588 this.dept = dept;
589 }
590
591 public void setWorkAreaObj(WorkArea.Builder workAreaObj) {
592 this.workAreaObj = workAreaObj;
593 }
594
595 public void setWorkArea(Long workArea) {
596 if (workArea == null) {
597 throw new IllegalArgumentException("workArea is null");
598 }
599 this.workArea = workArea;
600 }
601
602 public void setTask(Long task) {
603 if (task == null) {
604 throw new IllegalArgumentException("task is null");
605 }
606 this.task = task;
607 }
608
609 public void setTaskObj(Task.Builder taskObj) {
610 this.taskObj = taskObj;
611 }
612
613 public void setCalGroup(String calGroup) {
614 this.calGroup = calGroup;
615 }
616
617 public void setAssignmentKey(String assignmentKey) {
618 this.assignmentKey = assignmentKey;
619 }
620
621 public void setPrimaryAssign(boolean primaryAssign) {
622 this.primaryAssign = primaryAssign;
623 }
624
625 public void setAssignmentDescription(String assignmentDescription) {
626 this.assignmentDescription = assignmentDescription;
627 }
628
629 public void setVersionNumber(Long versionNumber) {
630 this.versionNumber = versionNumber;
631 }
632
633 public void setObjectId(String objectId) {
634 this.objectId = objectId;
635 }
636
637 public void setActive(boolean active) {
638 this.active = active;
639 }
640
641 public void setId(String id) {
642 this.id = id;
643 }
644
645 public void setEffectiveLocalDate(LocalDate effectiveLocalDate) {
646 this.effectiveLocalDate = effectiveLocalDate;
647 }
648
649 public void setCreateTime(DateTime createTime) {
650 this.createTime = createTime;
651 }
652
653 public void setUserPrincipalId(String userPrincipalId) {
654 this.userPrincipalId = userPrincipalId;
655 }
656
657 }
658
659
660
661
662
663
664 static class Constants {
665
666 final static String ROOT_ELEMENT_NAME = "assignment";
667 final static String TYPE_NAME = "AssignmentType";
668
669 }
670
671
672
673
674
675
676 static class Elements {
677
678 final static String NAME = "name";
679 final static String ASSIGNMENT_ACCOUNTS = "assignmentAccounts";
680 final static String ASSIGNMENT_ACCOUNT = "assignmentAccount";
681 final static String PRINCIPAL_ID = "principalId";
682 final static String JOB = "job";
683 final static String JOB_NUMBER = "jobNumber";
684 final static String CLOCK_TEXT = "clockText";
685 final static String TK_ASSIGNMENT_ID = "tkAssignmentId";
686 final static String DEPT = "dept";
687 final static String WORK_AREA_OBJ = "workAreaObj";
688 final static String WORK_AREA = "workArea";
689 final static String TASK = "task";
690 final static String TASK_OBJ = "taskObj";
691 final static String CAL_GROUP = "calGroup";
692 final static String ASSIGNMENT_KEY = "assignmentKey";
693 final static String PRIMARY_ASSIGN = "primaryAssign";
694 final static String ASSIGNMENT_DESCRIPTION = "assignmentDescription";
695 final static String ACTIVE = "active";
696 final static String ID = "id";
697 final static String EFFECTIVE_LOCAL_DATE = "effectiveLocalDate";
698 final static String CREATE_TIME = "createTime";
699 final static String USER_PRINCIPAL_ID = "userPrincipalId";
700
701 }
702
703 }