1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.rules.clocklocation;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.kpme.core.api.authorization.DepartmentalRule;
22 import org.kuali.kpme.core.department.DepartmentBo;
23 import org.kuali.kpme.core.job.JobBo;
24 import org.kuali.kpme.core.workarea.WorkAreaBo;
25 import org.kuali.kpme.tklm.api.common.TkConstants;
26 import org.kuali.kpme.tklm.api.time.rules.clocklocation.ClockLocationRuleContract;
27 import org.kuali.kpme.tklm.time.rules.TkRule;
28 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
29 import org.kuali.rice.kim.api.identity.Person;
30
31 import com.google.common.collect.ImmutableList;
32 import com.google.common.collect.ImmutableMap;
33
34 public class ClockLocationRule extends TkRule implements DepartmentalRule, ClockLocationRuleContract {
35
36 static class KeyFields {
37 private static final String PRINCIPAL_ID = "principalId";
38 private static final String JOB_NUMBER = "jobNumber";
39 private static final String WORK_AREA = "workArea";
40 private static final String DEPT = "dept";
41 private static final String GROUP_KEY_CODE = "groupKeyCode";
42 }
43
44 private static final long serialVersionUID = 959554402289679184L;
45
46 public static final String CACHE_NAME = TkConstants.Namespace.NAMESPACE_PREFIX + "ClockLocationRule";
47
48
49 public static final ImmutableList<String> BUSINESS_KEYS = new ImmutableList.Builder<String>()
50 .add(KeyFields.DEPT)
51 .add(KeyFields.WORK_AREA)
52 .add(KeyFields.JOB_NUMBER)
53 .add(KeyFields.PRINCIPAL_ID)
54 .add(KeyFields.GROUP_KEY_CODE)
55 .build();
56
57 private String tkClockLocationRuleId;
58
59 private DepartmentBo department;
60 private String dept;
61 private String hrDeptId;
62
63 private Long workArea;
64 private String tkWorkAreaId;
65 private String principalId;
66 private Long jobNumber;
67 private String hrJobId;
68
69 private List<ClockLocationRuleIpAddress> ipAddresses = new ArrayList<ClockLocationRuleIpAddress>();
70
71 private WorkAreaBo workAreaObj;
72 private JobBo job;
73 private transient Person principal;
74
75 @Override
76 public ImmutableMap<String, Object> getBusinessKeyValuesMap() {
77 return new ImmutableMap.Builder<String, Object>()
78 .put(KeyFields.DEPT, this.getDept())
79 .put(KeyFields.WORK_AREA, this.getWorkArea())
80 .put(KeyFields.JOB_NUMBER, this.getJobNumber())
81 .put(KeyFields.PRINCIPAL_ID, this.getPrincipalId())
82 .put(KeyFields.GROUP_KEY_CODE, this.getGroupKeyCode())
83 .build();
84 }
85
86 public Long getWorkArea() {
87 return workArea;
88 }
89
90 public void setWorkArea(Long workArea) {
91 this.workArea = workArea;
92 }
93
94 public String getPrincipalId() {
95 return principalId;
96 }
97
98 public void setPrincipalId(String principalId) {
99 this.principalId = principalId;
100 }
101
102 public Long getJobNumber() {
103 return jobNumber;
104 }
105
106 public void setJobNumber(Long jobNumber) {
107 this.jobNumber = jobNumber;
108 }
109 public DepartmentBo getDepartment() {
110 return department;
111 }
112
113 public void setDepartment(DepartmentBo department) {
114 this.department = department;
115 }
116
117 public WorkAreaBo getWorkAreaObj() {
118 return workAreaObj;
119 }
120
121 public void setWorkAreaObj(WorkAreaBo workAreaObj) {
122 this.workAreaObj = workAreaObj;
123 }
124
125 public JobBo getJob() {
126 return job;
127 }
128
129 public void setJob(JobBo job) {
130 this.job = job;
131 }
132
133 public String getTkClockLocationRuleId() {
134 return tkClockLocationRuleId;
135 }
136
137 public void setTkClockLocationRuleId(String tkClockLocationRuleId) {
138 this.tkClockLocationRuleId = tkClockLocationRuleId;
139 }
140
141 public String getDept() {
142 return dept;
143 }
144
145 public void setDept(String dept) {
146 this.dept = dept;
147 }
148
149 public Person getPrincipal() {
150 return principal;
151 }
152
153 public void setPrincipal(Person principal) {
154 this.principal = principal;
155 }
156
157 public String getHrDeptId() {
158 return hrDeptId;
159 }
160
161 public void setHrDeptId(String hrDeptId) {
162 this.hrDeptId = hrDeptId;
163 }
164
165 public String getTkWorkAreaId() {
166 return tkWorkAreaId;
167 }
168
169 public void setTkWorkAreaId(String tkWorkAreaId) {
170 this.tkWorkAreaId = tkWorkAreaId;
171 }
172
173 public String getHrJobId() {
174 return hrJobId;
175 }
176
177 public void setHrJobId(String hrJobId) {
178 this.hrJobId = hrJobId;
179 }
180
181 @Override
182 public String getUniqueKey() {
183 String clockLocKey = getDept()+"_"+getPrincipalId()+"_"+
184 (getJobNumber()!=null ? getJobNumber().toString(): "") +"_" +
185 (getWorkArea() !=null ? getWorkArea().toString() : "") +"_" +
186 (getGroupKeyCode() !=null ? getGroupKeyCode().toString() : "");
187
188 return clockLocKey;
189 }
190
191 @Override
192 public String getId() {
193 return getTkClockLocationRuleId();
194 }
195
196 @Override
197 public void setId(String id) {
198 setTkClockLocationRuleId(id);
199 }
200
201 public List<ClockLocationRuleIpAddress> getIpAddresses() {
202 if(ipAddresses.isEmpty()) {
203 TkServiceLocator.getClockLocationRuleService().populateIPAddressesForCLR(this);
204 }
205 return ipAddresses;
206 }
207
208 public void setIpAddresses(List<ClockLocationRuleIpAddress> ipAddresses) {
209 this.ipAddresses = ipAddresses;
210 }
211
212
213 public String getIpAddressesString() {
214 String aString = "";
215 for(ClockLocationRuleIpAddress ip : this.getIpAddresses()) {
216 aString += ip.getIpAddress() + ", ";
217 }
218 return aString;
219 }
220
221 }