MtasSolrComponentCollection.java.html 53.1 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
<?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>MtasSolrComponentCollection.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> &gt; <a href="index.source.html" class="el_package">mtas.solr.handler.component.util</a> &gt; <span class="el_source">MtasSolrComponentCollection.java</span></div><h1>MtasSolrComponentCollection.java</h1><pre class="source lang-java linenums">package mtas.solr.handler.component.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.Map.Entry;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.handler.component.ShardRequest;
import org.apache.solr.handler.component.ShardResponse;
import org.noggit.JSONParser;
import org.noggit.JSONUtil;

import mtas.codec.util.CodecComponent.ComponentFields;
import mtas.codec.util.CodecComponent.ComponentCollection;
import mtas.solr.handler.component.MtasSolrSearchComponent;

/**
 * The Class MtasSolrComponentCollection.
 */
public class MtasSolrComponentCollection
    implements MtasSolrComponent&lt;ComponentCollection&gt; {

  /** The Constant log. */
<span class="fc" id="L36">  private static final Log log = LogFactory</span>
<span class="fc" id="L37">      .getLog(MtasSolrComponentCollection.class);</span>

  /** The Constant PARAM_MTAS_COLLECTION. */
  public static final String PARAM_MTAS_COLLECTION = MtasSolrSearchComponent.PARAM_MTAS
      + &quot;.collection&quot;;

  /** The Constant NAME_MTAS_COLLECTION_ACTION. */
  public static final String NAME_MTAS_COLLECTION_ACTION = &quot;action&quot;;

  /** The Constant NAME_MTAS_COLLECTION_ID. */
  public static final String NAME_MTAS_COLLECTION_ID = &quot;id&quot;;

  /** The Constant NAME_MTAS_COLLECTION_FIELD. */
  public static final String NAME_MTAS_COLLECTION_FIELD = &quot;field&quot;;

  /** The Constant NAME_MTAS_COLLECTION_POST. */
  public static final String NAME_MTAS_COLLECTION_POST = &quot;post&quot;;

  /** The Constant NAME_MTAS_COLLECTION_URL. */
  public static final String NAME_MTAS_COLLECTION_URL = &quot;url&quot;;

  /** The Constant NAME_MTAS_COLLECTION_COLLECTION. */
  public static final String NAME_MTAS_COLLECTION_COLLECTION = &quot;collection&quot;;

  /** The Constant NAME_MTAS_COLLECTION_KEY. */
  public static final String NAME_MTAS_COLLECTION_KEY = &quot;key&quot;;

  /** The search component. */
  private MtasSolrSearchComponent searchComponent;

  /**
   * Instantiates a new mtas solr component collection.
   *
   * @param searchComponent the search component
   */
<span class="fc" id="L72">  public MtasSolrComponentCollection(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L73">    this.searchComponent = searchComponent;</span>
<span class="fc" id="L74">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#prepare(org.apache.solr.
   * handler.component.ResponseBuilder,
   * mtas.codec.util.CodecComponent.ComponentFields)
   */
  public void prepare(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
    //System.out.println(
    //&quot;collection: &quot; + System.nanoTime() + &quot; - &quot; +
    //Thread.currentThread().getId()
    //+ &quot; - &quot; + rb.req.getParams().getBool(&quot;isShard&quot;, false) + &quot; PREPARE &quot;
    //+ rb.stage + &quot; &quot; + rb.req.getParamString());
<span class="fc" id="L91">    Set&lt;String&gt; ids = MtasSolrResultUtil</span>
<span class="fc" id="L92">        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_COLLECTION);</span>
<span class="pc bpc" id="L93" title="1 of 2 branches missed.">    if (!ids.isEmpty()) {</span>
<span class="fc" id="L94">      int tmpCounter = 0;</span>
<span class="fc" id="L95">      String[] keys = new String[ids.size()];</span>
<span class="fc" id="L96">      String[] actions = new String[ids.size()];</span>
<span class="fc" id="L97">      String[] fields = new String[ids.size()];</span>
<span class="fc" id="L98">      String[] collectionIds = new String[ids.size()];</span>
<span class="fc" id="L99">      String[] posts = new String[ids.size()];</span>
<span class="fc" id="L100">      String[] urls = new String[ids.size()];</span>
<span class="fc" id="L101">      String[] collections = new String[ids.size()];</span>
<span class="fc bfc" id="L102" title="All 2 branches covered.">      for (String id : ids) {</span>
<span class="fc" id="L103">        actions[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_COLLECTION + &quot;.&quot;</span>
            + id + &quot;.&quot; + NAME_MTAS_COLLECTION_ACTION, null);
<span class="fc" id="L105">        keys[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_KEY,
<span class="fc" id="L107">            String.valueOf(tmpCounter)).trim();</span>
<span class="fc" id="L108">        fields[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_FIELD,
            null);
<span class="fc" id="L111">        collectionIds[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_ID,
            null);
<span class="fc" id="L114">        posts[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_POST,
            null);
<span class="fc" id="L117">        urls[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_URL,
            null);
<span class="fc" id="L120">        collections[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_COLLECTION</span>
            + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_COLLECTION, null);
        //always id for post
<span class="pc bpc" id="L123" title="2 of 8 branches missed.">        if(actions[tmpCounter]!=null &amp;&amp; (actions[tmpCounter].equals(ComponentCollection.ACTION_POST) || actions[tmpCounter].equals(ComponentCollection.ACTION_IMPORT) || actions[tmpCounter].equals(ComponentCollection.ACTION_CREATE))) {</span>
<span class="pc bpc" id="L124" title="2 of 4 branches missed.">          if(collectionIds[tmpCounter]==null || collectionIds[tmpCounter].isEmpty()) {</span>
<span class="nc" id="L125">            collectionIds[tmpCounter] = UUID.randomUUID().toString();</span>
<span class="nc" id="L126">            ModifiableSolrParams changedParams = new ModifiableSolrParams(rb.req.getParams());</span>
<span class="nc" id="L127">            changedParams.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_ID);</span>
<span class="nc" id="L128">            changedParams.set(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_ID, collectionIds[tmpCounter]);            </span>
<span class="nc" id="L129">            rb.req.setParams(changedParams);</span>
          }          
        }
<span class="fc" id="L132">        tmpCounter++;</span>
<span class="fc" id="L133">      }</span>
<span class="fc" id="L134">      mtasFields.doCollection = true;</span>
<span class="fc" id="L135">      MtasSolrResultUtil.compareAndCheck(keys, actions,</span>
<span class="fc" id="L136">          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_ACTION, true);</span>
<span class="fc" id="L137">      MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_COLLECTION_KEY,</span>
<span class="fc" id="L138">          NAME_MTAS_COLLECTION_FIELD, false);</span>
<span class="fc" id="L139">      MtasSolrResultUtil.compareAndCheck(keys, collectionIds,</span>
<span class="fc" id="L140">          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_ID, false);</span>
<span class="fc" id="L141">      MtasSolrResultUtil.compareAndCheck(keys, posts, NAME_MTAS_COLLECTION_KEY,</span>
<span class="fc" id="L142">          NAME_MTAS_COLLECTION_POST, false);</span>
<span class="fc" id="L143">      MtasSolrResultUtil.compareAndCheck(keys, urls, NAME_MTAS_COLLECTION_KEY,</span>
<span class="fc" id="L144">          NAME_MTAS_COLLECTION_URL, false);</span>
<span class="fc" id="L145">      MtasSolrResultUtil.compareAndCheck(keys, collections,</span>
<span class="fc" id="L146">          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_COLLECTION, false);</span>
<span class="fc bfc" id="L147" title="All 2 branches covered.">      for (int i = 0; i &lt; actions.length; i++) {</span>
<span class="pc bpc" id="L148" title="1 of 2 branches missed.">        if (actions[i] != null) {</span>
          ComponentCollection componentCollection;
<span class="pc bpc" id="L150" title="19 of 34 branches missed.">          switch (actions[i]) {</span>
          case ComponentCollection.ACTION_LIST:
<span class="fc" id="L152">            componentCollection = new ComponentCollection(keys[i],</span>
                ComponentCollection.ACTION_LIST);
<span class="fc" id="L154">            componentCollection.setListVariables();</span>
<span class="fc" id="L155">            mtasFields.collection.add(componentCollection);</span>
<span class="fc" id="L156">            break;</span>
          case ComponentCollection.ACTION_CHECK:
<span class="pc bpc" id="L158" title="1 of 2 branches missed.">            if (collectionIds[i] != null) {</span>
<span class="fc" id="L159">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_CHECK);
<span class="fc" id="L161">              componentCollection.setCheckVariables(collectionIds[i]);</span>
<span class="fc" id="L162">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L164">              throw new IOException(</span>
                  &quot;no id defined for collection (&quot; + actions[i] + &quot;)&quot;);
            }
            break;
          case ComponentCollection.ACTION_GET:
<span class="nc bnc" id="L169" title="All 2 branches missed.">            if (collectionIds[i] != null) {</span>
<span class="nc" id="L170">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_GET);
<span class="nc" id="L172">              componentCollection.setGetVariables(collectionIds[i]);</span>
<span class="nc" id="L173">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L175">              throw new IOException(</span>
                  &quot;no id defined for collection (&quot; + actions[i] + &quot;)&quot;);
            }
            break;
          case ComponentCollection.ACTION_CREATE:
<span class="pc bpc" id="L180" title="1 of 2 branches missed.">            if(collectionIds[i]==null) {</span>
<span class="nc" id="L181">              collectionIds[i] = UUID.randomUUID().toString();</span>
            }
<span class="pc bpc" id="L183" title="1 of 2 branches missed.">            if (fields[i] != null) {</span>
<span class="fc" id="L184">              Set&lt;String&gt; fieldList = new HashSet&lt;&gt;(</span>
<span class="fc" id="L185">                  Arrays.asList(fields[i].split(&quot;,&quot;)));</span>
<span class="fc" id="L186">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_CREATE);
<span class="fc" id="L188">              componentCollection.setCreateVariables(collectionIds[i],</span>
                  fieldList);
<span class="fc" id="L190">              mtasFields.doCollection = true;</span>
<span class="fc" id="L191">              mtasFields.collection.add(componentCollection);</span>
<span class="fc" id="L192">              rb.setNeedDocSet(true);</span>
<span class="fc" id="L193">            } else {</span>
<span class="nc" id="L194">              throw new IOException(</span>
                  &quot;no field defined for collection (&quot; + actions[i] + &quot;)&quot;);
            }
            break;
          case ComponentCollection.ACTION_POST:
<span class="pc bpc" id="L199" title="1 of 2 branches missed.">            if (posts[i] != null) {</span>
<span class="fc" id="L200">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_POST);
<span class="fc" id="L202">              componentCollection.setPostVariables(collectionIds[i],</span>
<span class="fc" id="L203">                  stringToStringValues(posts[i]));</span>
<span class="fc" id="L204">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L206">              throw new IOException(</span>
                  &quot;no post defined for collection (&quot; + actions[i] + &quot;)&quot;);
            }
            break;
          case ComponentCollection.ACTION_IMPORT:
<span class="nc bnc" id="L211" title="All 4 branches missed.">            if (urls[i] != null &amp;&amp; collections[i] != null) {</span>
<span class="nc" id="L212">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_IMPORT);
<span class="nc" id="L214">              componentCollection.setImportVariables(collectionIds[i], urls[i],</span>
                  collections[i]);
<span class="nc" id="L216">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L218">              throw new IOException(</span>
                  &quot;no url or collection defined for collection (&quot; + actions[i] + &quot;)&quot;);
            }
            break;
          case ComponentCollection.ACTION_DELETE:
<span class="pc bpc" id="L223" title="1 of 2 branches missed.">            if (collectionIds[i] != null) {</span>
<span class="fc" id="L224">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_DELETE);
<span class="fc" id="L226">              componentCollection.setDeleteVariables(collectionIds[i]);</span>
<span class="fc" id="L227">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L229">              throw new IOException(</span>
                  &quot;no id defined for collection (&quot; + actions[i] + &quot;)&quot;);
            }
            break;
          case ComponentCollection.ACTION_EMPTY:
<span class="nc" id="L234">            componentCollection = new ComponentCollection(keys[i],</span>
                ComponentCollection.ACTION_EMPTY);
<span class="nc" id="L236">            mtasFields.collection.add(componentCollection);</span>
<span class="nc" id="L237">            break;</span>
          default:
<span class="nc" id="L239">            throw new IOException(</span>
                &quot;unrecognized action '&quot; + actions[i] + &quot;' for collection&quot;);
          }
<span class="fc" id="L242">        } else {</span>
<span class="nc" id="L243">          throw new IOException(&quot;no action defined for collection&quot;);</span>
        }
      }
    }
<span class="fc" id="L247">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#modifyRequest(org.apache
   * .solr.handler.component.ResponseBuilder,
   * org.apache.solr.handler.component.SearchComponent,
   * org.apache.solr.handler.component.ShardRequest)
   */
  public void modifyRequest(ResponseBuilder rb, SearchComponent who,
      ShardRequest sreq) {
    // System.out.println(
    // &quot;collection: &quot; + System.nanoTime() + &quot; - &quot; +
    // Thread.currentThread().getId()
    // + &quot; - &quot; + rb.req.getParams().getBool(&quot;isShard&quot;, false)
    // + &quot; MODIFYREQUEST &quot; + rb.stage + &quot; &quot; + rb.req.getParamString());
<span class="pc bpc" id="L265" title="1 of 2 branches missed.">    if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="pc bpc" id="L266" title="1 of 2 branches missed.">        &amp;&amp; sreq.params.getBool(PARAM_MTAS_COLLECTION, false)) {</span>
<span class="fc bfc" id="L267" title="All 2 branches covered.">      if ((sreq.purpose &amp; ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {</span>
        //do nothing
      } else {
        // remove for other requests
<span class="fc" id="L271">        Set&lt;String&gt; keys = MtasSolrResultUtil</span>
<span class="fc" id="L272">            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_COLLECTION);</span>
<span class="fc" id="L273">        sreq.params.remove(PARAM_MTAS_COLLECTION);</span>
<span class="fc bfc" id="L274" title="All 2 branches covered.">        for (String key : keys) {</span>
<span class="fc" id="L275">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_ACTION);
<span class="fc" id="L277">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_ID);
<span class="fc" id="L279">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_FIELD);
<span class="fc" id="L281">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_POST);
<span class="fc" id="L283">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_KEY);
<span class="fc" id="L285">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_URL);
<span class="fc" id="L287">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_COLLECTION);
<span class="fc" id="L289">        }</span>
      }
    }
<span class="fc" id="L292">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.
   * CodecComponent.BasicComponent, java.lang.Boolean)
   */
  public SimpleOrderedMap&lt;Object&gt; create(
      ComponentCollection componentCollection, Boolean encode)
      throws IOException {
<span class="fc" id="L304">    MtasSolrCollectionResult data = createMtasSolrCollectionResult(</span>
<span class="fc bfc" id="L305" title="All 2 branches covered.">        componentCollection, encode ? false : true);</span>
    // Create response
<span class="fc" id="L307">    SimpleOrderedMap&lt;Object&gt; mtasCollectionResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="fc" id="L308">    mtasCollectionResponse.add(&quot;key&quot;, componentCollection.key);</span>
<span class="fc bfc" id="L309" title="All 2 branches covered.">    if (encode) {</span>
<span class="fc" id="L310">      mtasCollectionResponse.add(&quot;_encoded_data&quot;,</span>
<span class="fc" id="L311">          MtasSolrResultUtil.encode(data));</span>
    } else {
<span class="fc" id="L313">      mtasCollectionResponse.add(&quot;data&quot;, data);</span>
<span class="fc" id="L314">      MtasSolrResultUtil.rewrite(mtasCollectionResponse, searchComponent);</span>
    }
<span class="fc" id="L316">    return mtasCollectionResponse;</span>
  }

  /**
   * Creates the mtas solr collection result.
   *
   * @param componentCollection the component collection
   * @param storeIfRelevant the store if relevant
   * @return the mtas solr collection result
   * @throws IOException Signals that an I/O exception has occurred.
   */
  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.
   * CodecComponent.BasicComponent, java.lang.Boolean)
   */
  private MtasSolrCollectionResult createMtasSolrCollectionResult(
      ComponentCollection componentCollection, boolean storeIfRelevant)
      throws IOException {
    // System.out.println(&quot;collection: &quot; + System.nanoTime() + &quot; - &quot;
    // + Thread.currentThread().getId() + &quot; - &quot; + &quot; CREATE &quot;);
<span class="pc bpc" id="L339" title="1 of 2 branches missed.">    if (componentCollection != null) {</span>
      // Create response
<span class="fc" id="L341">      MtasSolrCollectionResult data = new MtasSolrCollectionResult(</span>
          componentCollection);
<span class="fc" id="L343">      if (componentCollection.action()</span>
<span class="fc bfc" id="L344" title="All 2 branches covered.">          .equals(ComponentCollection.ACTION_CREATE)) {</span>
<span class="pc bpc" id="L345" title="1 of 4 branches missed.">        if (storeIfRelevant &amp;&amp; componentCollection.version == null) {</span>
<span class="fc" id="L346">          componentCollection.version = searchComponent.getCollectionCache()</span>
<span class="fc" id="L347">              .create(componentCollection.id,</span>
<span class="fc" id="L348">                  componentCollection.values().size(),</span>
<span class="fc" id="L349">                  componentCollection.values());</span>
        }
<span class="fc" id="L351">        data.setCreate(searchComponent.getCollectionCache().now(),</span>
<span class="fc" id="L352">            searchComponent.getCollectionCache().check(componentCollection.id));</span>
<span class="fc" id="L353">      } else if (componentCollection.action()</span>
<span class="fc bfc" id="L354" title="All 2 branches covered.">          .equals(ComponentCollection.ACTION_LIST)) {</span>
        // retrieve and add list to result
<span class="fc" id="L356">        data.setList(searchComponent.getCollectionCache().now(),</span>
<span class="fc" id="L357">            searchComponent.getCollectionCache().list());</span>
<span class="fc" id="L358">      } else if (componentCollection.action()</span>
<span class="fc bfc" id="L359" title="All 2 branches covered.">          .equals(ComponentCollection.ACTION_CHECK)) {</span>
        // retrieve and add status to result
<span class="fc" id="L361">        data.setCheck(searchComponent.getCollectionCache().now(),</span>
<span class="fc" id="L362">            searchComponent.getCollectionCache().check(componentCollection.id));</span>
<span class="fc" id="L363">      } else if (componentCollection.action()</span>
<span class="pc bpc" id="L364" title="1 of 2 branches missed.">          .equals(ComponentCollection.ACTION_GET)) {</span>
        // retrieve and add status to result
<span class="nc" id="L366">        HashSet&lt;String&gt; values = searchComponent.getCollectionCache()</span>
<span class="nc" id="L367">            .getDataById(componentCollection.id);</span>
<span class="nc bnc" id="L368" title="All 2 branches missed.">        if (values != null) {</span>
<span class="nc" id="L369">          data.setGet(searchComponent.getCollectionCache().now(),</span>
<span class="nc" id="L370">              searchComponent.getCollectionCache()</span>
<span class="nc" id="L371">                  .check(componentCollection.id),</span>
              values);
        }
<span class="pc" id="L374">      } else if (componentCollection.action()</span>
<span class="pc bpc" id="L375" title="1 of 2 branches missed.">          .equals(ComponentCollection.ACTION_EMPTY)) {</span>
        // empty
<span class="nc" id="L377">        searchComponent.getCollectionCache().empty();</span>
<span class="fc" id="L378">      } else if (componentCollection.action()</span>
<span class="fc bfc" id="L379" title="All 2 branches covered.">          .equals(ComponentCollection.ACTION_POST)) {</span>
        // store if not already stored
<span class="pc bpc" id="L381" title="1 of 2 branches missed.">        if (componentCollection.version == null) {</span>
<span class="fc" id="L382">          componentCollection.version = searchComponent.getCollectionCache()</span>
<span class="fc" id="L383">              .create(componentCollection.id,</span>
<span class="fc" id="L384">                  componentCollection.values().size(),</span>
<span class="fc" id="L385">                  componentCollection.values());</span>
        }
        // add status to result
<span class="fc" id="L388">        data.setPost(searchComponent.getCollectionCache().now(),</span>
<span class="fc" id="L389">            searchComponent.getCollectionCache().check(componentCollection.id));</span>
<span class="fc" id="L390">      } else if (componentCollection.action()</span>
<span class="pc bpc" id="L391" title="1 of 2 branches missed.">          .equals(ComponentCollection.ACTION_IMPORT)) {</span>
        // import if not already stored
<span class="nc bnc" id="L393" title="All 2 branches missed.">        if (componentCollection.version == null) {</span>
<span class="nc" id="L394">          componentCollection.version = searchComponent.getCollectionCache()</span>
<span class="nc" id="L395">              .create(componentCollection.id,</span>
<span class="nc" id="L396">                  componentCollection.values().size(),</span>
<span class="nc" id="L397">                  componentCollection.values());</span>
        }
        // add status to result
<span class="nc" id="L400">        data.setImport(searchComponent.getCollectionCache().now(),</span>
<span class="nc" id="L401">            searchComponent.getCollectionCache().check(componentCollection.id));</span>
<span class="fc" id="L402">      } else if (componentCollection.action()</span>
<span class="pc bpc" id="L403" title="1 of 2 branches missed.">          .equals(ComponentCollection.ACTION_DELETE)) {</span>
<span class="fc" id="L404">        searchComponent.getCollectionCache().deleteById(componentCollection.id);</span>
      }
<span class="fc" id="L406">      return data;</span>
    } else {
<span class="nc" id="L408">      throw new IOException(&quot;no componentCollection available&quot;);</span>
    }
  }

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache.
   * solr.handler.component.ResponseBuilder)
   */
  public void finishStage(ResponseBuilder rb) {
    // System.out.println(
    // &quot;collection: &quot; + System.nanoTime() + &quot; - &quot; +
    // Thread.currentThread().getId()
    // + &quot; - &quot; + rb.req.getParams().getBool(&quot;isShard&quot;, false)
    // + &quot; FINISHSTAGE &quot; + rb.stage + &quot; &quot; + rb.req.getParamString());
<span class="pc bpc" id="L425" title="1 of 2 branches missed.">    if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {</span>
<span class="fc bfc" id="L426" title="All 4 branches covered.">      if (rb.stage &gt;= ResponseBuilder.STAGE_EXECUTE_QUERY</span>
          &amp;&amp; rb.stage &lt; ResponseBuilder.STAGE_GET_FIELDS) {
<span class="fc" id="L428">        ComponentFields mtasFields = getMtasFields(rb);</span>
<span class="pc bpc" id="L429" title="1 of 2 branches missed.">        if (mtasFields.doCollection) {</span>
<span class="fc bfc" id="L430" title="All 2 branches covered.">          if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {</span>
            // mtas response
<span class="fc" id="L432">            NamedList&lt;Object&gt; mtasResponse = null;</span>
            try {
<span class="fc" id="L434">              mtasResponse = (NamedList&lt;Object&gt;) rb.rsp.getValues().get(&quot;mtas&quot;);</span>
<span class="nc" id="L435">            } catch (ClassCastException e) {</span>
<span class="nc" id="L436">              log.debug(e);</span>
<span class="nc" id="L437">              mtasResponse = null;</span>
<span class="fc" id="L438">            }</span>
<span class="pc bpc" id="L439" title="1 of 2 branches missed.">            if (mtasResponse == null) {</span>
<span class="nc" id="L440">              mtasResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L441">              rb.rsp.add(&quot;mtas&quot;, mtasResponse);</span>
            }
            ArrayList&lt;Object&gt; mtasCollectionResponses;
<span class="pc bpc" id="L444" title="1 of 2 branches missed.">            if (mtasResponse.get(&quot;collection&quot;) != null</span>
<span class="nc bnc" id="L445" title="All 2 branches missed.">                &amp;&amp; mtasResponse.get(&quot;collection&quot;) instanceof ArrayList) {</span>
<span class="nc" id="L446">              mtasCollectionResponses = (ArrayList&lt;Object&gt;) mtasResponse</span>
<span class="nc" id="L447">                  .get(&quot;collection&quot;);</span>
            } else {
<span class="fc" id="L449">              mtasCollectionResponses = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L450">              mtasResponse.add(&quot;collection&quot;, mtasCollectionResponses);</span>
            }
            MtasSolrCollectionResult collectionResult;
<span class="fc bfc" id="L453" title="All 2 branches covered.">            for (ComponentCollection componentCollection : mtasFields.collection) {</span>
              try {
<span class="fc" id="L455">                collectionResult = createMtasSolrCollectionResult(</span>
                    componentCollection, false);
                // Create response
<span class="fc" id="L458">                SimpleOrderedMap&lt;Object&gt; mtasCollectionResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="fc" id="L459">                mtasCollectionResponse.add(&quot;key&quot;, componentCollection.key);</span>
<span class="fc" id="L460">                mtasCollectionResponse.add(&quot;data&quot;, collectionResult);</span>
<span class="fc" id="L461">                mtasCollectionResponses.add(mtasCollectionResponse);</span>
<span class="nc" id="L462">              } catch (IOException e) {</span>
<span class="nc" id="L463">                log.debug(e);</span>
<span class="fc" id="L464">              }</span>
<span class="fc" id="L465">            }</span>
          }
          // decode shard responses
<span class="fc bfc" id="L468" title="All 2 branches covered.">          for (ShardRequest sreq : rb.finished) {</span>
<span class="pc bpc" id="L469" title="1 of 2 branches missed.">            if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="pc bpc" id="L470" title="1 of 2 branches missed.">                &amp;&amp; sreq.params.getBool(PARAM_MTAS_COLLECTION, false)) {</span>
<span class="fc bfc" id="L471" title="All 2 branches covered.">              for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="fc" id="L472">                NamedList&lt;Object&gt; solrShardResponse = shardResponse</span>
<span class="fc" id="L473">                    .getSolrResponse().getResponse();</span>
                try {
<span class="fc" id="L475">                  ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt; data = (ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt;) solrShardResponse</span>
<span class="fc" id="L476">                      .findRecursive(&quot;mtas&quot;, &quot;collection&quot;);</span>
<span class="pc bpc" id="L477" title="1 of 2 branches missed.">                  if (data != null) {</span>
<span class="fc" id="L478">                    MtasSolrResultUtil.decode(data);</span>
<span class="fc bfc" id="L479" title="All 2 branches covered.">                    if (rb.stage &gt; ResponseBuilder.STAGE_EXECUTE_QUERY) {</span>
<span class="fc" id="L480">                      ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt; filteredData = new ArrayList&lt;&gt;();</span>
<span class="fc bfc" id="L481" title="All 2 branches covered.">                      for (SimpleOrderedMap&lt;Object&gt; dataItem : data) {</span>
<span class="pc bpc" id="L482" title="1 of 2 branches missed.">                        if (dataItem.get(&quot;data&quot;) != null &amp;&amp; dataItem</span>
<span class="pc bpc" id="L483" title="1 of 2 branches missed.">                            .get(&quot;data&quot;) instanceof MtasSolrCollectionResult) {</span>
<span class="fc" id="L484">                          MtasSolrCollectionResult collectionResult = (MtasSolrCollectionResult) dataItem</span>
<span class="fc" id="L485">                              .get(&quot;data&quot;);</span>
<span class="fc bfc" id="L486" title="All 2 branches covered.">                          if (rb.stage &lt;= MtasSolrSearchComponent.STAGE_COLLECTION_INIT) {</span>
<span class="fc" id="L487">                            if (!collectionResult.action()</span>
<span class="pc bpc" id="L488" title="1 of 2 branches missed.">                                .equals(ComponentCollection.ACTION_CREATE)</span>
<span class="fc" id="L489">                                &amp;&amp; !collectionResult.action()</span>
<span class="pc bpc" id="L490" title="1 of 2 branches missed.">                                    .equals(ComponentCollection.ACTION_LIST)</span>
<span class="fc" id="L491">                                &amp;&amp; !collectionResult.action()</span>
<span class="pc bpc" id="L492" title="1 of 2 branches missed.">                                    .equals(ComponentCollection.ACTION_CHECK)) {</span>
<span class="fc" id="L493">                              filteredData.add(dataItem);</span>
                            }
<span class="pc bpc" id="L495" title="1 of 2 branches missed.">                          } else if (rb.stage &lt;= MtasSolrSearchComponent.STAGE_COLLECTION_FINISH) {</span>
<span class="fc" id="L496">                            if (!collectionResult.action()</span>
<span class="pc bpc" id="L497" title="1 of 2 branches missed.">                                .equals(ComponentCollection.ACTION_POST)</span>
<span class="nc" id="L498">                                &amp;&amp; !collectionResult.action()</span>
<span class="nc bnc" id="L499" title="All 2 branches missed.">                                    .equals(ComponentCollection.ACTION_IMPORT)</span>
<span class="nc" id="L500">                                &amp;&amp; !collectionResult.action()</span>
<span class="nc bnc" id="L501" title="All 2 branches missed.">                                    .equals(ComponentCollection.ACTION_CHECK)) {</span>
<span class="nc" id="L502">                              filteredData.add(dataItem);</span>
                            }
                          }
<span class="fc" id="L505">                        } else {</span>
<span class="nc" id="L506">                          filteredData.add(dataItem);</span>
                        }
<span class="fc" id="L508">                      }</span>
<span class="fc" id="L509">                      data.clear();</span>
<span class="fc" id="L510">                      data.addAll(filteredData);</span>
                    }
                  }
<span class="nc" id="L513">                } catch (ClassCastException e) {</span>
<span class="nc" id="L514">                  log.debug(e);</span>
                  // shouldn't happen
<span class="fc" id="L516">                }</span>
<span class="fc" id="L517">              }</span>
            }
<span class="fc" id="L519">          }</span>
        }
      }
    }
<span class="fc" id="L523">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org.
   * apache.solr.handler.component.ResponseBuilder,
   * mtas.codec.util.CodecComponent.ComponentFields)
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
    // System.out.println(&quot;collection: &quot; + System.nanoTime() + &quot; - &quot;
    // + Thread.currentThread().getId() + &quot; - &quot;
    // + rb.req.getParams().getBool(&quot;isShard&quot;, false) + &quot; DISTRIBUTEDPROCESS &quot;
    // + rb.stage + &quot; &quot; + rb.req.getParamString());
<span class="fc" id="L540">    NamedList&lt;Object&gt; mtasResponse = null;</span>
    try {
<span class="fc" id="L542">      mtasResponse = (NamedList&lt;Object&gt;) rb.rsp.getValues().get(&quot;mtas&quot;);</span>
<span class="nc" id="L543">    } catch (ClassCastException e) {</span>
<span class="nc" id="L544">      log.debug(e);</span>
<span class="nc" id="L545">      mtasResponse = null;</span>
<span class="fc" id="L546">    }</span>
<span class="pc bpc" id="L547" title="1 of 2 branches missed.">    if (mtasResponse != null) {</span>
<span class="fc bfc" id="L548" title="All 2 branches covered.">      if (rb.stage == MtasSolrSearchComponent.STAGE_COLLECTION_INIT) {</span>
        // build index
<span class="fc" id="L550">        Map&lt;String, MtasSolrCollectionResult&gt; index = new HashMap&lt;&gt;();</span>
        ArrayList&lt;Object&gt; mtasResponseCollection;
        try {
<span class="fc" id="L553">          mtasResponseCollection = (ArrayList&lt;Object&gt;) mtasResponse</span>
<span class="fc" id="L554">              .get(&quot;collection&quot;);</span>
<span class="fc bfc" id="L555" title="All 2 branches covered.">          for (Object item : mtasResponseCollection) {</span>
<span class="pc bpc" id="L556" title="1 of 2 branches missed.">            if (item instanceof SimpleOrderedMap) {</span>
<span class="fc" id="L557">              SimpleOrderedMap&lt;Object&gt; itemMap = (SimpleOrderedMap&lt;Object&gt;) item;</span>
<span class="pc bpc" id="L558" title="1 of 2 branches missed.">              if (itemMap.get(&quot;data&quot;) != null</span>
<span class="pc bpc" id="L559" title="1 of 2 branches missed.">                  &amp;&amp; itemMap.get(&quot;data&quot;) instanceof MtasSolrCollectionResult) {</span>
<span class="fc" id="L560">                MtasSolrCollectionResult collectionItem = (MtasSolrCollectionResult) itemMap</span>
<span class="fc" id="L561">                    .get(&quot;data&quot;);</span>
<span class="fc" id="L562">                index.put(collectionItem.id(), collectionItem);</span>
              }
            }
<span class="fc" id="L565">          }</span>
<span class="nc" id="L566">        } catch (ClassCastException e) {</span>
<span class="nc" id="L567">          log.debug(e);</span>
<span class="nc" id="L568">          mtasResponse.remove(&quot;collection&quot;);</span>
<span class="fc" id="L569">        }</span>
        // check and remove previous responses
<span class="fc" id="L571">        Map&lt;String, Set&lt;String&gt;&gt; createPostAfterMissingCheckResult = new HashMap&lt;&gt;();</span>
<span class="fc bfc" id="L572" title="All 2 branches covered.">        for (ShardRequest sreq : rb.finished) {</span>
<span class="pc bpc" id="L573" title="1 of 2 branches missed.">          if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="pc bpc" id="L574" title="1 of 2 branches missed.">              &amp;&amp; sreq.params.getBool(PARAM_MTAS_COLLECTION, false)) {</span>
<span class="fc bfc" id="L575" title="All 2 branches covered.">            for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="fc" id="L576">              NamedList&lt;Object&gt; solrShardResponse = shardResponse</span>
<span class="fc" id="L577">                  .getSolrResponse().getResponse();</span>
              try {
<span class="fc" id="L579">                ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt; data = (ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt;) solrShardResponse</span>
<span class="fc" id="L580">                    .findRecursive(&quot;mtas&quot;, &quot;collection&quot;);</span>
<span class="pc bpc" id="L581" title="1 of 2 branches missed.">                if (data != null) {</span>
<span class="fc bfc" id="L582" title="All 2 branches covered.">                  for (SimpleOrderedMap&lt;Object&gt; dataItem : data) {</span>
<span class="pc bpc" id="L583" title="1 of 2 branches missed.">                    if (dataItem.get(&quot;data&quot;) != null &amp;&amp; dataItem</span>
<span class="pc bpc" id="L584" title="1 of 2 branches missed.">                        .get(&quot;data&quot;) instanceof MtasSolrCollectionResult) {</span>
<span class="fc" id="L585">                      MtasSolrCollectionResult dataItemResult = (MtasSolrCollectionResult) dataItem</span>
<span class="fc" id="L586">                          .get(&quot;data&quot;);</span>
<span class="pc bpc" id="L587" title="1 of 2 branches missed.">                      if (index.containsKey(dataItemResult.id())</span>
<span class="fc" id="L588">                          &amp;&amp; index.get(dataItemResult.id()).action()</span>
<span class="fc bfc" id="L589" title="All 2 branches covered.">                              .equals(ComponentCollection.ACTION_CHECK)) {</span>
<span class="fc bfc" id="L590" title="All 2 branches covered.">                        if (dataItemResult.status == null) {</span>
<span class="fc" id="L591">                          if (!createPostAfterMissingCheckResult</span>
<span class="fc bfc" id="L592" title="All 2 branches covered.">                              .containsKey(shardResponse.getShard())) {</span>
<span class="fc" id="L593">                            createPostAfterMissingCheckResult</span>
<span class="fc" id="L594">                                .put(shardResponse.getShard(), new HashSet&lt;&gt;());</span>
                          }
<span class="fc" id="L596">                          createPostAfterMissingCheckResult</span>
<span class="fc" id="L597">                              .get(shardResponse.getShard())</span>
<span class="fc" id="L598">                              .add(dataItemResult.id());</span>
                        }
                      }
                    }
<span class="fc" id="L602">                  }</span>
<span class="fc" id="L603">                  data.clear();</span>
                }
<span class="nc" id="L605">              } catch (ClassCastException e) {</span>
<span class="nc" id="L606">                log.debug(e);</span>
                // shouldn't happen
<span class="fc" id="L608">              }</span>
<span class="fc" id="L609">            }</span>
          }
<span class="fc" id="L611">        }</span>
        // construct new requests
<span class="fc" id="L613">        HashMap&lt;String, ModifiableSolrParams&gt; requestParamList = new HashMap&lt;&gt;();</span>
<span class="fc" id="L614">        int id = 0;</span>
<span class="fc bfc" id="L615" title="All 2 branches covered.">        for (ComponentCollection componentCollection : mtasFields.collection) {</span>
<span class="fc" id="L616">          if (componentCollection.action()</span>
<span class="fc bfc" id="L617" title="All 2 branches covered.">              .equals(ComponentCollection.ACTION_CHECK)) {</span>
<span class="fc bfc" id="L618" title="All 2 branches covered.">            for (String shardAddress : rb.shards) {</span>
<span class="fc bfc" id="L619" title="All 2 branches covered.">              if (createPostAfterMissingCheckResult.containsKey(shardAddress)) {</span>
<span class="fc" id="L620">                if (createPostAfterMissingCheckResult.get(shardAddress)</span>
<span class="pc bpc" id="L621" title="1 of 2 branches missed.">                    .contains(componentCollection.id)) {</span>
<span class="fc" id="L622">                  HashSet&lt;String&gt; values = searchComponent.getCollectionCache()</span>
<span class="fc" id="L623">                      .getDataById(componentCollection.id);</span>
<span class="fc bfc" id="L624" title="All 2 branches covered.">                  if (values != null) {</span>
                    ModifiableSolrParams paramsNewRequest;
<span class="fc bfc" id="L626" title="All 2 branches covered.">                    if (!requestParamList.containsKey(shardAddress)) {</span>
<span class="fc" id="L627">                      paramsNewRequest = new ModifiableSolrParams();</span>
<span class="fc" id="L628">                      requestParamList.put(shardAddress, paramsNewRequest);</span>
                    } else {
<span class="fc" id="L630">                      paramsNewRequest = requestParamList.get(shardAddress);</span>
                    }
<span class="fc" id="L632">                    paramsNewRequest.add(</span>
                        PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                            + NAME_MTAS_COLLECTION_KEY,
                        componentCollection.key);
<span class="fc" id="L636">                    paramsNewRequest.add(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;</span>
                        + NAME_MTAS_COLLECTION_ID, componentCollection.id);
<span class="fc" id="L638">                    paramsNewRequest.add(</span>
                        PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                            + NAME_MTAS_COLLECTION_ACTION,
                        ComponentCollection.ACTION_POST);
<span class="fc" id="L642">                    paramsNewRequest.add(</span>
                        PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                            + NAME_MTAS_COLLECTION_POST,
<span class="fc" id="L645">                        stringValuesToString(values));</span>
<span class="fc" id="L646">                    id++;</span>
                  }
                }
              }
            }
<span class="fc" id="L651">          } else if (componentCollection.action()</span>
<span class="fc bfc" id="L652" title="All 2 branches covered.">              .equals(ComponentCollection.ACTION_CREATE)) {</span>
<span class="pc bpc" id="L653" title="1 of 2 branches missed.">            if (componentCollection.version == null) {</span>
<span class="fc" id="L654">              componentCollection.version = searchComponent.getCollectionCache()</span>
<span class="fc" id="L655">                  .create(componentCollection.id,</span>
<span class="fc" id="L656">                      componentCollection.values().size(),</span>
<span class="fc" id="L657">                      componentCollection.values());</span>
            }
<span class="pc bpc" id="L659" title="1 of 2 branches missed.">            if (index.containsKey(componentCollection.id)) {</span>
<span class="fc" id="L660">              index.get(componentCollection.id).setCreate(</span>
<span class="fc" id="L661">                  searchComponent.getCollectionCache().now(), searchComponent</span>
<span class="fc" id="L662">                      .getCollectionCache().check(componentCollection.id));</span>
            }
<span class="fc bfc" id="L664" title="All 2 branches covered.">            for (String shardAddress : rb.shards) {</span>
              ModifiableSolrParams paramsNewRequest;
<span class="pc bpc" id="L666" title="1 of 2 branches missed.">              if (!requestParamList.containsKey(shardAddress)) {</span>
<span class="fc" id="L667">                paramsNewRequest = new ModifiableSolrParams();</span>
<span class="fc" id="L668">                requestParamList.put(shardAddress, paramsNewRequest);</span>
              } else {
<span class="nc" id="L670">                paramsNewRequest = requestParamList.get(shardAddress);</span>
              }
<span class="fc" id="L672">              paramsNewRequest.add(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;</span>
                  + NAME_MTAS_COLLECTION_KEY, componentCollection.key);
<span class="fc" id="L674">              paramsNewRequest.add(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;</span>
                  + NAME_MTAS_COLLECTION_ID, componentCollection.id);
<span class="fc" id="L676">              paramsNewRequest.add(</span>
                  PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                      + NAME_MTAS_COLLECTION_ACTION,
                  ComponentCollection.ACTION_POST);
<span class="fc" id="L680">              paramsNewRequest.add(</span>
                  PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                      + NAME_MTAS_COLLECTION_POST,
<span class="fc" id="L683">                  stringValuesToString(componentCollection.values()));</span>
            }
          } 
<span class="fc" id="L686">          id++;</span>
<span class="fc" id="L687">        }</span>
        // add new requests
<span class="fc bfc" id="L689" title="All 2 branches covered.">        for (Entry&lt;String, ModifiableSolrParams&gt; entry : requestParamList</span>
<span class="fc" id="L690">            .entrySet()) {</span>
<span class="fc" id="L691">          ShardRequest newSreq = new ShardRequest();</span>
<span class="fc" id="L692">          newSreq.shards = new String[] { entry.getKey() };</span>
<span class="fc" id="L693">          newSreq.purpose = ShardRequest.PURPOSE_PRIVATE;</span>
<span class="fc" id="L694">          newSreq.params = entry.getValue();</span>
<span class="fc" id="L695">          newSreq.params.add(&quot;q&quot;, &quot;*&quot;);</span>
<span class="fc" id="L696">          newSreq.params.add(&quot;rows&quot;, &quot;0&quot;);</span>
<span class="fc" id="L697">          newSreq.params.add(MtasSolrSearchComponent.PARAM_MTAS,</span>
<span class="fc" id="L698">              rb.req.getOriginalParams()</span>
<span class="fc" id="L699">                  .getParams(MtasSolrSearchComponent.PARAM_MTAS));</span>
<span class="fc" id="L700">          newSreq.params.add(PARAM_MTAS_COLLECTION,</span>
<span class="fc" id="L701">              rb.req.getOriginalParams().getParams(PARAM_MTAS_COLLECTION));</span>
<span class="fc" id="L702">          rb.addRequest(searchComponent, newSreq);</span>
<span class="fc" id="L703">        }</span>
<span class="pc bpc" id="L704" title="1 of 2 branches missed.">      } else if (rb.stage == MtasSolrSearchComponent.STAGE_COLLECTION_FINISH) {</span>
        // just rewrite
        ArrayList&lt;Object&gt; mtasResponseCollection;
        try {
<span class="fc" id="L708">          mtasResponseCollection = (ArrayList&lt;Object&gt;) mtasResponse</span>
<span class="fc" id="L709">              .get(&quot;collection&quot;);</span>
<span class="pc bpc" id="L710" title="1 of 2 branches missed.">          if (mtasResponseCollection != null) {</span>
<span class="fc" id="L711">            MtasSolrResultUtil.rewrite(mtasResponseCollection, searchComponent);</span>
          }
<span class="nc" id="L713">        } catch (ClassCastException e) {</span>
<span class="nc" id="L714">          log.debug(e);</span>
<span class="nc" id="L715">          mtasResponse.remove(&quot;collection&quot;);</span>
<span class="fc" id="L716">        }</span>
      }
    }
<span class="fc" id="L719">  }</span>

  /**
   * Gets the mtas fields.
   *
   * @param rb the rb
   * @return the mtas fields
   */
  private ComponentFields getMtasFields(ResponseBuilder rb) {
<span class="fc" id="L728">    return (ComponentFields) rb.req.getContext().get(ComponentFields.class);</span>
  }

  /**
   * String values to string.
   *
   * @param stringValues the string values
   * @return the string
   */
  private static String stringValuesToString(HashSet&lt;String&gt; stringValues) {
<span class="fc" id="L738">    return JSONUtil.toJSON(stringValues);</span>
  }

  /**
   * String to string values.
   *
   * @param stringValue the string value
   * @return the hash set
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private static HashSet&lt;String&gt; stringToStringValues(String stringValue)
      throws IOException {
    // should be improved to support escaped characters
<span class="fc" id="L751">    HashSet&lt;String&gt; stringValues = new HashSet&lt;&gt;();</span>
<span class="fc" id="L752">    JSONParser jsonParser = new JSONParser(stringValue);</span>
<span class="fc" id="L753">    int event = jsonParser.nextEvent();</span>
<span class="pc bpc" id="L754" title="1 of 2 branches missed.">    if (event == JSONParser.ARRAY_START) {</span>
<span class="fc bfc" id="L755" title="All 2 branches covered.">      while ((event = jsonParser.nextEvent()) != JSONParser.ARRAY_END) {</span>
<span class="pc bpc" id="L756" title="1 of 2 branches missed.">        if (jsonParser.getLevel() == 1) {</span>
<span class="pc bpc" id="L757" title="2 of 4 branches missed.">          switch (event) {</span>
          case JSONParser.STRING:
<span class="fc" id="L759">            stringValues.add(jsonParser.getString());</span>
<span class="fc" id="L760">            break;</span>
          case JSONParser.BIGNUMBER:
          case JSONParser.NUMBER:
          case JSONParser.LONG:
<span class="fc" id="L764">            stringValues.add(jsonParser.getNumberChars().toString());</span>
<span class="fc" id="L765">            break;</span>
          case JSONParser.BOOLEAN:
<span class="nc" id="L767">            stringValues.add(Boolean.toString(jsonParser.getBoolean()));</span>
<span class="nc" id="L768">            break;</span>
          default:
            // do nothing
          }
        }
      }
    } else {
<span class="nc" id="L775">      throw new IOException(&quot;unsupported json structure&quot;);</span>
    }
<span class="fc" id="L777">    return stringValues;</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>