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 | 0 | public class ParameterRule extends MaintenanceDocumentRuleBase { |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
@Override |
51 | |
protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) { |
52 | 0 | boolean result = super.processCustomRouteDocumentBusinessRules( document ); |
53 | |
|
54 | 0 | result &= checkAllowsMaintenanceEdit( document.getDocumentHeader().getWorkflowDocument() |
55 | |
.getRouteHeader().getInitiatorPrincipalId(), (Parameter)getNewBo() ); |
56 | |
|
57 | 0 | result &= checkComponent((Parameter) getNewBo()); |
58 | |
|
59 | 0 | return result; |
60 | |
} |
61 | |
|
62 | |
protected boolean checkAllowsMaintenanceEdit(String initiatorPrincipalId, Parameter newBO) { |
63 | |
|
64 | 0 | boolean allowsEdit = false; |
65 | 0 | Parameter parm = (Parameter)newBO; |
66 | |
|
67 | 0 | AttributeSet permissionDetails = new AttributeSet(); |
68 | 0 | permissionDetails.put(KimAttributes.NAMESPACE_CODE, parm.getParameterNamespaceCode()); |
69 | 0 | permissionDetails.put(KimAttributes.COMPONENT_NAME, parm.getParameterDetailTypeCode()); |
70 | 0 | permissionDetails.put(KimAttributes.PARAMETER_NAME, parm.getParameterName()); |
71 | 0 | allowsEdit = KIMServiceLocator.getIdentityManagementService().isAuthorizedByTemplateName( |
72 | |
GlobalVariables.getUserSession().getPerson().getPrincipalId(), |
73 | |
KNSConstants.KNS_NAMESPACE, |
74 | |
KimConstants.PermissionTemplateNames.MAINTAIN_SYSTEM_PARAMETER, |
75 | |
permissionDetails, null); |
76 | 0 | if(!allowsEdit){ |
77 | 0 | putGlobalError(RiceKeyConstants.AUTHORIZATION_ERROR_PARAMETER); |
78 | |
} |
79 | 0 | return allowsEdit; |
80 | |
} |
81 | |
|
82 | |
public boolean checkComponent(Parameter param) { |
83 | 0 | String component = param.getParameterDetailTypeCode(); |
84 | 0 | String namespace = param.getParameterNamespaceCode(); |
85 | 0 | boolean result = false; |
86 | |
|
87 | |
try { |
88 | 0 | List<ParameterDetailType> dataDictionaryAndSpringComponents = KNSServiceLocator.getParameterServerService().getNonDatabaseComponents(); |
89 | 0 | for (ParameterDetailType pdt : dataDictionaryAndSpringComponents) { |
90 | 0 | if (pdt.getParameterNamespaceCode().equals(namespace) && pdt.getParameterDetailTypeCode().equals(component)) { |
91 | 0 | result = true; |
92 | 0 | break; |
93 | |
} |
94 | |
} |
95 | |
|
96 | 0 | if (!result) { |
97 | 0 | Map<String, String> primaryKeys = new HashMap<String, String>(2); |
98 | 0 | primaryKeys.put("parameterNamespaceCode", namespace); |
99 | 0 | primaryKeys.put("parameterDetailTypeCode", component); |
100 | 0 | result = ObjectUtils.isNotNull(getBoService().findByPrimaryKey(ParameterDetailType.class, primaryKeys)); |
101 | |
} |
102 | |
|
103 | 0 | if (!result) { |
104 | 0 | putFieldError("parameterDetailTypeCode", "error.document.parameter.detailType.invalid", component); |
105 | |
} |
106 | |
|
107 | 0 | return result; |
108 | |
} |
109 | 0 | catch (DataDictionaryException ex) { |
110 | 0 | throw new RuntimeException("Problem parsing data dictionary during full load required for rule validation: " + ex.getMessage(), ex); |
111 | |
} |
112 | |
} |
113 | |
} |
114 | |
|