Clover Coverage Report - Kuali Student 1.2-M3-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Jun 6 2011 05:02:46 EDT
../../../../../../img/srcFileCovDistChart0.png 52% of files have more coverage
102   250   50   4.43
46   198   0.49   11.5
23     2.17  
2    
 
  AssemblerUtils       Line # 29 100 0% 48 167 0% 0.0
  AssemblerUtils.VersionProperties       Line # 30 2 0% 2 4 0% 0.0
 
No Tests
 
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.assembly.util;
17   
18    import java.util.ArrayList;
19    import java.util.List;
20   
21    import org.kuali.student.common.assembly.data.Data;
22    import org.kuali.student.common.assembly.data.Metadata;
23    import org.kuali.student.common.assembly.data.QueryPath;
24    import org.kuali.student.common.assembly.data.Data.DataType;
25    import org.kuali.student.common.assembly.data.Data.Key;
26    import org.kuali.student.common.assembly.helper.PropertyEnum;
27    import org.kuali.student.common.assembly.helper.RuntimeDataHelper;
28   
 
29    public class AssemblerUtils {
 
30    public enum VersionProperties implements PropertyEnum {
31    TYPENAME("typeName"), ID("id"), VERSION_INDICATOR("versionIndicator");
32   
33    private final String key;
34   
 
35  0 toggle private VersionProperties(final String key) {
36  0 this.key = key;
37    }
38   
 
39  0 toggle @Override
40    public String getKey() {
41  0 return this.key;
42    }
43    }
44   
 
45  0 toggle public static String getVersionIndicator(Data data) {
46  0 String result = null;
47  0 Data versions = getVersions(data);
48  0 if (versions == null) {
49  0 return null;
50    }
51  0 if (versions.size() > 0) {
52  0 Data v = versions.get(0);
53  0 if (v != null) {
54  0 result = v.get(VersionProperties.VERSION_INDICATOR.getKey());
55    }
56    }
57  0 return result;
58    }
59   
 
60  0 toggle public static String getVersionIndicator(Data data, String typeName) {
61  0 return getVersionIndicator(data, typeName, null);
62    }
63   
 
64  0 toggle public static String getVersionIndicator(Data data, String typeName, String id) {
65  0 Data version = getVersionData(data, typeName, id);
66  0 if (version == null) {
67  0 return null;
68    } else {
69  0 return version.get(VersionProperties.VERSION_INDICATOR.getKey());
70    }
71    }
72   
 
73  0 toggle public static Data getVersionData(Data data, String typeName, String id) {
74  0 Data result = null;
75  0 Data versions = getVersions(data);
76  0 if (versions == null) {
77  0 return null;
78    }
79  0 for (Data.Property p : versions) {
80  0 Data v = p.getValue();
81  0 if (typeName.equals((String) v.get(VersionProperties.TYPENAME.getKey())) && (id == null || id.equals((String) v.get(VersionProperties.ID.getKey())))) {
82  0 result = v;
83  0 break;
84    }
85    }
86  0 return result;
87   
88    }
89   
 
90  0 toggle public static Data getVersions(Data data) {
91  0 Data result = null;
92   
93  0 if (data != null) {
94    // TODO need a "standard properties" enum for values that could be present on any object?
95  0 Data runtime = data.get("_runtimeData");
96  0 if (runtime != null) {
97  0 result = runtime.get(RuntimeDataHelper.Properties.VERSIONS.getKey());
98    }
99    }
100   
101  0 return result;
102    }
103   
 
104  0 toggle public static void addVersionIndicator(Data data, String typeName, String id, String version) {
105  0 Data existing = getVersionData(data, typeName, id);
106  0 if (existing == null) {
107  0 Data d = new Data();
108  0 d.set(VersionProperties.TYPENAME.getKey(), typeName);
109  0 d.set(VersionProperties.ID.getKey(), id);
110  0 d.set(VersionProperties.VERSION_INDICATOR.getKey(), version);
111  0 Data versions = getVersions(data);
112  0 if (versions == null) {
113  0 versions = new Data();
114  0 setVersions(data, versions);
115    }
116  0 versions.add(d);
117    } else {
118  0 existing.set(VersionProperties.VERSION_INDICATOR.getKey(), version);
119    }
120    }
 
121  0 toggle public static void setVersions(Data data, Data versions) {
122  0 if (data != null) {
123    // TODO need a "standard properties" enum for values that could be present on any object?
124  0 Data runtime = data.get("_runtimeData");
125  0 if (runtime == null) {
126  0 runtime = new Data();
127  0 data.set("_runtimeData", runtime);
128    }
129  0 runtime.set(RuntimeDataHelper.Properties.VERSIONS.getKey(), versions);
130    }
131    }
132   
 
133  0 toggle public static boolean isCreated(Data data) {
134  0 return isFlagSet(data, RuntimeDataHelper.Properties.CREATED.getKey());
135    }
136   
 
137  0 toggle public static boolean isDeleted(Data data) {
138  0 return isFlagSet(data, RuntimeDataHelper.Properties.DELETED.getKey());
139    }
140   
 
141  0 toggle public static boolean isUpdated(Data data) {
142  0 return isFlagSet(data, RuntimeDataHelper.Properties.UPDATED.getKey());
143    }
144   
 
145  0 toggle public static boolean isModified(Data data) {
146  0 return isCreated(data) || isUpdated(data) || isDeleted(data); //|| isFlagSet(data, RuntimeDataHelper.Properties.DIRTY.getKey());
147    }
148   
 
149  0 toggle public static void setCreated(Data data, boolean flag) {
150  0 setFlag(data, RuntimeDataHelper.Properties.CREATED.getKey(), flag);
151    }
152   
 
153  0 toggle public static void setDeleted(Data data, boolean flag) {
154  0 setFlag(data, RuntimeDataHelper.Properties.DELETED.getKey(), flag);
155    }
156   
 
157  0 toggle public static void setUpdated(Data data, boolean flag) {
158  0 setFlag(data, RuntimeDataHelper.Properties.UPDATED.getKey(), flag);
159    }
160   
 
161  0 toggle private static void setFlag(Data data, String key, Boolean flag) {
162  0 if (data != null) {
163  0 Data runtime = data.get("_runtimeData");
164  0 if (runtime == null) {
165  0 runtime = new Data();
166  0 data.set("_runtimeData", runtime);
167    }
168  0 runtime.set(key, flag);
169    }
170    }
 
171  0 toggle private static boolean isFlagSet(Data data, String key) {
172  0 boolean result = false;
173   
174  0 if (data != null) {
175  0 Data runtime = data.get("_runtimeData");
176  0 if (runtime != null) {
177  0 result = runtime.get(key) != null && (Boolean) runtime.get(key);
178    }
179    }
180   
181  0 return result;
182    }
183   
184   
 
185  0 toggle public static List<QueryPath> findDirtyElements(Data data) {
186  0 List<QueryPath> results = new ArrayList<QueryPath>();
187  0 _findDirtyElements(data, results, new QueryPath());
188  0 return results;
189    }
 
190  0 toggle private static void _findDirtyElements(Data data, List<QueryPath> results, QueryPath currentFrame) {
191  0 if (data == null) {
192  0 return;
193    }
194   
195  0 Data flags = getDirtyFlags(data);
196  0 if (flags != null && flags.size() > 0) {
197  0 for (Data.Property p : flags) {
198  0 QueryPath q = new QueryPath();
199  0 q.addAll(currentFrame);
200  0 Key key = p.getWrappedKey();
201  0 q.add(key);
202  0 results.add(q);
203    }
204    }
205   
206  0 for (Data.Property p : data) {
207  0 if (p.getValueType().equals(Data.class) && p.getValue() != null) {
208  0 QueryPath q = new QueryPath();
209  0 q.addAll(currentFrame);
210  0 Key key = p.getWrappedKey();
211  0 q.add(key);
212   
213  0 _findDirtyElements((Data) p.getValue(), results, q);
214    }
215    }
216    }
 
217  0 toggle public static Data getDirtyFlags(Data data) {
218  0 Data result = null;
219  0 Data runtime = data.get("_runtimeData");
220  0 if (runtime != null) {
221  0 result = runtime.get("dirty");
222   
223    }
224  0 return result;
225    }
226    /*public static Metadata get(Metadata metadata, QueryPath path) {
227   
228    }*/
 
229  0 toggle public static Metadata get(Metadata metadata, QueryPath frame) {
230  0 if(frame.size() == 1) {
231  0 return metadata.getProperties().get(frame.get(0).get());
232    } else {
233  0 if (metadata.getDataType() == DataType.LIST){
234  0 return get(metadata, frame, DataType.LIST);
235    }
236    else{
237  0 return get(metadata.getProperties().get(frame.get(0).get()), frame.subPath(1, frame.size()));
238    }
239    }
240    }
241   
 
242  0 toggle private static Metadata get(Metadata metadata, QueryPath frame, DataType type){
243  0 if(type == DataType.LIST){
244  0 return get(metadata.getProperties().get(QueryPath.getWildCard()), frame.subPath(1, frame.size()));
245    }
246    else{
247  0 return get(metadata.getProperties().get(frame.get(0).get()), frame.subPath(1, frame.size()));
248    }
249    }
250    }