Clover Coverage Report - KS LUM UI Common 1.2.1-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
87   172   22   12.43
20   132   0.25   7
7     3.14  
1    
 
  LOBuilderBinding       Line # 18 87 0% 22 114 0% 0.0
 
No Tests
 
1    package org.kuali.student.lum.common.client.lo;
2   
3    import java.util.ArrayList;
4    import java.util.HashMap;
5    import java.util.Iterator;
6    import java.util.List;
7    import java.util.Map;
8   
9    import org.kuali.student.common.assembly.data.Data;
10    import org.kuali.student.common.assembly.data.QueryPath;
11    import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport;
12    import org.kuali.student.common.ui.client.mvc.DataModel;
13    import org.kuali.student.lum.lo.dto.LoCategoryInfo;
14   
15    /**
16    * @author Igor
17    */
 
18    public class LOBuilderBinding extends ModelWidgetBindingSupport<LOBuilder> {
19   
20    public static LOBuilderBinding INSTANCE = new LOBuilderBinding();
21   
 
22  0 toggle private LOBuilderBinding() {}
23   
24    /**
25    * Gets a list of OutlineNode from LOBuilder. Goes through the list one by one.
26    * While going through the list the algorithm keeps track of the current parent of
27    * a particular level.
28    */
 
29  0 toggle @Override
30    public void setModelValue(LOBuilder builder, DataModel model, String path) {
31  0 Data losData = new Data();
32  0 Map<Integer, Data> parentStore = new HashMap<Integer, Data>();
33  0 int sequence = 0; // the ordering information of DisplayInfo
34  0 List<OutlineNode<LOPicker>> value = stripOutEmptyInput(builder.getValue());
35  0 if (value != null) {
36  0 for (OutlineNode<LOPicker> node : value) {
37  0 if (node.getIndentLevel() == 0) {
38  0 Data item = createLoDisplayInfoData(node, sequence);
39  0 parentStore.put(new Integer(0), item);
40  0 losData.add(item);
41    } else {
42  0 Data item = createLoDisplayInfoData(node, sequence);
43  0 LoDisplayInfoHelper parentItemHelper = null;
44  0 parentStore.put(node.getIndentLevel(), item);
45  0 parentItemHelper = new LoDisplayInfoHelper(
46    parentStore.get(node.getIndentLevel() - 1));
47  0 parentItemHelper.getDisplayInfoList().add(item);
48    }
49  0 sequence++;
50    }
51    }
52  0 model.set(QueryPath.parse(path), losData);
53    }
54   
 
55  0 toggle @Override
56    public void setWidgetValue(LOBuilder builder, DataModel model, String path) {
57  0 List<OutlineNode<LOPicker>> loOutlineNodes = new ArrayList<OutlineNode<LOPicker>>();
58   
59    // change the 'courseSpecificLOs' elements into a List of OutlineNode's
60  0 QueryPath qPath = QueryPath.parse(path);
61   
62  0 Data data = null;
63  0 if (model != null) {
64  0 data = model.get(qPath);
65    }
66   
67  0 dataToOutlineNodes(data, loOutlineNodes, 0);
68  0 builder.setValue(loOutlineNodes);
69    }
70   
 
71  0 toggle private List<OutlineNode<LOPicker>> stripOutEmptyInput(List<OutlineNode<LOPicker>> input) {
72  0 List<OutlineNode<LOPicker>> value = new ArrayList<OutlineNode<LOPicker>>();
73  0 boolean allEmptyNodes = true;
74  0 if (input != null) {
75  0 for (OutlineNode<LOPicker> node : input) {
76  0 String desc = node.getUserObject().getLOText();
77  0 int indentLevel = node.getIndentLevel();
78  0 List<LoCategoryInfo> categories = node.getUserObject().getLoCategories();
79  0 if (desc != null && desc.trim().length() > 0 || indentLevel > 0 || categories != null && !categories.isEmpty()) {
80  0 allEmptyNodes = false;
81  0 value.add(node);
82    }
83    }
84    }
85  0 if (allEmptyNodes) {
86  0 value = null;
87    }
88  0 return value;
89    }
90   
 
91  0 toggle private void dataToOutlineNodes(Data data, List<OutlineNode<LOPicker>> loOutlineNodes, int identLevel) {
92  0 if (data != null) {
93  0 LoDisplayInfoSortedSet sortedDisplayInfos = new LoDisplayInfoSortedSet();
94  0 for (Data.Property property : data) {
95  0 Data loDisplayInfoData = property.getValue();
96  0 LoDisplayInfoHelper loDisplayInfoHelper = new LoDisplayInfoHelper(loDisplayInfoData);
97  0 sortedDisplayInfos.add(loDisplayInfoHelper);
98    }
99  0 for (LoDisplayInfoHelper loDisplayInfoHelper : sortedDisplayInfos) {
100  0 LOPicker picker = new LOPicker(LOBuilder.getMessageGroup(), LOBuilder.getType(), LOBuilder.getState(), LOBuilder.getRepoKey(), LOBuilder.getLoListDescLength());
101   
102  0 LoInfoHelper loInfoHelper = new LoInfoHelper(loDisplayInfoHelper.getLoInfo());
103  0 RichTextHelper descriptionHelper = new RichTextHelper(loInfoHelper.getDesc());
104  0 picker.setLOText(descriptionHelper.getPlain());
105  0 List<LoCategoryInfo> categories = getCategoryList(loDisplayInfoHelper);
106  0 picker.setLOCategories(categories);
107  0 picker.setMetaInfoData(loInfoHelper.getMetaInfo());
108  0 OutlineNode<LOPicker> node = new OutlineNode<LOPicker>();
109   
110  0 node.setUserObject(picker);
111  0 node.setOpaque(loInfoHelper.getId());
112  0 node.setIndentLevel(identLevel);
113  0 loOutlineNodes.add(node);
114    // recurse
115  0 dataToOutlineNodes(loDisplayInfoHelper.getDisplayInfoList(), loOutlineNodes, identLevel + 1);
116    }
117    }
118    }
119   
 
120  0 toggle private List<LoCategoryInfo> getCategoryList(LoDisplayInfoHelper loDisplayInfoHelper) {
121  0 List<LoCategoryInfo> categoryInfos = new ArrayList<LoCategoryInfo>();
122  0 Data categoriesData = loDisplayInfoHelper.getCategoryInfoList();
123   
124  0 if (null != categoriesData) {
125  0 Iterator<Data.Property> itr = categoriesData.realPropertyIterator();
126   
127  0 while (itr.hasNext()) {
128  0 Data.Property catProp = itr.next();
129  0 Data catData = catProp.getValue();
130  0 LoCategoryInfo catInfo = CategoryDataUtil.toLoCategoryInfo(catData);
131  0 categoryInfos.add(catInfo);
132    }
133    }
134  0 return categoryInfos;
135    }
136   
 
137  0 toggle private Data createLoDisplayInfoData(OutlineNode<LOPicker> node, int sequence) {
138  0 Data result = null;
139  0 LoDisplayInfoHelper loDisplayInfoDataHelper = new LoDisplayInfoHelper(new Data());
140  0 LoInfoHelper loInfoHelper = new LoInfoHelper(new Data());
141    // loInfo.id
142  0 loInfoHelper.setId((String) node.getOpaque());
143    // loInfo.desc
144  0 RichTextHelper richTextHelper = new RichTextHelper();
145  0 String loDesc = node.getUserObject().getLOText();
146  0 richTextHelper.setFormatted(loDesc);
147  0 richTextHelper.setPlain(loDesc);
148  0 loInfoHelper.setDesc(richTextHelper.getData());
149    // loInfo.name
150  0 if (null == loInfoHelper.getName() || loInfoHelper.getName().length() == 0) {
151  0 loInfoHelper.setName("SINGLE USE LO");
152    }
153   
154    // loCategoryInfoList
155  0 Data categoriesData = new Data();
156  0 for (LoCategoryInfo cat : node.getUserObject().getLoCategories()) {
157  0 categoriesData.add(CategoryDataUtil.toData(cat));
158    }
159   
160    // loInfo.sequence
161  0 loInfoHelper.setSequence(Integer.toString(sequence));
162   
163    // loInfo.metaInfo
164  0 loInfoHelper.setMetaInfo(node.getUserObject().getMetaInfoData());
165   
166  0 loDisplayInfoDataHelper.setLoInfo(loInfoHelper.getData());
167  0 loDisplayInfoDataHelper.setCategoryInfoList(categoriesData);
168  0 result = loDisplayInfoDataHelper.getData();
169  0 return result;
170    }
171   
172    }