View Javadoc

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