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