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 public class ParameterRule extends MaintenanceDocumentRuleBase {
45
46
47
48
49
50
51 @Override
52 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
53 boolean result = super.processCustomRouteDocumentBusinessRules( document );
54
55 result &= checkAllowsMaintenanceEdit( document.getDocumentHeader().getWorkflowDocument()
56 .getInitiatorPrincipalId(), (ParameterBo)getNewBo() );
57
58 result &= checkComponent((ParameterBo) getNewBo());
59
60 return result;
61 }
62
63 protected boolean checkAllowsMaintenanceEdit(String initiatorPrincipalId, ParameterBo newBO) {
64
65 boolean allowsEdit = false;
66 ParameterBo parm = newBO;
67
68 Map<String, String> permissionDetails = new HashMap<String, String>();
69 permissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, parm.getNamespaceCode());
70 permissionDetails.put(KimConstants.AttributeConstants.COMPONENT_NAME, parm.getComponentCode());
71 permissionDetails.put(KimConstants.AttributeConstants.PARAMETER_NAME, parm.getName());
72 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 if(!allowsEdit){
78 putGlobalError(RiceKeyConstants.AUTHORIZATION_ERROR_PARAMETER);
79 }
80 return allowsEdit;
81 }
82
83 public boolean checkComponent(ParameterBo param) {
84 String componentCode = param.getComponentCode();
85 String namespace = param.getNamespaceCode();
86 boolean result = false;
87 Component component = CoreApiServiceLocator.getComponentService().getComponentByCode(namespace, componentCode);
88 if (component != null) {
89 result = true;
90 }
91 if (!result) {
92 putFieldError("code", "error.document.parameter.detailType.invalid", componentCode);
93 }
94 return result;
95 }
96 }
97