1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.web.parameter; |
17 | |
|
18 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
19 | |
import org.kuali.rice.core.api.component.Component; |
20 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
21 | |
import org.kuali.rice.core.impl.component.ComponentBo; |
22 | |
import org.kuali.rice.core.impl.parameter.ParameterBo; |
23 | |
import org.kuali.rice.kim.api.KimConstants; |
24 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
25 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
26 | |
import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; |
27 | |
import org.kuali.rice.krad.datadictionary.DataDictionaryException; |
28 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
29 | |
import org.kuali.rice.krad.util.GlobalVariables; |
30 | |
import org.kuali.rice.krad.util.KRADConstants; |
31 | |
import org.kuali.rice.krad.util.ObjectUtils; |
32 | |
|
33 | |
import java.util.Collections; |
34 | |
import java.util.HashMap; |
35 | |
import java.util.List; |
36 | |
import java.util.Map; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class ParameterRule extends MaintenanceDocumentRuleBase { |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@Override |
52 | |
protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) { |
53 | 0 | boolean result = super.processCustomRouteDocumentBusinessRules( document ); |
54 | |
|
55 | 0 | result &= checkAllowsMaintenanceEdit( document.getDocumentHeader().getWorkflowDocument() |
56 | |
.getInitiatorPrincipalId(), (ParameterBo)getNewBo() ); |
57 | |
|
58 | 0 | result &= checkComponent((ParameterBo) getNewBo()); |
59 | |
|
60 | 0 | return result; |
61 | |
} |
62 | |
|
63 | |
protected boolean checkAllowsMaintenanceEdit(String initiatorPrincipalId, ParameterBo newBO) { |
64 | |
|
65 | 0 | boolean allowsEdit = false; |
66 | 0 | ParameterBo parm = newBO; |
67 | |
|
68 | 0 | Map<String, String> permissionDetails = new HashMap<String, String>(); |
69 | 0 | permissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, parm.getNamespaceCode()); |
70 | 0 | permissionDetails.put(KimConstants.AttributeConstants.COMPONENT_NAME, parm.getComponentCode()); |
71 | 0 | permissionDetails.put(KimConstants.AttributeConstants.PARAMETER_NAME, parm.getName()); |
72 | 0 | allowsEdit = KimApiServiceLocator.getPermissionService().isAuthorizedByTemplateName( |
73 | |
GlobalVariables.getUserSession().getPerson().getPrincipalId(), |
74 | |
KRADConstants.KRAD_NAMESPACE, |
75 | |
KimConstants.PermissionTemplateNames.MAINTAIN_SYSTEM_PARAMETER, |
76 | |
permissionDetails, Collections.<String, String>emptyMap()); |
77 | 0 | if(!allowsEdit){ |
78 | 0 | putGlobalError(RiceKeyConstants.AUTHORIZATION_ERROR_PARAMETER); |
79 | |
} |
80 | 0 | return allowsEdit; |
81 | |
} |
82 | |
|
83 | |
public boolean checkComponent(ParameterBo param) { |
84 | 0 | String componentCode = param.getComponentCode(); |
85 | 0 | String namespace = param.getNamespaceCode(); |
86 | 0 | boolean result = false; |
87 | 0 | Component component = CoreApiServiceLocator.getComponentService().getComponentByCode(namespace, componentCode); |
88 | 0 | if (component != null) { |
89 | 0 | result = true; |
90 | |
} |
91 | 0 | if (!result) { |
92 | 0 | putFieldError("code", "error.document.parameter.detailType.invalid", componentCode); |
93 | |
} |
94 | 0 | return result; |
95 | |
} |
96 | |
} |
97 | |
|