|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  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 |     | 
     | 
  |  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 |     | 
     | 
  |  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 |     | 
     | 
  |  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 |     | 
     | 
  |  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 |     | 
     | 
  |  94 |     | 
     | 
  |  95 |     | 
       public BusinessObjectDao getBusinessObjectDao() { | 
  |  96 |    0 |            return businessObjectDao;  | 
  |  97 |     | 
       }  | 
  |  98 |     | 
     | 
  |  99 |     | 
         | 
  |  100 |     | 
     | 
  |  101 |     | 
     | 
  |  102 |     | 
       public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) { | 
  |  103 |    0 |            this.businessObjectDao = businessObjectDao;  | 
  |  104 |    0 |        }  | 
  |  105 |     | 
     | 
  |  106 |     | 
         | 
  |  107 |     | 
     | 
  |  108 |     | 
     | 
  |  109 |     | 
     | 
  |  110 |     | 
     | 
  |  111 |     | 
       public PersistenceStructureService getPersistenceStructureService() { | 
  |  112 |    0 |            return persistenceStructureService;  | 
  |  113 |     | 
       }  | 
  |  114 |     | 
     | 
  |  115 |     | 
         | 
  |  116 |     | 
     | 
  |  117 |     | 
     | 
  |  118 |     | 
     | 
  |  119 |     | 
     | 
  |  120 |     | 
       public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) { | 
  |  121 |    0 |            this.persistenceStructureService = persistenceStructureService;  | 
  |  122 |    0 |        }  | 
  |  123 |     | 
     | 
  |  124 |     | 
         | 
  |  125 |     | 
     | 
  |  126 |     | 
     | 
  |  127 |     | 
     | 
  |  128 |     | 
     | 
  |  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 |     | 
     | 
  |  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 |     | 
   }  |