1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.coreservice.web.component;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.coreservice.impl.component.ComponentBo;
21 import org.kuali.rice.coreservice.impl.component.DerivedComponentBo;
22 import org.kuali.rice.kns.lookup.HtmlData;
23 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
24 import org.kuali.rice.kns.service.KNSServiceLocator;
25 import org.kuali.rice.krad.bo.BusinessObject;
26 import org.kuali.rice.krad.lookup.CollectionIncomplete;
27 import org.kuali.rice.kns.lookup.LookupUtils;
28 import org.kuali.rice.krad.service.KRADServiceLocator;
29 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
30
31 import java.util.Collection;
32 import java.util.List;
33
34 public class ComponentLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
35
36 private static final long serialVersionUID = -3978422770535345525L;
37
38 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ComponentLookupableHelperServiceImpl.class);
39
40 private static final String ACTIVE = "active";
41 private static final String CODE = "code";
42 private static final String NAMESPACE_CODE = "namespaceCode";
43 private static final String NAME = "name";
44
45 @Override
46 public List<? extends BusinessObject> getSearchResults(java.util.Map<String, String> fieldValues) {
47
48 List<BusinessObject> baseLookup = (List<BusinessObject>) super.getSearchResults(fieldValues);
49
50 String activeCheck = fieldValues.get(ACTIVE);
51 if (activeCheck == null) {
52 activeCheck = "";
53 }
54 int maxResultsCount = LookupUtils.getSearchResultsLimit(ComponentBo.class);
55
56 if (baseLookup instanceof CollectionIncomplete && !activeCheck.equals("N")) {
57 long originalCount = Math.max(baseLookup.size(), ((CollectionIncomplete) baseLookup).getActualSizeIfTruncated());
58 long totalCount = originalCount;
59
60 Collection<DerivedComponentBo> derivedComponentBos = null;
61 if (StringUtils.isBlank(fieldValues.get(CODE)) && StringUtils.isBlank(fieldValues.get(NAMESPACE_CODE))
62 && StringUtils.isBlank(fieldValues.get(NAME))) {
63 derivedComponentBos = KNSServiceLocator.getBusinessObjectService().findAll(DerivedComponentBo.class);
64 } else {
65 derivedComponentBos = getLookupService().findCollectionBySearchHelper(DerivedComponentBo.class, fieldValues, false);
66 }
67 if (CollectionUtils.isNotEmpty(derivedComponentBos)) {
68 for (DerivedComponentBo derivedComponentBo : derivedComponentBos) {
69 if (totalCount++ < maxResultsCount) {
70 baseLookup.add(DerivedComponentBo.toComponentBo(derivedComponentBo));
71 } else {
72 break;
73 }
74 }
75 }
76
77 if (totalCount > maxResultsCount) {
78 ((CollectionIncomplete) baseLookup).setActualSizeIfTruncated(totalCount);
79 }
80 else {
81 ((CollectionIncomplete) baseLookup).setActualSizeIfTruncated(0L);
82 }
83 }
84
85 return baseLookup;
86 }
87
88
89
90
91 @Override
92 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
93 if ( ((ComponentBo)businessObject).getObjectId() == null ) {
94 return super.getEmptyActionUrls();
95 }
96 return super.getCustomActionUrls(businessObject, pkNames);
97 }
98
99 }