1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.index.tree.internal.parentchild; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import javax.inject.Inject; |
29 |
|
import javax.inject.Named; |
30 |
|
import javax.inject.Singleton; |
31 |
|
|
32 |
|
import org.apache.commons.lang3.StringUtils; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
import org.xwiki.model.reference.DocumentReference; |
35 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
36 |
|
import org.xwiki.model.reference.EntityReference; |
37 |
|
import org.xwiki.query.Query; |
38 |
|
import org.xwiki.query.QueryException; |
39 |
|
import org.xwiki.query.QueryFilter; |
40 |
|
import org.xwiki.query.QueryManager; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
@since |
48 |
|
|
49 |
|
@Component(roles = DocumentQueryHelper.class) |
50 |
|
@Singleton |
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 4 |
Complexity Density: 0.15 |
|
51 |
|
public class DocumentQueryHelper |
52 |
|
{ |
53 |
|
@Inject |
54 |
|
@Named("explicit") |
55 |
|
private DocumentReferenceResolver<String> explicitDocumentReferenceResolver; |
56 |
|
|
57 |
|
@Inject |
58 |
|
@Named("hidden/document") |
59 |
|
private QueryFilter hiddenDocumentQueryFilter; |
60 |
|
|
61 |
|
@Inject |
62 |
|
private QueryManager queryManager; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@param |
68 |
|
@param |
69 |
|
@param |
70 |
|
@return |
71 |
|
@throws |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 3 |
Complexity Density: 0.14 |
|
73 |
0 |
public Query getQuery(List<String> constraints, Map<String, Object> parameters, Map<String, Object> config)... |
74 |
|
throws QueryException |
75 |
|
{ |
76 |
0 |
String fromClause = ""; |
77 |
0 |
List<String> finalConstraints = new ArrayList<String>(); |
78 |
0 |
Map<String, Object> finalParameters = new HashMap<String, Object>(); |
79 |
0 |
String xclass = (String) config.get("filterByClass"); |
80 |
0 |
if (!StringUtils.isEmpty(xclass)) { |
81 |
0 |
fromClause = ", BaseObject as obj"; |
82 |
0 |
finalConstraints.add("obj.name = doc.fullName"); |
83 |
0 |
finalConstraints.add("obj.className = :class"); |
84 |
0 |
finalConstraints.add("doc.fullName <> :template"); |
85 |
0 |
finalParameters.put("class", xclass); |
86 |
0 |
finalParameters.put("template", StringUtils.removeEnd(xclass, "Class") + "Template"); |
87 |
|
} |
88 |
0 |
finalConstraints.addAll(constraints); |
89 |
0 |
finalParameters.putAll(parameters); |
90 |
0 |
String whereClause = "where " + StringUtils.join(finalConstraints, " and "); |
91 |
0 |
String statement = |
92 |
|
StringUtils.join(Arrays.asList(fromClause, whereClause, "order by lower(doc.name), doc.name"), ' '); |
93 |
0 |
Query query = this.queryManager.createQuery(statement, Query.HQL); |
94 |
0 |
for (Map.Entry<String, Object> entry : finalParameters.entrySet()) { |
95 |
0 |
query.bindValue(entry.getKey(), entry.getValue()); |
96 |
|
} |
97 |
0 |
if (Boolean.TRUE.equals(config.get("filterHiddenDocuments"))) { |
98 |
0 |
query.addFilter(this.hiddenDocumentQueryFilter); |
99 |
|
} |
100 |
0 |
return query; |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
@link |
105 |
|
|
106 |
|
@param@link |
107 |
|
@param |
108 |
|
@param |
109 |
|
@param |
110 |
|
@return |
111 |
|
@throws |
112 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
113 |
0 |
public List<DocumentReference> resolve(Query query, int offset, int limit, EntityReference parentReference)... |
114 |
|
throws QueryException |
115 |
|
{ |
116 |
0 |
query.setOffset(offset); |
117 |
0 |
query.setLimit(limit); |
118 |
0 |
List<DocumentReference> documentReferences = new ArrayList<DocumentReference>(); |
119 |
0 |
for (Object result : query.execute()) { |
120 |
0 |
documentReferences.add(this.explicitDocumentReferenceResolver.resolve((String) result, parentReference)); |
121 |
|
} |
122 |
0 |
return documentReferences; |
123 |
|
} |
124 |
|
} |