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