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 if ( entry == null ) {
126 entry = getDocumentEntry(ddIndex, className);
127 }
128 return entry;
129 }
130
131
132
133
134 @Override
135 public DataObjectEntry getDataObjectEntry(DataDictionaryIndex index, String className) {
136 DataObjectEntry entry = getDataObjectEntryForConcreteClass(index, className);
137
138 if (entry == null) {
139 Class<?> boClass = null;
140 try{
141 boClass = Class.forName(className);
142 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
143 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
144 entry = responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
145 }
146 } catch(ClassNotFoundException cnfex){
147
148 }
149 }
150
151 return entry;
152 }
153
154 public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className ) {
155 BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className);
156 if (entry == null) {
157 Class boClass = null;
158 try{
159 boClass = Class.forName(className);
160 ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(boClass);
161 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
162 return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
163 }
164 } catch(ClassNotFoundException cnfex){
165 }
166 return null;
167 }
168 else {
169 return entry;
170 }
171 }
172
173
174
175
176 public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) {
177 return Collections.unmodifiableMap(index.getDocumentEntries());
178 }
179
180
181
182
183 public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) {
184
185 if (StringUtils.isBlank(documentTypeDDKey)) {
186 throw new IllegalArgumentException("invalid (blank) documentTypeName");
187 }
188 if ( LOG.isDebugEnabled() ) {
189 LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'");
190 }
191
192 DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey);
193
194 if ( de == null ) {
195 try {
196 Class<?> clazz = Class.forName( documentTypeDDKey );
197 de = index.getDocumentEntriesByBusinessObjectClass().get(clazz);
198 if ( de == null ) {
199 de = index.getDocumentEntriesByMaintainableClass().get(clazz);
200 }
201 } catch ( ClassNotFoundException ex ) {
202 LOG.warn( "Unable to find document entry for key: " + documentTypeDDKey );
203 }
204 }
205
206 return de;
207 }
208
209
210
211
212 public String getDocumentTypeName(DataDictionaryIndex index,
213 String documentTypeName) {
214
215 return null;
216 }
217
218
219
220
221 public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index, Class<?> businessObjectClass) {
222 if (businessObjectClass == null) {
223 throw new IllegalArgumentException("invalid (null) dataObjectClass");
224 }
225 if ( LOG.isDebugEnabled() ) {
226 LOG.debug("calling getDocumentEntry by dataObjectClass '" + businessObjectClass + "'");
227 }
228
229 return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass);
230 }
231
232
233
234
235
236 public View getViewById(UifDictionaryIndex index, String viewId) {
237 if (StringUtils.isBlank(viewId)) {
238 throw new IllegalArgumentException("invalid (blank) view id");
239 }
240 if (LOG.isDebugEnabled()) {
241 LOG.debug("calling getViewById by id '" + viewId + "'");
242 }
243
244 return index.getViewById(viewId);
245 }
246
247
248
249
250
251 public View getViewByTypeIndex(UifDictionaryIndex index, UifConstants.ViewType viewTypeName, Map<String, String> indexKey) {
252 if (viewTypeName == null) {
253 throw new IllegalArgumentException("invalid (blank) view type name");
254 }
255 if ((indexKey == null) || indexKey.isEmpty()) {
256 throw new IllegalArgumentException("index key must have at least one entry");
257 }
258
259 return index.getViewByTypeIndex(viewTypeName, indexKey);
260 }
261
262
263
264
265
266 public boolean viewByTypeExist(UifDictionaryIndex index, UifConstants.ViewType viewTypeName,
267 Map<String, String> indexKey) {
268 if (viewTypeName == null) {
269 throw new IllegalArgumentException("invalid (blank) view type name");
270 }
271 if ((indexKey == null) || indexKey.isEmpty()) {
272 throw new IllegalArgumentException("index key must have at least one entry");
273 }
274
275 return index.viewByTypeExist(viewTypeName, indexKey);
276 }
277
278
279
280
281
282 public PropertyValues getViewPropertiesById(UifDictionaryIndex index, String viewId) {
283 if (StringUtils.isBlank(viewId)) {
284 throw new IllegalArgumentException("invalid (blank) view id");
285 }
286
287 return index.getViewPropertiesById(viewId);
288 }
289
290
291
292
293
294 public PropertyValues getViewPropertiesByType(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.getViewPropertiesByType(viewTypeName, indexKey);
304 }
305
306
307
308
309
310 public List<View> getViewsForType(UifDictionaryIndex index, UifConstants.ViewType viewTypeName) {
311 if (viewTypeName == null) {
312 throw new IllegalArgumentException("invalid (blank) view type name");
313 }
314
315 return index.getViewsForType(viewTypeName);
316 }
317
318 }