| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.uif.widget; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.krad.bo.DataObjectRelationship; |
| 20 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
| 21 | |
import org.kuali.rice.krad.uif.UifParameters; |
| 22 | |
import org.kuali.rice.krad.uif.container.CollectionGroup; |
| 23 | |
import org.kuali.rice.krad.uif.field.InputField; |
| 24 | |
import org.kuali.rice.krad.uif.view.View; |
| 25 | |
import org.kuali.rice.krad.uif.component.BindingInfo; |
| 26 | |
import org.kuali.rice.krad.uif.component.Component; |
| 27 | |
import org.kuali.rice.krad.uif.field.ActionField; |
| 28 | |
import org.kuali.rice.krad.uif.util.ViewModelUtils; |
| 29 | |
import org.kuali.rice.krad.util.KRADUtils; |
| 30 | |
|
| 31 | |
import java.util.HashMap; |
| 32 | |
import java.util.List; |
| 33 | |
import java.util.Map; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public class QuickFinder extends WidgetBase { |
| 41 | |
private static final long serialVersionUID = 3302390972815386785L; |
| 42 | |
|
| 43 | |
|
| 44 | |
private String baseLookupUrl; |
| 45 | |
private String dataObjectClassName; |
| 46 | |
private String viewName; |
| 47 | |
|
| 48 | |
private String referencesToRefresh; |
| 49 | |
|
| 50 | |
private Map<String, String> fieldConversions; |
| 51 | |
private Map<String, String> lookupParameters; |
| 52 | |
|
| 53 | |
|
| 54 | |
private String readOnlySearchFields; |
| 55 | |
|
| 56 | |
private Boolean hideReturnLink; |
| 57 | |
private Boolean suppressActions; |
| 58 | |
private Boolean autoSearch; |
| 59 | |
private Boolean lookupCriteriaEnabled; |
| 60 | |
private Boolean supplementalActionsEnabled; |
| 61 | |
private Boolean disableSearchButtons; |
| 62 | |
private Boolean headerBarEnabled; |
| 63 | |
private Boolean showMaintenanceLinks; |
| 64 | |
|
| 65 | |
private Boolean multipleValuesSelect; |
| 66 | |
private String lookupCollectionName; |
| 67 | |
|
| 68 | |
private ActionField quickfinderActionField; |
| 69 | |
|
| 70 | |
public QuickFinder() { |
| 71 | 0 | super(); |
| 72 | |
|
| 73 | 0 | fieldConversions = new HashMap<String, String>(); |
| 74 | 0 | lookupParameters = new HashMap<String, String>(); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
@Override |
| 98 | |
public void performFinalize(View view, Object model, Component parent) { |
| 99 | 0 | super.performFinalize(view, model, parent); |
| 100 | |
|
| 101 | 0 | if (!isRender()) { |
| 102 | 0 | return; |
| 103 | |
} |
| 104 | |
|
| 105 | 0 | if (parent instanceof InputField) { |
| 106 | 0 | InputField field = (InputField) parent; |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | 0 | if (StringUtils.isBlank(dataObjectClassName)) { |
| 111 | 0 | DataObjectRelationship relationship = getRelationshipForField(view, model, field); |
| 112 | |
|
| 113 | |
|
| 114 | 0 | if (relationship == null) { |
| 115 | 0 | setRender(false); |
| 116 | 0 | return; |
| 117 | |
} |
| 118 | |
|
| 119 | 0 | dataObjectClassName = relationship.getRelatedClass().getName(); |
| 120 | |
|
| 121 | 0 | if ((fieldConversions == null) || fieldConversions.isEmpty()) { |
| 122 | 0 | generateFieldConversions(field, relationship); |
| 123 | |
} |
| 124 | |
|
| 125 | 0 | if ((lookupParameters == null) || lookupParameters.isEmpty()) { |
| 126 | 0 | generateLookupParameters(field, relationship); |
| 127 | |
} |
| 128 | |
} |
| 129 | |
|
| 130 | |
|
| 131 | 0 | updateFieldConversions(field.getBindingInfo()); |
| 132 | 0 | updateLookupParameters(field.getBindingInfo()); |
| 133 | 0 | } else if (parent instanceof CollectionGroup) { |
| 134 | 0 | CollectionGroup collectionGroup = (CollectionGroup) parent; |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | 0 | if (StringUtils.isBlank(getDataObjectClassName())) { |
| 139 | 0 | Class<?> collectionObjectClass = collectionGroup.getCollectionObjectClass(); |
| 140 | 0 | boolean isCollectionClassLookupable = KRADServiceLocatorWeb.getViewDictionaryService().isLookupable( |
| 141 | |
collectionObjectClass); |
| 142 | 0 | if (isCollectionClassLookupable) { |
| 143 | 0 | setDataObjectClassName(collectionObjectClass.getName()); |
| 144 | |
|
| 145 | 0 | if ((fieldConversions == null) || fieldConversions.isEmpty()) { |
| 146 | |
|
| 147 | 0 | List<String> collectionObjectPKFields = |
| 148 | |
KRADServiceLocatorWeb.getDataObjectMetaDataService().listPrimaryKeyFieldNames( |
| 149 | |
collectionObjectClass); |
| 150 | |
|
| 151 | 0 | for (String pkField : collectionObjectPKFields) { |
| 152 | 0 | fieldConversions.put(pkField, pkField); |
| 153 | |
} |
| 154 | 0 | } |
| 155 | |
} else { |
| 156 | |
|
| 157 | 0 | setRender(false); |
| 158 | |
} |
| 159 | |
} |
| 160 | |
|
| 161 | |
|
| 162 | 0 | if (isRender() && StringUtils.isBlank(getLookupCollectionName())) { |
| 163 | 0 | setLookupCollectionName(collectionGroup.getBindingInfo().getBindingPath()); |
| 164 | |
} |
| 165 | |
} |
| 166 | |
|
| 167 | 0 | quickfinderActionField.addActionParameter(UifParameters.BASE_LOOKUP_URL, baseLookupUrl); |
| 168 | 0 | quickfinderActionField.addActionParameter(UifParameters.DATA_OBJECT_CLASS_NAME, dataObjectClassName); |
| 169 | |
|
| 170 | 0 | if (!fieldConversions.isEmpty()) { |
| 171 | 0 | quickfinderActionField.addActionParameter(UifParameters.CONVERSION_FIELDS, |
| 172 | |
KRADUtils.buildMapParameterString(fieldConversions)); |
| 173 | |
} |
| 174 | |
|
| 175 | 0 | if (!lookupParameters.isEmpty()) { |
| 176 | 0 | quickfinderActionField.addActionParameter(UifParameters.LOOKUP_PARAMETERS, |
| 177 | |
KRADUtils.buildMapParameterString(lookupParameters)); |
| 178 | |
} |
| 179 | |
|
| 180 | 0 | addActionParameterIfNotNull(UifParameters.VIEW_NAME, viewName); |
| 181 | 0 | addActionParameterIfNotNull(UifParameters.READ_ONLY_FIELDS, readOnlySearchFields); |
| 182 | 0 | addActionParameterIfNotNull(UifParameters.HIDE_RETURN_LINK, hideReturnLink); |
| 183 | 0 | addActionParameterIfNotNull(UifParameters.SUPRESS_ACTIONS, suppressActions); |
| 184 | 0 | addActionParameterIfNotNull(UifParameters.REFERENCES_TO_REFRESH, referencesToRefresh); |
| 185 | 0 | addActionParameterIfNotNull(UifParameters.AUTO_SEARCH, autoSearch); |
| 186 | 0 | addActionParameterIfNotNull(UifParameters.LOOKUP_CRITERIA_ENABLED, lookupCriteriaEnabled); |
| 187 | 0 | addActionParameterIfNotNull(UifParameters.SUPPLEMENTAL_ACTIONS_ENABLED, supplementalActionsEnabled); |
| 188 | 0 | addActionParameterIfNotNull(UifParameters.DISABLE_SEARCH_BUTTONS, disableSearchButtons); |
| 189 | 0 | addActionParameterIfNotNull(UifParameters.HEADER_BAR_ENABLED, headerBarEnabled); |
| 190 | 0 | addActionParameterIfNotNull(UifParameters.SHOW_MAINTENANCE_LINKS, showMaintenanceLinks); |
| 191 | 0 | addActionParameterIfNotNull(UifParameters.MULTIPLE_VALUES_SELECT, multipleValuesSelect); |
| 192 | 0 | addActionParameterIfNotNull(UifParameters.LOOKUP_COLLECTION_NAME, lookupCollectionName); |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | 0 | } |
| 198 | |
|
| 199 | |
protected void addActionParameterIfNotNull(String parameterName, Object parameterValue) { |
| 200 | 0 | if ((parameterValue != null) && StringUtils.isNotBlank(parameterValue.toString())) { |
| 201 | 0 | quickfinderActionField.addActionParameter(parameterName, parameterValue.toString()); |
| 202 | |
} |
| 203 | 0 | } |
| 204 | |
|
| 205 | |
protected DataObjectRelationship getRelationshipForField(View view, Object model, InputField field) { |
| 206 | 0 | String propertyName = field.getBindingInfo().getBindingName(); |
| 207 | |
|
| 208 | |
|
| 209 | 0 | Object parentObject = ViewModelUtils.getParentObjectForMetadata(view, model, field); |
| 210 | 0 | Class<?> parentObjectClass = null; |
| 211 | 0 | if (parentObject != null) { |
| 212 | 0 | parentObjectClass = parentObject.getClass(); |
| 213 | |
} |
| 214 | |
|
| 215 | |
|
| 216 | 0 | return KRADServiceLocatorWeb.getDataObjectMetaDataService().getDataObjectRelationship(parentObject, |
| 217 | |
parentObjectClass, propertyName, "", true, true, false); |
| 218 | |
} |
| 219 | |
|
| 220 | |
protected void generateFieldConversions(InputField field, DataObjectRelationship relationship) { |
| 221 | 0 | fieldConversions = new HashMap<String, String>(); |
| 222 | 0 | for (Map.Entry<String, String> entry : relationship.getParentToChildReferences().entrySet()) { |
| 223 | 0 | String fromField = entry.getValue(); |
| 224 | 0 | String toField = entry.getKey(); |
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | 0 | fieldConversions.put(fromField, toField); |
| 231 | 0 | } |
| 232 | 0 | } |
| 233 | |
|
| 234 | |
protected void generateLookupParameters(InputField field, DataObjectRelationship relationship) { |
| 235 | 0 | lookupParameters = new HashMap<String, String>(); |
| 236 | 0 | for (Map.Entry<String, String> entry : relationship.getParentToChildReferences().entrySet()) { |
| 237 | 0 | String fromField = entry.getKey(); |
| 238 | 0 | String toField = entry.getValue(); |
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | 0 | if (relationship.getUserVisibleIdentifierKey() == null || relationship.getUserVisibleIdentifierKey().equals( |
| 245 | |
fromField)) { |
| 246 | 0 | lookupParameters.put(fromField, toField); |
| 247 | |
} |
| 248 | 0 | } |
| 249 | 0 | } |
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
public void updateFieldConversions(BindingInfo bindingInfo) { |
| 258 | 0 | Map<String, String> adjustedFieldConversions = new HashMap<String, String>(); |
| 259 | 0 | for (String fromField : fieldConversions.keySet()) { |
| 260 | 0 | String toField = fieldConversions.get(fromField); |
| 261 | 0 | String adjustedToFieldPath = bindingInfo.getPropertyAdjustedBindingPath(toField); |
| 262 | |
|
| 263 | 0 | adjustedFieldConversions.put(fromField, adjustedToFieldPath); |
| 264 | 0 | } |
| 265 | |
|
| 266 | 0 | this.fieldConversions = adjustedFieldConversions; |
| 267 | 0 | } |
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
public void updateLookupParameters(BindingInfo bindingInfo) { |
| 276 | 0 | Map<String, String> adjustedLookupParameters = new HashMap<String, String>(); |
| 277 | 0 | for (String fromField : lookupParameters.keySet()) { |
| 278 | 0 | String toField = lookupParameters.get(fromField); |
| 279 | 0 | String adjustedFromFieldPath = bindingInfo.getPropertyAdjustedBindingPath(fromField); |
| 280 | |
|
| 281 | 0 | adjustedLookupParameters.put(adjustedFromFieldPath, toField); |
| 282 | 0 | } |
| 283 | |
|
| 284 | 0 | this.lookupParameters = adjustedLookupParameters; |
| 285 | 0 | } |
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
@Override |
| 291 | |
public List<Component> getComponentsForLifecycle() { |
| 292 | 0 | List<Component> components = super.getComponentsForLifecycle(); |
| 293 | |
|
| 294 | 0 | components.add(quickfinderActionField); |
| 295 | |
|
| 296 | 0 | return components; |
| 297 | |
} |
| 298 | |
|
| 299 | |
public String getBaseLookupUrl() { |
| 300 | 0 | return this.baseLookupUrl; |
| 301 | |
} |
| 302 | |
|
| 303 | |
public void setBaseLookupUrl(String baseLookupUrl) { |
| 304 | 0 | this.baseLookupUrl = baseLookupUrl; |
| 305 | 0 | } |
| 306 | |
|
| 307 | |
public String getDataObjectClassName() { |
| 308 | 0 | return this.dataObjectClassName; |
| 309 | |
} |
| 310 | |
|
| 311 | |
public void setDataObjectClassName(String dataObjectClassName) { |
| 312 | 0 | this.dataObjectClassName = dataObjectClassName; |
| 313 | 0 | } |
| 314 | |
|
| 315 | |
public String getViewName() { |
| 316 | 0 | return this.viewName; |
| 317 | |
} |
| 318 | |
|
| 319 | |
public void setViewName(String viewName) { |
| 320 | 0 | this.viewName = viewName; |
| 321 | 0 | } |
| 322 | |
|
| 323 | |
public String getReferencesToRefresh() { |
| 324 | 0 | return this.referencesToRefresh; |
| 325 | |
} |
| 326 | |
|
| 327 | |
public void setReferencesToRefresh(String referencesToRefresh) { |
| 328 | 0 | this.referencesToRefresh = referencesToRefresh; |
| 329 | 0 | } |
| 330 | |
|
| 331 | |
public Map<String, String> getFieldConversions() { |
| 332 | 0 | return this.fieldConversions; |
| 333 | |
} |
| 334 | |
|
| 335 | |
public void setFieldConversions(Map<String, String> fieldConversions) { |
| 336 | 0 | this.fieldConversions = fieldConversions; |
| 337 | 0 | } |
| 338 | |
|
| 339 | |
public Map<String, String> getLookupParameters() { |
| 340 | 0 | return this.lookupParameters; |
| 341 | |
} |
| 342 | |
|
| 343 | |
public void setLookupParameters(Map<String, String> lookupParameters) { |
| 344 | 0 | this.lookupParameters = lookupParameters; |
| 345 | 0 | } |
| 346 | |
|
| 347 | |
public String getReadOnlySearchFields() { |
| 348 | 0 | return this.readOnlySearchFields; |
| 349 | |
} |
| 350 | |
|
| 351 | |
public void setReadOnlySearchFields(String readOnlySearchFields) { |
| 352 | 0 | this.readOnlySearchFields = readOnlySearchFields; |
| 353 | 0 | } |
| 354 | |
|
| 355 | |
public Boolean getHideReturnLink() { |
| 356 | 0 | return this.hideReturnLink; |
| 357 | |
} |
| 358 | |
|
| 359 | |
public void setHideReturnLink(Boolean hideReturnLink) { |
| 360 | 0 | this.hideReturnLink = hideReturnLink; |
| 361 | 0 | } |
| 362 | |
|
| 363 | |
public Boolean getSuppressActions() { |
| 364 | 0 | return suppressActions; |
| 365 | |
} |
| 366 | |
|
| 367 | |
public void setSuppressActions(Boolean suppressActions) { |
| 368 | 0 | this.suppressActions = suppressActions; |
| 369 | 0 | } |
| 370 | |
|
| 371 | |
public Boolean getAutoSearch() { |
| 372 | 0 | return this.autoSearch; |
| 373 | |
} |
| 374 | |
|
| 375 | |
public void setAutoSearch(Boolean autoSearch) { |
| 376 | 0 | this.autoSearch = autoSearch; |
| 377 | 0 | } |
| 378 | |
|
| 379 | |
public Boolean getLookupCriteriaEnabled() { |
| 380 | 0 | return this.lookupCriteriaEnabled; |
| 381 | |
} |
| 382 | |
|
| 383 | |
public void setLookupCriteriaEnabled(Boolean lookupCriteriaEnabled) { |
| 384 | 0 | this.lookupCriteriaEnabled = lookupCriteriaEnabled; |
| 385 | 0 | } |
| 386 | |
|
| 387 | |
public Boolean getSupplementalActionsEnabled() { |
| 388 | 0 | return this.supplementalActionsEnabled; |
| 389 | |
} |
| 390 | |
|
| 391 | |
public void setSupplementalActionsEnabled(Boolean supplementalActionsEnabled) { |
| 392 | 0 | this.supplementalActionsEnabled = supplementalActionsEnabled; |
| 393 | 0 | } |
| 394 | |
|
| 395 | |
public Boolean getDisableSearchButtons() { |
| 396 | 0 | return this.disableSearchButtons; |
| 397 | |
} |
| 398 | |
|
| 399 | |
public void setDisableSearchButtons(Boolean disableSearchButtons) { |
| 400 | 0 | this.disableSearchButtons = disableSearchButtons; |
| 401 | 0 | } |
| 402 | |
|
| 403 | |
public Boolean getHeaderBarEnabled() { |
| 404 | 0 | return this.headerBarEnabled; |
| 405 | |
} |
| 406 | |
|
| 407 | |
public void setHeaderBarEnabled(Boolean headerBarEnabled) { |
| 408 | 0 | this.headerBarEnabled = headerBarEnabled; |
| 409 | 0 | } |
| 410 | |
|
| 411 | |
public Boolean getShowMaintenanceLinks() { |
| 412 | 0 | return this.showMaintenanceLinks; |
| 413 | |
} |
| 414 | |
|
| 415 | |
public void setShowMaintenanceLinks(Boolean showMaintenanceLinks) { |
| 416 | 0 | this.showMaintenanceLinks = showMaintenanceLinks; |
| 417 | 0 | } |
| 418 | |
|
| 419 | |
public ActionField getQuickfinderActionField() { |
| 420 | 0 | return this.quickfinderActionField; |
| 421 | |
} |
| 422 | |
|
| 423 | |
public void setQuickfinderActionField(ActionField quickfinderActionField) { |
| 424 | 0 | this.quickfinderActionField = quickfinderActionField; |
| 425 | 0 | } |
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
|
| 432 | |
public Boolean getMultipleValuesSelect() { |
| 433 | 0 | return multipleValuesSelect; |
| 434 | |
} |
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
public void setMultipleValuesSelect(Boolean multipleValuesSelect) { |
| 442 | 0 | this.multipleValuesSelect = multipleValuesSelect; |
| 443 | 0 | } |
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | |
|
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
public String getLookupCollectionName() { |
| 457 | 0 | return lookupCollectionName; |
| 458 | |
} |
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | |
|
| 464 | |
|
| 465 | |
public void setLookupCollectionName(String lookupCollectionName) { |
| 466 | 0 | this.lookupCollectionName = lookupCollectionName; |
| 467 | 0 | } |
| 468 | |
} |