1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects.classes; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import javax.script.ScriptContext; |
28 |
|
|
29 |
|
import org.apache.commons.lang3.StringUtils; |
30 |
|
import org.apache.ecs.xhtml.option; |
31 |
|
import org.apache.ecs.xhtml.select; |
32 |
|
import org.slf4j.Logger; |
33 |
|
import org.slf4j.LoggerFactory; |
34 |
|
import org.xwiki.script.ScriptContextManager; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWikiContext; |
37 |
|
import com.xpn.xwiki.internal.xml.XMLAttributeValueFilter; |
38 |
|
import com.xpn.xwiki.objects.BaseCollection; |
39 |
|
import com.xpn.xwiki.objects.BaseProperty; |
40 |
|
import com.xpn.xwiki.objects.ListProperty; |
41 |
|
import com.xpn.xwiki.objects.meta.PropertyMetaClass; |
42 |
|
import com.xpn.xwiki.web.Utils; |
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
|
|
|
| 62.2% |
Uncovered Elements: 126 (333) |
Complexity: 82 |
Complexity Density: 0.38 |
|
47 |
|
public class DBTreeListClass extends DBListClass |
48 |
|
{ |
49 |
|
private static final String XCLASSNAME = "dbtreelist"; |
50 |
|
|
51 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(DBTreeListClass.class); |
52 |
|
|
53 |
|
|
54 |
|
private List<ListItem> cachedDBTreeList; |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
18 |
public DBTreeListClass(PropertyMetaClass wclass)... |
57 |
|
{ |
58 |
18 |
super(XCLASSNAME, "DB Tree List", wclass); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
18 |
public DBTreeListClass()... |
62 |
|
{ |
63 |
18 |
this(null); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
55 |
public String getParentField()... |
67 |
|
{ |
68 |
55 |
return getStringValue("parentField"); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
20 |
public void setParentField(String parentField)... |
72 |
|
{ |
73 |
20 |
setStringValue("parentField", parentField); |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
@param |
80 |
|
@return |
81 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
82 |
2 |
protected List<ListItem> getCachedDBTreeList(XWikiContext context)... |
83 |
|
{ |
84 |
2 |
if (isCache()) { |
85 |
|
|
86 |
|
|
87 |
0 |
return this.cachedDBTreeList; |
88 |
|
} else { |
89 |
|
|
90 |
|
|
91 |
2 |
return (List<ListItem>) context.get(context.getWikiId() + ":" + getFieldFullName() + "-tree"); |
92 |
|
} |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
@param |
99 |
|
@param |
100 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
101 |
1 |
protected void setCachedDBTreeList(List<ListItem> cachedDBTreeList, XWikiContext context)... |
102 |
|
{ |
103 |
1 |
if (isCache()) { |
104 |
|
|
105 |
|
|
106 |
0 |
this.cachedDBTreeList = cachedDBTreeList; |
107 |
|
} else { |
108 |
|
|
109 |
|
|
110 |
1 |
context.put(context.getWikiId() + ":" + getFieldFullName() + "-tree", cachedDBTreeList); |
111 |
|
} |
112 |
|
} |
113 |
|
|
|
|
| 71.4% |
Uncovered Elements: 4 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
114 |
2 |
public Map<String, List<ListItem>> getTreeMap(XWikiContext context)... |
115 |
|
{ |
116 |
2 |
List<ListItem> list = getDBList(context); |
117 |
2 |
Map<String, List<ListItem>> map = new HashMap<String, List<ListItem>>(); |
118 |
2 |
if ((list == null) || (list.size() == 0)) { |
119 |
0 |
return map; |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
2 |
List<String> validParents = this.getList(context); |
125 |
2 |
for (ListItem item : list) { |
126 |
6 |
if (validParents.contains(item.getParent())) { |
127 |
0 |
addToList(map, item.getParent(), item); |
128 |
|
} else { |
129 |
6 |
addToList(map, "", item); |
130 |
|
} |
131 |
|
} |
132 |
2 |
return map; |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
@param |
140 |
|
@param |
141 |
|
@param |
142 |
|
@return |
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
144 |
2 |
protected List<ListItem> getTreeList(Map<String, List<ListItem>> treemap, Map<String, ListItem> map,... |
145 |
|
XWikiContext context) |
146 |
|
{ |
147 |
2 |
List<ListItem> list = getCachedDBTreeList(context); |
148 |
2 |
if (list == null) { |
149 |
1 |
list = new ArrayList<ListItem>(); |
150 |
1 |
addToTreeList(list, treemap, map, "", context); |
151 |
1 |
setCachedDBTreeList(list, context); |
152 |
|
} |
153 |
2 |
return list; |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
156 |
4 |
protected void addToTreeList(List<ListItem> treelist, Map<String, List<ListItem>> treemap,... |
157 |
|
Map<String, ListItem> map, String parent, XWikiContext context) |
158 |
|
{ |
159 |
4 |
List<ListItem> list = treemap.get(parent); |
160 |
4 |
if (list != null) { |
161 |
1 |
for (ListItem item : list) { |
162 |
3 |
ListItem item2 = |
163 |
|
new ListItem(item.getId(), getDisplayValue(item.getId(), "", map, context), item.getParent()); |
164 |
3 |
treelist.add(item2); |
165 |
3 |
addToTreeList(treelist, treemap, map, item.getId(), context); |
166 |
|
} |
167 |
|
} |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
170 |
6 |
protected void addToList(Map<String, List<ListItem>> map, String key, ListItem item)... |
171 |
|
{ |
172 |
6 |
List<ListItem> list = map.get(key); |
173 |
6 |
if (list == null) { |
174 |
2 |
list = new ArrayList<ListItem>(); |
175 |
2 |
map.put(key, list); |
176 |
|
} |
177 |
6 |
list.add(item); |
178 |
|
} |
179 |
|
|
|
|
| 61.1% |
Uncovered Elements: 7 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
180 |
2 |
@Override... |
181 |
|
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, |
182 |
|
XWikiContext context) |
183 |
|
{ |
184 |
2 |
List<String> selectlist; |
185 |
2 |
BaseProperty prop = (BaseProperty) object.safeget(name); |
186 |
2 |
if (prop == null) { |
187 |
0 |
selectlist = new ArrayList<String>(); |
188 |
2 |
} else if (prop instanceof ListProperty) { |
189 |
2 |
selectlist = ((ListProperty) prop).getList(); |
190 |
|
} else { |
191 |
0 |
selectlist = new ArrayList<String>(); |
192 |
0 |
selectlist.add(String.valueOf(prop.getValue())); |
193 |
|
} |
194 |
2 |
String result = displayFlatView(selectlist, context); |
195 |
2 |
if (result.equals("")) { |
196 |
2 |
super.displayView(buffer, name, prefix, object, context); |
197 |
|
} else { |
198 |
0 |
buffer.append(result); |
199 |
|
} |
200 |
|
} |
201 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
202 |
0 |
@Override... |
203 |
|
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, |
204 |
|
XWikiContext context) |
205 |
|
{ |
206 |
0 |
BaseProperty prop = (BaseProperty) object.safeget(name); |
207 |
0 |
List<String> selectlist = toList(prop); |
208 |
|
|
209 |
0 |
if (isPicker()) { |
210 |
0 |
String result = displayTree(name, prefix, selectlist, "edit", context); |
211 |
0 |
if (result.equals("")) { |
212 |
0 |
displayTreeSelectEdit(buffer, name, prefix, object, context); |
213 |
|
} else { |
214 |
0 |
displayHidden(buffer, name, prefix, object, context); |
215 |
0 |
buffer.append(result); |
216 |
|
} |
217 |
|
} else { |
218 |
0 |
displayTreeSelectEdit(buffer, name, prefix, object, context); |
219 |
|
} |
220 |
|
} |
221 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
222 |
2 |
private String displayFlatView(List<String> selectlist, XWikiContext context)... |
223 |
|
{ |
224 |
2 |
Map<String, ListItem> map = getMap(context); |
225 |
2 |
Map<String, List<ListItem>> treemap = getTreeMap(context); |
226 |
2 |
List<ListItem> fullTreeList = getTreeList(treemap, map, context); |
227 |
2 |
List<List<ListItem>> resList = new ArrayList<List<ListItem>>(selectlist.size()); |
228 |
|
|
229 |
2 |
for (String item : selectlist) { |
230 |
3 |
List<ListItem> itemPath = getItemPath(item, fullTreeList, new ArrayList<ListItem>()); |
231 |
3 |
mergeItems(itemPath, resList); |
232 |
|
} |
233 |
|
|
234 |
2 |
return renderItemsList(resList); |
235 |
|
} |
236 |
|
|
|
|
| 21.1% |
Uncovered Elements: 15 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
237 |
2 |
protected String renderItemsList(List<List<ListItem>> resList)... |
238 |
|
{ |
239 |
2 |
StringBuffer buff = new StringBuffer(); |
240 |
|
|
241 |
2 |
for (int i = 0; i < resList.size(); i++) { |
242 |
0 |
List<ListItem> items = resList.get(i); |
243 |
0 |
for (int j = 0; j < items.size(); j++) { |
244 |
0 |
ListItem item = items.get(j); |
245 |
0 |
buff.append(item.getValue()); |
246 |
0 |
if (j < items.size() - 1) { |
247 |
0 |
buff.append(" > "); |
248 |
|
} |
249 |
|
} |
250 |
0 |
if (i < resList.size() - 1) { |
251 |
0 |
buff.append("<br />"); |
252 |
|
} |
253 |
|
} |
254 |
2 |
return buff.toString(); |
255 |
|
} |
256 |
|
|
|
|
| 12% |
Uncovered Elements: 22 (25) |
Complexity: 7 |
Complexity Density: 0.47 |
|
257 |
3 |
private void mergeItems(List<ListItem> itemPath, List<List<ListItem>> resList)... |
258 |
|
{ |
259 |
3 |
if (itemPath == null || itemPath.size() == 0) { |
260 |
3 |
return; |
261 |
|
} |
262 |
|
|
263 |
0 |
for (int i = 0; i < resList.size(); i++) { |
264 |
0 |
List<ListItem> items = resList.get(i); |
265 |
0 |
if (items.size() < itemPath.size()) { |
266 |
0 |
ListItem item1 = items.get(items.size() - 1); |
267 |
0 |
ListItem item2 = itemPath.get(items.size() - 1); |
268 |
0 |
if (item1.equals(item2)) { |
269 |
0 |
resList.set(i, itemPath); |
270 |
0 |
return; |
271 |
|
} |
272 |
|
} else { |
273 |
0 |
ListItem item1 = items.get(itemPath.size() - 1); |
274 |
0 |
ListItem item2 = itemPath.get(itemPath.size() - 1); |
275 |
0 |
if (item1.equals(item2)) { |
276 |
0 |
return; |
277 |
|
} |
278 |
|
} |
279 |
|
} |
280 |
0 |
resList.add(itemPath); |
281 |
|
} |
282 |
|
|
|
|
| 36.4% |
Uncovered Elements: 7 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
283 |
3 |
private List<ListItem> getItemPath(String item, List<ListItem> treeList, ArrayList<ListItem> resList)... |
284 |
|
{ |
285 |
3 |
for (ListItem tmpItem : treeList) { |
286 |
9 |
if (item.equals(tmpItem.getId())) { |
287 |
0 |
if (tmpItem.getParent().length() > 0) { |
288 |
0 |
getItemPath(tmpItem.getParent(), treeList, resList); |
289 |
|
} |
290 |
0 |
resList.add(tmpItem); |
291 |
0 |
return resList; |
292 |
|
} |
293 |
|
} |
294 |
3 |
return null; |
295 |
|
} |
296 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
297 |
0 |
private String displayTree(String name, String prefix, List<String> selectlist, String mode, XWikiContext context)... |
298 |
|
{ |
299 |
0 |
ScriptContextManager scriptManager = Utils.getComponent(ScriptContextManager.class); |
300 |
0 |
ScriptContext scontext = scriptManager.getCurrentScriptContext(); |
301 |
|
|
302 |
0 |
Map<String, ListItem> map = getMap(context); |
303 |
0 |
Map<String, List<ListItem>> treemap = getTreeMap(context); |
304 |
|
|
305 |
0 |
scontext.setAttribute("selectlist", selectlist, ScriptContext.ENGINE_SCOPE); |
306 |
0 |
scontext.setAttribute("fieldname", prefix + name, ScriptContext.ENGINE_SCOPE); |
307 |
0 |
scontext.setAttribute("tree", map, ScriptContext.ENGINE_SCOPE); |
308 |
0 |
scontext.setAttribute("treelist", getTreeList(treemap, map, context), ScriptContext.ENGINE_SCOPE); |
309 |
0 |
scontext.setAttribute("treemap", treemap, ScriptContext.ENGINE_SCOPE); |
310 |
0 |
scontext.setAttribute("mode", mode, ScriptContext.ENGINE_SCOPE); |
311 |
|
|
312 |
0 |
return context.getWiki().parseTemplate("treeview.vm", context); |
313 |
|
} |
314 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
315 |
0 |
protected void addToSelect(select select, List<String> selectlist, Map<String, ListItem> map,... |
316 |
|
Map<String, List<ListItem>> treemap, String parent, String level, XWikiContext context) |
317 |
|
{ |
318 |
0 |
List<ListItem> list = treemap.get(parent); |
319 |
0 |
if (list != null) { |
320 |
0 |
for (ListItem item : list) { |
321 |
0 |
String display = level + getDisplayValue(item.getId(), "", map, context); |
322 |
0 |
option option = new option(display, item.getId()); |
323 |
0 |
option.addElement(display); |
324 |
0 |
if (selectlist.contains(item.getId())) { |
325 |
0 |
option.setSelected(true); |
326 |
|
} |
327 |
0 |
select.addElement(option); |
328 |
0 |
addToSelect(select, selectlist, map, treemap, item.getId(), level + "\u00A0", context); |
329 |
|
} |
330 |
|
} |
331 |
|
} |
332 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 3 |
Complexity Density: 0.16 |
|
333 |
0 |
protected void displayTreeSelectEdit(StringBuffer buffer, String name, String prefix, BaseCollection object,... |
334 |
|
XWikiContext context) |
335 |
|
{ |
336 |
0 |
select select = new select(prefix + name, 1); |
337 |
0 |
select.setAttributeFilter(new XMLAttributeValueFilter()); |
338 |
0 |
select.setMultiple(isMultiSelect()); |
339 |
0 |
select.setSize(getSize()); |
340 |
0 |
select.setName(prefix + name); |
341 |
0 |
select.setID(prefix + name); |
342 |
0 |
select.setDisabled(isDisabled()); |
343 |
|
|
344 |
0 |
Map<String, ListItem> map = getMap(context); |
345 |
0 |
Map<String, List<ListItem>> treemap = getTreeMap(context); |
346 |
0 |
List<String> selectlist; |
347 |
|
|
348 |
0 |
BaseProperty prop = (BaseProperty) object.safeget(name); |
349 |
0 |
if (prop == null) { |
350 |
0 |
selectlist = new ArrayList<String>(); |
351 |
0 |
} else if (prop instanceof ListProperty) { |
352 |
0 |
selectlist = ((ListProperty) prop).getList(); |
353 |
|
} else { |
354 |
0 |
selectlist = new ArrayList<String>(); |
355 |
0 |
selectlist.add(String.valueOf(prop.getValue())); |
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
0 |
addToSelect(select, selectlist, map, treemap, "", "", context); |
360 |
0 |
buffer.append(select.toString()); |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
@param@link |
387 |
|
@return |
388 |
|
|
|
|
| 98.3% |
Uncovered Elements: 2 (120) |
Complexity: 34 |
Complexity Density: 0.46 |
|
389 |
57 |
@Override... |
390 |
|
public String getQuery(XWikiContext context) |
391 |
|
{ |
392 |
|
|
393 |
57 |
String sql = getSql(); |
394 |
|
|
395 |
|
|
396 |
57 |
if (StringUtils.isBlank(sql)) { |
397 |
55 |
if (context.getWiki().getHibernateStore() != null) { |
398 |
|
|
399 |
55 |
String classname = StringUtils.defaultString(getClassname()); |
400 |
55 |
String idField = StringUtils.defaultString(getIdField()); |
401 |
55 |
String valueField = StringUtils.defaultString(getValueField()); |
402 |
55 |
String parentField = StringUtils.defaultString(getParentField()); |
403 |
|
|
404 |
|
|
405 |
55 |
boolean hasClassname = !StringUtils.isBlank(classname); |
406 |
55 |
boolean hasIdField = !StringUtils.isBlank(idField); |
407 |
55 |
boolean hasValueField = !StringUtils.isBlank(valueField); |
408 |
55 |
boolean hasParentField = !StringUtils.isBlank(parentField); |
409 |
|
|
410 |
55 |
if (!(hasIdField || hasValueField)) { |
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
3 |
if (hasClassname) { |
416 |
2 |
sql = "select distinct doc.fullName, doc.fullName, " |
417 |
2 |
+ (hasParentField ? parentField : "doc.parent") |
418 |
|
+ " from XWikiDocument as doc, BaseObject as obj" |
419 |
|
+ " where doc.fullName=obj.name and obj.className='" + classname + "'"; |
420 |
|
} else { |
421 |
|
|
422 |
|
|
423 |
1 |
sql = DEFAULT_QUERY; |
424 |
|
} |
425 |
3 |
return sql; |
426 |
|
} |
427 |
|
|
428 |
|
|
429 |
52 |
if (!hasIdField && hasValueField) { |
430 |
1 |
idField = valueField; |
431 |
51 |
} else if (hasIdField && !hasValueField) { |
432 |
26 |
valueField = idField; |
433 |
|
} |
434 |
|
|
435 |
|
|
436 |
52 |
if (!hasParentField) { |
437 |
24 |
parentField = "doc.parent"; |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
|
|
442 |
|
|
443 |
52 |
boolean usesObj = hasClassname || idField.startsWith("obj.") || valueField.startsWith("obj.") |
444 |
|
|| parentField.startsWith("obj."); |
445 |
|
|
446 |
|
|
447 |
|
|
448 |
52 |
boolean usesDoc = |
449 |
|
idField.startsWith("doc.") || valueField.startsWith("doc.") || parentField.startsWith("doc."); |
450 |
52 |
if ((!idField.startsWith("obj.") || !valueField.startsWith("obj.") || !parentField.startsWith("obj.")) |
451 |
|
&& !hasClassname) { |
452 |
27 |
usesDoc = true; |
453 |
|
} |
454 |
|
|
455 |
|
|
456 |
52 |
StringBuffer select = new StringBuffer("select distinct "); |
457 |
|
|
458 |
52 |
ArrayList<String> fromStatements = new ArrayList<String>(); |
459 |
52 |
ArrayList<String> whereStatements = new ArrayList<String>(); |
460 |
|
|
461 |
|
|
462 |
52 |
if (usesDoc) { |
463 |
41 |
fromStatements.add("XWikiDocument as doc"); |
464 |
41 |
if (usesObj) { |
465 |
26 |
whereStatements.add("doc.fullName=obj.name"); |
466 |
|
} |
467 |
|
} |
468 |
|
|
469 |
52 |
if (usesObj) { |
470 |
37 |
fromStatements.add("BaseObject as obj"); |
471 |
37 |
if (hasClassname) { |
472 |
23 |
whereStatements.add("obj.className='" + classname + "'"); |
473 |
|
} |
474 |
|
} |
475 |
|
|
476 |
|
|
477 |
52 |
if (idField.startsWith("doc.") || idField.startsWith("obj.")) { |
478 |
32 |
select.append(idField); |
479 |
20 |
} else if (!hasClassname) { |
480 |
9 |
select.append("doc." + idField); |
481 |
|
} else { |
482 |
11 |
select.append("idprop.value"); |
483 |
11 |
fromStatements.add("StringProperty as idprop"); |
484 |
11 |
whereStatements.add("obj.id=idprop.id.id and idprop.id.name='" + idField + "'"); |
485 |
|
} |
486 |
|
|
487 |
|
|
488 |
52 |
if (valueField.startsWith("doc.") || valueField.startsWith("obj.")) { |
489 |
31 |
select.append(", ").append(valueField); |
490 |
21 |
} else if (!hasClassname) { |
491 |
9 |
select.append(", doc." + valueField); |
492 |
|
} else { |
493 |
12 |
if (valueField.equals(idField)) { |
494 |
7 |
select.append(", idprop.value"); |
495 |
|
} else { |
496 |
5 |
select.append(", valueprop.value"); |
497 |
5 |
fromStatements.add("StringProperty as valueprop"); |
498 |
5 |
whereStatements.add("obj.id=valueprop.id.id and valueprop.id.name='" + valueField + "'"); |
499 |
|
} |
500 |
|
} |
501 |
|
|
502 |
|
|
503 |
52 |
if (parentField.startsWith("doc.") || parentField.startsWith("obj.")) { |
504 |
40 |
select.append(", ").append(parentField); |
505 |
12 |
} else if (!hasClassname) { |
506 |
4 |
select.append(", doc." + parentField); |
507 |
|
} else { |
508 |
8 |
if (parentField.equals(idField)) { |
509 |
3 |
select.append(", idprop.value"); |
510 |
5 |
} else if (parentField.equals(valueField)) { |
511 |
1 |
select.append(", valueprop.value"); |
512 |
|
} else { |
513 |
4 |
select.append(", parentprop.value"); |
514 |
4 |
fromStatements.add("StringProperty as parentprop"); |
515 |
4 |
whereStatements.add("obj.id=parentprop.id.id and parentprop.id.name='" + parentField + "'"); |
516 |
|
} |
517 |
|
} |
518 |
|
|
519 |
52 |
select.append(" from "); |
520 |
52 |
select.append(StringUtils.join(fromStatements.iterator(), ", ")); |
521 |
52 |
if (whereStatements.size() > 0) { |
522 |
35 |
select.append(" where "); |
523 |
35 |
select.append(StringUtils.join(whereStatements.iterator(), " and ")); |
524 |
|
} |
525 |
52 |
sql = select.toString(); |
526 |
|
} else { |
527 |
|
|
528 |
|
|
529 |
|
} |
530 |
|
} |
531 |
|
|
532 |
|
|
533 |
54 |
try { |
534 |
54 |
sql = context.getWiki().parseContent(sql, context); |
535 |
|
} catch (Exception e) { |
536 |
0 |
LOGGER.error("Failed to parse SQL script [" + sql + "]. Continuing with non-rendered script.", e); |
537 |
|
} |
538 |
54 |
return sql; |
539 |
|
} |
540 |
|
} |