1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kns.lookup; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.apache.ojb.broker.query.Criteria; |
21 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
22 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
23 | |
import org.kuali.rice.core.api.datetime.DateTimeService; |
24 | |
import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform; |
25 | |
import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator; |
26 | |
import org.kuali.rice.kns.service.BusinessObjectMetaDataService; |
27 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
28 | |
import org.kuali.rice.kns.web.comparator.NullValueComparator; |
29 | |
import org.kuali.rice.kns.web.ui.Field; |
30 | |
import org.kuali.rice.kns.web.ui.ResultRow; |
31 | |
import org.kuali.rice.krad.bo.BusinessObject; |
32 | |
import org.kuali.rice.krad.bo.DataObjectRelationship; |
33 | |
import org.kuali.rice.krad.datadictionary.RelationshipDefinition; |
34 | |
import org.kuali.rice.krad.datadictionary.control.ControlDefinition; |
35 | |
import org.kuali.rice.krad.exception.ClassNotPersistableException; |
36 | |
import org.kuali.rice.krad.lookup.SelectiveReferenceRefresher; |
37 | |
import org.kuali.rice.krad.service.BusinessObjectDictionaryService; |
38 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
39 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
40 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
41 | |
import org.kuali.rice.krad.service.PersistenceStructureService; |
42 | |
import org.kuali.rice.krad.util.KRADConstants; |
43 | |
import org.kuali.rice.krad.util.ObjectUtils; |
44 | |
|
45 | |
import java.util.ArrayList; |
46 | |
import java.util.Collection; |
47 | |
import java.util.Comparator; |
48 | |
import java.util.HashMap; |
49 | |
import java.util.HashSet; |
50 | |
import java.util.Iterator; |
51 | |
import java.util.List; |
52 | |
import java.util.Map; |
53 | |
import java.util.Set; |
54 | |
import java.util.StringTokenizer; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public class LookupUtils { |
60 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LookupUtils.class); |
61 | |
|
62 | 0 | public LookupUtils() { |
63 | |
|
64 | 0 | } |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public static void removeHiddenCriteriaFields(Class businessObjectClass, Map fieldValues) { |
73 | 0 | List<String> lookupFieldAttributeList = |
74 | |
getBusinessObjectMetaDataService().getLookupableFieldNames(businessObjectClass); |
75 | 0 | if (lookupFieldAttributeList != null) { |
76 | 0 | for (Iterator iter = lookupFieldAttributeList.iterator(); iter.hasNext(); ) { |
77 | 0 | String attributeName = (String) iter.next(); |
78 | 0 | if (fieldValues.containsKey(attributeName)) { |
79 | 0 | ControlDefinition controlDef = getDataDictionaryService() |
80 | |
.getAttributeControlDefinition(businessObjectClass, attributeName); |
81 | 0 | if (controlDef != null && controlDef.isHidden()) { |
82 | 0 | fieldValues.remove(attributeName); |
83 | |
} |
84 | |
} |
85 | 0 | } |
86 | |
} |
87 | 0 | } |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public static Integer getSearchResultsLimit(Class businessObjectClass) { |
99 | 0 | Integer limit = null; |
100 | 0 | if (BusinessObject.class.isAssignableFrom(businessObjectClass)) { |
101 | 0 | limit = getBusinessObjectSearchResultsLimit(businessObjectClass); |
102 | |
} |
103 | 0 | if (limit == null) { |
104 | 0 | limit = getApplicationSearchResultsLimit(); |
105 | |
} |
106 | 0 | return limit; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public static Integer getApplicationSearchResultsLimit() { |
113 | 0 | String limitString = CoreFrameworkServiceLocator.getParameterService() |
114 | |
.getParameterValueAsString(KRADConstants.KRAD_NAMESPACE, |
115 | |
KRADConstants.DetailTypes.LOOKUP_PARM_DETAIL_TYPE, |
116 | |
KRADConstants.SystemGroupParameterNames.LOOKUP_RESULTS_LIMIT); |
117 | 0 | if (limitString != null) { |
118 | 0 | return Integer.valueOf(limitString); |
119 | |
} |
120 | 0 | return null; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public static Integer getBusinessObjectSearchResultsLimit(Class businessObjectClass) { |
130 | 0 | return getBusinessObjectDictionaryService().getLookupResultSetLimit(businessObjectClass); |
131 | |
} |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
public static void applySearchResultsLimit(Class businessObjectClass, Criteria criteria, |
141 | |
DatabasePlatform platform) { |
142 | 0 | Integer limit = getSearchResultsLimit(businessObjectClass); |
143 | 0 | if (limit != null) { |
144 | 0 | platform.applyLimit(limit, criteria); |
145 | |
} |
146 | 0 | } |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public static void applySearchResultsLimit(Class businessObjectClass, |
155 | |
org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria criteria) { |
156 | 0 | Integer limit = getSearchResultsLimit(businessObjectClass); |
157 | 0 | if (limit != null) { |
158 | 0 | criteria.setSearchLimit(limit); |
159 | |
} |
160 | 0 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public static Integer getApplicationMaximumSearchResulsPerPageForMultipleValueLookups() { |
169 | 0 | String limitString = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KRADConstants.KRAD_NAMESPACE, KRADConstants.DetailTypes.LOOKUP_PARM_DETAIL_TYPE, KRADConstants.SystemGroupParameterNames.MULTIPLE_VALUE_LOOKUP_RESULTS_PER_PAGE); |
170 | 0 | if (limitString != null) { |
171 | 0 | return Integer.valueOf(limitString); |
172 | |
} |
173 | 0 | return null; |
174 | |
} |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
public static List<String> translateReadOnlyFieldsToList(String readOnlyFieldsString) { |
183 | 0 | List<String> readOnlyFieldsList = new ArrayList<String>(); |
184 | 0 | if (StringUtils.isNotEmpty(readOnlyFieldsString)) { |
185 | 0 | if (readOnlyFieldsString.indexOf(",") > 0) { |
186 | 0 | StringTokenizer token = new StringTokenizer(readOnlyFieldsString, ","); |
187 | 0 | while (token.hasMoreTokens()) { |
188 | 0 | String element = token.nextToken(); |
189 | 0 | readOnlyFieldsList.add(element); |
190 | 0 | } |
191 | 0 | } |
192 | |
else { |
193 | 0 | readOnlyFieldsList.add(readOnlyFieldsString); |
194 | |
} |
195 | |
} |
196 | 0 | return readOnlyFieldsList; |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
public static Map translateFieldConversions(String fieldConversionsString) { |
206 | 0 | Map fieldConversionsMap = new HashMap(); |
207 | 0 | if (StringUtils.isNotEmpty(fieldConversionsString)) { |
208 | 0 | if (fieldConversionsString.indexOf(",") > 0) { |
209 | 0 | StringTokenizer token = new StringTokenizer(fieldConversionsString, ","); |
210 | 0 | while (token.hasMoreTokens()) { |
211 | 0 | String element = token.nextToken(); |
212 | 0 | fieldConversionsMap.put(element.substring(0, element.indexOf(":")), element.substring(element.indexOf(":") + 1)); |
213 | 0 | } |
214 | 0 | } |
215 | |
else { |
216 | 0 | fieldConversionsMap.put(fieldConversionsString.substring(0, fieldConversionsString.indexOf(":")), fieldConversionsString.substring(fieldConversionsString.indexOf(":") + 1)); |
217 | |
} |
218 | |
} |
219 | 0 | return fieldConversionsMap; |
220 | |
} |
221 | |
|
222 | |
@Deprecated |
223 | |
public static Field setFieldQuickfinder(BusinessObject businessObject, |
224 | |
String attributeName, Field field, List displayedFieldNames) { |
225 | 0 | return setFieldQuickfinder( businessObject, (String)null, false, 0, attributeName, field, displayedFieldNames ); |
226 | |
} |
227 | |
|
228 | |
@Deprecated |
229 | |
public static Field setFieldQuickfinder(BusinessObject businessObject, |
230 | |
String attributeName, Field field, List displayedFieldNames, SelectiveReferenceRefresher srr) { |
231 | 0 | return setFieldQuickfinder( businessObject, (String)null, false, 0, attributeName, field, displayedFieldNames, srr ); |
232 | |
} |
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
@Deprecated |
238 | |
public static Field setFieldQuickfinder(BusinessObject businessObject, String collectionName, boolean addLine, int index, |
239 | |
String attributeName, Field field, List displayedFieldNames, SelectiveReferenceRefresher srr) { |
240 | 0 | field = setFieldQuickfinder(businessObject, collectionName, addLine, index, attributeName, field, displayedFieldNames); |
241 | 0 | if (srr != null) { |
242 | 0 | String collectionPrefix = ""; |
243 | 0 | if ( collectionName != null ) { |
244 | 0 | if (addLine) { |
245 | 0 | collectionPrefix = KRADConstants.MAINTENANCE_ADD_PREFIX + collectionName + "."; |
246 | |
} |
247 | |
else { |
248 | 0 | collectionPrefix = collectionName + "[" + index + "]."; |
249 | |
} |
250 | |
} |
251 | 0 | field.setReferencesToRefresh(convertReferencesToSelectCollectionToString( |
252 | |
srr.getAffectedReferencesFromLookup(businessObject, attributeName, collectionPrefix))); |
253 | |
} |
254 | 0 | return field; |
255 | |
} |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
@Deprecated |
261 | |
public static Field setFieldQuickfinder(BusinessObject businessObject, String collectionName, boolean addLine, int index, |
262 | |
String attributeName, Field field, List displayedFieldNames) { |
263 | 0 | boolean noLookup = false; |
264 | 0 | if (businessObject == null) { |
265 | 0 | return field; |
266 | |
} |
267 | |
|
268 | 0 | Boolean noLookupField = getBusinessObjectDictionaryService().noLookupFieldLookup(businessObject.getClass(), attributeName); |
269 | 0 | if (noLookupField != null && noLookupField) { |
270 | 0 | noLookup = true; |
271 | |
} |
272 | |
|
273 | 0 | return setFieldQuickfinder(businessObject, collectionName, addLine, index, attributeName, field, displayedFieldNames, noLookup); |
274 | |
|
275 | |
} |
276 | |
|
277 | |
@Deprecated |
278 | |
public static Field setFieldQuickfinder(BusinessObject businessObject, String collectionName, boolean addLine, int index, String attributeName, Field field, List displayedFieldNames, boolean noLookupField) |
279 | |
{ |
280 | 0 | if (businessObject == null) { |
281 | 0 | return field; |
282 | |
} |
283 | |
|
284 | 0 | if (noLookupField) { |
285 | 0 | return field; |
286 | |
} |
287 | 0 | DataObjectRelationship relationship = null; |
288 | 0 | if ( LOG.isDebugEnabled() ) { |
289 | 0 | LOG.debug( "setFieldQuickfinder("+businessObject.getClass().getName()+","+attributeName+","+field+","+displayedFieldNames+")" ); |
290 | |
} |
291 | |
|
292 | 0 | relationship = getBusinessObjectMetaDataService().getBusinessObjectRelationship(businessObject, businessObject.getClass(), attributeName, "", false); |
293 | |
|
294 | 0 | String collectionPrefix = ""; |
295 | 0 | if ( collectionName != null ) { |
296 | 0 | if (addLine) { |
297 | 0 | collectionPrefix = KRADConstants.MAINTENANCE_ADD_PREFIX + collectionName + "."; |
298 | |
} |
299 | |
else { |
300 | 0 | collectionPrefix = collectionName + "[" + index + "]."; |
301 | |
} |
302 | |
} |
303 | |
|
304 | 0 | if (relationship == null) { |
305 | 0 | Class c = ObjectUtils.getPropertyType(businessObject, attributeName, getPersistenceStructureService()); |
306 | |
|
307 | 0 | if(c!=null) { |
308 | 0 | if (attributeName.contains(".")) { |
309 | 0 | attributeName = StringUtils.substringBeforeLast( attributeName, "." ); |
310 | |
} |
311 | |
|
312 | 0 | RelationshipDefinition ddReference = getBusinessObjectMetaDataService().getBusinessObjectRelationshipDefinition(businessObject, attributeName); |
313 | 0 | relationship = getBusinessObjectMetaDataService().getBusinessObjectRelationship(ddReference, businessObject, businessObject.getClass(), attributeName, "", false); |
314 | 0 | if(relationship!=null) { |
315 | 0 | field.setQuickFinderClassNameImpl(relationship.getRelatedClass().getName()); |
316 | 0 | field.setFieldConversions(generateFieldConversions( businessObject, collectionPrefix, relationship, field.getPropertyPrefix(), displayedFieldNames, null)); |
317 | 0 | field.setLookupParameters(generateLookupParameters( businessObject, collectionPrefix, relationship, field.getPropertyPrefix(), displayedFieldNames, null)); |
318 | 0 | field.setBaseLookupUrl(LookupUtils.getBaseLookupUrl(false)); |
319 | 0 | field.setImageSrc(getBusinessObjectDictionaryService().getSearchIconOverride(businessObject.getClass())); |
320 | |
} |
321 | |
} |
322 | |
|
323 | 0 | return field; |
324 | |
} |
325 | 0 | if (ObjectUtils.isNestedAttribute(attributeName)) { |
326 | |
|
327 | 0 | String nestedAttributePrefix = StringUtils.substringBeforeLast(attributeName, "."); |
328 | |
|
329 | 0 | field.setQuickFinderClassNameImpl(relationship.getRelatedClass().getName()); |
330 | 0 | field.setFieldConversions( generateFieldConversions( businessObject, collectionPrefix, relationship, field.getPropertyPrefix(), displayedFieldNames, nestedAttributePrefix ) ); |
331 | 0 | field.setLookupParameters( generateLookupParameters( businessObject, collectionPrefix, relationship, field.getPropertyPrefix(), displayedFieldNames, nestedAttributePrefix ) ); |
332 | 0 | field.setBaseLookupUrl(LookupUtils.getBaseLookupUrl(false)); |
333 | 0 | } else { |
334 | 0 | field.setQuickFinderClassNameImpl(relationship.getRelatedClass().getName()); |
335 | 0 | field.setFieldConversions( generateFieldConversions( businessObject, collectionPrefix, relationship, field.getPropertyPrefix(), displayedFieldNames, null ) ); |
336 | 0 | field.setLookupParameters( generateLookupParameters( businessObject, collectionPrefix, relationship, field.getPropertyPrefix(), displayedFieldNames, null ) ); |
337 | 0 | field.setBaseLookupUrl(LookupUtils.getBaseLookupUrl(false)); |
338 | |
} |
339 | 0 | field.setImageSrc(getBusinessObjectDictionaryService().getSearchIconOverride(businessObject.getClass())); |
340 | |
|
341 | 0 | return field; |
342 | |
} |
343 | |
|
344 | 0 | private static String BASE_LOOKUP_ACTION_URL = null; |
345 | 0 | private static String BASE_MULTIPLE_VALUE_LOOKUP_ACTION_URL = null; |
346 | 0 | private static String BASE_INQUIRY_ACTION_URL = null; |
347 | |
|
348 | |
@Deprecated |
349 | |
public static String getBaseLookupUrl(boolean isMultipleValue) { |
350 | 0 | ConfigurationService kualiConfigurationService = KRADServiceLocator.getKualiConfigurationService(); |
351 | 0 | if ( isMultipleValue ) { |
352 | 0 | if ( BASE_MULTIPLE_VALUE_LOOKUP_ACTION_URL == null ) { |
353 | 0 | String lookupUrl = kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY); |
354 | 0 | if (!lookupUrl.endsWith("/")) { |
355 | 0 | lookupUrl = lookupUrl + "/"; |
356 | |
} |
357 | 0 | lookupUrl += "kr/" + KRADConstants.MULTIPLE_VALUE_LOOKUP_ACTION; |
358 | 0 | BASE_MULTIPLE_VALUE_LOOKUP_ACTION_URL = lookupUrl; |
359 | |
} |
360 | 0 | return BASE_MULTIPLE_VALUE_LOOKUP_ACTION_URL; |
361 | |
} else { |
362 | 0 | if ( BASE_LOOKUP_ACTION_URL == null ) { |
363 | 0 | String lookupUrl = kualiConfigurationService.getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY); |
364 | 0 | if (!lookupUrl.endsWith("/")) { |
365 | 0 | lookupUrl = lookupUrl + "/"; |
366 | |
} |
367 | 0 | lookupUrl += "kr/" + KRADConstants.LOOKUP_ACTION; |
368 | 0 | BASE_LOOKUP_ACTION_URL = lookupUrl; |
369 | |
} |
370 | 0 | return BASE_LOOKUP_ACTION_URL; |
371 | |
} |
372 | |
} |
373 | |
|
374 | |
@Deprecated |
375 | |
public static String getBaseInquiryUrl() { |
376 | 0 | if ( BASE_INQUIRY_ACTION_URL == null ) { |
377 | 0 | StringBuffer inquiryUrl = new StringBuffer( |
378 | |
KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString( |
379 | |
KRADConstants.APPLICATION_URL_KEY) ); |
380 | 0 | if (inquiryUrl.charAt(inquiryUrl.length()-1) != '/' ) { |
381 | 0 | inquiryUrl.append( '/' ); |
382 | |
} |
383 | 0 | inquiryUrl.append("kr/"); |
384 | 0 | inquiryUrl.append( KRADConstants.INQUIRY_ACTION ); |
385 | 0 | BASE_INQUIRY_ACTION_URL = inquiryUrl.toString(); |
386 | |
} |
387 | 0 | return BASE_INQUIRY_ACTION_URL; |
388 | |
} |
389 | |
|
390 | |
public static String transformLookupUrlToMultiple(String lookupUrl) { |
391 | 0 | return lookupUrl.replace("kr/" + KRADConstants.LOOKUP_ACTION, "kr/" + KRADConstants.MULTIPLE_VALUE_LOOKUP_ACTION); |
392 | |
} |
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
private static void setFieldDirectInquiry(Field field) { |
406 | 0 | if (StringUtils.isNotBlank(field.getFieldConversions())) { |
407 | 0 | boolean directInquiriesEnabled = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean( |
408 | |
KRADConstants.KRAD_NAMESPACE, KRADConstants.DetailTypes.ALL_DETAIL_TYPE, KRADConstants.SystemGroupParameterNames.ENABLE_DIRECT_INQUIRIES_IND); |
409 | 0 | if (directInquiriesEnabled) { |
410 | 0 | if (StringUtils.isNotBlank(field.getFieldConversions())) { |
411 | 0 | String fieldConversions = field.getFieldConversions(); |
412 | 0 | String newInquiryParameters = KRADConstants.EMPTY_STRING; |
413 | 0 | String[] conversions = StringUtils.split(fieldConversions, KRADConstants.FIELD_CONVERSIONS_SEPARATOR); |
414 | |
|
415 | 0 | for (int l = 0; l < conversions.length; l++) { |
416 | 0 | String conversion = conversions[l]; |
417 | |
|
418 | 0 | String[] conversionPair = StringUtils.split(conversion, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2); |
419 | 0 | String conversionFrom = conversionPair[0]; |
420 | 0 | String conversionTo = conversionPair[1]; |
421 | 0 | newInquiryParameters += (conversionTo + KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR + conversionFrom); |
422 | |
|
423 | 0 | if (l < conversions.length - 1) { |
424 | 0 | newInquiryParameters += KRADConstants.FIELD_CONVERSIONS_SEPARATOR; |
425 | |
} |
426 | |
} |
427 | |
|
428 | 0 | field.setInquiryParameters(newInquiryParameters); |
429 | |
} |
430 | |
} |
431 | 0 | field.setFieldDirectInquiryEnabled(directInquiriesEnabled); |
432 | 0 | } |
433 | |
else { |
434 | 0 | field.setFieldDirectInquiryEnabled(false); |
435 | |
} |
436 | 0 | } |
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
public static Field setFieldDirectInquiry(BusinessObject businessObject, String attributeName, Field field) |
444 | |
{ |
445 | 0 | if (businessObject == null) |
446 | |
{ |
447 | 0 | return field; |
448 | |
} |
449 | |
|
450 | 0 | Boolean noDirectInquiry = getBusinessObjectDictionaryService().noDirectInquiryFieldLookup(businessObject.getClass(), attributeName); |
451 | |
|
452 | 0 | if (noDirectInquiry != null && noDirectInquiry.booleanValue() || noDirectInquiry == null) { |
453 | 0 | return field; |
454 | |
} |
455 | |
|
456 | 0 | setFieldDirectInquiry(field); |
457 | |
|
458 | 0 | return field; |
459 | |
} |
460 | |
|
461 | 0 | private static Map<Class,Map<String,Map>> referencesForForeignKey = new HashMap<Class, Map<String,Map>>(); |
462 | |
|
463 | |
@Deprecated |
464 | |
public static Map getPrimitiveReference(BusinessObject businessObject, String attributeName) { |
465 | 0 | Map chosenReferenceByKeySize = new HashMap(); |
466 | 0 | Map chosenReferenceByFieldName = new HashMap(); |
467 | |
|
468 | 0 | Map referenceClasses = null; |
469 | |
|
470 | |
try { |
471 | |
|
472 | 0 | Map<String,Map> propMap = referencesForForeignKey.get(businessObject.getClass()); |
473 | 0 | if ( propMap == null ) { |
474 | 0 | propMap = new HashMap<String, Map>(); |
475 | 0 | referencesForForeignKey.put(businessObject.getClass(), propMap); |
476 | |
} |
477 | 0 | if ( propMap.containsKey(attributeName) ) { |
478 | 0 | referenceClasses = propMap.get( attributeName ); |
479 | |
} else { |
480 | |
|
481 | 0 | referenceClasses = getBusinessObjectMetaDataService().getReferencesForForeignKey(businessObject, attributeName); |
482 | 0 | if(referenceClasses==null || referenceClasses.isEmpty()) { |
483 | 0 | if ( getPersistenceStructureService().isPersistable(businessObject.getClass()) ) { |
484 | 0 | referenceClasses = getPersistenceStructureService().getReferencesForForeignKey(businessObject.getClass(), attributeName); |
485 | |
} |
486 | |
} |
487 | 0 | propMap.put(attributeName, referenceClasses); |
488 | |
} |
489 | 0 | } catch ( ClassNotPersistableException ex ) { |
490 | |
|
491 | 0 | Map<String,Map> propMap = referencesForForeignKey.get(businessObject.getClass()); |
492 | 0 | propMap.put(attributeName, null); |
493 | 0 | } |
494 | |
|
495 | |
|
496 | 0 | if (referenceClasses == null || referenceClasses.isEmpty()) { |
497 | 0 | return chosenReferenceByKeySize; |
498 | |
} |
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | 0 | int minKeys = Integer.MAX_VALUE; |
505 | 0 | for (Iterator iter = referenceClasses.keySet().iterator(); iter.hasNext();) { |
506 | 0 | String attr = (String) iter.next(); |
507 | 0 | Class clazz = (Class) referenceClasses.get(attr); |
508 | 0 | List pkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(clazz); |
509 | |
|
510 | |
|
511 | 0 | if (pkNames.size() < minKeys) { |
512 | 0 | minKeys = pkNames.size(); |
513 | 0 | chosenReferenceByKeySize.clear(); |
514 | 0 | chosenReferenceByKeySize.put(attr, clazz); |
515 | |
} |
516 | |
|
517 | |
|
518 | 0 | if (attributeName.startsWith(attr)) { |
519 | 0 | chosenReferenceByFieldName.clear(); |
520 | 0 | chosenReferenceByFieldName.put(attr, clazz); |
521 | |
} |
522 | 0 | } |
523 | |
|
524 | |
|
525 | 0 | return chosenReferenceByFieldName.isEmpty() ? chosenReferenceByKeySize : chosenReferenceByFieldName; |
526 | |
} |
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
|
533 | |
|
534 | |
|
535 | |
|
536 | |
public static BusinessObject getNestedBusinessObject(BusinessObject bo, String attributeName) { |
537 | 0 | String[] nestedAttributes = StringUtils.split(attributeName, "."); |
538 | |
|
539 | 0 | BusinessObject childBO = null; |
540 | 0 | String attributeRefName = ""; |
541 | 0 | Class clazz = null; |
542 | 0 | if (nestedAttributes.length > 1) { |
543 | 0 | String attributeStringSoFar = ""; |
544 | 0 | for (int i = 0; i < nestedAttributes.length - 1; i++) { |
545 | |
|
546 | |
|
547 | |
|
548 | 0 | if (i != 0) { |
549 | 0 | attributeStringSoFar = attributeStringSoFar + "."; |
550 | |
} |
551 | 0 | attributeStringSoFar = attributeStringSoFar + nestedAttributes[i]; |
552 | |
|
553 | 0 | clazz = ObjectUtils.getPropertyType( bo, attributeStringSoFar, getPersistenceStructureService() ); |
554 | |
|
555 | 0 | if (clazz != null && BusinessObject.class.isAssignableFrom(clazz)) { |
556 | |
try { |
557 | 0 | childBO = (BusinessObject) ObjectUtils.createNewObjectFromClass(clazz); |
558 | |
} |
559 | 0 | catch (Exception e) { |
560 | 0 | return null; |
561 | 0 | } |
562 | |
} |
563 | |
} |
564 | |
} |
565 | 0 | return childBO; |
566 | |
} |
567 | |
|
568 | |
public static Class getNestedReferenceClass(BusinessObject businessObject, String attributeName) { |
569 | 0 | BusinessObject bo = getNestedBusinessObject(businessObject, attributeName); |
570 | 0 | return null == bo ? null : bo.getClass(); |
571 | |
} |
572 | |
|
573 | |
@Deprecated |
574 | |
private static String generateFieldConversions(BusinessObject businessObject, String collectionName, DataObjectRelationship relationship, String propertyPrefix, List displayedFieldNames, String nestedObjectPrefix) { |
575 | 0 | String fieldConversions = ""; |
576 | |
|
577 | 0 | if ( LOG.isDebugEnabled() ) { |
578 | 0 | LOG.debug( "generateFieldConversions(" + businessObject.getClass().getName() + "," + collectionName + ",\n" + relationship + "\n," + propertyPrefix + "," + displayedFieldNames + "," + nestedObjectPrefix + ")" ); |
579 | |
} |
580 | |
|
581 | |
|
582 | 0 | for ( Map.Entry<String,String> entry : relationship.getParentToChildReferences().entrySet() ) { |
583 | 0 | String fromField = entry.getValue(); |
584 | 0 | String toField = entry.getKey(); |
585 | |
|
586 | |
|
587 | 0 | if (!displayedFieldNames.contains(toField)) { |
588 | 0 | toField = translateToDisplayedField(businessObject.getClass(), toField, displayedFieldNames); |
589 | |
} |
590 | |
|
591 | 0 | if (StringUtils.isNotBlank(fieldConversions)) { |
592 | 0 | fieldConversions += ","; |
593 | |
} |
594 | |
|
595 | 0 | if ( StringUtils.isNotEmpty( propertyPrefix ) ) { |
596 | 0 | toField = propertyPrefix + "." + toField; |
597 | |
} |
598 | |
|
599 | 0 | if ( StringUtils.isNotEmpty( collectionName ) ) { |
600 | 0 | toField = collectionName + toField; |
601 | |
} |
602 | |
|
603 | 0 | fieldConversions += fromField + ":" + toField; |
604 | 0 | } |
605 | |
|
606 | 0 | return fieldConversions; |
607 | |
} |
608 | |
|
609 | |
@Deprecated |
610 | |
private static String generateLookupParameters(BusinessObject businessObject, String collectionName, DataObjectRelationship relationship, String propertyPrefix, List displayedFieldNames, String nestedObjectPrefix) { |
611 | |
|
612 | 0 | String lookupParameters = ""; |
613 | |
|
614 | 0 | List displayedQFFieldNames = getBusinessObjectDictionaryService().getLookupFieldNames(relationship.getRelatedClass()); |
615 | 0 | for ( Map.Entry<String,String> entry : relationship.getParentToChildReferences().entrySet() ) { |
616 | 0 | String fromField = entry.getKey(); |
617 | 0 | String toField = entry.getValue(); |
618 | |
|
619 | 0 | if ( relationship.getUserVisibleIdentifierKey() == null || relationship.getUserVisibleIdentifierKey().equals( fromField ) ) { |
620 | |
|
621 | 0 | if (!displayedFieldNames.contains(fromField)) { |
622 | 0 | fromField = translateToDisplayedField(businessObject.getClass(), fromField, displayedFieldNames); |
623 | |
} |
624 | |
|
625 | |
|
626 | 0 | if (displayedQFFieldNames != null && !displayedQFFieldNames.contains(toField)) { |
627 | 0 | toField = translateToDisplayedField(relationship.getRelatedClass(), toField, displayedQFFieldNames); |
628 | |
} |
629 | |
|
630 | 0 | if (StringUtils.isNotBlank(lookupParameters)) { |
631 | 0 | lookupParameters += ","; |
632 | |
} |
633 | |
|
634 | 0 | if (propertyPrefix != null && !propertyPrefix.equals("")) { |
635 | 0 | fromField = propertyPrefix + "." + fromField; |
636 | |
} |
637 | |
|
638 | 0 | if ( StringUtils.isNotEmpty( collectionName ) ) { |
639 | 0 | fromField = collectionName + fromField; |
640 | |
} |
641 | |
|
642 | 0 | lookupParameters += fromField + ":" + toField; |
643 | |
} |
644 | 0 | } |
645 | |
|
646 | 0 | return lookupParameters; |
647 | |
} |
648 | |
|
649 | |
@Deprecated |
650 | |
private static String translateToDisplayedField(Class businessObjectClass, String fieldName, List displayedFieldNames) { |
651 | 0 | if ( getPersistenceStructureService().isPersistable(businessObjectClass) ) { |
652 | 0 | Map nestedFkMap = getPersistenceStructureService().getNestedForeignKeyMap(businessObjectClass); |
653 | |
|
654 | |
|
655 | |
|
656 | |
|
657 | |
|
658 | |
|
659 | |
|
660 | 0 | if (!displayedFieldNames.contains(fieldName)) { |
661 | 0 | for (Iterator iterator = displayedFieldNames.iterator(); iterator.hasNext();) { |
662 | 0 | String dispField = (String) iterator.next(); |
663 | |
|
664 | 0 | if (nestedFkMap.containsKey(dispField) && nestedFkMap.get(dispField).equals(fieldName)) { |
665 | 0 | fieldName = dispField; |
666 | |
} |
667 | 0 | } |
668 | |
} |
669 | |
} |
670 | |
|
671 | 0 | return fieldName; |
672 | |
} |
673 | |
|
674 | |
public static String convertReferencesToSelectCollectionToString(Collection<String> referencesToRefresh) { |
675 | 0 | StringBuilder buf = new StringBuilder(); |
676 | 0 | for (String reference : referencesToRefresh) { |
677 | 0 | buf.append(reference).append(KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR); |
678 | |
} |
679 | 0 | if (!referencesToRefresh.isEmpty()) { |
680 | |
|
681 | 0 | buf.delete(buf.length() - KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR.length(), buf.length()); |
682 | |
} |
683 | 0 | return buf.toString(); |
684 | |
} |
685 | |
|
686 | |
public static String convertSetOfObjectIdsToString(Set<String> objectIds) { |
687 | 0 | if (objectIds.isEmpty()) { |
688 | 0 | return ""; |
689 | |
} |
690 | 0 | StringBuilder buf = new StringBuilder(); |
691 | 0 | for (String objectId : objectIds) { |
692 | 0 | if (objectId.contains(KRADConstants.MULTIPLE_VALUE_LOOKUP_OBJ_IDS_SEPARATOR)) { |
693 | 0 | throw new RuntimeException("object ID " + objectId + " contains the selected obj ID separator"); |
694 | |
} |
695 | 0 | buf.append(objectId).append(KRADConstants.MULTIPLE_VALUE_LOOKUP_OBJ_IDS_SEPARATOR); |
696 | |
} |
697 | |
|
698 | 0 | buf.delete(buf.length() - KRADConstants.MULTIPLE_VALUE_LOOKUP_OBJ_IDS_SEPARATOR.length(), buf.length()); |
699 | |
|
700 | 0 | return buf.toString(); |
701 | |
} |
702 | |
|
703 | |
public static Set<String> convertStringOfObjectIdsToSet(String objectIdsString) { |
704 | 0 | Set<String> set = new HashSet<String>(); |
705 | |
|
706 | 0 | if (StringUtils.isNotBlank(objectIdsString)) { |
707 | 0 | String[] objectIds = StringUtils.splitByWholeSeparator(objectIdsString, KRADConstants.MULTIPLE_VALUE_LOOKUP_OBJ_IDS_SEPARATOR); |
708 | 0 | for (String objectId : objectIds) { |
709 | 0 | set.add(objectId); |
710 | |
} |
711 | |
} |
712 | 0 | return set; |
713 | |
} |
714 | |
|
715 | |
|
716 | |
|
717 | |
|
718 | |
|
719 | |
|
720 | |
|
721 | |
|
722 | |
|
723 | |
|
724 | |
|
725 | |
public static Comparator findBestValueComparatorForColumn(List<ResultRow> resultTable, int column) { |
726 | |
|
727 | 0 | Comparator comp = NullValueComparator.getInstance(); |
728 | 0 | for (ResultRow row : resultTable) { |
729 | 0 | Comparator tempComp = row.getColumns().get(column).getValueComparator(); |
730 | 0 | if (tempComp != null && !NullValueComparator.class.equals(tempComp.getClass())) { |
731 | 0 | return tempComp; |
732 | |
} |
733 | 0 | } |
734 | 0 | return comp; |
735 | |
} |
736 | |
|
737 | |
|
738 | |
|
739 | |
|
740 | |
|
741 | |
|
742 | |
|
743 | |
|
744 | |
|
745 | |
|
746 | |
|
747 | |
|
748 | |
public static Map<String, String> generateCompositeSelectedObjectIds(Set<String> previouslySelectedObjectIds, Set<String> displayedObjectIds, Set<String> selectedObjectIds) { |
749 | 0 | Map<String, String> tempMap = new HashMap<String, String>(); |
750 | |
|
751 | |
|
752 | |
|
753 | |
|
754 | |
|
755 | |
|
756 | 0 | for (String previouslySelectedObjectId : previouslySelectedObjectIds) { |
757 | 0 | tempMap.put(previouslySelectedObjectId, previouslySelectedObjectId); |
758 | |
} |
759 | |
|
760 | 0 | for (String displayedObjectId : displayedObjectIds) { |
761 | 0 | tempMap.remove(displayedObjectId); |
762 | |
} |
763 | |
|
764 | 0 | for (String selectedObjectId : selectedObjectIds) { |
765 | 0 | tempMap.put(selectedObjectId, selectedObjectId); |
766 | |
} |
767 | 0 | return tempMap; |
768 | |
} |
769 | |
|
770 | |
public static DataDictionaryService getDataDictionaryService() { |
771 | 0 | return KRADServiceLocatorWeb.getDataDictionaryService(); |
772 | |
} |
773 | |
|
774 | |
public static PersistenceStructureService getPersistenceStructureService() { |
775 | 0 | return KRADServiceLocator.getPersistenceStructureService(); |
776 | |
} |
777 | |
|
778 | |
public static BusinessObjectDictionaryService getBusinessObjectDictionaryService() { |
779 | 0 | return KRADServiceLocatorWeb.getBusinessObjectDictionaryService(); |
780 | |
} |
781 | |
|
782 | |
public static BusinessObjectMetaDataService getBusinessObjectMetaDataService() { |
783 | 0 | return KNSServiceLocator.getBusinessObjectMetaDataService(); |
784 | |
} |
785 | |
|
786 | |
public static DateTimeService getDateTimeService() { |
787 | 0 | return CoreApiServiceLocator.getDateTimeService(); |
788 | |
} |
789 | |
} |