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.regex.Matcher;
19 import java.util.regex.Pattern;
20
21 import org.apache.log4j.Logger;
22 import org.kuali.hr.time.util.TkConstants;
23
24 public class AssignmentDescriptionKey {
25 private static final Logger LOG = Logger.getLogger(AssignmentDescriptionKey.class);
26
27 private Long jobNumber;
28 private Long workArea;
29 private Long task;
30
31 public AssignmentDescriptionKey() {
32
33 }
34
35
36
37 public AssignmentDescriptionKey(Assignment a) {
38 if (a != null) {
39 this.jobNumber = a.getJobNumber();
40 this.workArea = a.getWorkArea();
41 this.task = a.getTask();
42 }
43 }
44
45 public AssignmentDescriptionKey(String jobNumer, String workArea, String task) {
46 this.jobNumber = Long.parseLong(jobNumer);
47 this.workArea = Long.parseLong(workArea);
48 this.task = Long.parseLong(task);
49 }
50 public AssignmentDescriptionKey(Long jobNumer, Long workArea, Long task) {
51 this.jobNumber = jobNumer;
52 this.workArea = workArea;
53 this.task = task;
54 }
55 public AssignmentDescriptionKey(String assignmentKey) {
56
57 try {
58 Pattern keyPattern = Pattern.compile("^\\d{1,}_\\d{1,}_\\d{1,}");
59 Matcher match = keyPattern.matcher(assignmentKey);
60 if(!match.matches()) {
61 throw new RuntimeException("the format of the assignment key is wrong. it should be jobNumber_workArea_task");
62 }
63
64 String[] key = assignmentKey.split(TkConstants.ASSIGNMENT_KEY_DELIMITER);
65
66 this.jobNumber = Long.parseLong(key[0]);
67 this.workArea = Long.parseLong(key[1]);
68 this.task = Long.parseLong(key[2]);
69 }
70 catch(NullPointerException npe) {
71 LOG.error("The assignment key is null");
72 }
73
74 }
75 public Long getJobNumber() {
76 return jobNumber;
77 }
78 public void setJobNumber(Long jobNumber) {
79 this.jobNumber = jobNumber;
80 }
81 public Long getWorkArea() {
82 return workArea;
83 }
84 public void setWorkArea(Long workArea) {
85 this.workArea = workArea;
86 }
87 public Long getTask() {
88 return task;
89 }
90 public void setTask(Long task) {
91 this.task = task;
92 }
93
94 @Override
95 public String toString() {
96 return "jobNumber: " + jobNumber + "; workArea: " + workArea + "; task: " + task;
97 }
98
99 public String toAssignmentKeyString() {
100 return jobNumber + TkConstants.ASSIGNMENT_KEY_DELIMITER + workArea + TkConstants.ASSIGNMENT_KEY_DELIMITER + task;
101 }
102
103
104 public static String getAssignmentKeyString(Assignment a) {
105 return a.getJobNumber() + TkConstants.ASSIGNMENT_KEY_DELIMITER + a.getWorkArea() + TkConstants.ASSIGNMENT_KEY_DELIMITER + a.getTask();
106 }
107 }