1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.roles.validation;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.hr.time.roles.TkRole;
20 import org.kuali.hr.time.roles.TkRoleGroup;
21 import org.kuali.hr.time.util.TkConstants;
22 import org.kuali.rice.kns.document.MaintenanceDocument;
23 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
24 import org.kuali.rice.krad.bo.PersistableBusinessObject;
25
26 public class TkRoleValidation extends MaintenanceDocumentRuleBase{
27
28 private static final String ADD_LINE_LOCATION = "add.roles.";
29
30 protected boolean validateTkRole(TkRole role, String fieldPrefix) {
31 boolean valid = true;
32
33 if (fieldPrefix == null)
34 fieldPrefix = "";
35
36 String rname = role.getRoleName();
37 if (StringUtils.equalsIgnoreCase(rname, TkConstants.ROLE_TK_LOCATION_ADMIN) || StringUtils.equalsIgnoreCase(rname, TkConstants.ROLE_TK_LOCATION_VO)) {
38 if (StringUtils.isBlank(role.getChart())) {
39 this.putFieldError(fieldPrefix + "chart", "error.role.chart.required");
40 valid = false;
41 }
42 } else {
43 if (!StringUtils.isBlank(role.getChart())) {
44 this.putFieldError(fieldPrefix + "chart", "error.role.chart.disallowed");
45 valid = false;
46 }
47 }
48
49 return valid;
50 }
51
52
53
54
55
56
57
58 boolean validateTkRoleGroup(TkRoleGroup roleGroup) {
59 boolean valid = true;
60
61 int pos = 0;
62 for (TkRole role: roleGroup.getRoles()) {
63 StringBuffer prefix = new StringBuffer("roles[");
64 prefix.append(pos).append("].");
65 validateTkRole(role, prefix.toString());
66 pos++;
67 }
68
69 return valid;
70 }
71
72 @Override
73 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
74 boolean valid = true;
75
76 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
77 if (pbo instanceof TkRole) {
78 TkRole role = (TkRole)pbo;
79 valid = validateTkRole(role, null);
80 } else if (pbo instanceof TkRoleGroup) {
81 TkRoleGroup roleGroup = (TkRoleGroup)pbo;
82 valid = validateTkRoleGroup(roleGroup);
83 }
84
85 return valid;
86 }
87
88 @Override
89
90
91
92 public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject line) {
93 boolean valid = true;
94
95 if (line instanceof TkRole) {
96 TkRole role = (TkRole)line;
97 valid = validateTkRole(role, ADD_LINE_LOCATION);
98 }
99
100 return valid;
101 }
102 }