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