Coverage Report - org.kuali.rice.kns.lookup.ParameterDetailTypeLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ParameterDetailTypeLookupableHelperServiceImpl
0%
0/57
0%
0/32
8.333
 
 1  
 /*
 2  
  * Copyright 2007 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.kns.lookup;
 17  
 
 18  
 import java.util.List;
 19  
 import java.util.regex.Pattern;
 20  
 import java.util.regex.PatternSyntaxException;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.kuali.rice.kns.bo.BusinessObject;
 24  
 import org.kuali.rice.kns.bo.ParameterDetailType;
 25  
 import org.kuali.rice.kns.datadictionary.DataDictionaryException;
 26  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 27  
 import org.kuali.rice.kns.service.ParameterService;
 28  
 import org.kuali.rice.kns.service.RiceApplicationConfigurationService;
 29  
 
 30  0
 public class ParameterDetailTypeLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
 31  
 
 32  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ParameterDetailTypeLookupableHelperServiceImpl.class);
 33  
     private ParameterService parameterService;
 34  
 
 35  
     @Override
 36  
     public List<? extends BusinessObject> getSearchResults(java.util.Map<String, String> fieldValues) {
 37  
 
 38  0
         List<BusinessObject> baseLookup = (List<BusinessObject>) super.getSearchResults(fieldValues);
 39  
 
 40  
         // all step beans
 41  
         // all BO beans
 42  
         // all trans doc beans
 43  
 
 44  
         List<ParameterDetailType> components;
 45  
         try {
 46  0
                 components = KNSServiceLocator.getParameterServerService().getNonDatabaseComponents();
 47  
         }
 48  0
         catch (DataDictionaryException ex) {
 49  0
             throw new RuntimeException("Problem parsing data dictionary during full load required for lookup to function: " + ex.getMessage(), ex);
 50  0
         }
 51  
 
 52  0
         String activeCheck = fieldValues.get("active");
 53  0
         if (activeCheck == null) {
 54  0
             activeCheck = "";
 55  
         }
 56  0
         int maxResultsCount = LookupUtils.getSearchResultsLimit(ParameterDetailType.class);
 57  
         // only bother with the component lookup if returning active components
 58  0
         if (baseLookup instanceof CollectionIncomplete && !activeCheck.equals("N")) {
 59  0
             long originalCount = Math.max(baseLookup.size(), ((CollectionIncomplete) baseLookup).getActualSizeIfTruncated());
 60  0
             long totalCount = originalCount;
 61  0
             Pattern detailTypeRegex = null;
 62  0
             Pattern namespaceRegex = null;
 63  0
             Pattern nameRegex = null;
 64  
 
 65  0
             if (StringUtils.isNotBlank(fieldValues.get("parameterDetailTypeCode"))) {
 66  0
                 String patternStr = fieldValues.get("parameterDetailTypeCode").replace("*", ".*").toUpperCase();
 67  
                 try {
 68  0
                     detailTypeRegex = Pattern.compile(patternStr);
 69  
                 }
 70  0
                 catch (PatternSyntaxException ex) {
 71  0
                     LOG.error("Unable to parse parameterDetailTypeCode pattern, ignoring.", ex);
 72  0
                 }
 73  
             }
 74  0
             if (StringUtils.isNotBlank(fieldValues.get("parameterNamespaceCode"))) {
 75  0
                 String patternStr = fieldValues.get("parameterNamespaceCode").replace("*", ".*").toUpperCase();
 76  
                 try {
 77  0
                     namespaceRegex = Pattern.compile(patternStr);
 78  
                 }
 79  0
                 catch (PatternSyntaxException ex) {
 80  0
                     LOG.error("Unable to parse parameterNamespaceCode pattern, ignoring.", ex);
 81  0
                 }
 82  
             }
 83  0
             if (StringUtils.isNotBlank(fieldValues.get("parameterDetailTypeName"))) {
 84  0
                 String patternStr = fieldValues.get("parameterDetailTypeName").replace("*", ".*").toUpperCase();
 85  
                 try {
 86  0
                     nameRegex = Pattern.compile(patternStr);
 87  
                 }
 88  0
                 catch (PatternSyntaxException ex) {
 89  0
                     LOG.error("Unable to parse parameterDetailTypeName pattern, ignoring.", ex);
 90  0
                 }
 91  
             }
 92  0
             for (ParameterDetailType pdt : components) {
 93  0
                 boolean includeType = true;
 94  0
                 if (detailTypeRegex != null) {
 95  0
                     includeType = detailTypeRegex.matcher(pdt.getParameterDetailTypeCode().toUpperCase()).matches();
 96  
                 }
 97  0
                 if (includeType && namespaceRegex != null) {
 98  0
                     includeType = namespaceRegex.matcher(pdt.getParameterNamespaceCode().toUpperCase()).matches();
 99  
                 }
 100  0
                 if (includeType && nameRegex != null) {
 101  0
                     includeType = nameRegex.matcher(pdt.getParameterDetailTypeName().toUpperCase()).matches();
 102  
                 }
 103  0
                 if (includeType) {
 104  0
                     if (totalCount < maxResultsCount) {
 105  0
                         baseLookup.add(pdt);
 106  
                     }
 107  0
                     totalCount++;
 108  
                 }
 109  0
             }
 110  0
             if (totalCount > maxResultsCount) {
 111  0
                 ((CollectionIncomplete) baseLookup).setActualSizeIfTruncated(totalCount);
 112  
             }
 113  
             else {
 114  0
                 ((CollectionIncomplete) baseLookup).setActualSizeIfTruncated(0L);
 115  
             }
 116  
         }
 117  
 
 118  0
         return baseLookup;
 119  
     }
 120  
 
 121  
     /**
 122  
      * Suppress the edit/copy links on synthetic detail types.
 123  
      * 
 124  
      * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, java.util.List)
 125  
      */
 126  
     @Override
 127  
     public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
 128  0
         if ( ((ParameterDetailType)businessObject).getObjectId() == null ) {
 129  0
             return super.getEmptyActionUrls();
 130  
         }
 131  
         // TODO Auto-generated method stub
 132  0
         return super.getCustomActionUrls(businessObject, pkNames);
 133  
     }
 134  
 
 135  
     public void setParameterService(ParameterService parameterService) {
 136  0
         this.parameterService = parameterService;
 137  0
     }
 138  
 
 139  
 }