MtasSolrMtasResult.java.html
22.8 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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?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>MtasSolrMtasResult.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">MtasSolrMtasResult.java</span></div><h1>MtasSolrMtasResult.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.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import mtas.codec.util.DataCollector;
import mtas.codec.util.collector.MtasDataCollector;
import mtas.codec.util.collector.MtasDataCollectorResult;
import mtas.codec.util.collector.MtasDataItem;
/**
* The Class MtasSolrMtasResult.
*/
public class MtasSolrMtasResult implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The data type. */
public String dataType;
/** The stats type. */
public String statsType;
/** The stats items. */
public SortedSet<String> statsItems;
/** The sort type. */
public String sortType;
/** The sort direction. */
public String sortDirection;
/** The start. */
public Integer start;
/** The number. */
public Integer number;
/** The data collector. */
<span class="fc" id="L48"> public MtasDataCollector<?, ?> dataCollector = null;</span>
/** The function data. */
public Map<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData;
/** The sub data type. */
private String[] subDataType;
/** The sub stats type. */
private String[] subStatsType;
/** The sub stats items. */
private SortedSet<String>[] subStatsItems;
/** The sub sort type. */
private String[] subSortType;
/** The sub sort direction. */
private String[] subSortDirection;
/** The sub start. */
private Integer[] subStart;
/** The sub number. */
private Integer[] subNumber;
/**
* Instantiates a new mtas solr mtas result.
*
* @param dataCollector the data collector
* @param dataType the data type
* @param statsType the stats type
* @param statsItems the stats items
* @param sortType the sort type
* @param sortDirection the sort direction
* @param start the start
* @param number the number
* @param functionData the function data
*/
@SuppressWarnings("unchecked")
public MtasSolrMtasResult(MtasDataCollector<?, ?> dataCollector,
String[] dataType, String[] statsType, SortedSet<String>[] statsItems,
String[] sortType, String[] sortDirection, Integer[] start,
Integer[] number,
<span class="fc" id="L92"> Map<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData) {</span>
<span class="fc" id="L93"> this.dataCollector = dataCollector;</span>
<span class="fc" id="L94"> this.functionData = functionData;</span>
<span class="pc bpc" id="L95" title="1 of 2 branches missed."> this.dataType = (dataType == null) ? null : dataType[0];</span>
<span class="pc bpc" id="L96" title="1 of 2 branches missed."> this.statsType = (statsType == null) ? null : statsType[0];</span>
<span class="pc bpc" id="L97" title="1 of 2 branches missed."> this.statsItems = (statsItems == null) ? null : statsItems[0];</span>
<span class="pc bpc" id="L98" title="1 of 2 branches missed."> this.sortType = (sortType == null) ? null : sortType[0];</span>
<span class="pc bpc" id="L99" title="1 of 2 branches missed."> this.sortDirection = (sortDirection == null) ? null : sortDirection[0];</span>
<span class="pc bpc" id="L100" title="1 of 2 branches missed."> this.start = (start == null) ? null : start[0];</span>
<span class="pc bpc" id="L101" title="1 of 2 branches missed."> this.number = (number == null) ? null : number[0];</span>
<span class="fc" id="L102"> this.subStart = null;</span>
<span class="fc" id="L103"> this.subNumber = null;</span>
<span class="pc bpc" id="L104" title="2 of 4 branches missed."> if ((dataType != null) && (dataType.length > 1)) {</span>
<span class="nc" id="L105"> subDataType = new String[dataType.length - 1];</span>
<span class="nc" id="L106"> subStatsType = new String[dataType.length - 1];</span>
<span class="nc" id="L107"> subStatsItems = new TreeSet[dataType.length - 1];</span>
<span class="nc" id="L108"> subSortType = new String[dataType.length - 1];</span>
<span class="nc" id="L109"> subSortDirection = new String[dataType.length - 1];</span>
<span class="nc" id="L110"> System.arraycopy(dataType, 1, subDataType, 0, dataType.length - 1);</span>
<span class="nc" id="L111"> System.arraycopy(statsType, 1, subStatsType, 0, dataType.length - 1);</span>
<span class="nc" id="L112"> System.arraycopy(statsItems, 1, subStatsItems, 0, dataType.length - 1);</span>
<span class="nc" id="L113"> System.arraycopy(sortType, 1, subSortType, 0, dataType.length - 1);</span>
<span class="nc" id="L114"> System.arraycopy(sortDirection, 1, subSortDirection, 0,</span>
dataType.length - 1);
} else {
<span class="fc" id="L117"> subDataType = null;</span>
<span class="fc" id="L118"> subStatsType = null;</span>
<span class="fc" id="L119"> subStatsItems = null;</span>
<span class="fc" id="L120"> subSortType = null;</span>
<span class="fc" id="L121"> subSortDirection = null;</span>
}
<span class="fc" id="L123"> }</span>
/**
* Instantiates a new mtas solr mtas result.
*
* @param dataCollector the data collector
* @param dataType the data type
* @param statsType the stats type
* @param statsItems the stats items
* @param functionData the function data
*/
@SuppressWarnings("unchecked")
public MtasSolrMtasResult(MtasDataCollector<?, ?> dataCollector,
String dataType, String statsType, SortedSet<String> statsItems,
Map<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData) {
<span class="fc" id="L138"> this(dataCollector, new String[] { dataType }, new String[] { statsType },</span>
new SortedSet[] { statsItems }, new String[] { null },
<span class="fc" id="L140"> new String[] { null }, new Integer[] { 0 }, new Integer[] { 1 },</span>
functionData);
<span class="fc" id="L142"> }</span>
/**
* Merge.
*
* @param newItem the new item
* @throws IOException Signals that an I/O exception has occurred.
*/
void merge(MtasSolrMtasResult newItem) throws IOException {
<span class="fc" id="L151"> HashMap<MtasDataCollector<?, ?>, MtasDataCollector<?, ?>> map = new HashMap<>();</span>
<span class="fc bfc" id="L152" title="All 2 branches covered."> if (newItem.dataCollector.withTotal()) {</span>
<span class="fc" id="L153"> dataCollector.setWithTotal();</span>
}
<span class="fc" id="L155"> dataCollector.merge(newItem.dataCollector, map, true);</span>
<span class="fc bfc" id="L156" title="All 2 branches covered."> if (newItem.functionData != null) {</span>
<span class="pc bpc" id="L157" title="1 of 2 branches missed."> if (functionData == null) {</span>
<span class="nc" id="L158"> functionData = new HashMap<>();</span>
}
<span class="fc bfc" id="L160" title="All 2 branches covered."> for (MtasDataCollector<?, ?> keyCollector : newItem.functionData</span>
<span class="fc" id="L161"> .keySet()) {</span>
<span class="pc bpc" id="L162" title="1 of 2 branches missed."> if (map.containsKey(keyCollector)) {</span>
// compute mapped key
<span class="fc" id="L164"> MtasDataCollector<?, ?> newKeyCollector = keyCollector;</span>
<span class="fc bfc" id="L165" title="All 2 branches covered."> while (map.containsKey(newKeyCollector)) {</span>
<span class="fc" id="L166"> newKeyCollector = map.get(keyCollector);</span>
}
<span class="pc bpc" id="L168" title="1 of 2 branches missed."> if (functionData.containsKey(newKeyCollector)) {</span>
<span class="fc" id="L169"> HashMap<String, MtasSolrMtasResult> tmpList = functionData</span>
<span class="fc" id="L170"> .get(newKeyCollector);</span>
<span class="pc bpc" id="L171" title="1 of 2 branches missed."> for (String functionKey : newItem.functionData.get(keyCollector)</span>
<span class="fc" id="L172"> .keySet()) {</span>
<span class="nc bnc" id="L173" title="All 2 branches missed."> if (tmpList.containsKey(functionKey)) {</span>
<span class="nc" id="L174"> tmpList.get(functionKey).merge(</span>
<span class="nc" id="L175"> newItem.functionData.get(keyCollector).get(functionKey));</span>
} else {
<span class="nc" id="L177"> tmpList.put(functionKey,</span>
<span class="nc" id="L178"> newItem.functionData.get(keyCollector).get(functionKey));</span>
}
<span class="nc" id="L180"> }</span>
<span class="fc" id="L181"> } else {</span>
<span class="nc" id="L182"> functionData.put(newKeyCollector,</span>
<span class="nc" id="L183"> newItem.functionData.get(keyCollector));</span>
}
}
<span class="fc" id="L186"> }</span>
}
<span class="fc" id="L188"> }</span>
/**
* Gets the data.
*
* @param showDebugInfo the show debug info
* @return the data
* @throws IOException Signals that an I/O exception has occurred.
*/
NamedList<Object> getData(boolean showDebugInfo) throws IOException {
<span class="fc" id="L198"> if (dataCollector.getCollectorType()</span>
<span class="pc bpc" id="L199" title="1 of 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_DATA)) {</span>
<span class="fc" id="L200"> NamedList<Object> mtasResponse = new SimpleOrderedMap<>();</span>
// functions
<span class="fc" id="L202"> Map<String, NamedList<Object>> functionList = new HashMap<>();</span>
<span class="pc bpc" id="L203" title="1 of 4 branches missed."> if (functionData != null && functionData.containsKey(dataCollector)) {</span>
<span class="fc" id="L204"> HashMap<String, MtasSolrMtasResult> functionDataItem = functionData</span>
<span class="fc" id="L205"> .get(dataCollector);</span>
<span class="pc bpc" id="L206" title="1 of 2 branches missed."> for (Entry<String, MtasSolrMtasResult> entry : functionDataItem</span>
<span class="fc" id="L207"> .entrySet()) {</span>
<span class="nc" id="L208"> MtasSolrMtasResult functionResult = entry.getValue();</span>
<span class="nc" id="L209"> if (functionResult.dataCollector.getCollectorType()</span>
<span class="nc bnc" id="L210" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_DATA)) {</span>
<span class="nc" id="L211"> NamedList<Object> functionData = functionResult</span>
<span class="nc" id="L212"> .getData(showDebugInfo);</span>
<span class="nc" id="L213"> functionList.put(entry.getKey(), functionData);</span>
<span class="nc" id="L214"> } else {</span>
<span class="nc" id="L215"> throw new IOException("unexpected function collectorType "</span>
<span class="nc" id="L216"> + functionResult.dataCollector.getCollectorType());</span>
}
<span class="nc" id="L218"> }</span>
}
// main result
<span class="fc" id="L221"> MtasDataItem<?, ?> dataItem = dataCollector.getResult().getData();</span>
<span class="fc bfc" id="L222" title="All 2 branches covered."> if (dataItem != null) {</span>
<span class="fc" id="L223"> mtasResponse.addAll(dataItem.rewrite(showDebugInfo));</span>
<span class="pc bpc" id="L224" title="1 of 2 branches missed."> if (functionList.size() > 0) {</span>
<span class="nc" id="L225"> mtasResponse.add("functions", functionList);</span>
}
<span class="pc bpc" id="L227" title="3 of 4 branches missed."> if ((subDataType != null) && (dataItem.getSub() != null)) {</span>
<span class="nc" id="L228"> MtasSolrMtasResult css = new MtasSolrMtasResult(dataItem.getSub(),</span>
subDataType, subStatsType, subStatsItems, subSortType,
subSortDirection, subStart, subNumber, functionData);
<span class="nc" id="L231"> if (dataItem.getSub().getCollectorType()</span>
<span class="nc bnc" id="L232" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="nc" id="L233"> mtasResponse.add(dataItem.getSub().getCollectorType(),</span>
<span class="nc" id="L234"> css.getNamedList(showDebugInfo));</span>
<span class="nc" id="L235"> } else if (dataItem.getSub().getCollectorType()</span>
<span class="nc bnc" id="L236" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_DATA)) {</span>
<span class="nc" id="L237"> mtasResponse.add(dataItem.getSub().getCollectorType(),</span>
<span class="nc" id="L238"> css.getData(showDebugInfo));</span>
}
}
}
<span class="fc" id="L242"> return mtasResponse;</span>
} else {
<span class="nc" id="L244"> throw new IOException(</span>
"only allowed for " + DataCollector.COLLECTOR_TYPE_DATA);
}
}
/**
* Gets the key list.
*
* @return the key list
* @throws IOException Signals that an I/O exception has occurred.
*/
public Set<String> getKeyList() throws IOException {
<span class="fc" id="L256"> if (dataCollector.getCollectorType()</span>
<span class="pc bpc" id="L257" title="1 of 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="fc" id="L258"> return dataCollector.getResult().getComparatorList().keySet();</span>
} else {
<span class="nc" id="L260"> throw new IOException(</span>
"only allowed for " + DataCollector.COLLECTOR_TYPE_LIST);
}
}
/**
* Gets the full key list.
*
* @return the full key list
* @throws IOException Signals that an I/O exception has occurred.
*/
public Set<String> getFullKeyList() throws IOException {
<span class="nc" id="L272"> if (dataCollector.getCollectorType()</span>
<span class="nc bnc" id="L273" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="nc" id="L274"> return dataCollector.getKeyList();</span>
} else {
<span class="nc" id="L276"> throw new IOException(</span>
"only allowed for " + DataCollector.COLLECTOR_TYPE_LIST);
}
}
/**
* Gets the named list.
*
* @param showDebugInfo the show debug info
* @return the named list
* @throws IOException Signals that an I/O exception has occurred.
*/
NamedList<Object> getNamedList(boolean showDebugInfo) throws IOException {
<span class="fc" id="L289"> if (dataCollector.getCollectorType()</span>
<span class="pc bpc" id="L290" title="1 of 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="fc" id="L291"> SimpleOrderedMap<Object> mtasResponseList = new SimpleOrderedMap<>();</span>
// functions
<span class="fc" id="L293"> Map<String, SimpleOrderedMap<Object>> functionList = new HashMap<>();</span>
<span class="pc bpc" id="L294" title="2 of 4 branches missed."> if (functionData != null && functionData.containsKey(dataCollector)) {</span>
<span class="fc" id="L295"> HashMap<String, MtasSolrMtasResult> functionDataItem = functionData</span>
<span class="fc" id="L296"> .get(dataCollector);</span>
<span class="pc bpc" id="L297" title="1 of 2 branches missed."> for (Entry<String, MtasSolrMtasResult> entry : functionDataItem</span>
<span class="fc" id="L298"> .entrySet()) {</span>
<span class="nc" id="L299"> MtasSolrMtasResult functionResult = entry.getValue();</span>
<span class="nc" id="L300"> if (functionResult.dataCollector.getCollectorType()</span>
<span class="nc bnc" id="L301" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="nc" id="L302"> NamedList<Object> functionNamedList = functionResult</span>
<span class="nc" id="L303"> .getNamedList(showDebugInfo);</span>
<span class="nc bnc" id="L304" title="All 2 branches missed."> for (int i = 0; i < functionNamedList.size(); i++) {</span>
<span class="nc bnc" id="L305" title="All 2 branches missed."> if (functionList.containsKey(functionNamedList.getName(i))) {</span>
<span class="nc" id="L306"> SimpleOrderedMap<Object> tmpMap = functionList</span>
<span class="nc" id="L307"> .get(functionNamedList.getName(i));</span>
<span class="nc" id="L308"> tmpMap.add(entry.getKey(), functionNamedList.getVal(i));</span>
<span class="nc" id="L309"> } else {</span>
<span class="nc" id="L310"> SimpleOrderedMap<Object> tmpMap = new SimpleOrderedMap<>();</span>
<span class="nc" id="L311"> tmpMap.add(entry.getKey(), functionNamedList.getVal(i));</span>
<span class="nc" id="L312"> functionList.put(functionNamedList.getName(i), tmpMap);</span>
}
}
<span class="nc" id="L315"> } else {</span>
<span class="nc" id="L316"> throw new IOException("unexpected function collectorType "</span>
<span class="nc" id="L317"> + functionResult.dataCollector.getCollectorType());</span>
}
<span class="nc" id="L319"> }</span>
}
// main result
<span class="fc" id="L322"> Map<String, ?> dataList = dataCollector.getResult().getList();</span>
<span class="fc bfc" id="L323" title="All 2 branches covered."> for (Entry<String, ?> entry : dataList.entrySet()) {</span>
<span class="fc" id="L324"> SimpleOrderedMap<Object> mtasResponseListItem = new SimpleOrderedMap<>();</span>
<span class="fc" id="L325"> MtasDataItem<?, ?> dataItem = (MtasDataItem<?, ?>) entry.getValue();</span>
<span class="fc" id="L326"> mtasResponseListItem.addAll(dataItem.rewrite(showDebugInfo));</span>
<span class="pc bpc" id="L327" title="1 of 2 branches missed."> if (functionList.containsKey(entry.getKey())) {</span>
<span class="nc" id="L328"> mtasResponseListItem.add("functions",</span>
<span class="nc" id="L329"> functionList.get(entry.getKey()));</span>
}
<span class="pc bpc" id="L331" title="3 of 4 branches missed."> if ((subDataType != null) && (dataItem.getSub() != null)) {</span>
<span class="nc" id="L332"> MtasSolrMtasResult css = new MtasSolrMtasResult(dataItem.getSub(),</span>
subDataType, subStatsType, subStatsItems, subSortType,
subSortDirection, subStart, subNumber, functionData);
<span class="nc" id="L335"> if (dataItem.getSub().getCollectorType()</span>
<span class="nc bnc" id="L336" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="nc bnc" id="L337" title="All 2 branches missed."> if (css.dataCollector.withTotal()) {</span>
<span class="nc" id="L338"> mtasResponseListItem.add(</span>
DataCollector.COLLECTOR_TYPE_LIST + "Total",
<span class="nc" id="L340"> css.dataCollector.getSize());</span>
}
<span class="nc" id="L342"> mtasResponseListItem.add(DataCollector.COLLECTOR_TYPE_LIST,</span>
<span class="nc" id="L343"> css.getNamedList(showDebugInfo));</span>
<span class="nc" id="L344"> } else if (dataItem.getSub().getCollectorType()</span>
<span class="nc bnc" id="L345" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_DATA)) {</span>
<span class="nc" id="L346"> mtasResponseListItem.add(DataCollector.COLLECTOR_TYPE_DATA,</span>
<span class="nc" id="L347"> css.getData(showDebugInfo));</span>
}
}
<span class="fc" id="L350"> mtasResponseList.add(entry.getKey(), mtasResponseListItem);</span>
<span class="fc" id="L351"> }</span>
<span class="fc" id="L352"> return mtasResponseList;</span>
} else {
<span class="nc" id="L354"> throw new IOException(</span>
"only allowed for " + DataCollector.COLLECTOR_TYPE_LIST);
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
<span class="nc" id="L366"> if (dataCollector.getCollectorType()</span>
<span class="nc bnc" id="L367" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_DATA)) {</span>
<span class="nc" id="L368"> return this.getClass().getSimpleName()+"(data-" + hashCode() + ")";</span>
}
<span class="nc" id="L370"> if (dataCollector.getCollectorType()</span>
<span class="nc bnc" id="L371" title="All 2 branches missed."> .equals(DataCollector.COLLECTOR_TYPE_LIST)) {</span>
<span class="nc" id="L372"> return this.getClass().getSimpleName()+"(list(" + dataCollector.getSize() + ")-"</span>
<span class="nc" id="L373"> + hashCode() + ")";</span>
} else {
<span class="nc" id="L375"> return this.getClass().getSimpleName()+": unknown";</span>
}
}
/**
* Gets the result.
*
* @return the result
* @throws IOException Signals that an I/O exception has occurred.
*/
public MtasDataCollectorResult getResult() throws IOException {
<span class="fc" id="L386"> return dataCollector.getResult();</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>