001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.service.impl;
017:
018: import java.util.Collection;
019: import java.util.Map;
020:
021: import org.kuali.RicePropertyConstants;
022: import org.kuali.core.dao.BusinessObjectDao;
023: import org.kuali.core.service.KeyValuesService;
024: import org.kuali.core.service.PersistenceStructureService;
025: import org.kuali.core.util.spring.Cached;
026: import org.springframework.transaction.annotation.Transactional;
027:
028: /**
029: * This class provides collection retrievals to populate key value pairs of business objects.
030: */
031: @Transactional
032: @Cached
033: public class KeyValuesServiceImpl implements KeyValuesService {
034: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
035: .getLogger(KeyValuesServiceImpl.class);
036:
037: private BusinessObjectDao businessObjectDao;
038: private PersistenceStructureService persistenceStructureService;
039:
040: /**
041: * @see org.kuali.core.service.KeyValuesService#findAll(java.lang.Class)
042: */
043: public Collection findAll(Class clazz) {
044: if (containsActiveIndicator(clazz)) {
045: return businessObjectDao.findAllActive(clazz);
046: } else {
047: if (LOG.isDebugEnabled())
048: LOG.debug("Active indicator not found for class "
049: + clazz.getName());
050: return businessObjectDao.findAll(clazz);
051: }
052: }
053:
054: /**
055: * @see org.kuali.core.service.KeyValuesService#findAllOrderBy(java.lang.Class, java.lang.String, boolean)
056: */
057: public Collection findAllOrderBy(Class clazz, String sortField,
058: boolean sortAscending) {
059: if (containsActiveIndicator(clazz)) {
060: return businessObjectDao.findAllActiveOrderBy(clazz,
061: sortField, sortAscending);
062: } else {
063: if (LOG.isDebugEnabled())
064: LOG.debug("Active indicator not found for class "
065: + clazz.getName());
066: return businessObjectDao.findAllOrderBy(clazz, sortField,
067: sortAscending);
068: }
069: }
070:
071: /**
072: * @see org.kuali.core.service.BusinessObjectService#findMatching(java.lang.Class, java.util.Map)
073: */
074: public Collection findMatching(Class clazz, Map fieldValues) {
075: if (containsActiveIndicator(clazz)) {
076: return businessObjectDao.findMatchingActive(clazz,
077: fieldValues);
078: } else {
079: if (LOG.isDebugEnabled())
080: LOG.debug("Active indicator not found for class "
081: + clazz.getName());
082: return businessObjectDao.findMatching(clazz, fieldValues);
083: }
084: }
085:
086: /**
087: * @return Returns the businessObjectDao.
088: */
089: public BusinessObjectDao getBusinessObjectDao() {
090: return businessObjectDao;
091: }
092:
093: /**
094: * @param businessObjectDao The businessObjectDao to set.
095: */
096: public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) {
097: this .businessObjectDao = businessObjectDao;
098: }
099:
100: /**
101: * Gets the persistenceStructureService attribute.
102: *
103: * @return Returns the persistenceStructureService.
104: */
105: public PersistenceStructureService getPersistenceStructureService() {
106: return persistenceStructureService;
107: }
108:
109: /**
110: * Sets the persistenceStructureService attribute value.
111: *
112: * @param persistenceStructureService The persistenceStructureService to set.
113: */
114: public void setPersistenceStructureService(
115: PersistenceStructureService persistenceStructureService) {
116: this .persistenceStructureService = persistenceStructureService;
117: }
118:
119: /**
120: * Uses persistence service to determine if the active column is mapped up in ojb.
121: *
122: * @param clazz
123: * @return boolean if active column is mapped for Class
124: */
125: private boolean containsActiveIndicator(Class clazz) {
126: boolean containsActive = false;
127:
128: if (persistenceStructureService.listFieldNames(clazz).contains(
129: RicePropertyConstants.ACTIVE)) {
130: containsActive = true;
131: }
132:
133: return containsActive;
134: }
135: }
|