Coverage Report - org.kuali.rice.krad.service.impl.KeyValuesServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KeyValuesServiceImpl
0%
0/34
0%
0/20
2.4
 
 1  
 /*
 2  
  * Copyright 2006-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.krad.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.Collections;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.kuali.rice.krad.bo.BusinessObject;
 24  
 import org.kuali.rice.krad.bo.ExternalizableBusinessObject;
 25  
 import org.kuali.rice.krad.dao.BusinessObjectDao;
 26  
 import org.kuali.rice.krad.service.*;
 27  
 import org.kuali.rice.krad.util.KRADPropertyConstants;
 28  
 import org.kuali.rice.krad.util.spring.CacheNoCopy;
 29  
 
 30  
 /**
 31  
  * This class provides collection retrievals to populate key value pairs of business objects.
 32  
  */
 33  
 @CacheNoCopy
 34  0
 public class KeyValuesServiceImpl implements KeyValuesService {
 35  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KeyValuesServiceImpl.class);
 36  
 
 37  
     private BusinessObjectDao businessObjectDao;
 38  
     private PersistenceStructureService persistenceStructureService;
 39  
     
 40  
     /**
 41  
      * @see org.kuali.rice.krad.service.KeyValuesService#findAll(java.lang.Class)
 42  
      */
 43  
     @Override
 44  
         public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz) {
 45  0
             ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(clazz);
 46  0
                 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(clazz)){
 47  0
                         return (Collection<T>) responsibleModuleService.getExternalizableBusinessObjectsList((Class<ExternalizableBusinessObject>) clazz, Collections.<String, Object>emptyMap());
 48  
                 }
 49  0
         if (containsActiveIndicator(clazz)) {
 50  0
             return businessObjectDao.findAllActive(clazz);
 51  
         }
 52  0
         if (LOG.isDebugEnabled()) {
 53  0
                         LOG.debug("Active indicator not found for class " + clazz.getName());
 54  
                 }
 55  0
         return businessObjectDao.findAll(clazz);
 56  
     }
 57  
     
 58  
         public static <E> Collection<E> createUnmodifiableUpcastList(Collection<? extends E> list, Class<E> type) {
 59  0
                 return new ArrayList<E>(list);
 60  
         }
 61  
 
 62  
     /**
 63  
      * @see org.kuali.rice.krad.service.KeyValuesService#findAllOrderBy(java.lang.Class, java.lang.String, boolean)
 64  
      */
 65  
     @Override
 66  
         public <T extends BusinessObject> Collection<T> findAllOrderBy(Class<T> clazz, String sortField, boolean sortAscending) {
 67  0
         if (containsActiveIndicator(clazz)) {
 68  0
             return businessObjectDao.findAllActiveOrderBy(clazz, sortField, sortAscending);
 69  
         }
 70  0
         if (LOG.isDebugEnabled()) {
 71  0
                         LOG.debug("Active indicator not found for class " + clazz.getName());
 72  
                 }
 73  0
         return businessObjectDao.findAllOrderBy(clazz, sortField, sortAscending);
 74  
     }
 75  
 
 76  
     /**
 77  
      * @see org.kuali.rice.krad.service.BusinessObjectService#findMatching(java.lang.Class, java.util.Map)
 78  
      */
 79  
     @Override
 80  
         public <T extends BusinessObject> Collection<T> findMatching(Class<T> clazz, Map<String, Object> fieldValues) {
 81  0
         if (containsActiveIndicator(clazz)) {
 82  0
             return businessObjectDao.findMatchingActive(clazz, fieldValues);
 83  
         }
 84  0
         if (LOG.isDebugEnabled()) {
 85  0
                         LOG.debug("Active indicator not found for class " + clazz.getName());
 86  
                 }
 87  0
         return businessObjectDao.findMatching(clazz, fieldValues);
 88  
     }
 89  
 
 90  
 
 91  
 
 92  
     /**
 93  
      * @return Returns the businessObjectDao.
 94  
      */
 95  
     public BusinessObjectDao getBusinessObjectDao() {
 96  0
         return businessObjectDao;
 97  
     }
 98  
 
 99  
     /**
 100  
      * @param businessObjectDao The businessObjectDao to set.
 101  
      */
 102  
     public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) {
 103  0
         this.businessObjectDao = businessObjectDao;
 104  0
     }
 105  
 
 106  
     /**
 107  
      * Gets the persistenceStructureService attribute.
 108  
      * 
 109  
      * @return Returns the persistenceStructureService.
 110  
      */
 111  
     public PersistenceStructureService getPersistenceStructureService() {
 112  0
         return persistenceStructureService;
 113  
     }
 114  
 
 115  
     /**
 116  
      * Sets the persistenceStructureService attribute value.
 117  
      * 
 118  
      * @param persistenceStructureService The persistenceStructureService to set.
 119  
      */
 120  
     public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) {
 121  0
         this.persistenceStructureService = persistenceStructureService;
 122  0
     }
 123  
 
 124  
     /**
 125  
      * Uses persistence service to determine if the active column is mapped up in ojb.
 126  
      * 
 127  
      * @param clazz
 128  
      * @return boolean if active column is mapped for Class
 129  
      */
 130  
     private <T extends BusinessObject> boolean containsActiveIndicator(Class<T> clazz) {
 131  0
         boolean containsActive = false;
 132  
 
 133  0
         if (persistenceStructureService.listFieldNames(clazz).contains(KRADPropertyConstants.ACTIVE)) {
 134  0
             containsActive = true;
 135  
         }
 136  
 
 137  0
         return containsActive;
 138  
     }
 139  
     
 140  
     /**
 141  
      * @see org.kuali.rice.krad.service.KeyValuesService#findAll(java.lang.Class)
 142  
      */
 143  
     @Override
 144  
         public <T extends BusinessObject> Collection<T> findAllInactive(Class<T> clazz) {
 145  0
             if (LOG.isDebugEnabled()) {
 146  0
                         LOG.debug("Active indicator not found for class " + clazz.getName());
 147  
                 }
 148  0
         return businessObjectDao.findAllInactive(clazz);
 149  
     }
 150  
 
 151  
 }