| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.core.web.component; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.core.api.component.Component; |
| 20 | |
import org.kuali.rice.core.framework.parameter.ParameterService; |
| 21 | |
import org.kuali.rice.core.impl.component.ComponentBo; |
| 22 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 23 | |
import org.kuali.rice.kns.datadictionary.DataDictionaryException; |
| 24 | |
import org.kuali.rice.kns.lookup.CollectionIncomplete; |
| 25 | |
import org.kuali.rice.kns.lookup.HtmlData; |
| 26 | |
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; |
| 27 | |
import org.kuali.rice.kns.lookup.LookupUtils; |
| 28 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 29 | |
|
| 30 | |
import java.util.List; |
| 31 | |
import java.util.regex.Pattern; |
| 32 | |
import java.util.regex.PatternSyntaxException; |
| 33 | |
|
| 34 | 0 | public class ComponentLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl { |
| 35 | |
|
| 36 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ComponentLookupableHelperServiceImpl.class); |
| 37 | |
private static final String ACTIVE = "active"; |
| 38 | |
private static final String CODE = "code"; |
| 39 | |
private static final String NAMESPACE_CODE = "namespaceCode"; |
| 40 | |
private static final String NAME = "name"; |
| 41 | |
private ParameterService parameterService; |
| 42 | |
|
| 43 | |
@Override |
| 44 | |
public List<? extends BusinessObject> getSearchResults(java.util.Map<String, String> fieldValues) { |
| 45 | |
|
| 46 | 0 | List<BusinessObject> baseLookup = (List<BusinessObject>) super.getSearchResults(fieldValues); |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
List<Component> components; |
| 53 | |
try { |
| 54 | 0 | components = KNSServiceLocatorWeb.getRiceApplicationConfigurationMediationService().getNonDatabaseComponents(); |
| 55 | |
} |
| 56 | 0 | catch (DataDictionaryException ex) { |
| 57 | 0 | throw new RuntimeException("Problem parsing data dictionary during full load required for lookup to function: " + ex.getMessage(), ex); |
| 58 | 0 | } |
| 59 | |
|
| 60 | 0 | String activeCheck = fieldValues.get(ACTIVE); |
| 61 | 0 | if (activeCheck == null) { |
| 62 | 0 | activeCheck = ""; |
| 63 | |
} |
| 64 | 0 | int maxResultsCount = LookupUtils.getSearchResultsLimit(ComponentBo.class); |
| 65 | |
|
| 66 | 0 | if (baseLookup instanceof CollectionIncomplete && !activeCheck.equals("N")) { |
| 67 | 0 | long originalCount = Math.max(baseLookup.size(), ((CollectionIncomplete) baseLookup).getActualSizeIfTruncated()); |
| 68 | 0 | long totalCount = originalCount; |
| 69 | 0 | Pattern detailTypeRegex = null; |
| 70 | 0 | Pattern namespaceRegex = null; |
| 71 | 0 | Pattern nameRegex = null; |
| 72 | |
|
| 73 | 0 | if (StringUtils.isNotBlank(fieldValues.get(CODE))) { |
| 74 | 0 | String patternStr = fieldValues.get(CODE).replace("*", ".*").toUpperCase(); |
| 75 | |
try { |
| 76 | 0 | detailTypeRegex = Pattern.compile(patternStr); |
| 77 | |
} |
| 78 | 0 | catch (PatternSyntaxException ex) { |
| 79 | 0 | LOG.error("Unable to parse code pattern, ignoring.", ex); |
| 80 | 0 | } |
| 81 | |
} |
| 82 | 0 | if (StringUtils.isNotBlank(fieldValues.get(NAMESPACE_CODE))) { |
| 83 | 0 | String patternStr = fieldValues.get(NAMESPACE_CODE).replace("*", ".*").toUpperCase(); |
| 84 | |
try { |
| 85 | 0 | namespaceRegex = Pattern.compile(patternStr); |
| 86 | |
} |
| 87 | 0 | catch (PatternSyntaxException ex) { |
| 88 | 0 | LOG.error("Unable to parse namespaceCode pattern, ignoring.", ex); |
| 89 | 0 | } |
| 90 | |
} |
| 91 | 0 | if (StringUtils.isNotBlank(fieldValues.get(NAME))) { |
| 92 | 0 | String patternStr = fieldValues.get(NAME).replace("*", ".*").toUpperCase(); |
| 93 | |
try { |
| 94 | 0 | nameRegex = Pattern.compile(patternStr); |
| 95 | |
} |
| 96 | 0 | catch (PatternSyntaxException ex) { |
| 97 | 0 | LOG.error("Unable to parse name pattern, ignoring.", ex); |
| 98 | 0 | } |
| 99 | |
} |
| 100 | 0 | for (Component pdt : components) { |
| 101 | 0 | boolean includeType = true; |
| 102 | 0 | if (detailTypeRegex != null) { |
| 103 | 0 | includeType = detailTypeRegex.matcher(pdt.getCode().toUpperCase()).matches(); |
| 104 | |
} |
| 105 | 0 | if (includeType && namespaceRegex != null) { |
| 106 | 0 | includeType = namespaceRegex.matcher(pdt.getNamespaceCode().toUpperCase()).matches(); |
| 107 | |
} |
| 108 | 0 | if (includeType && nameRegex != null) { |
| 109 | 0 | includeType = nameRegex.matcher(pdt.getName().toUpperCase()).matches(); |
| 110 | |
} |
| 111 | 0 | if (includeType) { |
| 112 | 0 | if (totalCount < maxResultsCount) { |
| 113 | 0 | baseLookup.add(ComponentBo.from(pdt)); |
| 114 | |
} |
| 115 | 0 | totalCount++; |
| 116 | |
} |
| 117 | 0 | } |
| 118 | 0 | if (totalCount > maxResultsCount) { |
| 119 | 0 | ((CollectionIncomplete) baseLookup).setActualSizeIfTruncated(totalCount); |
| 120 | |
} |
| 121 | |
else { |
| 122 | 0 | ((CollectionIncomplete) baseLookup).setActualSizeIfTruncated(0L); |
| 123 | |
} |
| 124 | |
} |
| 125 | |
|
| 126 | 0 | return baseLookup; |
| 127 | |
} |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
@Override |
| 135 | |
public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) { |
| 136 | 0 | if ( ((ComponentBo)businessObject).getObjectId() == null ) { |
| 137 | 0 | return super.getEmptyActionUrls(); |
| 138 | |
} |
| 139 | 0 | return super.getCustomActionUrls(businessObject, pkNames); |
| 140 | |
} |
| 141 | |
|
| 142 | |
public void setParameterService(ParameterService parameterService) { |
| 143 | 0 | this.parameterService = parameterService; |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
} |