Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.binding.MultiplicityGroupBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
MultiplicityGroupBinding
0%
0/37
0%
0/20
3.75
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.common.ui.client.configurable.mvc.binding;
 17  
 
 18  
 import java.util.Iterator;
 19  
 
 20  
 import org.kuali.student.common.assembly.data.Data;
 21  
 import org.kuali.student.common.assembly.data.QueryPath;
 22  
 import org.kuali.student.common.assembly.data.Data.Property;
 23  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityGroup;
 24  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityGroupItem;
 25  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 26  
 
 27  
 /**
 28  
  * This goes through each item in the MultiplicityGroup and calls it's binding
 29  
  *
 30  
  * @author Kuali Student Team
 31  
  */
 32  0
 public class MultiplicityGroupBinding extends ModelWidgetBindingSupport<MultiplicityGroup> {
 33  0
     public static MultiplicityGroupBinding INSTANCE = new MultiplicityGroupBinding();
 34  
 
 35  0
     public MultiplicityGroupBinding() {};
 36  
 
 37  
     /**
 38  
      * @see ModelWidgetBindingSupport#setModelValue(Object,
 39  
      *      org.kuali.student.common.ui.client.mvc.DataModel, String)
 40  
      */
 41  
     public void setModelValue(MultiplicityGroup mcWidget, DataModel model, String path) {
 42  0
         for (MultiplicityGroupItem item : mcWidget.getItems()) {
 43  0
             MultiplicityGroupItemBinding.INSTANCE.setModelValue(item, model, mcWidget.getParentPath());
 44  
         }
 45  0
         for (MultiplicityGroupItem item : mcWidget.getRemovedItems()) {
 46  
             //Check flag to add model binding for only those elements that are either added to the DB or
 47  
             // loading frm the DB.
 48  0
             if(item.isCreated()==false){
 49  0
                 MultiplicityGroupItemBinding.INSTANCE.setModelValue(item, model, path);
 50  
             }
 51  
         }
 52  0
     }
 53  
 
 54  
     /**
 55  
      * @see ModelWidgetBindingSupport#setWidgetValue(Object,
 56  
      *      org.kuali.student.common.ui.client.mvc.DataModel, String)
 57  
      */
 58  
     public void setWidgetValue(MultiplicityGroup mg, DataModel model, String path) {
 59  0
         mg.clear();
 60  
 
 61  0
         String fieldPath = mg.translatePath(path);
 62  
  
 63  0
                 mg.setParentPath(fieldPath);
 64  
 
 65  0
         QueryPath qPath = QueryPath.parse(fieldPath);
 66  0
         Data data = null;
 67  0
         if(model!=null){
 68  0
                 data = model.get(qPath);
 69  
         }
 70  
 
 71  0
         if (data != null) {
 72  0
             Iterator<Property> itr = data.iterator();
 73  0
             while (itr.hasNext()) {
 74  0
                 Property p = (Property) itr.next();
 75  
 
 76  0
                 if (p.getKey() instanceof Integer && !isItemDeleted(model, path, (Integer)p.getKey(), mg)) {
 77  0
                         MultiplicityGroupItem mgi = mg.createItem();
 78  0
                     mgi.setCreated(false);
 79  0
                     mgi.setItemKey((Integer) p.getKey());
 80  0
                     MultiplicityGroupItemBinding.INSTANCE.setWidgetValue(mgi, model, fieldPath);
 81  0
                 } else {
 82  0
                         mg.incrementItemKey();
 83  
                 }
 84  0
             }
 85  
         }
 86  0
     }
 87  
 
 88  
     /**
 89  
      * Checks to see if an item at the given index in the multiplicity has been deleted
 90  
      *
 91  
      * @param model
 92  
      * @param path
 93  
      * @param index
 94  
      */
 95  
     public boolean isItemDeleted(DataModel model, String path, Integer index, MultiplicityGroup mcWidget){
 96  0
             boolean isDeleted = false;
 97  
 
 98  
             // If multiplicity read only no point checking for deletions
 99  0
             if (!mcWidget.getConfig().isUpdateable()) {
 100  
 
 101  0
                     QueryPath runtimeDeletedPath = QueryPath.concat(path, String.valueOf(index), MultiplicityGroupItemBinding.RT_DELETED);
 102  
 
 103  0
                     Boolean runtimeDeleted = model.get(runtimeDeletedPath);
 104  0
                     if (runtimeDeleted != null){
 105  0
                             isDeleted = runtimeDeleted;
 106  
                     }
 107  0
                     return isDeleted;
 108  
             }
 109  
 
 110  0
             return isDeleted;
 111  
     }
 112  
 
 113  
 
 114  
 }