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.component.Component; |
19 | |
import org.kuali.rice.core.impl.component.ComponentBo; |
20 | |
import org.kuali.rice.core.impl.parameter.ParameterBo; |
21 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
22 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
23 | |
import org.kuali.rice.kim.util.KimConstants; |
24 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
25 | |
import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; |
26 | |
import org.kuali.rice.krad.datadictionary.DataDictionaryException; |
27 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
28 | |
import org.kuali.rice.krad.util.GlobalVariables; |
29 | |
import org.kuali.rice.krad.util.KRADConstants; |
30 | |
import org.kuali.rice.krad.util.ObjectUtils; |
31 | |
|
32 | |
import java.util.HashMap; |
33 | |
import java.util.List; |
34 | |
import java.util.Map; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class ParameterRule extends MaintenanceDocumentRuleBase { |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@Override |
50 | |
protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) { |
51 | 0 | boolean result = super.processCustomRouteDocumentBusinessRules( document ); |
52 | |
|
53 | 0 | result &= checkAllowsMaintenanceEdit( document.getDocumentHeader().getWorkflowDocument() |
54 | |
.getInitiatorPrincipalId(), (ParameterBo)getNewBo() ); |
55 | |
|
56 | 0 | result &= checkComponent((ParameterBo) getNewBo()); |
57 | |
|
58 | 0 | return result; |
59 | |
} |
60 | |
|
61 | |
protected boolean checkAllowsMaintenanceEdit(String initiatorPrincipalId, ParameterBo newBO) { |
62 | |
|
63 | 0 | boolean allowsEdit = false; |
64 | 0 | ParameterBo parm = newBO; |
65 | |
|
66 | 0 | Map<String, String> permissionDetails = new HashMap<String, String>(); |
67 | 0 | permissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, parm.getNamespaceCode()); |
68 | 0 | permissionDetails.put(KimConstants.AttributeConstants.COMPONENT_NAME, parm.getComponentCode()); |
69 | 0 | permissionDetails.put(KimConstants.AttributeConstants.PARAMETER_NAME, parm.getName()); |
70 | 0 | allowsEdit = KimApiServiceLocator.getPermissionService().isAuthorizedByTemplateName( |
71 | |
GlobalVariables.getUserSession().getPerson().getPrincipalId(), |
72 | |
KRADConstants.KRAD_NAMESPACE, |
73 | |
KimConstants.PermissionTemplateNames.MAINTAIN_SYSTEM_PARAMETER, |
74 | |
permissionDetails, null); |
75 | 0 | if(!allowsEdit){ |
76 | 0 | putGlobalError(RiceKeyConstants.AUTHORIZATION_ERROR_PARAMETER); |
77 | |
} |
78 | 0 | return allowsEdit; |
79 | |
} |
80 | |
|
81 | |
public boolean checkComponent(ParameterBo param) { |
82 | 0 | String component = param.getComponentCode(); |
83 | 0 | String namespace = param.getNamespaceCode(); |
84 | 0 | boolean result = false; |
85 | |
|
86 | |
try { |
87 | 0 | List<Component> dataDictionaryAndSpringComponents = KRADServiceLocatorWeb |
88 | |
.getRiceApplicationConfigurationMediationService().getNonDatabaseComponents(); |
89 | 0 | for (Component pdt : dataDictionaryAndSpringComponents) { |
90 | 0 | if (namespace.equals(pdt.getNamespaceCode()) && component.equals(pdt.getCode())) { |
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("namespaceCode", namespace); |
99 | 0 | primaryKeys.put("code", component); |
100 | 0 | result = ObjectUtils.isNotNull(getBoService().findByPrimaryKey(ComponentBo.class, primaryKeys)); |
101 | |
} |
102 | |
|
103 | 0 | if (!result) { |
104 | 0 | putFieldError("code", "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 | |
|