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.core.xml.dto.AttributeSet; |
23 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
24 | |
import org.kuali.rice.kim.util.KimConstants; |
25 | |
import org.kuali.rice.kns.datadictionary.DataDictionaryException; |
26 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
27 | |
import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; |
28 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
29 | |
import org.kuali.rice.kns.util.GlobalVariables; |
30 | |
import org.kuali.rice.kns.util.KNSConstants; |
31 | |
import org.kuali.rice.kns.util.ObjectUtils; |
32 | |
|
33 | |
import java.util.HashMap; |
34 | |
import java.util.List; |
35 | |
import java.util.Map; |
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(), (ParameterBo)getNewBo() ); |
56 | |
|
57 | 0 | result &= checkComponent((ParameterBo) getNewBo()); |
58 | |
|
59 | 0 | return result; |
60 | |
} |
61 | |
|
62 | |
protected boolean checkAllowsMaintenanceEdit(String initiatorPrincipalId, ParameterBo newBO) { |
63 | |
|
64 | 0 | boolean allowsEdit = false; |
65 | 0 | ParameterBo parm = (ParameterBo)newBO; |
66 | |
|
67 | 0 | AttributeSet permissionDetails = new AttributeSet(); |
68 | 0 | permissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, parm.getNamespaceCode()); |
69 | 0 | permissionDetails.put(KimConstants.AttributeConstants.COMPONENT_NAME, parm.getComponentCode()); |
70 | 0 | permissionDetails.put(KimConstants.AttributeConstants.PARAMETER_NAME, parm.getName()); |
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(ParameterBo param) { |
83 | 0 | String component = param.getComponentCode(); |
84 | 0 | String namespace = param.getNamespaceCode(); |
85 | 0 | boolean result = false; |
86 | |
|
87 | |
try { |
88 | 0 | List<Component> dataDictionaryAndSpringComponents = KNSServiceLocatorWeb.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 | |
|