1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryIndex;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.service.ModuleService;
23 import org.kuali.rice.krad.uif.UifConstants;
24 import org.kuali.rice.krad.uif.view.View;
25 import org.springframework.beans.PropertyValues;
26
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32
33
34
35
36
37
38
39 public class DataDictionaryIndexMapper implements DataDictionaryMapper {
40 private static final Logger LOG = Logger.getLogger(DataDictionaryIndexMapper.class);
41
42
43
44
45
46 public Set<InactivationBlockingMetadata> getAllInactivationBlockingMetadatas(DataDictionaryIndex index,
47 Class<?> blockedClass) {
48 return index.getInactivationBlockersForClass().get(blockedClass);
49 }
50
51
52
53
54 public List<String> getBusinessObjectClassNames(DataDictionaryIndex index) {
55 List classNames = new ArrayList();
56 classNames.addAll(index.getBusinessObjectEntries().keySet());
57
58 return Collections.unmodifiableList(classNames);
59 }
60
61
62
63
64 public Map<String, BusinessObjectEntry> getBusinessObjectEntries(DataDictionaryIndex index) {
65 return index.getBusinessObjectEntries();
66 }
67
68
69
70
71
72 @Override
73 public DataObjectEntry getDataObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
74 if (StringUtils.isBlank(className)) {
75 throw new IllegalArgumentException("invalid (blank) className");
76 }
77 if (LOG.isDebugEnabled()) {
78 LOG.debug("calling getDataObjectEntry '" + className + "'");
79 }
80
81 String trimmedClassName = className;
82 int index = className.indexOf("$$");
83 if (index >= 0) {
84 trimmedClassName = className.substring(0, index);
85 }
86 return ddIndex.getDataObjectEntries().get(trimmedClassName);
87 }
88
89
90
91
92 public BusinessObjectEntry getBusinessObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
93 if (StringUtils.isBlank(className)) {
94 throw new IllegalArgumentException("invalid (blank) className");
95 }
96 if (LOG.isDebugEnabled()) {
97 LOG.debug("calling getBusinessObjectEntry '" + className + "'");
98 }
99 int index = className.indexOf("$$");
100 if (index >= 0) {
101 className = className.substring(0, index);
102 }
103 return ddIndex.getBusinessObjectEntries().get(className);
104 }
105
106
107
108
109
110 public DataDictionaryEntry getDictionaryObjectEntry(DataDictionaryIndex ddIndex, String className) {
111 if (StringUtils.isBlank(className)) {
112 throw new IllegalArgumentException("invalid (blank) className");
113 }
114 if (LOG.isDebugEnabled()) {
115 LOG.debug("calling getDictionaryObjectEntry '" + className + "'");
116 }
117 int index = className.indexOf("$$");
118 if (index >= 0) {
119 className = className.substring(0, index);
120 }
121
122
123 DataDictionaryEntry entry = null;
124 if (ddIndex.getEntriesByJstlKey() != null) {
125 entry = ddIndex.getEntriesByJstlKey().get(className);
126 }
127
128
129 if (entry == null) {
130 entry = ddIndex.getDataObjectEntries().get(className);
131 }
132
133
134 if (entry == null) {
135 entry = getBusinessObjectEntry(ddIndex, className);
136 }
137
138 if (entry == null) {
139 entry = getDocumentEntry(ddIndex, className);
140 }
141
142 return entry;
143 }
144
145
146
147
148
149 @Override
150 public DataObjectEntry getDataObjectEntry(DataDictionaryIndex index, String className) {
151 DataObjectEntry entry = getDataObjectEntryForConcreteClass(index, className);
152
153 if (entry == null) {
154 Class<?> boClass = null;
155 try {
156 boClass = Class.forName(className);
157 ModuleService responsibleModuleService =
158 KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
159 if (responsibleModuleService != null && responsibleModuleService.isExternalizable(boClass)) {
160 entry = responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
161 }
162 } catch (ClassNotFoundException cnfex) {
163
164 }
165 }
166
167 return entry;
168 }
169
170 public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className) {
171 BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className);
172 if (entry == null) {
173 Class boClass = null;
174 try {
175 boClass = Class.forName(className);
176 ModuleService responsibleModuleService =
177 KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
178 if (responsibleModuleService != null && responsibleModuleService.isExternalizable(boClass)) {
179 return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
180 }
181 } catch (ClassNotFoundException cnfex) {
182 }
183 return null;
184 } else {
185 return entry;
186 }
187 }
188
189
190
191
192 public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) {
193 return Collections.unmodifiableMap(index.getDocumentEntries());
194 }
195
196
197
198
199
200 public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) {
201
202 if (StringUtils.isBlank(documentTypeDDKey)) {
203 throw new IllegalArgumentException("invalid (blank) documentTypeName");
204 }
205 if (LOG.isDebugEnabled()) {
206 LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'");
207 }
208
209 DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey);
210
211 if (de == null) {
212 try {
213 Class<?> clazz = Class.forName(documentTypeDDKey);
214 de = index.getDocumentEntriesByBusinessObjectClass().get(clazz);
215 if (de == null) {
216 de = index.getDocumentEntriesByMaintainableClass().get(clazz);
217 }
218 } catch (ClassNotFoundException ex) {
219 LOG.warn("Unable to find document entry for key: " + documentTypeDDKey);
220 }
221 }
222
223 return de;
224 }
225
226
227
228
229
230 public String getDocumentTypeName(DataDictionaryIndex index, String documentTypeName) {
231
232 return null;
233 }
234
235
236
237
238
239 public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index,
240 Class<?> businessObjectClass) {
241 if (businessObjectClass == null) {
242 throw new IllegalArgumentException("invalid (null) dataObjectClass");
243 }
244 if (LOG.isDebugEnabled()) {
245 LOG.debug("calling getDocumentEntry by dataObjectClass '" + businessObjectClass + "'");
246 }
247
248 return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass);
249 }
250
251
252
253
254
255 public View getViewById(UifDictionaryIndex index, String viewId) {
256 if (StringUtils.isBlank(viewId)) {
257 throw new IllegalArgumentException("invalid (blank) view id");
258 }
259 if (LOG.isDebugEnabled()) {
260 LOG.debug("calling getViewById by id '" + viewId + "'");
261 }
262
263 return index.getViewById(viewId);
264 }
265
266
267
268
269
270 public View getViewByTypeIndex(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
271 Map<String, String> indexKey) {
272 if (viewTypeName == null) {
273 throw new IllegalArgumentException("invalid (blank) view type name");
274 }
275 if ((indexKey == null) || indexKey.isEmpty()) {
276 throw new IllegalArgumentException("index key must have at least one entry");
277 }
278
279 return index.getViewByTypeIndex(viewTypeName, indexKey);
280 }
281
282
283
284
285
286 public boolean viewByTypeExist(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
287 Map<String, String> indexKey) {
288 if (viewTypeName == null) {
289 throw new IllegalArgumentException("invalid (blank) view type name");
290 }
291 if ((indexKey == null) || indexKey.isEmpty()) {
292 throw new IllegalArgumentException("index key must have at least one entry");
293 }
294
295 return index.viewByTypeExist(viewTypeName, indexKey);
296 }
297
298
299
300
301
302 public PropertyValues getViewPropertiesById(UifDictionaryIndex index, String viewId) {
303 if (StringUtils.isBlank(viewId)) {
304 throw new IllegalArgumentException("invalid (blank) view id");
305 }
306
307 return index.getViewPropertiesById(viewId);
308 }
309
310
311
312
313
314 public PropertyValues getViewPropertiesByType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
315 Map<String, String> indexKey) {
316 if (viewTypeName == null) {
317 throw new IllegalArgumentException("invalid (blank) view type name");
318 }
319 if ((indexKey == null) || indexKey.isEmpty()) {
320 throw new IllegalArgumentException("index key must have at least one entry");
321 }
322
323 return index.getViewPropertiesByType(viewTypeName, indexKey);
324 }
325
326
327
328
329
330 public List<View> getViewsForType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName) {
331 if (viewTypeName == null) {
332 throw new IllegalArgumentException("invalid (blank) view type name");
333 }
334
335 return index.getViewsForType(viewTypeName);
336 }
337
338 }