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