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