1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
package org.kuali.rice.kns.service.impl; |
14 | |
|
15 | |
import java.util.ArrayList; |
16 | |
import java.util.Collections; |
17 | |
import java.util.HashMap; |
18 | |
import java.util.List; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.kuali.rice.kns.bo.BusinessObject; |
22 | |
import org.kuali.rice.kns.bo.ParameterDetailType; |
23 | |
import org.kuali.rice.kns.datadictionary.AttributeDefinition; |
24 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
25 | |
import org.kuali.rice.kns.datadictionary.DocumentEntry; |
26 | |
import org.kuali.rice.kns.datadictionary.TransactionalDocumentEntry; |
27 | |
import org.kuali.rice.kns.document.TransactionalDocument; |
28 | |
import org.kuali.rice.kns.lookup.LookupUtils; |
29 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
30 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
31 | |
import org.kuali.rice.kns.service.KualiConfigurationService; |
32 | |
import org.kuali.rice.kns.service.ParameterService; |
33 | |
import org.kuali.rice.kns.service.RiceApplicationConfigurationService; |
34 | |
import org.kuali.rice.kns.service.ParameterConstants.COMPONENT; |
35 | |
import org.kuali.rice.kns.util.KNSConstants; |
36 | |
import org.kuali.rice.kns.util.KNSUtils; |
37 | |
|
38 | |
|
39 | 0 | public class RiceApplicationConfigurationServiceImpl implements RiceApplicationConfigurationService { |
40 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RiceApplicationConfigurationServiceImpl.class); |
41 | |
|
42 | 0 | protected List<ParameterDetailType> components = new ArrayList<ParameterDetailType>(); |
43 | 0 | protected List<String> packagePrefixes = new ArrayList<String>(); |
44 | |
private KualiConfigurationService kualiConfigurationService; |
45 | |
private ParameterService parameterService; |
46 | |
private DataDictionaryService dataDictionaryService; |
47 | |
|
48 | |
public String getConfigurationParameter( String parameterName ){ |
49 | 0 | return getKualiConfigurationService().getPropertyString(parameterName); |
50 | |
} |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public List<ParameterDetailType> getNonDatabaseComponents() { |
59 | 0 | if (components.isEmpty()) { |
60 | 0 | Map<String, ParameterDetailType> uniqueParameterDetailTypeMap = new HashMap<String, ParameterDetailType>(); |
61 | |
|
62 | 0 | DataDictionaryService dataDictionaryService = KNSServiceLocator.getDataDictionaryService(); |
63 | |
|
64 | |
|
65 | 0 | for (BusinessObjectEntry businessObjectEntry : dataDictionaryService.getDataDictionary().getBusinessObjectEntries().values()) { |
66 | |
try { |
67 | 0 | ParameterDetailType parameterDetailType = getParameterDetailType((businessObjectEntry.getBaseBusinessObjectClass() != null) ? businessObjectEntry.getBaseBusinessObjectClass() : businessObjectEntry.getBusinessObjectClass()); |
68 | 0 | uniqueParameterDetailTypeMap.put(parameterDetailType.getParameterDetailTypeCode(), parameterDetailType); |
69 | |
} |
70 | 0 | catch (Exception e) { |
71 | 0 | LOG.error("The getDataDictionaryAndSpringComponents method of ParameterUtils encountered an exception while trying to create the detail type for business object class: " + businessObjectEntry.getBusinessObjectClass(), e); |
72 | 0 | } |
73 | |
} |
74 | 0 | for (DocumentEntry documentEntry : dataDictionaryService.getDataDictionary().getDocumentEntries().values()) { |
75 | 0 | if (documentEntry instanceof TransactionalDocumentEntry) { |
76 | |
try { |
77 | 0 | ParameterDetailType parameterDetailType = getParameterDetailType((documentEntry.getBaseDocumentClass() != null) ? documentEntry.getBaseDocumentClass() : documentEntry.getDocumentClass()); |
78 | 0 | uniqueParameterDetailTypeMap.put(parameterDetailType.getParameterDetailTypeCode(), parameterDetailType); |
79 | |
} |
80 | 0 | catch (Exception e) { |
81 | 0 | LOG.error("The getNonDatabaseDetailTypes method of ParameterServiceImpl encountered an exception while trying to create the detail type for transactional document class: " + |
82 | |
((documentEntry.getBaseDocumentClass() != null) ? documentEntry.getBaseDocumentClass() : documentEntry.getDocumentClass()), e); |
83 | 0 | } |
84 | |
} |
85 | |
} |
86 | 0 | components.addAll(uniqueParameterDetailTypeMap.values()); |
87 | |
} |
88 | 0 | return Collections.unmodifiableList(components); |
89 | |
} |
90 | |
|
91 | |
@SuppressWarnings("unchecked") |
92 | |
protected ParameterDetailType getParameterDetailType(Class documentOrStepClass) { |
93 | 0 | String detailTypeString = getParameterService().getDetailType(documentOrStepClass); |
94 | 0 | String detailTypeName = getDetailTypeName(documentOrStepClass); |
95 | 0 | ParameterDetailType detailType = new ParameterDetailType(getParameterService().getNamespace(documentOrStepClass), detailTypeString, (detailTypeName == null) ? detailTypeString : detailTypeName); |
96 | 0 | detailType.refreshNonUpdateableReferences(); |
97 | 0 | return detailType; |
98 | |
} |
99 | |
|
100 | |
@SuppressWarnings("unchecked") |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
protected String getDetailTypeName(Class documentOrStepClass) { |
108 | 0 | if (documentOrStepClass == null) { |
109 | 0 | throw new IllegalArgumentException("The getDetailTypeName method of ParameterServiceImpl requires non-null documentOrStepClass"); |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | 0 | if (documentOrStepClass.isAnnotationPresent(COMPONENT.class)) { |
119 | 0 | BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(documentOrStepClass.getName()); |
120 | 0 | if (boe != null) { |
121 | 0 | return boe.getObjectLabel(); |
122 | |
} |
123 | |
else { |
124 | 0 | return ((COMPONENT) documentOrStepClass.getAnnotation(COMPONENT.class)).component(); |
125 | |
} |
126 | |
} |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | 0 | if (TransactionalDocument.class.isAssignableFrom(documentOrStepClass)) { |
135 | 0 | return getDataDictionaryService().getDocumentLabelByClass(documentOrStepClass); |
136 | |
} |
137 | 0 | else if (BusinessObject.class.isAssignableFrom(documentOrStepClass) ) { |
138 | 0 | BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(documentOrStepClass.getName()); |
139 | 0 | if (boe != null) { |
140 | 0 | return boe.getObjectLabel(); |
141 | |
} |
142 | |
else { |
143 | 0 | return KNSUtils.getBusinessTitleForClass(documentOrStepClass); |
144 | |
} |
145 | |
} |
146 | 0 | throw new IllegalArgumentException("The getDetailTypeName method of ParameterServiceImpl requires TransactionalDocument, BusinessObject, or Step class. Was: " + documentOrStepClass.getName() ); |
147 | |
} |
148 | |
|
149 | |
protected KualiConfigurationService getKualiConfigurationService() { |
150 | 0 | if (kualiConfigurationService == null) { |
151 | 0 | kualiConfigurationService = KNSServiceLocator.getKualiConfigurationService(); |
152 | |
} |
153 | 0 | return kualiConfigurationService; |
154 | |
} |
155 | |
|
156 | |
protected ParameterService getParameterService() { |
157 | 0 | if (parameterService == null) { |
158 | 0 | parameterService = KNSServiceLocator.getParameterService(); |
159 | |
} |
160 | 0 | return parameterService; |
161 | |
} |
162 | |
|
163 | |
protected DataDictionaryService getDataDictionaryService() { |
164 | 0 | if (dataDictionaryService == null) { |
165 | 0 | dataDictionaryService = KNSServiceLocator.getDataDictionaryService(); |
166 | |
} |
167 | 0 | return dataDictionaryService; |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
public String getBaseInquiryUrl(String businessObjectClassName) { |
174 | 0 | return LookupUtils.getBaseInquiryUrl(); |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public String getBaseLookupUrl(String businessObjectClassName) { |
181 | |
|
182 | 0 | return LookupUtils.getBaseLookupUrl(false); |
183 | |
} |
184 | |
|
185 | |
public String getBaseHelpUrl(String businessObjectClassName) { |
186 | 0 | return KNSServiceLocator.getKualiConfigurationService().getPropertyString(KNSConstants.APPLICATION_URL_KEY) + "/kr/help.do"; |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
public boolean isResponsibleForPackage(String packageName) { |
193 | 0 | if ( LOG.isDebugEnabled() ) { |
194 | 0 | LOG.debug( "Checking if application ("+packagePrefixes+") is responsible for package: " + packageName ); |
195 | |
} |
196 | 0 | for ( String prefix : packagePrefixes ) { |
197 | 0 | if ( packageName.startsWith(prefix) ) { |
198 | 0 | if ( LOG.isDebugEnabled() ) { |
199 | 0 | LOG.debug("Found match ("+prefix+") - returning true"); |
200 | |
} |
201 | 0 | return true; |
202 | |
} |
203 | |
} |
204 | 0 | if ( LOG.isDebugEnabled() ) { |
205 | 0 | LOG.debug("No Match Found: packageName="+packageName+" / prefix list=" + packagePrefixes); |
206 | |
} |
207 | 0 | return false; |
208 | |
} |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
public boolean supportsBusinessObjectClass(String businessObjectClassName) { |
214 | 0 | return getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(businessObjectClassName) != null; |
215 | |
} |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
public AttributeDefinition getBusinessObjectAttributeDefinition( String businessObjectClassName, String attributeName) { |
221 | 0 | if ( LOG.isDebugEnabled() ) { |
222 | 0 | LOG.debug( "Asking ("+packagePrefixes+") for BO AttributeDefinition: " + businessObjectClassName + " / " + attributeName ); |
223 | |
} |
224 | 0 | BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(businessObjectClassName); |
225 | 0 | if ( boe == null ) { |
226 | 0 | if ( LOG.isInfoEnabled() ) { |
227 | 0 | LOG.info( "No BusinessObjectEntry found for class name: " + businessObjectClassName ); |
228 | |
} |
229 | 0 | return null; |
230 | |
} |
231 | 0 | return boe.getAttributeDefinition(attributeName); |
232 | |
} |
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
public List<String> getPackagePrefixes() { |
238 | 0 | return this.packagePrefixes; |
239 | |
} |
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
public void setPackagePrefixes(List<String> packagePrefixes) { |
245 | 0 | this.packagePrefixes = packagePrefixes; |
246 | 0 | } |
247 | |
} |