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.service.impl; 017 018 import java.util.ArrayList; 019 import java.util.HashMap; 020 import java.util.List; 021 import java.util.Map; 022 023 import org.kuali.kfs.sys.batch.Step; 024 import org.kuali.kfs.sys.context.ProxyUtils; 025 import org.kuali.kfs.sys.context.SpringContext; 026 import org.kuali.rice.kns.bo.BusinessObject; 027 import org.kuali.rice.kns.bo.ParameterDetailType; 028 import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; 029 import org.kuali.rice.kns.document.TransactionalDocument; 030 import org.kuali.rice.kns.service.DataDictionaryService; 031 import org.kuali.rice.kns.service.ParameterConstants.COMPONENT; 032 import org.kuali.rice.kns.service.impl.RiceApplicationConfigurationServiceImpl; 033 import org.kuali.rice.kns.util.KNSUtils; 034 035 public class KFSApplicationConfigurationServiceImpl extends RiceApplicationConfigurationServiceImpl { 036 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KFSApplicationConfigurationServiceImpl.class); 037 038 public List<ParameterDetailType> getNonDatabaseComponents() { 039 if (components.isEmpty()) { 040 List<ParameterDetailType> baseClassTypes = super.getNonDatabaseComponents(); 041 Map<String, ParameterDetailType> uniqueParameterDetailTypeMap = new HashMap<String, ParameterDetailType>(); 042 components.addAll(baseClassTypes); 043 for (Step step : SpringContext.getBeansOfType(Step.class).values()) { 044 step = (Step) ProxyUtils.getTargetIfProxied(step); 045 try { 046 ParameterDetailType parameterDetailType = getParameterDetailType(step.getClass()); 047 uniqueParameterDetailTypeMap.put(parameterDetailType.getParameterDetailTypeCode(), parameterDetailType); 048 } 049 catch (Exception e) { 050 LOG.error("The getDataDictionaryAndSpringComponents method of ParameterUtils encountered an exception while trying to create the detail type for step class: " + step.getClass(), e); 051 } 052 } 053 components.addAll(uniqueParameterDetailTypeMap.values()); 054 } 055 return components; 056 } 057 058 public String getDetailType(Class documentOrStepClass) { 059 if (documentOrStepClass.isAnnotationPresent(COMPONENT.class)) { 060 return ((COMPONENT) documentOrStepClass.getAnnotation(COMPONENT.class)).component(); 061 } 062 if (TransactionalDocument.class.isAssignableFrom(documentOrStepClass)) { 063 return documentOrStepClass.getSimpleName().replace("Document", ""); 064 } 065 else if (BusinessObject.class.isAssignableFrom(documentOrStepClass) || Step.class.isAssignableFrom(documentOrStepClass)) { 066 return documentOrStepClass.getSimpleName(); 067 } 068 throw new IllegalArgumentException("The getDetailType method of ParameterServiceImpl requires a TransactionalDocument, BusinessObject, or Step class."); 069 } 070 071 protected String getDetailTypeName(Class documentOrStepClass) { 072 if (documentOrStepClass.isAnnotationPresent(COMPONENT.class)) { 073 BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(documentOrStepClass.getName()); 074 if (boe != null) { 075 return boe.getObjectLabel(); 076 } 077 else { 078 return ((COMPONENT) documentOrStepClass.getAnnotation(COMPONENT.class)).component(); 079 } 080 } 081 if (TransactionalDocument.class.isAssignableFrom(documentOrStepClass)) { 082 return getDataDictionaryService().getDocumentLabelByClass(documentOrStepClass); 083 } 084 else if (BusinessObject.class.isAssignableFrom(documentOrStepClass) || Step.class.isAssignableFrom(documentOrStepClass)) { 085 BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(documentOrStepClass.getName()); 086 if (boe != null) { 087 return boe.getObjectLabel(); 088 } 089 else { 090 return KNSUtils.getBusinessTitleForClass(documentOrStepClass); 091 } 092 } 093 throw new IllegalArgumentException("The getDetailTypeName method of ParameterServiceImpl requires a TransactionalDocument, BusinessObject, or Step class."); 094 } 095 }