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