1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.positionreportsubcat.validation;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.kpme.core.util.ValidationUtils;
20 import org.kuali.kpme.pm.positionreportcat.PositionReportCategory;
21 import org.kuali.kpme.pm.positionreportsubcat.PositionReportSubCategory;
22 import org.kuali.kpme.pm.service.base.PmServiceLocator;
23 import org.kuali.rice.kns.document.MaintenanceDocument;
24 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
25
26 public class PositionReportSubCatValidation extends MaintenanceDocumentRuleBase {
27 @Override
28 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
29 boolean valid = false;
30 LOG.debug("entering custom validation for Position Report Sub Category");
31 PositionReportSubCategory prsc = (PositionReportSubCategory) this.getNewBo();
32
33 if (prsc != null) {
34 valid = true;
35 valid &= this.validatePositionReportCategory(prsc);
36 valid &= this.validateInstitution(prsc);
37 valid &= this.validateLocation(prsc);
38 }
39 return valid;
40 }
41
42 private boolean validatePositionReportCategory(PositionReportSubCategory prsc) {
43 PositionReportCategory aCat = PmServiceLocator.getPositionReportCatService().getPositionReportCat(prsc.getPositionReportCat(), prsc.getEffectiveLocalDate());
44
45 String errorMes = "PositionReportCategory '" + prsc.getPositionReportCat() + "'";
46 if(aCat == null) {
47 this.putFieldError("positionReportCat", "error.existence", errorMes);
48 return false;
49 } else {
50 if(!ValidationUtils.wildCardMatch(aCat.getInstitution(), prsc.getInstitution())) {
51 String[] params = new String[3];
52 params[0] = prsc.getInstitution();
53 params[1] = aCat.getInstitution();
54 params[2] = errorMes;
55 this.putFieldError("institution", "institution.inconsistent", params);
56 return false;
57 }
58 if(!ValidationUtils.wildCardMatch(aCat.getLocation(), prsc.getLocation())) {
59 String[] params = new String[3];
60 params[0] = prsc.getLocation();
61 params[1] = aCat.getLocation();
62 params[2] = errorMes;
63 this.putFieldError("location", "location.inconsistent", params);
64 return false;
65 }
66 }
67 return true;
68 }
69
70 private boolean validateInstitution(PositionReportSubCategory prsc) {
71 if (StringUtils.isNotEmpty(prsc.getInstitution())) {
72 if(!ValidationUtils.validateInstitution(prsc.getInstitution(), prsc.getEffectiveLocalDate())) {
73 this.putFieldError("institution", "error.existence", "Instituion '"
74 + prsc.getInstitution() + "'");
75 return false;
76 }
77 }
78 return true;
79 }
80
81 private boolean validateLocation(PositionReportSubCategory prsc) {
82 if (StringUtils.isNotEmpty(prsc.getLocation())) {
83 if(!ValidationUtils.validateLocation(prsc.getLocation(), prsc.getEffectiveLocalDate())) {
84 this.putFieldError("location", "error.existence", "Location '"
85 + prsc.getLocation() + "'");
86 return false;
87 }
88 }
89 return true;
90 }
91 }