1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.query.xwql.internal; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.LinkedHashMap; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
import java.util.Set; |
29 |
|
|
30 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
31 |
|
import org.xwiki.query.jpql.node.PPath; |
32 |
|
import org.xwiki.query.jpql.node.PXObjectDecl; |
33 |
|
import org.xwiki.query.jpql.node.Start; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
|
|
| 86.7% |
Uncovered Elements: 6 (45) |
Complexity: 15 |
Complexity Density: 0.56 |
|
38 |
|
public class QueryContext |
39 |
|
{ |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
private Start tree; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
private Map<String, DocumentInfo> documents = new HashMap<String, DocumentInfo>(); |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private Map<String, ObjectInfo> objects = new HashMap<String, ObjectInfo>(); |
54 |
|
|
55 |
|
private AliasGenerator aliasGenerator = new AliasGenerator(); |
56 |
|
|
57 |
|
private DocumentAccessBridge documentAccessBridge; |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
59 |
1032 |
public QueryContext(Start tree, DocumentAccessBridge documentAccessBridge)... |
60 |
|
{ |
61 |
1032 |
this.tree = tree; |
62 |
1032 |
this.documentAccessBridge = documentAccessBridge; |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
1032 |
public Start getTree()... |
66 |
|
{ |
67 |
1032 |
return tree; |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
113 |
public AliasGenerator getAliasGenerator()... |
71 |
|
{ |
72 |
113 |
return aliasGenerator; |
73 |
|
} |
74 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
75 |
|
public class DocumentInfo |
76 |
|
{ |
77 |
|
public String alias; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
public Map<String, ObjectInfo> unnamedObjects = new HashMap<String, ObjectInfo>(); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 5 |
Complexity Density: 0.38 |
|
86 |
|
public class ObjectInfo |
87 |
|
{ |
88 |
|
public String docAlias; |
89 |
|
|
90 |
|
public String className; |
91 |
|
|
92 |
|
public String alias; |
93 |
|
|
94 |
|
public String customMappingAlias; |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
public Map<String, PropertyInfo> properties = new LinkedHashMap<String, PropertyInfo>(); |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
101 |
397 |
public ObjectInfo(String docAlias, String className, String objAlias)... |
102 |
|
{ |
103 |
397 |
this.className = className; |
104 |
397 |
this.docAlias = docAlias; |
105 |
397 |
this.alias = objAlias; |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
108 |
172 |
public PropertyInfo addProperty(String propname, PPath location)... |
109 |
|
{ |
110 |
172 |
PropertyInfo prop = properties.get(propname); |
111 |
172 |
if (prop == null) { |
112 |
149 |
prop = new PropertyInfo(propname, this); |
113 |
149 |
properties.put(propname, prop); |
114 |
|
} |
115 |
172 |
prop.locations.add(location); |
116 |
172 |
return prop; |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
119 |
396 |
public boolean isCustomMapped() throws Exception... |
120 |
|
{ |
121 |
396 |
for (PropertyInfo p : properties.values()) { |
122 |
148 |
if (p.isCustomMapped()) { |
123 |
2 |
return true; |
124 |
|
} |
125 |
|
} |
126 |
394 |
return false; |
127 |
|
} |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 6 |
Complexity Density: 0.6 |
|
130 |
|
public class PropertyInfo |
131 |
|
{ |
132 |
|
public ObjectInfo object; |
133 |
|
|
134 |
|
public String name; |
135 |
|
|
136 |
|
public String alias; |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
138 |
149 |
public PropertyInfo(String name, ObjectInfo object)... |
139 |
|
{ |
140 |
149 |
this.name = name; |
141 |
149 |
this.object = object; |
142 |
|
} |
143 |
|
|
144 |
|
public List<PPath> locations = new ArrayList<PPath>(); |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
279 |
public String getType() throws Exception... |
147 |
|
{ |
148 |
279 |
return documentAccessBridge.getPropertyType(object.className, name); |
149 |
|
} |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
297 |
public boolean isCustomMapped() throws Exception... |
152 |
|
{ |
153 |
297 |
return documentAccessBridge.isPropertyCustomMapped(object.className, name); |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
156 |
132 |
public String getValueField() throws Exception... |
157 |
|
{ |
158 |
132 |
String type = getType(); |
159 |
132 |
if (type.endsWith("DBStringListProperty")) { |
160 |
2 |
return "list"; |
161 |
130 |
} else if (type.endsWith("StringListProperty")) { |
162 |
1 |
return "textValue"; |
163 |
|
} else { |
164 |
129 |
return "value"; |
165 |
|
} |
166 |
|
} |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
private Map<PXObjectDecl, ObjectInfo> nodeToObject = new HashMap<PXObjectDecl, ObjectInfo>(); |
173 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
174 |
397 |
public ObjectInfo addObject(String docAlias, String className, String objAlias, PXObjectDecl node)... |
175 |
|
{ |
176 |
397 |
DocumentInfo di = getDocument(docAlias); |
177 |
397 |
if (di == null) { |
178 |
0 |
throw new InvalidQueryException("Can't find document alias [" + docAlias + "]"); |
179 |
|
} |
180 |
397 |
ObjectInfo res = new ObjectInfo(docAlias, className, objAlias); |
181 |
397 |
if (objAlias != null) { |
182 |
394 |
objects.put(objAlias, res); |
183 |
3 |
} else if (di.unnamedObjects.get(className) == null) { |
184 |
2 |
di.unnamedObjects.put(className, res); |
185 |
|
} else { |
186 |
1 |
res = di.unnamedObjects.get(className); |
187 |
|
} |
188 |
397 |
nodeToObject.put(node, res); |
189 |
397 |
return res; |
190 |
|
} |
191 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
192 |
419 |
public void addDocument(String alias)... |
193 |
|
{ |
194 |
419 |
if (documents.get(alias) != null && !"doc".equals(alias)) { |
195 |
0 |
throw new InvalidQueryException("Redeclaration of document [" + alias + "]"); |
196 |
|
} |
197 |
419 |
documents.put(alias, new DocumentInfo()); |
198 |
|
} |
199 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
200 |
1868 |
public DocumentInfo getDocument(String alias)... |
201 |
|
{ |
202 |
1868 |
return documents.get(alias); |
203 |
|
} |
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
6187 |
public ObjectInfo getObject(String objAlias)... |
206 |
|
{ |
207 |
6187 |
return objects.get(objAlias); |
208 |
|
} |
209 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
3 |
public ObjectInfo getObject(PXObjectDecl node)... |
211 |
|
{ |
212 |
3 |
return nodeToObject.get(node); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
@return |
217 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
218 |
1032 |
public Collection<ObjectInfo> getObjects()... |
219 |
|
{ |
220 |
1032 |
List<ObjectInfo> res = new ArrayList<ObjectInfo>(); |
221 |
1032 |
res.addAll(objects.values()); |
222 |
1032 |
for (DocumentInfo di : documents.values()) { |
223 |
419 |
res.addAll(di.unnamedObjects.values()); |
224 |
|
} |
225 |
1032 |
return res; |
226 |
|
} |
227 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
228 |
0 |
public Set<String> getDocuments()... |
229 |
|
{ |
230 |
0 |
return documents.keySet(); |
231 |
|
} |
232 |
|
|
233 |
|
String DocumentFromName = "Document"; |
234 |
|
} |