1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.positionreportcat.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.positionreporttype.PositionReportType;
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 PositionReportCatValidation extends MaintenanceDocumentRuleBase {
27
28 @Override
29 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
30 boolean valid = false;
31 LOG.debug("entering custom validation for Position Report Category");
32 PositionReportCategory prc = (PositionReportCategory) this.getNewBo();
33
34 if (prc != null) {
35 valid = true;
36 valid &= this.validateInstitution(prc);
37 valid &= this.validateLocation(prc);
38 valid &= this.validatePositionReportType(prc);
39 }
40 return valid;
41 }
42
43 private boolean validatePositionReportType(PositionReportCategory prc) {
44
45 PositionReportType aType = PmServiceLocator.getPositionReportTypeService().getPositionReportType(prc.getPositionReportType(), prc.getEffectiveLocalDate());
46 String positionReportTypeError = "PositionReportType '" + prc.getPositionReportType() + "'";
47 if(aType == null) {
48 this.putFieldError("positionReportType", "error.existence", positionReportTypeError);
49 return false;
50 } else {
51 if(!ValidationUtils.wildCardMatch(aType.getInstitution(),prc.getInstitution())) {
52 String[] params = new String[3];
53 params[0] = prc.getInstitution();
54 params[1] = aType.getInstitution();
55 params[2] = positionReportTypeError;
56 this.putFieldError("institution", "institution.inconsistent", params);
57 return false;
58 }
59 if(!ValidationUtils.wildCardMatch(aType.getLocation(), prc.getLocation())) {
60 String[] params = new String[3];
61 params[0] = prc.getLocation();
62 params[1] = aType.getLocation();
63 params[2] = positionReportTypeError;
64 this.putFieldError("location", "location.inconsistent", params);
65 return false;
66 }
67 }
68 return true;
69 }
70
71 private boolean validateInstitution(PositionReportCategory prc) {
72 if (StringUtils.isNotEmpty(prc.getInstitution())) {
73 if(!ValidationUtils.validateInstitution(prc.getInstitution(), prc.getEffectiveLocalDate())) {
74 this.putFieldError("institution", "error.existence", "Instituion '"
75 + prc.getInstitution() + "'");
76 return false;
77 }
78 }
79 return true;
80 }
81
82 private boolean validateLocation(PositionReportCategory prc) {
83 if (StringUtils.isNotEmpty(prc.getLocation())) {
84 if(!ValidationUtils.validateLocation(prc.getLocation(), prc.getEffectiveLocalDate())) {
85 this.putFieldError("location", "error.existence", "Location '"
86 + prc.getLocation() + "'");
87 return false;
88 }
89 }
90 return true;
91 }
92
93 }