Coverage Report - org.kuali.rice.kns.service.impl.LookupServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
LookupServiceImpl
0%
0/38
0%
0/12
2
 
 1  
 /*
 2  
  * Copyright 2005-2008 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.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 
 24  
 import org.apache.commons.lang.StringUtils;
 25  
 import org.kuali.rice.kns.bo.PersistableBusinessObject;
 26  
 import org.kuali.rice.kns.dao.LookupDao;
 27  
 import org.kuali.rice.kns.service.DataDictionaryService;
 28  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 29  
 import org.kuali.rice.kns.service.KualiConfigurationService;
 30  
 import org.kuali.rice.kns.service.LookupService;
 31  
 import org.kuali.rice.kns.service.PersistenceStructureService;
 32  
 import org.kuali.rice.kns.util.KNSConstants;
 33  
 
 34  
 /**
 35  
  * This class is the service implementation for the Lookup structure. It Provides a generic search mechanism against Business
 36  
  * Objects. This is the default implementation, that is delivered with Kuali.
 37  
  */
 38  0
 public class LookupServiceImpl implements LookupService {
 39  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupServiceImpl.class);
 40  0
     private static final Collection EMPTY_COLLECTION = new ArrayList(0);
 41  
 
 42  
     private LookupDao lookupDao;
 43  
     private KualiConfigurationService kualiConfigurationService;
 44  
     private DataDictionaryService dataDictionaryService;
 45  
     private PersistenceStructureService persistenceStructureService;
 46  
     
 47  
     public Collection findCollectionBySearchUnbounded(Class example, Map formProps) {
 48  0
         return findCollectionBySearchHelper(example, formProps, true);
 49  
     }
 50  
 
 51  
     /**
 52  
      * Returns a collection of objects based on the given search parameters.
 53  
      * 
 54  
      * @return Collection returned from the search
 55  
      */
 56  
     public Collection findCollectionBySearch(Class example, Map formProps) {
 57  0
         return findCollectionBySearchHelper(example, formProps, false);
 58  
     }
 59  
 
 60  
     public Collection findCollectionBySearchHelper(Class example, Map formProps, boolean unbounded) {
 61  0
         return lookupDao.findCollectionBySearchHelper(example, formProps, unbounded, allPrimaryKeyValuesPresentAndNotWildcard(example, formProps));
 62  
     }
 63  
 
 64  
     /**
 65  
      * Retrieves a Object based on the search criteria, which should uniquely identify a record.
 66  
      * 
 67  
      * @return Object returned from the search
 68  
      */
 69  
     public Object findObjectBySearch(Class example, Map formProps) {
 70  0
         if (example == null || formProps == null) {
 71  0
             throw new IllegalArgumentException("Object and Map must not be null");
 72  
         }
 73  
 
 74  0
         PersistableBusinessObject obj = null;
 75  
         try {
 76  0
             obj = (PersistableBusinessObject) example.newInstance();
 77  
         }
 78  0
         catch (IllegalAccessException e) {
 79  0
             throw new RuntimeException("Cannot get new instance of " + example.getName(), e);
 80  
         }
 81  0
         catch (InstantiationException e) {
 82  0
             throw new RuntimeException("Cannot instantiate " + example.getName(), e);
 83  0
         }
 84  
 
 85  0
         return lookupDao.findObjectByMap(obj, formProps);
 86  
     }
 87  
     
 88  
     public boolean allPrimaryKeyValuesPresentAndNotWildcard(Class boClass, Map formProps) {
 89  0
         List pkFields = KNSServiceLocator.getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(boClass);
 90  0
         Iterator pkIter = pkFields.iterator();
 91  0
         boolean returnVal = true;
 92  0
         while (returnVal && pkIter.hasNext()) {
 93  0
             String pkName = (String) pkIter.next();
 94  0
             String pkValue = (String) formProps.get(pkName);
 95  
             
 96  0
             if (StringUtils.isBlank(pkValue)) {
 97  0
                 returnVal = false;
 98  
             }
 99  0
             else if (StringUtils.indexOfAny(pkValue, KNSConstants.QUERY_CHARACTERS) != -1) {
 100  0
                 returnVal = false;
 101  
             }
 102  0
         }
 103  0
         return returnVal;
 104  
     }
 105  
 
 106  
     /**
 107  
      * @return Returns the lookupDao.
 108  
      */
 109  
     public LookupDao getLookupDao() {
 110  0
         return lookupDao;
 111  
     }
 112  
 
 113  
     /**
 114  
      * @param lookupDao The lookupDao to set.
 115  
      */
 116  
     public void setLookupDao(LookupDao lookupDao) {
 117  0
         this.lookupDao = lookupDao;
 118  0
     }
 119  
 
 120  
     public KualiConfigurationService getKualiConfigurationService() {
 121  0
         return kualiConfigurationService;
 122  
     }
 123  
 
 124  
     public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) {
 125  0
         this.kualiConfigurationService = kualiConfigurationService;
 126  0
     }
 127  
 
 128  
     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
 129  0
         this.dataDictionaryService = dataDictionaryService;
 130  0
     }
 131  
 
 132  
     public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) {
 133  0
         this.persistenceStructureService = persistenceStructureService;
 134  0
     }
 135  
 }