1 package org.kuali.kpme.edo.reports;
2
3
4
5 import java.lang.reflect.Type;
6 import java.math.BigDecimal;
7 import java.util.ArrayList;
8 import java.util.Iterator;
9 import java.util.List;
10 import java.util.Map;
11
12 import org.apache.commons.lang.StringUtils;
13 import org.kuali.kpme.edo.api.reviewlayerdef.EdoReviewLayerDefinition;
14 import org.kuali.kpme.edo.reviewlayerdef.EdoReviewLayerDefinitionBo;
15 import org.kuali.kpme.edo.util.EdoConstants;
16 import org.kuali.kpme.edo.util.EdoConstants.VoteType;
17 import org.kuali.rice.kns.service.KNSServiceLocator;
18 import org.kuali.rice.krad.bo.BusinessObjectBase;
19 import org.kuali.rice.krad.service.KRADServiceLocator;
20 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21 import org.kuali.rice.krad.service.PersistenceService;
22 import org.kuali.rice.krad.util.ObjectUtils;
23
24 import com.google.gson.Gson;
25 import com.google.gson.reflect.TypeToken;
26
27 public class EdoPromotionAndTenureReport extends BusinessObjectBase {
28 private static final long serialVersionUID = -317961785047441240L;
29 private static transient PersistenceService persistenceService;
30
31 public static final List<String> VOTE_RECORD_VALUES = EdoConstants.VOTE_RECORD_VALUES;
32
33 private Integer voteRecordId;
34 private String candidateUsername;
35 private String iuLastNamePref;
36 private String iuFirstNamePref;
37 private String optionValue;
38 private String currentRank;
39 private BigDecimal dossierId;
40 private String dossierStatus;
41 private String rankSought;
42 private String departmentId;
43 private String schoolId;
44 private String gender;
45 private String dossierTypeName;
46 private BigDecimal dossierTypeId;
47 private Integer voteRound;
48 private BigDecimal routeLevel;
49 private String reviewLayer;
50 private String voteType;
51 private String workflowId;
52 private Integer absentCountPromotion;
53 private Integer absentCountTenure;
54 private Integer abstainCountPromotion;
55 private Integer abstainCountTenure;
56 private Integer noCountPromotion;
57 private Integer noCountTenure;
58 private Integer yesCountPromotion;
59 private Integer yesCountTenure;
60 private String aoeCode;
61 private String visaPermitType;
62 private String ethnicity;
63 private boolean early;
64
65 private Map<BigDecimal, EdoPromotionAndTenureReport> voteRecordMap;
66 private List<EdoReviewLayerDefinition> reviewRouteLevels;
67
68 public Integer getVoteRecordId() {
69 return voteRecordId;
70 }
71
72 public void setVoteRecordId(Integer voteRecordId) {
73 this.voteRecordId = voteRecordId;
74 }
75
76 public String getCandidateUsername() {
77 return candidateUsername;
78 }
79
80 public void setCandidateUsername(String candidateUsername) {
81 this.candidateUsername = candidateUsername;
82 }
83
84 public String getIuLastNamePref() {
85 return iuLastNamePref;
86 }
87
88 public void setIuLastNamePref(String iuLastNamePref) {
89 this.iuLastNamePref = iuLastNamePref;
90 }
91
92 public String getIuFirstNamePref() {
93 return iuFirstNamePref;
94 }
95
96 public void setIuFirstNamePref(String iuFirstNamePref) {
97 this.iuFirstNamePref = iuFirstNamePref;
98 }
99
100 public String getOptionValue() {
101 return optionValue;
102 }
103
104 public void setOptionValue(String optionValue) {
105 this.optionValue = optionValue;
106 }
107
108 public String getCurrentRank() {
109 return currentRank;
110 }
111
112 public void setCurrentRank(String currentRank) {
113 this.currentRank = currentRank;
114 }
115
116 public BigDecimal getDossierId() {
117 return dossierId;
118 }
119
120 public void setDossierId(BigDecimal dossierId) {
121 this.dossierId = dossierId;
122 }
123
124 public String getDossierStatus() {
125 return dossierStatus;
126 }
127
128 public void setDossierStatus(String dossierStatus) {
129 this.dossierStatus = dossierStatus;
130 }
131
132 public String getRankSought() {
133 return rankSought;
134 }
135
136 public void setRankSought(String rankSought) {
137 this.rankSought = rankSought;
138 }
139
140 public String getDepartmentId() {
141 return departmentId;
142 }
143
144 public void setDepartmentId(String departmentId) {
145 this.departmentId = departmentId;
146 }
147
148 public String getSchoolId() {
149 return schoolId;
150 }
151
152 public void setSchoolId(String schoolId) {
153 this.schoolId = schoolId;
154 }
155
156 public String getGender() {
157 return gender;
158 }
159
160 public void setGender(String gender) {
161 this.gender = gender;
162 }
163
164 public String getDossierTypeName() {
165 return dossierTypeName;
166 }
167
168 public void setDossierTypeName(String dossierTypeName) {
169 this.dossierTypeName = dossierTypeName;
170 }
171
172 public BigDecimal getDossierTypeId() {
173 return dossierTypeId;
174 }
175
176 public void setDossierTypeId(BigDecimal dossierTypeId) {
177 this.dossierTypeId = dossierTypeId;
178 }
179
180 public Integer getVoteRound() {
181 return voteRound;
182 }
183
184 public void setVoteRound(Integer voteRound) {
185 this.voteRound = voteRound;
186 }
187
188 public String getVoteRoundName() {
189 if (ObjectUtils.isNotNull(getVoteRound())) {
190 String voteRoundName = EdoConstants.VOTE_ROUNDS.get(getVoteRound());
191 if (ObjectUtils.isNotNull(voteRoundName) && StringUtils.isNotEmpty(voteRoundName)) {
192 return voteRoundName;
193 }
194 else {
195 return "Invalid Vote Round";
196 }
197 }
198 else {
199 return "Unknown Vote Round";
200 }
201 }
202
203 public BigDecimal getRouteLevel() {
204 return routeLevel;
205 }
206
207 public void setRouteLevel(BigDecimal routeLevel) {
208 this.routeLevel = routeLevel;
209 }
210
211 public String getReviewLayer() {
212 return reviewLayer;
213 }
214
215 public void setReviewLayer(String reviewLayer) {
216 this.reviewLayer = reviewLayer;
217 }
218
219 public String getVoteType() {
220 return voteType;
221 }
222
223 public void setVoteType(String voteType) {
224 this.voteType = voteType;
225 }
226
227 public String getWorkflowId() {
228 return workflowId;
229 }
230
231 public void setWorkflowId(String workflowId) {
232 this.workflowId = workflowId;
233 }
234
235 public Integer getAbsentCountPromotion() {
236 return (ObjectUtils.isNotNull(absentCountPromotion) ? absentCountPromotion : new Integer(0));
237 }
238
239 public void setAbsentCountPromotion(Integer absentCountPromotion) {
240 this.absentCountPromotion = (ObjectUtils.isNotNull(absentCountPromotion) ? absentCountPromotion : new Integer(0));
241 }
242
243 public Integer getAbsentCountTenure() {
244 return (ObjectUtils.isNotNull(absentCountTenure) ? absentCountTenure : new Integer(0));
245 }
246
247 public void setAbsentCountTenure(Integer absentCountTenure) {
248 this.absentCountTenure = (ObjectUtils.isNotNull(absentCountTenure) ? absentCountTenure : new Integer(0));
249 }
250
251 public Integer getAbstainCountPromotion() {
252 return (ObjectUtils.isNotNull(abstainCountPromotion) ? abstainCountPromotion : new Integer(0));
253 }
254
255 public void setAbstainCountPromotion(Integer abstainCountPromotion) {
256 this.abstainCountPromotion = (ObjectUtils.isNotNull(abstainCountPromotion) ? abstainCountPromotion : new Integer(0));
257 }
258
259 public Integer getAbstainCountTenure() {
260 return (ObjectUtils.isNotNull(abstainCountTenure) ? abstainCountTenure : new Integer(0));
261 }
262
263 public void setAbstainCountTenure(Integer abstainCountTenure) {
264 this.abstainCountTenure = (ObjectUtils.isNotNull(abstainCountTenure) ? abstainCountTenure : new Integer(0));
265 }
266
267 public Integer getNoCountPromotion() {
268 return (ObjectUtils.isNotNull(noCountPromotion) ? noCountPromotion : new Integer(0));
269 }
270
271 public void setNoCountPromotion(Integer noCountPromotion) {
272 this.noCountPromotion = (ObjectUtils.isNotNull(noCountPromotion) ? noCountPromotion : new Integer(0));
273 }
274
275 public Integer getNoCountTenure() {
276 return (ObjectUtils.isNotNull(noCountTenure) ? noCountTenure : new Integer(0));
277 }
278
279 public void setNoCountTenure(Integer noCountTenure) {
280 this.noCountTenure = (ObjectUtils.isNotNull(noCountTenure) ? noCountTenure : new Integer(0));
281 }
282
283 public Integer getYesCountPromotion() {
284 return (ObjectUtils.isNotNull(yesCountPromotion) ? yesCountPromotion : new Integer(0));
285 }
286
287 public void setYesCountPromotion(Integer yesCountPromotion) {
288 this.yesCountPromotion = (ObjectUtils.isNotNull(yesCountPromotion) ? yesCountPromotion : new Integer(0));
289 }
290
291 public Integer getYesCountTenure() {
292 return (ObjectUtils.isNotNull(yesCountTenure) ? yesCountTenure : new Integer(0));
293 }
294
295 public void setYesCountTenure(Integer yesCountTenure) {
296 this.yesCountTenure = (ObjectUtils.isNotNull(yesCountTenure) ? yesCountTenure : new Integer(0));
297 }
298
299 public String getAoeCode() {
300 return aoeCode;
301 }
302
303 public void setAoeCode(String aoeCode) {
304 this.aoeCode = aoeCode;
305 }
306
307 public String getVisaPermitType() {
308 return visaPermitType;
309 }
310
311 public void setVisaPermitType(String visaPermitType) {
312 this.visaPermitType = visaPermitType;
313 }
314
315 public String getEthnicity() {
316 return ethnicity;
317 }
318
319 public void setEthnicity(String ethnicity) {
320 this.ethnicity = ethnicity;
321 }
322
323 public boolean isEarly() {
324 return early;
325 }
326
327 public void setEarly(boolean early) {
328 this.early = early;
329 }
330
331 public Map<BigDecimal, EdoPromotionAndTenureReport> getVoteRecordMap() {
332 return voteRecordMap;
333 }
334
335 public void setVoteRecordMap(Map<BigDecimal, EdoPromotionAndTenureReport> voteRecordMap) {
336 this.voteRecordMap = voteRecordMap;
337 }
338
339 protected List<EdoReviewLayerDefinition> getReviewRouteLevels() {
340 return reviewRouteLevels;
341 }
342
343 public void setReviewRouteLevels(List<EdoReviewLayerDefinition> reviewRouteLevels) {
344 this.reviewRouteLevels = reviewRouteLevels;
345 }
346
347 public List<String> getVoteForReport() {
348 if (dossierTypeName.equals(VoteType.VOTE_TYPE_TENURE)) {
349 return getTenureVote();
350 }
351
352 if (dossierTypeName.equals(VoteType.VOTE_TYPE_PROMOTION)) {
353 return getPromotionVote();
354 }
355
356
357
358 return getTenureVote();
359 }
360
361 public String getVoteForReportDisplay() {
362 List<String> voteForReport = getVoteForReport();
363 if (voteForReport.isEmpty()) {
364 return "";
365 }
366 else if (voteForReport.size() == 1) {
367 return voteForReport.get(0);
368 }
369 else {
370 String result = "";
371 for(Iterator<String> iter = voteForReport.iterator(); iter.hasNext();) {
372 result += iter.next();
373 if (iter.hasNext()) {
374 result += "-";
375 }
376 }
377 return result;
378 }
379 }
380
381 protected List<String> getPromotionVote() {
382 List<String> result = new ArrayList<String>();
383
384 if (voteType.equals(EdoConstants.VOTE_TYPE_SINGLE)) {
385 result.addAll(evaluateForSingleVoteTypePromotion());
386 return result;
387 }
388 else if (voteType.equals(EdoConstants.VOTE_TYPE_MULTIPLE)) {
389 result.addAll(evaluateForMultipleVoteTypePromotion());
390 return result;
391 }
392
393 result.add("error");
394 return result;
395 }
396
397 protected List<String> getTenureVote() {
398 List<String> result = new ArrayList<String>();
399
400 if (voteType.equals(EdoConstants.VOTE_TYPE_SINGLE)) {
401 result.addAll(evaluateForSingleVoteTypeTenure());
402 return result;
403 }
404 else if (voteType.equals(EdoConstants.VOTE_TYPE_MULTIPLE)) {
405 result.addAll(evaluateForMultipleVoteTypeTenure());
406 return result;
407 }
408
409 result.add("error");
410 return result;
411 }
412
413
414
415
416
417
418
419 protected List<String> evaluateForSingleVoteTypePromotion() {
420 List<String> result = new ArrayList<String>();
421 if (getAbsentCountPromotion() + getAbstainCountPromotion() + getNoCountPromotion() + getYesCountPromotion() > 1) { result.add("ERROR"); }
422 else if (getYesCountPromotion() ==1) { result.add(VOTE_RECORD_VALUES.get(0)); }
423 else if (getNoCountPromotion() ==1) { result.add(VOTE_RECORD_VALUES.get(1)); }
424 else if (getAbstainCountPromotion() ==1) { result.add(VOTE_RECORD_VALUES.get(2)); }
425 else if (getAbsentCountPromotion() ==1) { result.add(VOTE_RECORD_VALUES.get(3)); }
426 else result.add("--");
427
428 return result;
429 }
430
431
432
433
434
435
436
437 protected List<String> evaluateForSingleVoteTypeTenure() {
438 List<String> result = new ArrayList<String>();
439 if (getAbsentCountTenure() + getAbstainCountTenure() + getNoCountTenure() + getYesCountTenure() > 1) { result.add("ERROR"); }
440 else if (getYesCountTenure() ==1) { result.add(VOTE_RECORD_VALUES.get(0)); }
441 else if (getNoCountTenure() ==1) { result.add(VOTE_RECORD_VALUES.get(1)); }
442 else if (getAbstainCountTenure() ==1) { result.add(VOTE_RECORD_VALUES.get(2)); }
443 else if (getAbsentCountTenure() ==1) { result.add(VOTE_RECORD_VALUES.get(3)); }
444 else result.add("--");
445
446 return result;
447 }
448
449
450
451
452
453 protected List<String> evaluateForMultipleVoteTypePromotion() {
454 List<String> result = new ArrayList<String>();
455 result.add(""+ getYesCountPromotion());
456 result.add(""+ getNoCountPromotion());
457 result.add(""+ getAbstainCountPromotion());
458 result.add(""+ getAbsentCountPromotion());
459 return result;
460 }
461
462
463
464
465
466 protected List<String> evaluateForMultipleVoteTypeTenure() {
467 List<String> result = new ArrayList<String>();
468 result.add(""+ getYesCountTenure());
469 result.add(""+ getNoCountTenure());
470 result.add(""+ getAbstainCountTenure());
471 result.add(""+ getAbsentCountTenure());
472 return result;
473 }
474
475 public String getPromotionAndTenureReportJSONString() {
476 ArrayList<String> tmp = new ArrayList<String>();
477 Type tmpType = new TypeToken<List<String>>() {}.getType();
478 Gson gson = new Gson();
479
480 tmp.add(getIuLastNamePref());
481 tmp.add(getIuFirstNamePref());
482
483
484
485 tmp.add("");
486 tmp.add(getOptionValue());
487 tmp.add(getCurrentRank());
488 tmp.add(getRankSought());
489 tmp.add(getDepartmentId().toString());
490 tmp.add(getSchoolId().toString());
491 tmp.add(getGender());
492 tmp.add(getEthnicity());
493 tmp.add(getVisaPermitType());
494
495
496 for(EdoReviewLayerDefinition reviewLayer : getReviewRouteLevels()) {
497 if (ObjectUtils.isNotNull(getVoteRecordMap())) {
498 EdoPromotionAndTenureReport voteRecord = getVoteRecordMap().get(reviewLayer.getRouteLevel());
499
500 if (ObjectUtils.isNotNull(voteRecord)) {
501 for(String vote : voteRecord.getVoteForReport()) {
502 tmp.add(vote);
503 }
504 }
505 else {
506 addEmptyVoteValues(tmp, reviewLayer);
507 }
508 }
509 else {
510 addEmptyVoteValues(tmp, reviewLayer);
511 }
512 }
513
514
515 tmp.add(getDossierTypeName().toString());
516 tmp.add(getVoteRoundName());
517
518 return gson.toJson(tmp, tmpType).toString();
519 }
520
521 protected void addEmptyVoteValues(List<String> tmp, EdoReviewLayerDefinition reviewLayer) {
522 if (reviewLayer.getVoteType().equals(EdoConstants.VOTE_TYPE_SINGLE)) {
523 tmp.add("--");
524 }
525 else if (reviewLayer.getVoteType().equals(EdoConstants.VOTE_TYPE_MULTIPLE)) {
526 tmp.add("--");
527 tmp.add("--");
528 tmp.add("--");
529 tmp.add("--");
530 }
531 }
532
533 @Override
534
535
536
537
538
539 public void refresh() {
540 getPersistenceService().retrieveNonKeyFields(this);
541 }
542
543
544
545
546 protected static PersistenceService getPersistenceService() {
547
548
549
550 return persistenceService;
551 }
552
553 }