Coverage Report - org.kuali.rice.core.web.component.ComponentLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentLookupableHelperServiceImpl
0%
0/57
0%
0/32
8.333
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
         // all step beans
 49  
         // all BO beans
 50  
         // all trans doc beans
 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  
         // only bother with the component lookup if returning active components
 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  
      * Suppress the edit/copy links on synthetic detail types.
 131  
      * 
 132  
      * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, java.util.List)
 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  
 }