1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.util;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.RiceKeyConstants;
20 import org.kuali.rice.krad.bo.GlobalBusinessObject;
21 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
22 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
23 import org.kuali.rice.krad.util.KRADConstants;
24 import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
25 import org.kuali.rice.krms.dto.RuleManagementWrapper;
26 import org.kuali.rice.krms.framework.type.ActionTypeService;
27 import org.kuali.rice.krms.impl.authorization.AgendaAuthorizationService;
28 import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
29 import org.kuali.rice.krms.impl.util.KRMSPropertyConstants;
30
31
32
33
34 public class RuleEditorBusRule extends MaintenanceDocumentRuleBase {
35
36 @Override
37 protected boolean primaryKeyCheck(MaintenanceDocument document) {
38
39 boolean success = true;
40 Class<?> dataObjectClass = document.getNewMaintainableObject().getDataObjectClass();
41
42
43 Object oldBo = ((RuleManagementWrapper) document.getOldMaintainableObject().getDataObject());
44 Object newDataObject = ((RuleManagementWrapper) document.getNewMaintainableObject().getDataObject());
45
46
47
48
49
50
51 if (newDataObject instanceof GlobalBusinessObject) {
52 return success;
53 }
54
55
56
57 if (document.isEdit()) {
58 if (!getDataObjectMetaDataService().equalsByPrimaryKeys(oldBo, newDataObject)) {
59
60 putDocumentError(KRADConstants.DOCUMENT_ERRORS,
61 RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_PRIMARY_KEYS_CHANGED_ON_EDIT,
62 getHumanReadablePrimaryKeyFieldNames(dataObjectClass));
63 success &= false;
64 }
65 }
66
67
68
69 else if (document.isNew()) {
70
71
72 }
73
74 return success;
75 }
76
77 @Override
78 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
79 return true;
80 }
81
82
83
84
85
86
87
88 private boolean validRuleType(String ruleTypeId, String contextId) {
89 if (StringUtils.isBlank(ruleTypeId)) {
90 return true;
91 }
92
93 if (getKrmsTypeRepositoryService().getRuleTypeByRuleTypeIdAndContextId(ruleTypeId, contextId) != null) {
94 return true;
95 } else {
96 this.putFieldError(KRMSPropertyConstants.Rule.TYPE, "error.rule.invalidType");
97 return false;
98 }
99 }
100
101
102
103
104
105
106
107 private boolean validRuleActionType(String typeId, String contextId) {
108 if (StringUtils.isBlank(typeId)) {
109 return true;
110 }
111
112 if (getKrmsTypeRepositoryService().getActionTypeByActionTypeIdAndContextId(typeId, contextId) != null) {
113 return true;
114 } else {
115 this.putFieldError(KRMSPropertyConstants.Action.TYPE, "error.action.invalidType");
116 return false;
117 }
118 }
119
120
121
122
123 private boolean validRuleActionName(String name) {
124 if (StringUtils.isNotBlank(name)) {
125 return true;
126 } else {
127 this.putFieldError(KRMSPropertyConstants.Action.NAME, "error.action.missingName");
128 return false;
129 }
130 }
131
132 public KrmsTypeRepositoryService getKrmsTypeRepositoryService() {
133 return KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService();
134 }
135
136 public ActionTypeService getActionTypeService(String serviceName) {
137 return (ActionTypeService)KrmsRepositoryServiceLocator.getService(serviceName);
138 }
139
140 public AgendaAuthorizationService getAgendaAuthorizationService() {
141 return KrmsRepositoryServiceLocator.getAgendaAuthorizationService();
142 }
143
144 }
145