MtasSolrCollectionResult.java.html
19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasSolrCollectionResult.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.solr.handler.component.util</a> > <span class="el_source">MtasSolrCollectionResult.java</span></div><h1>MtasSolrCollectionResult.java</h1><pre class="source lang-java linenums">package mtas.solr.handler.component.util;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import org.apache.solr.common.util.SimpleOrderedMap;
import mtas.codec.util.CodecComponent.ComponentCollection;
import mtas.solr.handler.component.MtasSolrSearchComponent;
/**
* The Class MtasSolrCollectionResult.
*/
public class MtasSolrCollectionResult implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The values. */
private HashSet<String> values;
/** The id. */
private String id;
/** The action. */
private String action;
/** The now. */
private Long now;
/** The list. */
private List<SimpleOrderedMap<Object>> list;
/** The status. */
public SimpleOrderedMap<Object> status;
/** The component collection. */
<span class="fc" id="L43"> private transient ComponentCollection componentCollection = null;</span>
/**
* Instantiates a new mtas solr collection result.
*
* @param componentCollection the component collection
* @throws IOException Signals that an I/O exception has occurred.
*/
<span class="fc" id="L51"> public MtasSolrCollectionResult(ComponentCollection componentCollection)</span>
throws IOException {
<span class="fc" id="L53"> this.componentCollection = componentCollection;</span>
<span class="pc bpc" id="L54" title="1 of 2 branches missed."> if (componentCollection != null) {</span>
<span class="fc" id="L55"> action = componentCollection.action();</span>
<span class="fc" id="L56"> id = null;</span>
<span class="fc" id="L57"> values = null;</span>
<span class="fc" id="L58"> now = null;</span>
<span class="fc" id="L59"> list = null;</span>
<span class="pc bpc" id="L60" title="15 of 25 branches missed."> switch (action) {</span>
case ComponentCollection.ACTION_CREATE:
<span class="fc" id="L62"> values = componentCollection.values();</span>
<span class="fc" id="L63"> id = componentCollection.id;</span>
<span class="fc" id="L64"> break;</span>
case ComponentCollection.ACTION_CHECK:
case ComponentCollection.ACTION_GET:
case ComponentCollection.ACTION_DELETE:
<span class="fc" id="L68"> id = componentCollection.id;</span>
<span class="fc" id="L69"> break;</span>
case ComponentCollection.ACTION_POST:
case ComponentCollection.ACTION_IMPORT:
<span class="fc" id="L72"> id = componentCollection.id;</span>
<span class="fc" id="L73"> values = componentCollection.values();</span>
<span class="fc" id="L74"> break;</span>
case ComponentCollection.ACTION_LIST:
case ComponentCollection.ACTION_EMPTY:
// do nothing
break;
default:
<span class="nc" id="L80"> throw new IOException("action " + action + " not allowed");</span>
}
<span class="nc" id="L82"> } else {</span>
<span class="nc" id="L83"> throw new IOException("no componentCollection available");</span>
}
<span class="fc" id="L85"> }</span>
/**
* Sets the list.
*
* @param now the now
* @param list the list
* @throws IOException Signals that an I/O exception has occurred.
*/
public void setList(long now, List<SimpleOrderedMap<Object>> list)
throws IOException {
<span class="pc bpc" id="L96" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_LIST)) {</span>
<span class="fc" id="L97"> this.now = now;</span>
<span class="fc" id="L98"> this.list = list;</span>
<span class="fc" id="L99"> } else {</span>
<span class="nc" id="L100"> throw new IOException("not allowed with action '" + action + "'");</span>
}
<span class="fc" id="L102"> }</span>
/**
* Sets the check.
*
* @param now the now
* @param status the status
* @throws IOException Signals that an I/O exception has occurred.
*/
public void setCheck(long now, SimpleOrderedMap<Object> status)
throws IOException {
<span class="pc bpc" id="L113" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_CHECK)) {</span>
<span class="fc" id="L114"> this.now = now;</span>
<span class="fc" id="L115"> this.status = status;</span>
<span class="fc" id="L116"> } else {</span>
<span class="nc" id="L117"> throw new IOException("not allowed with action '" + action + "'");</span>
}
<span class="fc" id="L119"> }</span>
/**
* Sets the get.
*
* @param now the now
* @param status the status
* @param stringValues the string values
* @throws IOException Signals that an I/O exception has occurred.
*/
public void setGet(long now, SimpleOrderedMap<Object> status,
HashSet<String> stringValues) throws IOException {
<span class="nc bnc" id="L131" title="All 2 branches missed."> if (action.equals(ComponentCollection.ACTION_GET)) {</span>
<span class="nc" id="L132"> this.now = now;</span>
<span class="nc" id="L133"> this.status = status;</span>
<span class="nc" id="L134"> this.values = stringValues;</span>
<span class="nc" id="L135"> } else {</span>
<span class="nc" id="L136"> throw new IOException("not allowed with action '" + action + "'");</span>
}
<span class="nc" id="L138"> }</span>
/**
* Sets the post.
*
* @param now the now
* @param status the status
* @throws IOException Signals that an I/O exception has occurred.
*/
public void setPost(long now, SimpleOrderedMap<Object> status)
throws IOException {
<span class="pc bpc" id="L149" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_POST)) {</span>
<span class="fc" id="L150"> this.now = now;</span>
<span class="fc" id="L151"> this.status = status;</span>
<span class="fc" id="L152"> } else {</span>
<span class="nc" id="L153"> throw new IOException("not allowed with action '" + action + "'");</span>
}
<span class="fc" id="L155"> }</span>
/**
* Sets the import.
*
* @param now the now
* @param status the status
* @throws IOException Signals that an I/O exception has occurred.
*/
public void setImport(long now, SimpleOrderedMap<Object> status)
throws IOException {
<span class="nc bnc" id="L166" title="All 2 branches missed."> if (action.equals(ComponentCollection.ACTION_IMPORT)) {</span>
<span class="nc" id="L167"> this.now = now;</span>
<span class="nc" id="L168"> this.status = status;</span>
<span class="nc" id="L169"> } else {</span>
<span class="nc" id="L170"> throw new IOException("not allowed with action '" + action + "'");</span>
}
<span class="nc" id="L172"> }</span>
/**
* Sets the create.
*
* @param now the now
* @param status the status
* @throws IOException Signals that an I/O exception has occurred.
*/
public void setCreate(long now, SimpleOrderedMap<Object> status)
throws IOException {
<span class="pc bpc" id="L183" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_CREATE)) {</span>
<span class="fc" id="L184"> this.now = now;</span>
<span class="fc" id="L185"> this.status = status;</span>
<span class="fc" id="L186"> } else {</span>
<span class="nc" id="L187"> throw new IOException("not allowed with action '" + action + "'");</span>
}
<span class="fc" id="L189"> }</span>
/**
* Id.
*
* @return the string
*/
public String id() {
<span class="fc" id="L197"> return id;</span>
}
/**
* Action.
*
* @return the string
*/
public String action() {
<span class="fc" id="L206"> return action;</span>
}
/**
* Rewrite.
*
* @param searchComponent the search component
* @return the simple ordered map
* @throws IOException Signals that an I/O exception has occurred.
*/
public SimpleOrderedMap<Object> rewrite(
MtasSolrSearchComponent searchComponent) throws IOException {
<span class="fc" id="L218"> SimpleOrderedMap<Object> response = new SimpleOrderedMap<>();</span>
Iterator<Entry<String, Object>> it;
<span class="pc bpc" id="L220" title="10 of 19 branches missed."> switch (action) {</span>
case ComponentCollection.ACTION_LIST:
<span class="fc" id="L222"> response.add("now", now);</span>
<span class="fc" id="L223"> response.add("list", list);</span>
<span class="fc" id="L224"> break;</span>
case ComponentCollection.ACTION_CREATE:
case ComponentCollection.ACTION_POST:
case ComponentCollection.ACTION_IMPORT:
<span class="pc bpc" id="L228" title="2 of 4 branches missed."> if (componentCollection != null && status != null) {</span>
<span class="fc" id="L229"> it = status.iterator();</span>
<span class="fc bfc" id="L230" title="All 2 branches covered."> while (it.hasNext()) {</span>
<span class="fc" id="L231"> Entry<String, Object> entry = it.next();</span>
<span class="fc" id="L232"> response.add(entry.getKey(), entry.getValue());</span>
}
}
<span class="fc" id="L235"> break;</span>
case ComponentCollection.ACTION_CHECK:
<span class="fc bfc" id="L237" title="All 2 branches covered."> if (status != null) {</span>
<span class="fc" id="L238"> it = status.iterator();</span>
<span class="fc bfc" id="L239" title="All 2 branches covered."> while (it.hasNext()) {</span>
<span class="fc" id="L240"> Entry<String, Object> entry = it.next();</span>
<span class="fc" id="L241"> response.add(entry.getKey(), entry.getValue());</span>
}
}
<span class="fc" id="L244"> break;</span>
case ComponentCollection.ACTION_GET:
<span class="nc bnc" id="L246" title="All 2 branches missed."> if (status != null) {</span>
<span class="nc" id="L247"> it = status.iterator();</span>
<span class="nc bnc" id="L248" title="All 2 branches missed."> while (it.hasNext()) {</span>
<span class="nc" id="L249"> Entry<String, Object> entry = it.next();</span>
<span class="nc" id="L250"> response.add(entry.getKey(), entry.getValue());</span>
}
}
<span class="nc bnc" id="L253" title="All 2 branches missed."> if (values != null) {</span>
<span class="nc" id="L254"> response.add("values", values);</span>
}
<span class="nc" id="L256"> break;</span>
default:
break;
}
<span class="fc" id="L260"> return response;</span>
}
/**
* Merge.
*
* @param newItem the new item
* @throws IOException Signals that an I/O exception has occurred.
*/
public void merge(MtasSolrCollectionResult newItem) throws IOException {
<span class="pc bpc" id="L270" title="2 of 4 branches missed."> if (action != null && newItem.action != null) {</span>
<span class="fc bfc" id="L271" title="All 2 branches covered."> if (action.equals(ComponentCollection.ACTION_CREATE)</span>
<span class="fc bfc" id="L272" title="All 2 branches covered."> && newItem.action.equals(ComponentCollection.ACTION_CREATE)) {</span>
<span class="fc" id="L273"> values.addAll(newItem.values);</span>
<span class="pc bpc" id="L274" title="3 of 6 branches missed."> if (id != null && (newItem.id == null || !newItem.id.equals(id))) {</span>
<span class="nc" id="L275"> id = null;</span>
}
<span class="pc bfc" id="L277" title="All 2 branches covered."> } else if (action.equals(ComponentCollection.ACTION_LIST)) {</span>
<span class="pc bpc" id="L278" title="1 of 2 branches missed."> if (list != null) {</span>
<span class="fc" id="L279"> HashMap<String, SimpleOrderedMap<Object>> index = new HashMap<>();</span>
<span class="fc bfc" id="L280" title="All 2 branches covered."> for (SimpleOrderedMap<Object> item : list) {</span>
<span class="pc bpc" id="L281" title="2 of 4 branches missed."> if (item.get("id") != null && item.get("id") instanceof String) {</span>
<span class="fc" id="L282"> index.put((String) item.get("id"), item);</span>
<span class="fc bfc" id="L283" title="All 2 branches covered."> if (item.get("shards") == null</span>
<span class="pc bpc" id="L284" title="1 of 2 branches missed."> || !(item.get("shards") instanceof List)) {</span>
<span class="fc" id="L285"> item.add("shards", new ArrayList<>());</span>
}
}
}
<span class="fc bfc" id="L289" title="All 2 branches covered."> for (SimpleOrderedMap<Object> item : newItem.list) {</span>
<span class="pc bpc" id="L290" title="2 of 4 branches missed."> if (item.get("id") != null && item.get("id") instanceof String) {</span>
<span class="fc" id="L291"> String id = (String) item.get("id");</span>
<span class="pc bpc" id="L292" title="1 of 2 branches missed."> if (index.containsKey(id)) {</span>
<span class="fc" id="L293"> SimpleOrderedMap<Object> indexItem = index.get(id);</span>
List<SimpleOrderedMap<Object>> shards;
<span class="pc bpc" id="L295" title="1 of 2 branches missed."> if (indexItem.get("shards") != null</span>
<span class="pc bpc" id="L296" title="1 of 2 branches missed."> && indexItem.get("shards") instanceof List) {</span>
<span class="fc" id="L297"> shards = (List<SimpleOrderedMap<Object>>) indexItem</span>
<span class="fc" id="L298"> .get("shards");</span>
<span class="fc" id="L299"> } else {</span>
<span class="nc" id="L300"> shards = new ArrayList<>();</span>
<span class="nc" id="L301"> indexItem.add("shards", shards);</span>
}
<span class="fc" id="L303"> shards.add(item);</span>
}
}
}
}
<span class="fc bfc" id="L308" title="All 2 branches covered."> } else if (action.equals(ComponentCollection.ACTION_CHECK)</span>
<span class="fc bfc" id="L309" title="All 2 branches covered."> || action.equals(ComponentCollection.ACTION_POST)</span>
<span class="pc bpc" id="L310" title="1 of 2 branches missed."> || action.equals(ComponentCollection.ACTION_IMPORT)</span>
<span class="fc bfc" id="L311" title="All 2 branches covered."> || action.equals(ComponentCollection.ACTION_CREATE)</span>
<span class="pc bpc" id="L312" title="1 of 2 branches missed."> || action.equals(ComponentCollection.ACTION_GET)) {</span>
<span class="pc bpc" id="L313" title="1 of 4 branches missed."> if (status != null && status.get("id") != null</span>
<span class="pc bpc" id="L314" title="1 of 2 branches missed."> && status.get("id") instanceof String) {</span>
<span class="fc" id="L315"> String id = (String) status.get("id");</span>
<span class="pc bpc" id="L316" title="1 of 2 branches missed."> if (id.equals(newItem.id)) {</span>
List<SimpleOrderedMap<Object>> shards;
<span class="fc bfc" id="L318" title="All 2 branches covered."> if (status.get("shards") != null</span>
<span class="pc bpc" id="L319" title="1 of 2 branches missed."> && status.get("shards") instanceof List) {</span>
<span class="fc" id="L320"> shards = (List<SimpleOrderedMap<Object>>) status.get("shards");</span>
<span class="fc" id="L321"> } else {</span>
<span class="fc" id="L322"> shards = new ArrayList<>();</span>
<span class="fc" id="L323"> status.add("shards", shards);</span>
}
<span class="fc bfc" id="L325" title="All 2 branches covered."> if (newItem.status != null) {</span>
<span class="pc bpc" id="L326" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_GET)) {</span>
<span class="nc" id="L327"> newItem.status.add("values", newItem.values);</span>
}
<span class="fc" id="L329"> shards.add(newItem.status);</span>
}
}
}
<span class="fc" id="L333"> } else {</span>
<span class="fc" id="L334"> throw new IOException("not allowed for action '" + action + "'");</span>
}
}
<span class="fc" id="L337"> }</span>
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
<span class="nc" id="L346"> StringBuilder text = new StringBuilder("");</span>
<span class="nc" id="L347"> text.append(MtasSolrCollectionResult.class.getSimpleName() + "[");</span>
<span class="nc" id="L348"> text.append(action + ", ");</span>
<span class="nc" id="L349"> text.append(id + ", ");</span>
<span class="nc bnc" id="L350" title="All 2 branches missed."> if (componentCollection != null) {</span>
<span class="nc" id="L351"> text.append(componentCollection.version + ", ");</span>
<span class="nc bnc" id="L352" title="All 2 branches missed."> } else if (status != null) {</span>
<span class="nc" id="L353"> text.append(status.get("version") + ", ");</span>
<span class="nc" id="L354"> } else {</span>
<span class="nc" id="L355"> text.append("null, ");</span>
}
<span class="nc bnc" id="L357" title="All 2 branches missed."> text.append((values != null) ? values.size() : "null");</span>
<span class="nc" id="L358"> text.append("]");</span>
<span class="nc" id="L359"> return text.toString();</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>