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