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.regex.Matcher;
19 import java.util.regex.Pattern;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.kpme.core.util.HrConstants;
23 import org.kuali.kpme.core.util.TKUtils;
24
25 public class AssignmentDescriptionKey {
26
27 private Long jobNumber;
28 private Long workArea;
29 private Long task;
30
31 public static AssignmentDescriptionKey get(String assignmentDescriptionKeyString) {
32 AssignmentDescriptionKey assignmentDescriptionKey = new AssignmentDescriptionKey();
33
34 Pattern keyPattern = Pattern.compile("^\\d{1,}_\\d{1,}_\\d{1,}");
35 Matcher match = keyPattern.matcher(assignmentDescriptionKeyString);
36 if (match.matches()) {
37 String[] key = StringUtils.split(assignmentDescriptionKeyString, HrConstants.ASSIGNMENT_KEY_DELIMITER);
38
39 assignmentDescriptionKey.setJobNumber(Long.parseLong(key[0]));
40 assignmentDescriptionKey.setWorkArea(Long.parseLong(key[1]));
41 assignmentDescriptionKey.setTask(Long.parseLong(key[2]));
42 }
43
44 return assignmentDescriptionKey;
45 }
46
47 public AssignmentDescriptionKey() {
48 }
49
50 public AssignmentDescriptionKey(Assignment assignment) {
51 if (assignment != null) {
52 this.jobNumber = assignment.getJobNumber();
53 this.workArea = assignment.getWorkArea();
54 this.task = assignment.getTask();
55 }
56 }
57
58 public AssignmentDescriptionKey(Long jobNumer, Long workArea, Long task) {
59 this.jobNumber = jobNumer;
60 this.workArea = workArea;
61 this.task = task;
62 }
63
64 public Long getJobNumber() {
65 return jobNumber;
66 }
67
68 public void setJobNumber(Long jobNumber) {
69 this.jobNumber = jobNumber;
70 }
71
72 public Long getWorkArea() {
73 return workArea;
74 }
75
76 public void setWorkArea(Long workArea) {
77 this.workArea = workArea;
78 }
79
80 public Long getTask() {
81 return task;
82 }
83
84 public void setTask(Long task) {
85 this.task = task;
86 }
87
88 public String toAssignmentKeyString() {
89 return TKUtils.formatAssignmentKey(jobNumber, workArea, task);
90 }
91
92 public static String getAssignmentKeyString(Assignment a) {
93
94 return TKUtils.formatAssignmentKey(a.getJobNumber(), a.getWorkArea(), a.getTask());
95 }
96
97 @Override
98 public String toString() {
99 return "jobNumber: " + jobNumber + "; workArea: " + workArea + "; task: " + task;
100 }
101
102 }