1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.store.wiki.internal.query; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.xwiki.crypto.BinaryStringEncoder; |
26 |
|
import org.xwiki.crypto.store.CertificateStoreException; |
27 |
|
import org.xwiki.model.EntityType; |
28 |
|
import org.xwiki.model.reference.EntityReference; |
29 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
30 |
|
import org.xwiki.query.Query; |
31 |
|
import org.xwiki.query.QueryException; |
32 |
|
import org.xwiki.query.QueryManager; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
|
|
| 75% |
Uncovered Elements: 13 (52) |
Complexity: 16 |
Complexity Density: 0.52 |
|
40 |
|
public abstract class AbstractX509StoreQuery |
41 |
|
{ |
42 |
|
private static final String FROM_STATEMENT = " from Document doc"; |
43 |
|
|
44 |
|
private static final String WHERE_STATEMENT = " where 1=1"; |
45 |
|
|
46 |
|
private static final String STORE = "store"; |
47 |
|
|
48 |
|
private static final String WHERE_SPACE_STATEMENT = " where doc.space=:" + STORE; |
49 |
|
|
50 |
|
private static final String WHERE_DOC_STATEMENT = " where doc.fullName=:" + STORE; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
private final BinaryStringEncoder encoder; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
private Query query; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
@param |
67 |
|
@param |
68 |
|
@param |
69 |
|
@param |
70 |
|
@param |
71 |
|
@param |
72 |
|
@throws |
73 |
|
|
|
|
| 77.4% |
Uncovered Elements: 7 (31) |
Complexity: 8 |
Complexity Density: 0.38 |
|
74 |
38 |
public AbstractX509StoreQuery(EntityReference store, String select, String from, String where,... |
75 |
|
BinaryStringEncoder encoder, QueryManager queryManager, EntityReferenceSerializer<String> serializer) |
76 |
|
throws CertificateStoreException |
77 |
|
{ |
78 |
38 |
EntityReference wiki = null; |
79 |
38 |
EntityType storeType = null; |
80 |
|
|
81 |
38 |
if (store != null) { |
82 |
38 |
wiki = store.extractReference(EntityType.WIKI); |
83 |
38 |
storeType = getEntityType(store); |
84 |
|
} |
85 |
|
|
86 |
38 |
if (wiki == null || storeType == null) { |
87 |
0 |
throw new IllegalArgumentException("Certificate could only be queried from wiki, space, or document."); |
88 |
|
} |
89 |
|
|
90 |
38 |
this.encoder = encoder; |
91 |
|
|
92 |
38 |
String statement = select + FROM_STATEMENT + from; |
93 |
|
|
94 |
38 |
if (storeType != EntityType.WIKI) { |
95 |
38 |
if (storeType == EntityType.DOCUMENT) { |
96 |
18 |
statement += WHERE_DOC_STATEMENT; |
97 |
|
} else { |
98 |
20 |
statement += WHERE_SPACE_STATEMENT; |
99 |
|
} |
100 |
|
} else { |
101 |
0 |
statement += WHERE_STATEMENT; |
102 |
|
} |
103 |
|
|
104 |
38 |
statement += where; |
105 |
|
|
106 |
38 |
try { |
107 |
38 |
this.query = queryManager.createQuery(statement, Query.XWQL); |
108 |
|
} catch (QueryException e) { |
109 |
0 |
throw new CertificateStoreException(e); |
110 |
|
} |
111 |
|
|
112 |
38 |
this.query.setWiki(wiki.getName()); |
113 |
|
|
114 |
38 |
if (storeType != EntityType.WIKI) { |
115 |
38 |
this.query.bindValue(STORE, serializer.serialize(store)); |
116 |
|
} |
117 |
|
} |
118 |
|
|
|
|
| 53.8% |
Uncovered Elements: 6 (13) |
Complexity: 5 |
Complexity Density: 0.71 |
|
119 |
38 |
private EntityType getEntityType(EntityReference store)... |
120 |
|
{ |
121 |
38 |
if (store.getType() == EntityType.DOCUMENT && store.getParent() != null) { |
122 |
18 |
return EntityType.DOCUMENT; |
123 |
|
} |
124 |
20 |
if (store.getType() == EntityType.SPACE) { |
125 |
20 |
return EntityType.SPACE; |
126 |
|
} |
127 |
0 |
if (store.getType() == EntityType.WIKI) { |
128 |
0 |
return EntityType.WIKI; |
129 |
|
} |
130 |
0 |
return null; |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
@return |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
26 |
protected Query getQuery()... |
137 |
|
{ |
138 |
26 |
return this.query; |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
@return |
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
28 |
protected BinaryStringEncoder getEncoder()... |
145 |
|
{ |
146 |
28 |
return this.encoder; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
@return |
153 |
|
@throws |
154 |
|
@throws |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
2 |
protected <T> List<T> execute() throws IOException, QueryException... |
157 |
|
{ |
158 |
2 |
return getQuery().execute(); |
159 |
|
} |
160 |
|
} |