| 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.KNSServiceLocator; |
| 27 | |
import org.kuali.rice.krad.datadictionary.control.ControlDefinition; |
| 28 | |
import org.kuali.rice.kns.service.BusinessObjectMetaDataService; |
| 29 | |
import org.kuali.rice.kns.web.comparator.NullValueComparator; |
| 30 | |
import org.kuali.rice.kns.web.ui.Field; |
| 31 | |
import org.kuali.rice.kns.web.ui.ResultRow; |
| 32 | |
import org.kuali.rice.krad.bo.BusinessObject; |
| 33 | |
import org.kuali.rice.krad.bo.BusinessObjectRelationship; |
| 34 | |
import org.kuali.rice.krad.datadictionary.RelationshipDefinition; |
| 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 | BusinessObjectRelationship 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.getPropertyString(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.getPropertyString(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().getPropertyString(KRADConstants.APPLICATION_URL_KEY) ); |
| 379 | 0 | if (inquiryUrl.charAt(inquiryUrl.length()-1) != '/' ) { |
| 380 | 0 | inquiryUrl.append( '/' ); |
| 381 | |
} |
| 382 | 0 | inquiryUrl.append("kr/"); |
| 383 | 0 | inquiryUrl.append( KRADConstants.INQUIRY_ACTION ); |
| 384 | 0 | BASE_INQUIRY_ACTION_URL = inquiryUrl.toString(); |
| 385 | |
} |
| 386 | 0 | return BASE_INQUIRY_ACTION_URL; |
| 387 | |
} |
| 388 | |
|
| 389 | |
public static String transformLookupUrlToMultiple(String lookupUrl) { |
| 390 | 0 | return lookupUrl.replace("kr/" + KRADConstants.LOOKUP_ACTION, "kr/" + KRADConstants.MULTIPLE_VALUE_LOOKUP_ACTION); |
| 391 | |
} |
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
private static void setFieldDirectInquiry(Field field) { |
| 405 | 0 | if (StringUtils.isNotBlank(field.getFieldConversions())) { |
| 406 | 0 | boolean directInquiriesEnabled = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean( |
| 407 | |
KRADConstants.KRAD_NAMESPACE, KRADConstants.DetailTypes.ALL_DETAIL_TYPE, KRADConstants.SystemGroupParameterNames.ENABLE_DIRECT_INQUIRIES_IND); |
| 408 | 0 | if (directInquiriesEnabled) { |
| 409 | 0 | if (StringUtils.isNotBlank(field.getFieldConversions())) { |
| 410 | 0 | String fieldConversions = field.getFieldConversions(); |
| 411 | 0 | String newInquiryParameters = KRADConstants.EMPTY_STRING; |
| 412 | 0 | String[] conversions = StringUtils.split(fieldConversions, KRADConstants.FIELD_CONVERSIONS_SEPARATOR); |
| 413 | |
|
| 414 | 0 | for (int l = 0; l < conversions.length; l++) { |
| 415 | 0 | String conversion = conversions[l]; |
| 416 | |
|
| 417 | 0 | String[] conversionPair = StringUtils.split(conversion, KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR, 2); |
| 418 | 0 | String conversionFrom = conversionPair[0]; |
| 419 | 0 | String conversionTo = conversionPair[1]; |
| 420 | 0 | newInquiryParameters += (conversionTo + KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR + conversionFrom); |
| 421 | |
|
| 422 | 0 | if (l < conversions.length - 1) { |
| 423 | 0 | newInquiryParameters += KRADConstants.FIELD_CONVERSIONS_SEPARATOR; |
| 424 | |
} |
| 425 | |
} |
| 426 | |
|
| 427 | 0 | field.setInquiryParameters(newInquiryParameters); |
| 428 | |
} |
| 429 | |
} |
| 430 | 0 | field.setFieldDirectInquiryEnabled(directInquiriesEnabled); |
| 431 | 0 | } |
| 432 | |
else { |
| 433 | 0 | field.setFieldDirectInquiryEnabled(false); |
| 434 | |
} |
| 435 | 0 | } |
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
public static Field setFieldDirectInquiry(BusinessObject businessObject, String attributeName, Field field) |
| 443 | |
{ |
| 444 | 0 | if (businessObject == null) |
| 445 | |
{ |
| 446 | 0 | return field; |
| 447 | |
} |
| 448 | |
|
| 449 | 0 | Boolean noDirectInquiry = getBusinessObjectDictionaryService().noDirectInquiryFieldLookup(businessObject.getClass(), attributeName); |
| 450 | |
|
| 451 | 0 | if (noDirectInquiry != null && noDirectInquiry.booleanValue() || noDirectInquiry == null) { |
| 452 | 0 | return field; |
| 453 | |
} |
| 454 | |
|
| 455 | 0 | setFieldDirectInquiry(field); |
| 456 | |
|
| 457 | 0 | return field; |
| 458 | |
} |
| 459 | |
|
| 460 | 0 | private static Map<Class,Map<String,Map>> referencesForForeignKey = new HashMap<Class, Map<String,Map>>(); |
| 461 | |
|
| 462 | |
@Deprecated |
| 463 | |
public static Map getPrimitiveReference(BusinessObject businessObject, String attributeName) { |
| 464 | 0 | Map chosenReferenceByKeySize = new HashMap(); |
| 465 | 0 | Map chosenReferenceByFieldName = new HashMap(); |
| 466 | |
|
| 467 | 0 | Map referenceClasses = null; |
| 468 | |
|
| 469 | |
try { |
| 470 | |
|
| 471 | 0 | Map<String,Map> propMap = referencesForForeignKey.get(businessObject.getClass()); |
| 472 | 0 | if ( propMap == null ) { |
| 473 | 0 | propMap = new HashMap<String, Map>(); |
| 474 | 0 | referencesForForeignKey.put(businessObject.getClass(), propMap); |
| 475 | |
} |
| 476 | 0 | if ( propMap.containsKey(attributeName) ) { |
| 477 | 0 | referenceClasses = propMap.get( attributeName ); |
| 478 | |
} else { |
| 479 | |
|
| 480 | 0 | referenceClasses = getBusinessObjectMetaDataService().getReferencesForForeignKey(businessObject, attributeName); |
| 481 | 0 | if(referenceClasses==null || referenceClasses.isEmpty()) { |
| 482 | 0 | if ( getPersistenceStructureService().isPersistable(businessObject.getClass()) ) { |
| 483 | 0 | referenceClasses = getPersistenceStructureService().getReferencesForForeignKey(businessObject.getClass(), attributeName); |
| 484 | |
} |
| 485 | |
} |
| 486 | 0 | propMap.put(attributeName, referenceClasses); |
| 487 | |
} |
| 488 | 0 | } catch ( ClassNotPersistableException ex ) { |
| 489 | |
|
| 490 | 0 | Map<String,Map> propMap = referencesForForeignKey.get(businessObject.getClass()); |
| 491 | 0 | propMap.put(attributeName, null); |
| 492 | 0 | } |
| 493 | |
|
| 494 | |
|
| 495 | 0 | if (referenceClasses == null || referenceClasses.isEmpty()) { |
| 496 | 0 | return chosenReferenceByKeySize; |
| 497 | |
} |
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | 0 | int minKeys = Integer.MAX_VALUE; |
| 504 | 0 | for (Iterator iter = referenceClasses.keySet().iterator(); iter.hasNext();) { |
| 505 | 0 | String attr = (String) iter.next(); |
| 506 | 0 | Class clazz = (Class) referenceClasses.get(attr); |
| 507 | 0 | List pkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(clazz); |
| 508 | |
|
| 509 | |
|
| 510 | 0 | if (pkNames.size() < minKeys) { |
| 511 | 0 | minKeys = pkNames.size(); |
| 512 | 0 | chosenReferenceByKeySize.clear(); |
| 513 | 0 | chosenReferenceByKeySize.put(attr, clazz); |
| 514 | |
} |
| 515 | |
|
| 516 | |
|
| 517 | 0 | if (attributeName.startsWith(attr)) { |
| 518 | 0 | chosenReferenceByFieldName.clear(); |
| 519 | 0 | chosenReferenceByFieldName.put(attr, clazz); |
| 520 | |
} |
| 521 | 0 | } |
| 522 | |
|
| 523 | |
|
| 524 | 0 | return chosenReferenceByFieldName.isEmpty() ? chosenReferenceByKeySize : chosenReferenceByFieldName; |
| 525 | |
} |
| 526 | |
|
| 527 | |
|
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
public static BusinessObject getNestedBusinessObject(BusinessObject bo, String attributeName) { |
| 536 | 0 | String[] nestedAttributes = StringUtils.split(attributeName, "."); |
| 537 | |
|
| 538 | 0 | BusinessObject childBO = null; |
| 539 | 0 | String attributeRefName = ""; |
| 540 | 0 | Class clazz = null; |
| 541 | 0 | if (nestedAttributes.length > 1) { |
| 542 | 0 | String attributeStringSoFar = ""; |
| 543 | 0 | for (int i = 0; i < nestedAttributes.length - 1; i++) { |
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | 0 | if (i != 0) { |
| 548 | 0 | attributeStringSoFar = attributeStringSoFar + "."; |
| 549 | |
} |
| 550 | 0 | attributeStringSoFar = attributeStringSoFar + nestedAttributes[i]; |
| 551 | |
|
| 552 | 0 | clazz = ObjectUtils.getPropertyType( bo, attributeStringSoFar, getPersistenceStructureService() ); |
| 553 | |
|
| 554 | 0 | if (clazz != null && BusinessObject.class.isAssignableFrom(clazz)) { |
| 555 | |
try { |
| 556 | 0 | childBO = (BusinessObject) ObjectUtils.createNewObjectFromClass(clazz); |
| 557 | |
} |
| 558 | 0 | catch (Exception e) { |
| 559 | 0 | return null; |
| 560 | 0 | } |
| 561 | |
} |
| 562 | |
} |
| 563 | |
} |
| 564 | 0 | return childBO; |
| 565 | |
} |
| 566 | |
|
| 567 | |
public static Class getNestedReferenceClass(BusinessObject businessObject, String attributeName) { |
| 568 | 0 | BusinessObject bo = getNestedBusinessObject(businessObject, attributeName); |
| 569 | 0 | return null == bo ? null : bo.getClass(); |
| 570 | |
} |
| 571 | |
|
| 572 | |
@Deprecated |
| 573 | |
private static String generateFieldConversions(BusinessObject businessObject, String collectionName, BusinessObjectRelationship relationship, String propertyPrefix, List displayedFieldNames, String nestedObjectPrefix) { |
| 574 | 0 | String fieldConversions = ""; |
| 575 | |
|
| 576 | 0 | if ( LOG.isDebugEnabled() ) { |
| 577 | 0 | LOG.debug( "generateFieldConversions(" + businessObject.getClass().getName() + "," + collectionName + ",\n" + relationship + "\n," + propertyPrefix + "," + displayedFieldNames + "," + nestedObjectPrefix + ")" ); |
| 578 | |
} |
| 579 | |
|
| 580 | |
|
| 581 | 0 | for ( Map.Entry<String,String> entry : relationship.getParentToChildReferences().entrySet() ) { |
| 582 | 0 | String fromField = entry.getValue(); |
| 583 | 0 | String toField = entry.getKey(); |
| 584 | |
|
| 585 | |
|
| 586 | 0 | if (!displayedFieldNames.contains(toField)) { |
| 587 | 0 | toField = translateToDisplayedField(businessObject.getClass(), toField, displayedFieldNames); |
| 588 | |
} |
| 589 | |
|
| 590 | 0 | if (StringUtils.isNotBlank(fieldConversions)) { |
| 591 | 0 | fieldConversions += ","; |
| 592 | |
} |
| 593 | |
|
| 594 | 0 | if ( StringUtils.isNotEmpty( propertyPrefix ) ) { |
| 595 | 0 | toField = propertyPrefix + "." + toField; |
| 596 | |
} |
| 597 | |
|
| 598 | 0 | if ( StringUtils.isNotEmpty( collectionName ) ) { |
| 599 | 0 | toField = collectionName + toField; |
| 600 | |
} |
| 601 | |
|
| 602 | 0 | fieldConversions += fromField + ":" + toField; |
| 603 | 0 | } |
| 604 | |
|
| 605 | 0 | return fieldConversions; |
| 606 | |
} |
| 607 | |
|
| 608 | |
@Deprecated |
| 609 | |
private static String generateLookupParameters(BusinessObject businessObject, String collectionName, BusinessObjectRelationship relationship, String propertyPrefix, List displayedFieldNames, String nestedObjectPrefix) { |
| 610 | |
|
| 611 | 0 | String lookupParameters = ""; |
| 612 | |
|
| 613 | 0 | List displayedQFFieldNames = getBusinessObjectDictionaryService().getLookupFieldNames(relationship.getRelatedClass()); |
| 614 | 0 | for ( Map.Entry<String,String> entry : relationship.getParentToChildReferences().entrySet() ) { |
| 615 | 0 | String fromField = entry.getKey(); |
| 616 | 0 | String toField = entry.getValue(); |
| 617 | |
|
| 618 | 0 | if ( relationship.getUserVisibleIdentifierKey() == null || relationship.getUserVisibleIdentifierKey().equals( fromField ) ) { |
| 619 | |
|
| 620 | 0 | if (!displayedFieldNames.contains(fromField)) { |
| 621 | 0 | fromField = translateToDisplayedField(businessObject.getClass(), fromField, displayedFieldNames); |
| 622 | |
} |
| 623 | |
|
| 624 | |
|
| 625 | 0 | if (displayedQFFieldNames != null && !displayedQFFieldNames.contains(toField)) { |
| 626 | 0 | toField = translateToDisplayedField(relationship.getRelatedClass(), toField, displayedQFFieldNames); |
| 627 | |
} |
| 628 | |
|
| 629 | 0 | if (StringUtils.isNotBlank(lookupParameters)) { |
| 630 | 0 | lookupParameters += ","; |
| 631 | |
} |
| 632 | |
|
| 633 | 0 | if (propertyPrefix != null && !propertyPrefix.equals("")) { |
| 634 | 0 | fromField = propertyPrefix + "." + fromField; |
| 635 | |
} |
| 636 | |
|
| 637 | 0 | if ( StringUtils.isNotEmpty( collectionName ) ) { |
| 638 | 0 | fromField = collectionName + fromField; |
| 639 | |
} |
| 640 | |
|
| 641 | 0 | lookupParameters += fromField + ":" + toField; |
| 642 | |
} |
| 643 | 0 | } |
| 644 | |
|
| 645 | 0 | return lookupParameters; |
| 646 | |
} |
| 647 | |
|
| 648 | |
@Deprecated |
| 649 | |
private static String translateToDisplayedField(Class businessObjectClass, String fieldName, List displayedFieldNames) { |
| 650 | 0 | if ( getPersistenceStructureService().isPersistable(businessObjectClass) ) { |
| 651 | 0 | Map nestedFkMap = getPersistenceStructureService().getNestedForeignKeyMap(businessObjectClass); |
| 652 | |
|
| 653 | |
|
| 654 | |
|
| 655 | |
|
| 656 | |
|
| 657 | |
|
| 658 | |
|
| 659 | 0 | if (!displayedFieldNames.contains(fieldName)) { |
| 660 | 0 | for (Iterator iterator = displayedFieldNames.iterator(); iterator.hasNext();) { |
| 661 | 0 | String dispField = (String) iterator.next(); |
| 662 | |
|
| 663 | 0 | if (nestedFkMap.containsKey(dispField) && nestedFkMap.get(dispField).equals(fieldName)) { |
| 664 | 0 | fieldName = dispField; |
| 665 | |
} |
| 666 | 0 | } |
| 667 | |
} |
| 668 | |
} |
| 669 | |
|
| 670 | 0 | return fieldName; |
| 671 | |
} |
| 672 | |
|
| 673 | |
public static String convertReferencesToSelectCollectionToString(Collection<String> referencesToRefresh) { |
| 674 | 0 | StringBuilder buf = new StringBuilder(); |
| 675 | 0 | for (String reference : referencesToRefresh) { |
| 676 | 0 | buf.append(reference).append(KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR); |
| 677 | |
} |
| 678 | 0 | if (!referencesToRefresh.isEmpty()) { |
| 679 | |
|
| 680 | 0 | buf.delete(buf.length() - KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR.length(), buf.length()); |
| 681 | |
} |
| 682 | 0 | return buf.toString(); |
| 683 | |
} |
| 684 | |
|
| 685 | |
public static String convertSetOfObjectIdsToString(Set<String> objectIds) { |
| 686 | 0 | if (objectIds.isEmpty()) { |
| 687 | 0 | return ""; |
| 688 | |
} |
| 689 | 0 | StringBuilder buf = new StringBuilder(); |
| 690 | 0 | for (String objectId : objectIds) { |
| 691 | 0 | if (objectId.contains(KRADConstants.MULTIPLE_VALUE_LOOKUP_OBJ_IDS_SEPARATOR)) { |
| 692 | 0 | throw new RuntimeException("object ID " + objectId + " contains the selected obj ID separator"); |
| 693 | |
} |
| 694 | 0 | buf.append(objectId).append(KRADConstants.MULTIPLE_VALUE_LOOKUP_OBJ_IDS_SEPARATOR); |
| 695 | |
} |
| 696 | |
|
| 697 | 0 | buf.delete(buf.length() - KRADConstants.MULTIPLE_VALUE_LOOKUP_OBJ_IDS_SEPARATOR.length(), buf.length()); |
| 698 | |
|
| 699 | 0 | return buf.toString(); |
| 700 | |
} |
| 701 | |
|
| 702 | |
public static Set<String> convertStringOfObjectIdsToSet(String objectIdsString) { |
| 703 | 0 | Set<String> set = new HashSet<String>(); |
| 704 | |
|
| 705 | 0 | if (StringUtils.isNotBlank(objectIdsString)) { |
| 706 | 0 | String[] objectIds = StringUtils.splitByWholeSeparator(objectIdsString, KRADConstants.MULTIPLE_VALUE_LOOKUP_OBJ_IDS_SEPARATOR); |
| 707 | 0 | for (String objectId : objectIds) { |
| 708 | 0 | set.add(objectId); |
| 709 | |
} |
| 710 | |
} |
| 711 | 0 | return set; |
| 712 | |
} |
| 713 | |
|
| 714 | |
|
| 715 | |
|
| 716 | |
|
| 717 | |
|
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
public static Comparator findBestValueComparatorForColumn(List<ResultRow> resultTable, int column) { |
| 725 | |
|
| 726 | 0 | Comparator comp = NullValueComparator.getInstance(); |
| 727 | 0 | for (ResultRow row : resultTable) { |
| 728 | 0 | Comparator tempComp = row.getColumns().get(column).getValueComparator(); |
| 729 | 0 | if (tempComp != null && !NullValueComparator.class.equals(tempComp.getClass())) { |
| 730 | 0 | return tempComp; |
| 731 | |
} |
| 732 | 0 | } |
| 733 | 0 | return comp; |
| 734 | |
} |
| 735 | |
|
| 736 | |
|
| 737 | |
|
| 738 | |
|
| 739 | |
|
| 740 | |
|
| 741 | |
|
| 742 | |
|
| 743 | |
|
| 744 | |
|
| 745 | |
|
| 746 | |
|
| 747 | |
public static Map<String, String> generateCompositeSelectedObjectIds(Set<String> previouslySelectedObjectIds, Set<String> displayedObjectIds, Set<String> selectedObjectIds) { |
| 748 | 0 | Map<String, String> tempMap = new HashMap<String, String>(); |
| 749 | |
|
| 750 | |
|
| 751 | |
|
| 752 | |
|
| 753 | |
|
| 754 | |
|
| 755 | 0 | for (String previouslySelectedObjectId : previouslySelectedObjectIds) { |
| 756 | 0 | tempMap.put(previouslySelectedObjectId, previouslySelectedObjectId); |
| 757 | |
} |
| 758 | |
|
| 759 | 0 | for (String displayedObjectId : displayedObjectIds) { |
| 760 | 0 | tempMap.remove(displayedObjectId); |
| 761 | |
} |
| 762 | |
|
| 763 | 0 | for (String selectedObjectId : selectedObjectIds) { |
| 764 | 0 | tempMap.put(selectedObjectId, selectedObjectId); |
| 765 | |
} |
| 766 | 0 | return tempMap; |
| 767 | |
} |
| 768 | |
|
| 769 | |
public static DataDictionaryService getDataDictionaryService() { |
| 770 | 0 | return KRADServiceLocatorWeb.getDataDictionaryService(); |
| 771 | |
} |
| 772 | |
|
| 773 | |
public static PersistenceStructureService getPersistenceStructureService() { |
| 774 | 0 | return KRADServiceLocator.getPersistenceStructureService(); |
| 775 | |
} |
| 776 | |
|
| 777 | |
public static BusinessObjectDictionaryService getBusinessObjectDictionaryService() { |
| 778 | 0 | return KRADServiceLocatorWeb.getBusinessObjectDictionaryService(); |
| 779 | |
} |
| 780 | |
|
| 781 | |
public static BusinessObjectMetaDataService getBusinessObjectMetaDataService() { |
| 782 | 0 | return KNSServiceLocator.getBusinessObjectMetaDataService(); |
| 783 | |
} |
| 784 | |
|
| 785 | |
public static DateTimeService getDateTimeService() { |
| 786 | 0 | return CoreApiServiceLocator.getDateTimeService(); |
| 787 | |
} |
| 788 | |
} |