| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.uif.service.impl; |
| 17 | |
|
| 18 | |
import java.lang.reflect.Field; |
| 19 | |
import java.util.Collection; |
| 20 | |
import java.util.HashMap; |
| 21 | |
import java.util.HashSet; |
| 22 | |
import java.util.List; |
| 23 | |
import java.util.Map; |
| 24 | |
import java.util.Map.Entry; |
| 25 | |
import java.util.Properties; |
| 26 | |
import java.util.Set; |
| 27 | |
|
| 28 | |
import org.apache.commons.lang.StringUtils; |
| 29 | |
import org.kuali.rice.kim.bo.Person; |
| 30 | |
import org.kuali.rice.kns.datadictionary.AttributeDefinition; |
| 31 | |
import org.kuali.rice.kns.inquiry.Inquirable; |
| 32 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
| 33 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 34 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 35 | |
import org.kuali.rice.kns.uif.UifConstants; |
| 36 | |
import org.kuali.rice.kns.uif.authorization.Authorizer; |
| 37 | |
import org.kuali.rice.kns.uif.authorization.PresentationController; |
| 38 | |
import org.kuali.rice.kns.uif.container.CollectionGroup; |
| 39 | |
import org.kuali.rice.kns.uif.container.Container; |
| 40 | |
import org.kuali.rice.kns.uif.container.View; |
| 41 | |
import org.kuali.rice.kns.uif.core.Component; |
| 42 | |
import org.kuali.rice.kns.uif.core.PropertyReplacer; |
| 43 | |
import org.kuali.rice.kns.uif.core.RequestParameter; |
| 44 | |
import org.kuali.rice.kns.uif.field.AttributeField; |
| 45 | |
import org.kuali.rice.kns.uif.layout.LayoutManager; |
| 46 | |
import org.kuali.rice.kns.uif.modifier.ComponentModifier; |
| 47 | |
import org.kuali.rice.kns.uif.service.ExpressionEvaluatorService; |
| 48 | |
import org.kuali.rice.kns.uif.service.ViewDictionaryService; |
| 49 | |
import org.kuali.rice.kns.uif.service.ViewHelperService; |
| 50 | |
import org.kuali.rice.kns.uif.util.CloneUtils; |
| 51 | |
import org.kuali.rice.kns.uif.util.ObjectPropertyUtils; |
| 52 | |
import org.kuali.rice.kns.uif.util.ViewModelUtils; |
| 53 | |
import org.kuali.rice.kns.uif.widget.Inquiry; |
| 54 | |
import org.kuali.rice.kns.util.GlobalVariables; |
| 55 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 56 | |
import org.kuali.rice.kns.util.ObjectUtils; |
| 57 | |
import org.kuali.rice.kns.web.spring.form.UifFormBase; |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | 0 | public class ViewHelperServiceImpl implements ViewHelperService { |
| 65 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ViewHelperServiceImpl.class); |
| 66 | |
|
| 67 | |
private transient DataDictionaryService dataDictionaryService; |
| 68 | |
private transient ExpressionEvaluatorService expressionEvaluatorService; |
| 69 | |
private transient ViewDictionaryService viewDictionaryService; |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
@Override |
| 85 | |
public void populateViewFromRequestParameters(View view, Map<String, String> parameters) { |
| 86 | |
|
| 87 | 0 | Set<String> fieldNamesToPopulate = new HashSet<String>(); |
| 88 | |
|
| 89 | 0 | Field[] fields = CloneUtils.getFields(view.getClass(), true); |
| 90 | 0 | for (int i = 0; i < fields.length; i++) { |
| 91 | 0 | Field field = fields[i]; |
| 92 | |
|
| 93 | 0 | RequestParameter requestParameter = field.getAnnotation(RequestParameter.class); |
| 94 | 0 | if (requestParameter != null) { |
| 95 | |
|
| 96 | 0 | if (StringUtils.isNotBlank(requestParameter.parameterName())) { |
| 97 | 0 | fieldNamesToPopulate.add(requestParameter.parameterName()); |
| 98 | |
} |
| 99 | |
else { |
| 100 | 0 | fieldNamesToPopulate.add(field.getName()); |
| 101 | |
} |
| 102 | |
} |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | 0 | Map<String, Set<PropertyReplacer>> viewPropertyReplacers = new HashMap<String, Set<PropertyReplacer>>(); |
| 107 | 0 | for (PropertyReplacer replacer : view.getPropertyReplacers()) { |
| 108 | 0 | Set<PropertyReplacer> propertyReplacers = new HashSet<PropertyReplacer>(); |
| 109 | 0 | if (viewPropertyReplacers.containsKey(replacer.getPropertyName())) { |
| 110 | 0 | propertyReplacers = viewPropertyReplacers.get(replacer.getPropertyName()); |
| 111 | |
} |
| 112 | 0 | propertyReplacers.add(replacer); |
| 113 | |
|
| 114 | 0 | viewPropertyReplacers.put(replacer.getPropertyName(), propertyReplacers); |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
|
| 118 | 0 | Map<String, String> viewRequestParameters = new HashMap<String, String>(); |
| 119 | 0 | for (String fieldToPopulate : fieldNamesToPopulate) { |
| 120 | 0 | if (parameters.containsKey(fieldToPopulate)) { |
| 121 | 0 | String fieldValue = parameters.get(fieldToPopulate); |
| 122 | |
|
| 123 | 0 | if (StringUtils.isNotBlank(fieldValue)) { |
| 124 | 0 | viewRequestParameters.put(fieldToPopulate, fieldValue); |
| 125 | 0 | ObjectPropertyUtils.setPropertyValue(view, fieldToPopulate, fieldValue); |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | 0 | String conditionalProperty = StringUtils.substring(fieldToPopulate, 0, 1).toLowerCase() |
| 130 | |
+ StringUtils.substring(fieldToPopulate, 1, fieldToPopulate.length()); |
| 131 | 0 | conditionalProperty = UifConstants.EL_CONDITIONAL_PROPERTY_PREFIX + conditionalProperty; |
| 132 | 0 | ObjectPropertyUtils.setPropertyValue(view, conditionalProperty, fieldValue, true); |
| 133 | |
|
| 134 | 0 | if (viewPropertyReplacers.containsKey(fieldToPopulate)) { |
| 135 | 0 | Set<PropertyReplacer> propertyReplacers = viewPropertyReplacers.get(fieldToPopulate); |
| 136 | 0 | for (PropertyReplacer replacer : propertyReplacers) { |
| 137 | 0 | view.getPropertyReplacers().remove(replacer); |
| 138 | |
} |
| 139 | |
} |
| 140 | |
} |
| 141 | 0 | } |
| 142 | |
} |
| 143 | |
|
| 144 | 0 | view.setViewRequestParameters(viewRequestParameters); |
| 145 | 0 | } |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
@Override |
| 152 | |
public void performInitialization(View view) { |
| 153 | 0 | performComponentInitialization(view, view); |
| 154 | 0 | } |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
public void performComponentInitialization(View view, Component component) { |
| 181 | 0 | if (component == null) { |
| 182 | 0 | return; |
| 183 | |
} |
| 184 | |
|
| 185 | 0 | LOG.debug("Initializing component: " + component.getId() + " with type: " + component.getClass()); |
| 186 | |
|
| 187 | |
|
| 188 | 0 | component.performInitialization(view); |
| 189 | |
|
| 190 | |
|
| 191 | 0 | if (component instanceof AttributeField) { |
| 192 | 0 | initializeAttributeFieldFromDataDictionary(view, (AttributeField) component); |
| 193 | |
|
| 194 | |
|
| 195 | 0 | view.getViewIndex().addAttributeField((AttributeField) component); |
| 196 | |
} |
| 197 | |
|
| 198 | |
|
| 199 | 0 | if (component instanceof CollectionGroup) { |
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | 0 | view.getViewIndex().addCollection((CollectionGroup) component); |
| 204 | |
} |
| 205 | |
|
| 206 | |
|
| 207 | 0 | runComponentModifiers(view, component, null, UifConstants.ViewPhases.INITIALIZE); |
| 208 | |
|
| 209 | |
|
| 210 | 0 | for (Component nestedComponent : component.getNestedComponents()) { |
| 211 | 0 | performComponentInitialization(view, nestedComponent); |
| 212 | |
} |
| 213 | |
|
| 214 | |
|
| 215 | 0 | for (PropertyReplacer replacer : component.getPropertyReplacers()) { |
| 216 | 0 | if (Component.class.isAssignableFrom(replacer.getReplacement().getClass())) { |
| 217 | 0 | performComponentInitialization(view, (Component) replacer.getReplacement()); |
| 218 | |
} |
| 219 | |
} |
| 220 | |
|
| 221 | |
|
| 222 | 0 | performCustomInitialization(view, component); |
| 223 | 0 | } |
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
protected void initializeAttributeFieldFromDataDictionary(View view, AttributeField field) { |
| 235 | |
|
| 236 | 0 | String dictionaryAttributeName = field.getDictionaryAttributeName(); |
| 237 | 0 | String dictionaryObjectEntry = field.getDictionaryObjectEntry(); |
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | 0 | if (StringUtils.isNotBlank(dictionaryObjectEntry) && StringUtils.isBlank(dictionaryAttributeName)) { |
| 242 | 0 | dictionaryAttributeName = field.getPropertyName(); |
| 243 | |
} |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | 0 | if (StringUtils.isBlank(dictionaryAttributeName) && StringUtils.isBlank(dictionaryObjectEntry) |
| 249 | |
&& !field.getBindingInfo().isBindToForm()) { |
| 250 | 0 | dictionaryAttributeName = field.getPropertyName(); |
| 251 | 0 | Class<?> dictionaryModelClass = getDictionaryModelClass(view, field); |
| 252 | 0 | if (dictionaryModelClass != null) { |
| 253 | 0 | dictionaryObjectEntry = dictionaryModelClass.getName(); |
| 254 | |
} |
| 255 | |
} |
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | 0 | if (StringUtils.isNotBlank(dictionaryAttributeName) && StringUtils.isNotBlank(dictionaryObjectEntry)) { |
| 260 | 0 | AttributeDefinition attributeDefinition = getDataDictionaryService().getAttributeDefinition( |
| 261 | |
dictionaryObjectEntry, dictionaryAttributeName); |
| 262 | 0 | if (attributeDefinition != null) { |
| 263 | 0 | field.copyFromAttributeDefinition(attributeDefinition); |
| 264 | |
} |
| 265 | |
|
| 266 | |
|
| 267 | 0 | field.setDictionaryAttributeName(dictionaryAttributeName); |
| 268 | 0 | field.setDictionaryObjectEntry(dictionaryObjectEntry); |
| 269 | |
} |
| 270 | 0 | } |
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
protected Class<?> getDictionaryModelClass(View view, AttributeField field) { |
| 283 | 0 | return ViewModelUtils.getParentObjectClassForMetadata(view, field); |
| 284 | |
} |
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
@Override |
| 291 | |
public void performApplyModel(View view, Object model) { |
| 292 | |
|
| 293 | |
|
| 294 | 0 | invokeAuthorizerPresentationController(view, (UifFormBase) model); |
| 295 | |
|
| 296 | |
|
| 297 | 0 | setViewContext(view, model); |
| 298 | |
|
| 299 | 0 | performComponentApplyModel(view, view, model); |
| 300 | 0 | } |
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
protected void invokeAuthorizerPresentationController(View view, UifFormBase model) { |
| 314 | 0 | PresentationController presentationController = ObjectUtils.newInstance(view.getPresentationControllerClass()); |
| 315 | 0 | Authorizer authorizer = ObjectUtils.newInstance(view.getAuthorizerClass()); |
| 316 | |
|
| 317 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
| 318 | |
|
| 319 | 0 | Set<String> actionFlags = presentationController.getActionFlags(model); |
| 320 | 0 | actionFlags = authorizer.getActionFlags(model, user, actionFlags); |
| 321 | 0 | view.setActionFlags(actionFlags); |
| 322 | |
|
| 323 | 0 | Set<String> editModes = presentationController.getEditModes(model); |
| 324 | 0 | editModes = authorizer.getEditModes(model, user, editModes); |
| 325 | 0 | view.setEditModes(editModes); |
| 326 | 0 | } |
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
protected void setViewContext(View view, Object model) { |
| 338 | 0 | view.pushObjectToContext(UifConstants.ContextVariableNames.VIEW, view); |
| 339 | |
|
| 340 | 0 | Properties properties = KNSServiceLocator.getKualiConfigurationService().getAllProperties(); |
| 341 | 0 | view.pushObjectToContext(UifConstants.ContextVariableNames.CONFIG_PROPERTIES, properties); |
| 342 | |
|
| 343 | 0 | view.pushObjectToContext(UifConstants.ContextVariableNames.CONSTANTS, KNSConstants.class); |
| 344 | |
|
| 345 | |
|
| 346 | 0 | for (Entry<String, String> variableExpression : view.getExpressionVariables().entrySet()) { |
| 347 | 0 | String variableName = variableExpression.getKey(); |
| 348 | 0 | Object value = getExpressionEvaluatorService().evaluateExpression(model, view.getContext(), |
| 349 | |
variableExpression.getValue()); |
| 350 | 0 | view.pushObjectToContext(variableName, value); |
| 351 | 0 | } |
| 352 | 0 | } |
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
protected void performComponentApplyModel(View view, Component component, Object model) { |
| 373 | 0 | if (component == null) { |
| 374 | 0 | return; |
| 375 | |
} |
| 376 | |
|
| 377 | |
|
| 378 | 0 | component.getContext().putAll(getCommonContext(view, component)); |
| 379 | 0 | getExpressionEvaluatorService().evaluateObjectProperties(component, model, component.getContext()); |
| 380 | |
|
| 381 | 0 | if (component instanceof Container) { |
| 382 | 0 | LayoutManager layoutManager = ((Container) component).getLayoutManager(); |
| 383 | |
|
| 384 | 0 | if (layoutManager != null) { |
| 385 | 0 | layoutManager.getContext().putAll(getCommonContext(view, component)); |
| 386 | 0 | layoutManager.pushObjectToContext(UifConstants.ContextVariableNames.PARENT, component); |
| 387 | 0 | layoutManager.pushObjectToContext(UifConstants.ContextVariableNames.MANAGER, layoutManager); |
| 388 | 0 | getExpressionEvaluatorService().evaluateObjectProperties(layoutManager, model, |
| 389 | |
layoutManager.getContext()); |
| 390 | |
} |
| 391 | |
} |
| 392 | |
|
| 393 | |
|
| 394 | 0 | component.performApplyModel(view, model); |
| 395 | |
|
| 396 | |
|
| 397 | 0 | performCustomApplyModel(view, component, model); |
| 398 | |
|
| 399 | |
|
| 400 | 0 | runComponentModifiers(view, component, model, UifConstants.ViewPhases.APPLY_MODEL); |
| 401 | |
|
| 402 | |
|
| 403 | 0 | for (Component nestedComponent : component.getNestedComponents()) { |
| 404 | 0 | if (nestedComponent != null) { |
| 405 | 0 | nestedComponent.pushObjectToContext(UifConstants.ContextVariableNames.PARENT, component); |
| 406 | |
} |
| 407 | |
|
| 408 | 0 | performComponentApplyModel(view, nestedComponent, model); |
| 409 | |
} |
| 410 | 0 | } |
| 411 | |
|
| 412 | |
|
| 413 | |
|
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
protected void runComponentModifiers(View view, Component component, Object model, String runPhase) { |
| 427 | 0 | for (ComponentModifier modifier : component.getComponentModifiers()) { |
| 428 | |
|
| 429 | 0 | if (StringUtils.equals(modifier.getRunPhase(), runPhase)) { |
| 430 | |
|
| 431 | 0 | boolean runModifier = true; |
| 432 | 0 | if (StringUtils.isNotBlank(modifier.getRunCondition())) { |
| 433 | 0 | Map<String, Object> context = new HashMap<String, Object>(); |
| 434 | 0 | context.put(UifConstants.ContextVariableNames.COMPONENT, component); |
| 435 | 0 | context.put(UifConstants.ContextVariableNames.VIEW, view); |
| 436 | |
|
| 437 | 0 | String conditionEvaluation = getExpressionEvaluatorService().evaluateExpressionTemplate(model, |
| 438 | |
context, modifier.getRunCondition()); |
| 439 | 0 | runModifier = Boolean.parseBoolean(conditionEvaluation); |
| 440 | |
} |
| 441 | |
|
| 442 | 0 | if (runModifier) { |
| 443 | 0 | modifier.performModification(view, component); |
| 444 | |
} |
| 445 | 0 | } |
| 446 | |
} |
| 447 | 0 | } |
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
protected Map<String, Object> getCommonContext(View view, Component component) { |
| 459 | 0 | Map<String, Object> context = new HashMap<String, Object>(); |
| 460 | |
|
| 461 | 0 | context.putAll(view.getContext()); |
| 462 | 0 | context.put(UifConstants.ContextVariableNames.COMPONENT, component); |
| 463 | |
|
| 464 | 0 | return context; |
| 465 | |
} |
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
|
| 470 | |
|
| 471 | |
@Override |
| 472 | |
public void performFinalize(View view, Object model) { |
| 473 | 0 | performComponentFinalize(view, view, model, null); |
| 474 | 0 | } |
| 475 | |
|
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
protected void performComponentFinalize(View view, Component component, Object model, Component parent) { |
| 490 | 0 | if (component == null) { |
| 491 | 0 | return; |
| 492 | |
} |
| 493 | |
|
| 494 | |
|
| 495 | 0 | component.performFinalize(view, model, parent); |
| 496 | |
|
| 497 | |
|
| 498 | 0 | performCustomFinalize(view, component, model, parent); |
| 499 | |
|
| 500 | |
|
| 501 | 0 | runComponentModifiers(view, component, model, UifConstants.ViewPhases.FINALIZE); |
| 502 | |
|
| 503 | |
|
| 504 | 0 | for (Component nestedComponent : component.getNestedComponents()) { |
| 505 | 0 | performComponentFinalize(view, nestedComponent, model, component); |
| 506 | |
} |
| 507 | 0 | } |
| 508 | |
|
| 509 | |
|
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
@Override |
| 514 | |
public void processCollectionAddLine(View view, Object model, String collectionPath) { |
| 515 | |
|
| 516 | 0 | CollectionGroup collectionGroup = view.getViewIndex().getCollectionGroupByPath(collectionPath); |
| 517 | 0 | if (collectionGroup == null) { |
| 518 | 0 | logAndThrowRuntime("Unable to get collection group component for path: " + collectionPath); |
| 519 | |
} |
| 520 | |
|
| 521 | |
|
| 522 | 0 | Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(model, collectionPath); |
| 523 | 0 | if (collection == null) { |
| 524 | 0 | logAndThrowRuntime("Unable to get collection property from model for path: " + collectionPath); |
| 525 | |
} |
| 526 | |
|
| 527 | |
|
| 528 | 0 | String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath(); |
| 529 | 0 | Object addLine = ObjectPropertyUtils.getPropertyValue(model, addLinePath); |
| 530 | 0 | if (addLine == null) { |
| 531 | 0 | logAndThrowRuntime("Add line instance not found for path: " + addLinePath); |
| 532 | |
} |
| 533 | |
|
| 534 | 0 | processBeforeAddLine(view, collectionGroup, model, addLine); |
| 535 | |
|
| 536 | |
|
| 537 | 0 | boolean isValidLine = performAddLineValidation(view, collectionGroup, model, addLine); |
| 538 | 0 | if (isValidLine) { |
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | 0 | collection.add(addLine); |
| 543 | |
|
| 544 | |
|
| 545 | 0 | collectionGroup.initializeNewCollectionLine(view, model, collectionGroup, true); |
| 546 | |
} |
| 547 | |
|
| 548 | 0 | processAfterAddLine(view, collectionGroup, model, addLine); |
| 549 | 0 | } |
| 550 | |
|
| 551 | |
|
| 552 | |
|
| 553 | |
|
| 554 | |
|
| 555 | |
|
| 556 | |
|
| 557 | |
|
| 558 | |
|
| 559 | |
|
| 560 | |
|
| 561 | |
|
| 562 | |
|
| 563 | |
|
| 564 | |
|
| 565 | |
|
| 566 | |
|
| 567 | |
protected boolean performAddLineValidation(View view, CollectionGroup collectionGroup, Object model, Object addLine) { |
| 568 | 0 | boolean isValid = true; |
| 569 | |
|
| 570 | |
|
| 571 | |
|
| 572 | |
|
| 573 | 0 | return isValid; |
| 574 | |
} |
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
public void processCollectionDeleteLine(View view, Object model, String collectionPath, int lineIndex) { |
| 581 | |
|
| 582 | 0 | CollectionGroup collectionGroup = view.getViewIndex().getCollectionGroupByPath(collectionPath); |
| 583 | 0 | if (collectionGroup == null) { |
| 584 | 0 | logAndThrowRuntime("Unable to get collection group component for path: " + collectionPath); |
| 585 | |
} |
| 586 | |
|
| 587 | |
|
| 588 | 0 | Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(model, collectionPath); |
| 589 | 0 | if (collection == null) { |
| 590 | 0 | logAndThrowRuntime("Unable to get collection property from model for path: " + collectionPath); |
| 591 | |
} |
| 592 | |
|
| 593 | |
|
| 594 | |
|
| 595 | 0 | if (collection instanceof List) { |
| 596 | 0 | Object deleteLine = ((List<Object>) collection).get(lineIndex); |
| 597 | |
|
| 598 | |
|
| 599 | 0 | boolean isValid = performDeleteLineValidation(view, collectionGroup, deleteLine); |
| 600 | 0 | if (isValid) { |
| 601 | 0 | ((List<Object>) collection).remove(lineIndex); |
| 602 | |
} |
| 603 | 0 | } |
| 604 | |
else { |
| 605 | 0 | logAndThrowRuntime("Only List collection implementations are supported for the delete by index method"); |
| 606 | |
} |
| 607 | 0 | } |
| 608 | |
|
| 609 | |
|
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
|
| 615 | |
|
| 616 | |
|
| 617 | |
|
| 618 | |
|
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
protected boolean performDeleteLineValidation(View view, CollectionGroup collectionGroup, Object deleteLine) { |
| 623 | 0 | boolean isValid = true; |
| 624 | |
|
| 625 | |
|
| 626 | |
|
| 627 | |
|
| 628 | 0 | return isValid; |
| 629 | |
} |
| 630 | |
|
| 631 | |
|
| 632 | |
|
| 633 | |
|
| 634 | |
|
| 635 | |
|
| 636 | |
|
| 637 | |
|
| 638 | |
public void buildInquiryLink(Object dataObject, String propertyName, Inquiry inquiry) { |
| 639 | 0 | Inquirable inquirable = getViewDictionaryService().getInquirable(dataObject.getClass(), |
| 640 | |
inquiry.getViewName()); |
| 641 | 0 | if (inquirable != null) { |
| 642 | 0 | inquirable.buildInquirableLink(dataObject, propertyName, inquiry); |
| 643 | |
} |
| 644 | |
else { |
| 645 | |
|
| 646 | 0 | inquiry.setRender(false); |
| 647 | |
} |
| 648 | 0 | } |
| 649 | |
|
| 650 | |
|
| 651 | |
|
| 652 | |
|
| 653 | |
|
| 654 | |
|
| 655 | |
|
| 656 | |
|
| 657 | |
|
| 658 | |
|
| 659 | |
protected void performCustomInitialization(View view, Component component) { |
| 660 | |
|
| 661 | 0 | } |
| 662 | |
|
| 663 | |
|
| 664 | |
|
| 665 | |
|
| 666 | |
|
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
|
| 674 | |
|
| 675 | |
protected void performCustomApplyModel(View view, Component component, Object model) { |
| 676 | |
|
| 677 | 0 | } |
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
|
| 682 | |
|
| 683 | |
|
| 684 | |
|
| 685 | |
|
| 686 | |
|
| 687 | |
|
| 688 | |
|
| 689 | |
|
| 690 | |
|
| 691 | |
protected void performCustomFinalize(View view, Component component, Object model, Component parent) { |
| 692 | |
|
| 693 | 0 | } |
| 694 | |
|
| 695 | |
|
| 696 | |
|
| 697 | |
|
| 698 | |
|
| 699 | |
|
| 700 | |
|
| 701 | |
|
| 702 | |
|
| 703 | |
|
| 704 | |
|
| 705 | |
|
| 706 | |
|
| 707 | |
|
| 708 | |
|
| 709 | |
|
| 710 | |
protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) { |
| 711 | |
|
| 712 | 0 | } |
| 713 | |
|
| 714 | |
|
| 715 | |
|
| 716 | |
|
| 717 | |
|
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
|
| 726 | |
|
| 727 | |
|
| 728 | |
|
| 729 | |
protected void processAfterAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) { |
| 730 | |
|
| 731 | 0 | } |
| 732 | |
|
| 733 | |
protected void logAndThrowRuntime(String message) { |
| 734 | 0 | LOG.error(message); |
| 735 | 0 | throw new RuntimeException(message); |
| 736 | |
} |
| 737 | |
|
| 738 | |
protected DataDictionaryService getDataDictionaryService() { |
| 739 | 0 | if (this.dataDictionaryService == null) { |
| 740 | 0 | this.dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService(); |
| 741 | |
} |
| 742 | |
|
| 743 | 0 | return this.dataDictionaryService; |
| 744 | |
} |
| 745 | |
|
| 746 | |
public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
| 747 | 0 | this.dataDictionaryService = dataDictionaryService; |
| 748 | 0 | } |
| 749 | |
|
| 750 | |
protected ExpressionEvaluatorService getExpressionEvaluatorService() { |
| 751 | 0 | if (this.expressionEvaluatorService == null) { |
| 752 | 0 | this.expressionEvaluatorService = KNSServiceLocatorWeb.getExpressionEvaluatorService(); |
| 753 | |
} |
| 754 | |
|
| 755 | 0 | return this.expressionEvaluatorService; |
| 756 | |
} |
| 757 | |
|
| 758 | |
public void setExpressionEvaluatorService(ExpressionEvaluatorService expressionEvaluatorService) { |
| 759 | 0 | this.expressionEvaluatorService = expressionEvaluatorService; |
| 760 | 0 | } |
| 761 | |
|
| 762 | |
public ViewDictionaryService getViewDictionaryService() { |
| 763 | 0 | if (this.viewDictionaryService == null) { |
| 764 | 0 | this.viewDictionaryService = KNSServiceLocatorWeb.getViewDictionaryService(); |
| 765 | |
} |
| 766 | 0 | return this.viewDictionaryService; |
| 767 | |
} |
| 768 | |
|
| 769 | |
public void setViewDictionaryService(ViewDictionaryService viewDictionaryService) { |
| 770 | 0 | this.viewDictionaryService = viewDictionaryService; |
| 771 | 0 | } |
| 772 | |
|
| 773 | |
} |