001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.sys.businessobject.lookup;
017    
018    import java.util.ArrayList;
019    import java.util.List;
020    import java.util.Map;
021    
022    import org.apache.commons.lang.StringUtils;
023    import org.kuali.kfs.sys.KFSConstants;
024    import org.kuali.kfs.sys.businessobject.KualiModuleBO;
025    import org.kuali.kfs.sys.context.SpringContext;
026    import org.kuali.rice.kns.bo.BusinessObject;
027    import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
028    import org.kuali.rice.kns.service.BusinessObjectDictionaryService;
029    import org.kuali.rice.kns.service.KualiConfigurationService;
030    import org.kuali.rice.kns.service.KualiModuleService;
031    import org.kuali.rice.kns.service.ModuleService;
032    
033    public class ModuleLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
034    
035        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BatchJobStatusLookupableHelperServiceImpl.class);
036    
037        private KualiConfigurationService configService;
038        private Map fieldConversions;
039    
040        @Override
041        public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
042            super.setBackLocation((String) fieldValues.get(KFSConstants.BACK_LOCATION));
043            super.setDocFormKey((String) fieldValues.get(KFSConstants.DOC_FORM_KEY));
044            List<ModuleService> modules = SpringContext.getBean(KualiModuleService.class).getInstalledModuleServices();
045            String codeValue = fieldValues.get("moduleCode");
046            String nameValue = fieldValues.get("moduleName");
047            List<KualiModuleBO> boModules = new ArrayList();
048            String tempNamespaceName;
049            for (ModuleService mod : modules) {
050                if (!StringUtils.isEmpty(nameValue) && !StringUtils.containsIgnoreCase(mod.getModuleConfiguration().getNamespaceCode(), nameValue)) {
051                    continue;
052                }
053                tempNamespaceName = SpringContext.getBean(KualiModuleService.class).getNamespaceName(mod.getModuleConfiguration().getNamespaceCode());
054                if (!StringUtils.isEmpty(codeValue) && !StringUtils.containsIgnoreCase(tempNamespaceName, codeValue)) {
055                    continue;
056                }
057                boModules.add(new KualiModuleBO(mod.getModuleConfiguration().getNamespaceCode(), 
058                        mod.getModuleConfiguration().getNamespaceCode(), tempNamespaceName));
059            }
060            return boModules;
061        }
062    
063    
064        public void setConfigService(KualiConfigurationService configService) {
065            this.configService = configService;
066        }
067    
068        public List getReturnKeys() {
069            List returnKeys;
070    
071            if (fieldConversions != null && !fieldConversions.isEmpty()) {
072                returnKeys = new ArrayList(fieldConversions.keySet());
073            }
074            else {
075                returnKeys = SpringContext.getBean(BusinessObjectDictionaryService.class).getLookupFieldNames(org.kuali.kfs.sys.businessobject.KualiModuleBO.class);
076            }
077    
078            return returnKeys;
079        }
080    
081        public void setFieldConversions(Map fieldConversions) {
082            this.fieldConversions = fieldConversions;
083        }
084    
085    
086    }