1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.pstnrptgrpsubcat.validation;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.kpme.core.util.ValidationUtils;
20 import org.kuali.kpme.pm.positionreportgroup.PositionReportGroup;
21 import org.kuali.kpme.pm.positionreportsubcat.PositionReportSubCategory;
22 import org.kuali.kpme.pm.pstnrptgrpsubcat.PositionReportGroupSubCategory;
23 import org.kuali.kpme.pm.service.base.PmServiceLocator;
24 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
25 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
26
27 public class PstnRptGrpSubCatValidation extends MaintenanceDocumentRuleBase {
28 @Override
29 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
30 boolean valid = false;
31 LOG.debug("entering custom validation for Position Report Group Sub Category");
32 PositionReportGroupSubCategory prgsc = (PositionReportGroupSubCategory) this.getNewDataObject();
33
34 if (prgsc != null) {
35 valid = true;
36 valid &= this.validatePstnRptSubCat(prgsc);
37 valid &= this.validateInstitution(prgsc);
38 valid &= this.validateLocation(prgsc);
39 valid &= this.validatePstnRptGroup(prgsc);
40
41 }
42 return valid;
43 }
44
45 private boolean validatePstnRptSubCat(PositionReportGroupSubCategory prgsc) {
46
47 PositionReportSubCategory aPrsc = PmServiceLocator.getPositionReportSubCatService().getPositionReportSubCat(prgsc.getPositionReportSubCat(), prgsc.getEffectiveLocalDate());
48 String errorMes = "PositionReportSubCategory '" + prgsc.getPositionReportSubCat() + "'";
49 if(aPrsc == null) {
50 this.putFieldError("dataObject.positionReportSubCat", "error.existence", errorMes);
51 return false;
52 } else {
53 if(!ValidationUtils.wildCardMatch(aPrsc.getInstitution(), prgsc.getInstitution())) {
54 String[] params = new String[3];
55 params[0] = prgsc.getInstitution();
56 params[1] = aPrsc.getInstitution();
57 params[2] = errorMes;
58 this.putFieldError("dataObject.institution", "institution.inconsistent", params);
59 return false;
60 }
61 if(!ValidationUtils.wildCardMatch(aPrsc.getLocation(), prgsc.getLocation())) {
62 String[] params = new String[3];
63 params[0] = prgsc.getLocation();
64 params[1] = aPrsc.getLocation();
65 params[2] = errorMes;
66 this.putFieldError("dataObject.location", "location.inconsistent", params);
67 return false;
68 }
69 }
70 return true;
71 }
72
73 private boolean validateInstitution(PositionReportGroupSubCategory prgsc) {
74 if (StringUtils.isNotEmpty(prgsc.getInstitution())
75 && !ValidationUtils.validateInstitution(prgsc.getInstitution(), prgsc.getEffectiveLocalDate())) {
76 this.putFieldError("dataObject.institution", "error.existence", "Instituion '"
77 + prgsc.getInstitution() + "'");
78 return false;
79 } else {
80 return true;
81 }
82 }
83
84 private boolean validateLocation(PositionReportGroupSubCategory prgsc) {
85 if (StringUtils.isNotEmpty(prgsc.getLocation())
86 && !ValidationUtils.validateLocation(prgsc.getLocation(), prgsc.getEffectiveLocalDate())) {
87 this.putFieldError("dataObject.location", "error.existence", "Location '"
88 + prgsc.getLocation() + "'");
89 return false;
90 } else {
91 return true;
92 }
93 }
94
95 private boolean validatePstnRptGroup(PositionReportGroupSubCategory prgsc) {
96 PositionReportGroup aPrg = PmServiceLocator.getPositionReportGroupService().getPositionReportGroup(prgsc.getPositionReportGroup(), prgsc.getEffectiveLocalDate());
97 String errorMes = "PositionReportGroup '" + prgsc.getPositionReportGroup() + "'";
98 if(aPrg == null) {
99 this.putFieldError("dataObject.positionReportGroup", "error.existence", errorMes);
100 return false;
101 } else {
102 if(!ValidationUtils.wildCardMatch(aPrg.getInstitution(), prgsc.getInstitution())) {
103 String[] params = new String[3];
104 params[0] = prgsc.getInstitution();
105 params[1] = aPrg.getInstitution();
106 params[2] = errorMes;
107 this.putFieldError("dataObject.institution", "institution.inconsistent", params);
108 return false;
109 }
110 if(!ValidationUtils.wildCardMatch(aPrg.getLocation(), prgsc.getLocation())) {
111 String[] params = new String[3];
112 params[0] = prgsc.getLocation();
113 params[1] = aPrg.getLocation();
114 params[2] = errorMes;
115 this.putFieldError("dataObject.location", "location.inconsistent", params);
116 return false;
117 }
118 }
119
120 return true;
121
122 }
123 }