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