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