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