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