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 public Set<InactivationBlockingMetadata> getAllInactivationBlockingMetadatas(DataDictionaryIndex index, Class<?> blockedClass) {
46 return index.getInactivationBlockersForClass().get(blockedClass);
47 }
48
49
50
51
52 public List<String> getBusinessObjectClassNames(DataDictionaryIndex index) {
53 List classNames = new ArrayList();
54 classNames.addAll(index.getBusinessObjectEntries().keySet());
55
56 return Collections.unmodifiableList(classNames);
57 }
58
59
60
61
62 public Map<String, BusinessObjectEntry> getBusinessObjectEntries(DataDictionaryIndex index) {
63 return index.getBusinessObjectEntries();
64 }
65
66
67
68
69 @Override
70 public DataObjectEntry getDataObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
71 if (StringUtils.isBlank(className)) {
72 throw new IllegalArgumentException("invalid (blank) className");
73 }
74 if ( LOG.isDebugEnabled() ) {
75 LOG.debug("calling getDataObjectEntry '" + className + "'");
76 }
77
78 String trimmedClassName = className;
79 int index = className.indexOf("$$");
80 if (index >= 0) {
81 trimmedClassName = className.substring(0, index);
82 }
83 return ddIndex.getDataObjectEntries().get(trimmedClassName);
84 }
85
86
87
88
89 public BusinessObjectEntry getBusinessObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
90 if (StringUtils.isBlank(className)) {
91 throw new IllegalArgumentException("invalid (blank) className");
92 }
93 if ( LOG.isDebugEnabled() ) {
94 LOG.debug("calling getBusinessObjectEntry '" + className + "'");
95 }
96 int index = className.indexOf("$$");
97 if (index >= 0) {
98 className = className.substring(0, index);
99 }
100 return ddIndex.getBusinessObjectEntries().get(className);
101 }
102
103
104
105
106 public DataDictionaryEntry getDictionaryObjectEntry(DataDictionaryIndex ddIndex, String className) {
107 if (StringUtils.isBlank(className)) {
108 throw new IllegalArgumentException("invalid (blank) className");
109 }
110 if ( LOG.isDebugEnabled() ) {
111 LOG.debug("calling getDictionaryObjectEntry '" + className + "'");
112 }
113 int index = className.indexOf("$$");
114 if (index >= 0) {
115 className = className.substring(0, index);
116 }
117
118
119 DataDictionaryEntry entry = null;
120 if (ddIndex.getEntriesByJstlKey() != null) {
121 entry = ddIndex.getEntriesByJstlKey().get(className);
122 }
123
124
125 if (entry == null){
126 entry = ddIndex.getDataObjectEntries().get(className);
127 }
128
129
130 if ( entry == null ) {
131 entry = getBusinessObjectEntry(ddIndex, className);
132 }
133
134 if ( entry == null ) {
135 entry = getDocumentEntry(ddIndex, className);
136 }
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 public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className ) {
165 BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className);
166 if (entry == null) {
167 Class boClass = null;
168 try{
169 boClass = Class.forName(className);
170 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
171 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
172 return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
173 }
174 } catch(ClassNotFoundException cnfex){
175 }
176 return null;
177 }
178 else {
179 return entry;
180 }
181 }
182
183
184
185
186 public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) {
187 return Collections.unmodifiableMap(index.getDocumentEntries());
188 }
189
190
191
192
193 public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) {
194
195 if (StringUtils.isBlank(documentTypeDDKey)) {
196 throw new IllegalArgumentException("invalid (blank) documentTypeName");
197 }
198 if ( LOG.isDebugEnabled() ) {
199 LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'");
200 }
201
202 DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey);
203
204 if ( de == null ) {
205 try {
206 Class<?> clazz = Class.forName( documentTypeDDKey );
207 de = index.getDocumentEntriesByBusinessObjectClass().get(clazz);
208 if ( de == null ) {
209 de = index.getDocumentEntriesByMaintainableClass().get(clazz);
210 }
211 } catch ( ClassNotFoundException ex ) {
212 LOG.warn( "Unable to find document entry for key: " + documentTypeDDKey );
213 }
214 }
215
216 return de;
217 }
218
219
220
221
222 public String getDocumentTypeName(DataDictionaryIndex index,
223 String documentTypeName) {
224
225 return null;
226 }
227
228
229
230
231 public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index, Class<?> businessObjectClass) {
232 if (businessObjectClass == null) {
233 throw new IllegalArgumentException("invalid (null) dataObjectClass");
234 }
235 if ( LOG.isDebugEnabled() ) {
236 LOG.debug("calling getDocumentEntry by dataObjectClass '" + businessObjectClass + "'");
237 }
238
239 return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass);
240 }
241
242
243
244
245
246 public View getViewById(UifDictionaryIndex index, String viewId) {
247 if (StringUtils.isBlank(viewId)) {
248 throw new IllegalArgumentException("invalid (blank) view id");
249 }
250 if (LOG.isDebugEnabled()) {
251 LOG.debug("calling getViewById by id '" + viewId + "'");
252 }
253
254 return index.getViewById(viewId);
255 }
256
257
258
259
260
261 public View getViewByTypeIndex(UifDictionaryIndex index, UifConstants.ViewType viewTypeName, Map<String, String> indexKey) {
262 if (viewTypeName == null) {
263 throw new IllegalArgumentException("invalid (blank) view type name");
264 }
265 if ((indexKey == null) || indexKey.isEmpty()) {
266 throw new IllegalArgumentException("index key must have at least one entry");
267 }
268
269 return index.getViewByTypeIndex(viewTypeName, indexKey);
270 }
271
272
273
274
275
276 public boolean viewByTypeExist(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
277 Map<String, String> indexKey) {
278 if (viewTypeName == null) {
279 throw new IllegalArgumentException("invalid (blank) view type name");
280 }
281 if ((indexKey == null) || indexKey.isEmpty()) {
282 throw new IllegalArgumentException("index key must have at least one entry");
283 }
284
285 return index.viewByTypeExist(viewTypeName, indexKey);
286 }
287
288
289
290
291
292 public PropertyValues getViewPropertiesById(UifDictionaryIndex index, String viewId) {
293 if (StringUtils.isBlank(viewId)) {
294 throw new IllegalArgumentException("invalid (blank) view id");
295 }
296
297 return index.getViewPropertiesById(viewId);
298 }
299
300
301
302
303
304 public PropertyValues getViewPropertiesByType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
305 Map<String, String> indexKey) {
306 if (viewTypeName == null) {
307 throw new IllegalArgumentException("invalid (blank) view type name");
308 }
309 if ((indexKey == null) || indexKey.isEmpty()) {
310 throw new IllegalArgumentException("index key must have at least one entry");
311 }
312
313 return index.getViewPropertiesByType(viewTypeName, indexKey);
314 }
315
316
317
318
319
320 public List<View> getViewsForType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName) {
321 if (viewTypeName == null) {
322 throw new IllegalArgumentException("invalid (blank) view type name");
323 }
324
325 return index.getViewsForType(viewTypeName);
326 }
327
328 }