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.apache.commons.lang.StringUtils; |
19 | |
import org.apache.commons.logging.Log; |
20 | |
import org.apache.commons.logging.LogFactory; |
21 | |
import org.kuali.rice.core.framework.parameter.ParameterService; |
22 | |
import org.kuali.rice.core.impl.component.ComponentBo; |
23 | |
import org.kuali.rice.core.impl.component.DerivedComponentBo; |
24 | |
import org.kuali.rice.core.impl.parameter.ParameterBo; |
25 | |
import org.kuali.rice.kim.api.KimConstants; |
26 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
27 | |
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; |
28 | |
import org.kuali.rice.krad.bo.BusinessObject; |
29 | |
import org.kuali.rice.krad.util.GlobalVariables; |
30 | |
import org.kuali.rice.krad.util.KRADConstants; |
31 | |
|
32 | |
import java.util.Collection; |
33 | |
import java.util.Collections; |
34 | |
import java.util.HashMap; |
35 | |
import java.util.List; |
36 | |
import java.util.Map; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class ParameterLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl { |
45 | |
|
46 | |
private static final long serialVersionUID = 4381873774407301041L; |
47 | |
|
48 | 0 | private static final Log LOG = LogFactory.getLog(ParameterLookupableHelperServiceImpl.class); |
49 | |
private static final String COMPONENT_NAME = "component.name"; |
50 | |
private static final String DERIVED_COMPONENT_NAME = "derivedComponent.name"; |
51 | |
private static final String NAMESPACE_CODE = "namespaceCode"; |
52 | |
|
53 | |
@Override |
54 | |
protected boolean allowsMaintenanceEditAction(BusinessObject businessObject) { |
55 | |
|
56 | 0 | ParameterBo parm = (ParameterBo)businessObject; |
57 | |
|
58 | 0 | Map<String, String> permissionDetails = new HashMap<String, String>(); |
59 | 0 | permissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, parm.getNamespaceCode()); |
60 | 0 | permissionDetails.put(KimConstants.AttributeConstants.COMPONENT_NAME, parm.getComponentCode()); |
61 | 0 | permissionDetails.put(KimConstants.AttributeConstants.PARAMETER_NAME, parm.getName()); |
62 | 0 | return KimApiServiceLocator.getPermissionService().isAuthorizedByTemplateName( |
63 | |
GlobalVariables.getUserSession().getPerson().getPrincipalId(), |
64 | |
KRADConstants.KRAD_NAMESPACE, |
65 | |
KimConstants.PermissionTemplateNames.MAINTAIN_SYSTEM_PARAMETER, |
66 | |
permissionDetails, Collections.<String, String>emptyMap()); |
67 | |
} |
68 | |
|
69 | |
@Override |
70 | |
public List<? extends BusinessObject> getSearchResults(java.util.Map<String, String> fieldValues) { |
71 | |
|
72 | 0 | List<ParameterBo> parametersWithDerivedComponents = null; |
73 | |
|
74 | 0 | if (fieldValues.containsKey(COMPONENT_NAME) && StringUtils.isNotBlank(fieldValues.get(COMPONENT_NAME))) { |
75 | |
|
76 | 0 | Map<String, String> derivedComponentFieldValues = new HashMap<String, String>(fieldValues); |
77 | 0 | String componentName = derivedComponentFieldValues.remove(COMPONENT_NAME); |
78 | 0 | derivedComponentFieldValues.put(DERIVED_COMPONENT_NAME, componentName); |
79 | 0 | parametersWithDerivedComponents = (List<ParameterBo>)super.getSearchResultsUnbounded(derivedComponentFieldValues); |
80 | |
} |
81 | |
|
82 | 0 | List<ParameterBo> results = (List<ParameterBo>)super.getSearchResultsUnbounded(fieldValues); |
83 | 0 | if (parametersWithDerivedComponents != null) { |
84 | 0 | results.addAll(parametersWithDerivedComponents); |
85 | |
} |
86 | 0 | normalizeParameterComponents(results); |
87 | 0 | return results; |
88 | |
} |
89 | |
|
90 | |
private void normalizeParameterComponents(List<ParameterBo> parameters) { |
91 | |
|
92 | 0 | for (ParameterBo parameterBo : parameters) { |
93 | 0 | if (parameterBo.getComponent() == null) { |
94 | 0 | parameterBo.setComponent(DerivedComponentBo.toComponentBo(parameterBo.getDerivedComponent())); |
95 | |
} |
96 | |
} |
97 | 0 | } |
98 | |
|
99 | |
} |
100 | |
|