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