1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sec.document.validation.impl;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.kuali.ole.sec.SecKeyConstants;
22 import org.kuali.ole.sec.businessobject.SecurityDefinition;
23 import org.kuali.ole.sys.OLEPropertyConstants;
24 import org.kuali.rice.kns.document.MaintenanceDocument;
25 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
26 import org.kuali.rice.krad.util.GlobalVariables;
27 import org.kuali.rice.krad.util.KRADConstants;
28
29
30
31
32
33 public class SecurityDefinitionRule extends MaintenanceDocumentRuleBase {
34 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SecurityDefinitionRule.class);
35
36 protected SecurityDefinition oldSecurityDefinition;
37 protected SecurityDefinition newSecurityDefinition;
38
39
40
41
42 @Override
43 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
44 boolean isValid = super.processCustomApproveDocumentBusinessRules(document);
45
46 if (!isValid) {
47 return isValid;
48 }
49
50 boolean isMaintenanceEdit = document.isEdit();
51
52 isValid &= validateSecurityDefinition(isMaintenanceEdit);
53
54 return isValid;
55 }
56
57
58
59
60 @Override
61 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
62 boolean isValid = super.processCustomRouteDocumentBusinessRules(document);
63
64 if (!isValid) {
65 return isValid;
66 }
67
68 boolean isMaintenanceEdit = document.isEdit();
69
70 isValid &= validateSecurityDefinition(isMaintenanceEdit);
71
72 return isValid;
73 }
74
75
76
77
78 @Override
79 public void setupConvenienceObjects() {
80 oldSecurityDefinition = (SecurityDefinition) super.getOldBo();
81 newSecurityDefinition = (SecurityDefinition) super.getNewBo();
82 }
83
84
85
86
87
88
89
90 protected boolean validateSecurityDefinition(boolean isMaintenanceEdit) {
91 boolean isValid = true;
92
93 if (!isMaintenanceEdit) {
94 boolean validDefinitionName = verifyDefinitionNameIsUnique(newSecurityDefinition, KRADConstants.MAINTENANCE_NEW_MAINTAINABLE);
95 if (!validDefinitionName) {
96 isValid = false;
97 }
98 }
99
100 return isValid;
101 }
102
103
104
105
106
107
108
109
110 protected boolean verifyDefinitionNameIsUnique(SecurityDefinition securityDefinition, String errorKeyPrefix) {
111 boolean isValid = true;
112
113 Map<String, String> searchValues = new HashMap<String, String>();
114 searchValues.put(OLEPropertyConstants.NAME, securityDefinition.getName());
115
116 int matchCount = getBoService().countMatching(SecurityDefinition.class, searchValues);
117 if (matchCount > 0) {
118 GlobalVariables.getMessageMap().putError(errorKeyPrefix + OLEPropertyConstants.NAME, SecKeyConstants.ERROR_DEFINITION_NAME_NON_UNIQUE, securityDefinition.getName());
119 isValid = false;
120 }
121
122
123 return isValid;
124 }
125
126
127 }