1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.rules;
17
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.kuali.rice.kim.bo.impl.KimAttributes;
23 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
24 import org.kuali.rice.kim.service.KIMServiceLocator;
25 import org.kuali.rice.kim.util.KimConstants;
26 import org.kuali.rice.kns.bo.Parameter;
27 import org.kuali.rice.kns.bo.ParameterDetailType;
28 import org.kuali.rice.kns.datadictionary.DataDictionaryException;
29 import org.kuali.rice.kns.document.MaintenanceDocument;
30 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
31 import org.kuali.rice.kns.service.KNSServiceLocator;
32 import org.kuali.rice.kns.util.GlobalVariables;
33 import org.kuali.rice.kns.util.KNSConstants;
34 import org.kuali.rice.kns.util.ObjectUtils;
35 import org.kuali.rice.kns.util.RiceKeyConstants;
36
37
38
39
40
41
42
43 public class ParameterRule extends MaintenanceDocumentRuleBase {
44
45
46
47
48
49
50 @Override
51 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
52 boolean result = super.processCustomRouteDocumentBusinessRules( document );
53
54 result &= checkAllowsMaintenanceEdit( document.getDocumentHeader().getWorkflowDocument()
55 .getRouteHeader().getInitiatorPrincipalId(), (Parameter)getNewBo() );
56
57 result &= checkComponent((Parameter) getNewBo());
58
59 return result;
60 }
61
62 protected boolean checkAllowsMaintenanceEdit(String initiatorPrincipalId, Parameter newBO) {
63
64 boolean allowsEdit = false;
65 Parameter parm = (Parameter)newBO;
66
67 AttributeSet permissionDetails = new AttributeSet();
68 permissionDetails.put(KimAttributes.NAMESPACE_CODE, parm.getParameterNamespaceCode());
69 permissionDetails.put(KimAttributes.COMPONENT_NAME, parm.getParameterDetailTypeCode());
70 permissionDetails.put(KimAttributes.PARAMETER_NAME, parm.getParameterName());
71 allowsEdit = KIMServiceLocator.getIdentityManagementService().isAuthorizedByTemplateName(
72 GlobalVariables.getUserSession().getPerson().getPrincipalId(),
73 KNSConstants.KNS_NAMESPACE,
74 KimConstants.PermissionTemplateNames.MAINTAIN_SYSTEM_PARAMETER,
75 permissionDetails, null);
76 if(!allowsEdit){
77 putGlobalError(RiceKeyConstants.AUTHORIZATION_ERROR_PARAMETER);
78 }
79 return allowsEdit;
80 }
81
82 public boolean checkComponent(Parameter param) {
83 String component = param.getParameterDetailTypeCode();
84 String namespace = param.getParameterNamespaceCode();
85 boolean result = false;
86
87 try {
88 List<ParameterDetailType> dataDictionaryAndSpringComponents = KNSServiceLocator.getParameterServerService().getNonDatabaseComponents();
89 for (ParameterDetailType pdt : dataDictionaryAndSpringComponents) {
90 if (pdt.getParameterNamespaceCode().equals(namespace) && pdt.getParameterDetailTypeCode().equals(component)) {
91 result = true;
92 break;
93 }
94 }
95
96 if (!result) {
97 Map<String, String> primaryKeys = new HashMap<String, String>(2);
98 primaryKeys.put("parameterNamespaceCode", namespace);
99 primaryKeys.put("parameterDetailTypeCode", component);
100 result = ObjectUtils.isNotNull(getBoService().findByPrimaryKey(ParameterDetailType.class, primaryKeys));
101 }
102
103 if (!result) {
104 putFieldError("parameterDetailTypeCode", "error.document.parameter.detailType.invalid", component);
105 }
106
107 return result;
108 }
109 catch (DataDictionaryException ex) {
110 throw new RuntimeException("Problem parsing data dictionary during full load required for rule validation: " + ex.getMessage(), ex);
111 }
112 }
113 }
114