View Javadoc

1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  //        return a.getJobNumber() + HrConstants.ASSIGNMENT_KEY_DELIMITER + a.getWorkArea() + HrConstants.ASSIGNMENT_KEY_DELIMITER + a.getTask();
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 }