View Javadoc
1   package org.kuali.ole.deliver.maintenance.drools;
2   
3   import org.kuali.rice.krad.maintenance.MaintainableImpl;
4   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
5   import org.kuali.rice.krad.uif.UifConstants;
6   import org.kuali.rice.krad.uif.container.CollectionGroup;
7   import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
8   import org.kuali.rice.krad.uif.view.View;
9   import org.kuali.rice.krad.web.form.UifFormBase;
10  
11  import java.util.Collection;
12  import java.util.Map;
13  
14  /**
15   * Created by sheiksalahudeenm on 7/7/15.
16   */
17  public class DroolEditorMaintaintainableImpl extends MaintainableImpl {
18      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DroolEditorMaintaintainableImpl.class);
19  
20  
21      @Override
22      public void processCollectionAddLine(View view, Object model, String collectionPath) {
23          CollectionGroup collectionGroup = view.getViewIndex().getCollectionGroupByPath(collectionPath);
24          if (collectionGroup == null) {
25              super.logAndThrowRuntime("Unable to get collection group component for path: " + collectionPath);
26          }
27  
28          // get the collection instance for adding the new line
29          Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(model, collectionPath);
30          if (collection == null) {
31              super.logAndThrowRuntime("Unable to get collection property from model for path: " + collectionPath);
32          }
33  
34          // now get the new line we need to add
35          String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
36          Object addLine = ObjectPropertyUtils.getPropertyValue(model, addLinePath);
37          if (addLine == null) {
38              super.logAndThrowRuntime("Add line instance not found for path: " + addLinePath);
39          }
40  
41          super.processBeforeAddLine(view, collectionGroup, model, addLine);
42  
43          // validate the line to make sure it is ok to add
44          boolean isValidLine = super.performAddLineValidation(view, collectionGroup, model, addLine);
45          if (isValidLine) {
46              // TODO: should check to see if there is an add line method on the
47              // collection parent and if so call that instead of just adding to
48              // the collection (so that sequence can be set)
49              super.addLine(collection, addLine, collectionGroup.getAddLinePlacement().equals(
50                      UifConstants.Position.TOP.name()));
51  
52              // make a new instance for the add line
53              collectionGroup.initializeNewCollectionLine(view, model, collectionGroup, true);
54          }
55  
56          ((UifFormBase) model).getAddedCollectionItems().add(addLine);
57  
58          super.processAfterAddLine(view, collectionGroup, model, addLine, isValidLine);
59      }
60  
61  
62      public void processCollectionAddLineForFine(View view, Object model, String collectionPath) {
63          CollectionGroup collectionGroup = view.getViewIndex().getCollectionGroupByPath(collectionPath);
64          if (collectionGroup == null) {
65              super.logAndThrowRuntime("Unable to get collection group component for path: " + collectionPath);
66          }
67  
68          // get the collection instance for adding the new line
69          Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(model, collectionPath);
70          if (collection == null) {
71              super.logAndThrowRuntime("Unable to get collection property from model for path: " + collectionPath);
72          }
73  
74          // now get the new line we need to add
75          String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
76          if(addLinePath.startsWith("droolsRuleBos[")){
77              addLinePath = "newCollectionLines['document.newMaintainableObject.dataObject." + (addLinePath.replace("[","_")).replace("]","_") + ".finesAndLimitsBoList']";
78          }
79          Object addLine = ObjectPropertyUtils.getPropertyValue(model, addLinePath);
80          if (addLine == null) {
81              super.logAndThrowRuntime("Add line instance not found for path: " + addLinePath);
82          }
83  
84          super.processBeforeAddLine(view, collectionGroup, model, addLine);
85  
86          // validate the line to make sure it is ok to add
87          boolean isValidLine = super.performAddLineValidation(view, collectionGroup, model, addLine);
88          if (isValidLine) {
89              // TODO: should check to see if there is an add line method on the
90              // collection parent and if so call that instead of just adding to
91              // the collection (so that sequence can be set)
92              super.addLine(collection, addLine, collectionGroup.getAddLinePlacement().equals(
93                      UifConstants.Position.TOP.name()));
94  
95              // make a new instance for the add line
96              collectionGroup.initializeNewCollectionLine(view, model, collectionGroup, true);
97          }
98  
99          ((UifFormBase) model).getAddedCollectionItems().add(addLine);
100 
101         super.processAfterAddLine(view, collectionGroup, model, addLine, isValidLine);
102     }
103 }