MtasSolrComponentCollection.java.html 53.7 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 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
<?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="L73">  public MtasSolrComponentCollection(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L74">    this.searchComponent = searchComponent;</span>
<span class="fc" id="L75">  }</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="L92">    Set&lt;String&gt; ids = MtasSolrResultUtil</span>
<span class="fc" id="L93">        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_COLLECTION);</span>
<span class="pc bpc" id="L94" title="1 of 2 branches missed.">    if (!ids.isEmpty()) {</span>
<span class="fc" id="L95">      int tmpCounter = 0;</span>
<span class="fc" id="L96">      String[] keys = new String[ids.size()];</span>
<span class="fc" id="L97">      String[] actions = new String[ids.size()];</span>
<span class="fc" id="L98">      String[] fields = new String[ids.size()];</span>
<span class="fc" id="L99">      String[] collectionIds = new String[ids.size()];</span>
<span class="fc" id="L100">      String[] posts = new String[ids.size()];</span>
<span class="fc" id="L101">      String[] urls = new String[ids.size()];</span>
<span class="fc" id="L102">      String[] collections = new String[ids.size()];</span>
<span class="fc bfc" id="L103" title="All 2 branches covered.">      for (String id : ids) {</span>
<span class="fc" id="L104">        actions[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_COLLECTION + &quot;.&quot;</span>
            + id + &quot;.&quot; + NAME_MTAS_COLLECTION_ACTION, null);
<span class="fc" id="L106">        keys[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_KEY,
<span class="fc" id="L108">            String.valueOf(tmpCounter)).trim();</span>
<span class="fc" id="L109">        fields[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_FIELD,
            null);
<span class="fc" id="L112">        collectionIds[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_ID,
            null);
<span class="fc" id="L115">        posts[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_POST,
            null);
<span class="fc" id="L118">        urls[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_COLLECTION_URL,
            null);
<span class="fc" id="L121">        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="L124" title="1 of 2 branches missed.">        if (actions[tmpCounter] != null &amp;&amp; (actions[tmpCounter]</span>
<span class="fc bfc" id="L125" title="All 2 branches covered.">            .equals(ComponentCollection.ACTION_POST)</span>
<span class="pc bpc" id="L126" title="1 of 2 branches missed.">            || actions[tmpCounter].equals(ComponentCollection.ACTION_IMPORT)</span>
<span class="fc bfc" id="L127" title="All 2 branches covered.">            || actions[tmpCounter].equals(ComponentCollection.ACTION_CREATE))) {</span>
<span class="pc bpc" id="L128" title="1 of 2 branches missed.">          if (collectionIds[tmpCounter] == null</span>
<span class="pc bpc" id="L129" title="1 of 2 branches missed.">              || collectionIds[tmpCounter].isEmpty()) {</span>
<span class="nc" id="L130">            collectionIds[tmpCounter] = UUID.randomUUID().toString();</span>
<span class="nc" id="L131">            ModifiableSolrParams changedParams = new ModifiableSolrParams(</span>
<span class="nc" id="L132">                rb.req.getParams());</span>
<span class="nc" id="L133">            changedParams.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;</span>
                + NAME_MTAS_COLLECTION_ID);
<span class="nc" id="L135">            changedParams.set(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;</span>
                + NAME_MTAS_COLLECTION_ID, collectionIds[tmpCounter]);
<span class="nc" id="L137">            rb.req.setParams(changedParams);</span>
          }
        }
<span class="fc" id="L140">        tmpCounter++;</span>
<span class="fc" id="L141">      }</span>
<span class="fc" id="L142">      mtasFields.doCollection = true;</span>
<span class="fc" id="L143">      MtasSolrResultUtil.compareAndCheck(keys, actions,</span>
<span class="fc" id="L144">          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_ACTION, true);</span>
<span class="fc" id="L145">      MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_COLLECTION_KEY,</span>
<span class="fc" id="L146">          NAME_MTAS_COLLECTION_FIELD, false);</span>
<span class="fc" id="L147">      MtasSolrResultUtil.compareAndCheck(keys, collectionIds,</span>
<span class="fc" id="L148">          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_ID, false);</span>
<span class="fc" id="L149">      MtasSolrResultUtil.compareAndCheck(keys, posts, NAME_MTAS_COLLECTION_KEY,</span>
<span class="fc" id="L150">          NAME_MTAS_COLLECTION_POST, false);</span>
<span class="fc" id="L151">      MtasSolrResultUtil.compareAndCheck(keys, urls, NAME_MTAS_COLLECTION_KEY,</span>
<span class="fc" id="L152">          NAME_MTAS_COLLECTION_URL, false);</span>
<span class="fc" id="L153">      MtasSolrResultUtil.compareAndCheck(keys, collections,</span>
<span class="fc" id="L154">          NAME_MTAS_COLLECTION_KEY, NAME_MTAS_COLLECTION_COLLECTION, false);</span>
<span class="fc bfc" id="L155" title="All 2 branches covered.">      for (int i = 0; i &lt; actions.length; i++) {</span>
<span class="pc bpc" id="L156" title="1 of 2 branches missed.">        if (actions[i] != null) {</span>
          ComponentCollection componentCollection;
<span class="pc bpc" id="L158" title="19 of 34 branches missed.">          switch (actions[i]) {</span>
          case ComponentCollection.ACTION_LIST:
<span class="fc" id="L160">            componentCollection = new ComponentCollection(keys[i],</span>
                ComponentCollection.ACTION_LIST);
<span class="fc" id="L162">            componentCollection.setListVariables();</span>
<span class="fc" id="L163">            mtasFields.collection.add(componentCollection);</span>
<span class="fc" id="L164">            break;</span>
          case ComponentCollection.ACTION_CHECK:
<span class="pc bpc" id="L166" title="1 of 2 branches missed.">            if (collectionIds[i] != null) {</span>
<span class="fc" id="L167">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_CHECK);
<span class="fc" id="L169">              componentCollection.setCheckVariables(collectionIds[i]);</span>
<span class="fc" id="L170">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L172">              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="L177" title="All 2 branches missed.">            if (collectionIds[i] != null) {</span>
<span class="nc" id="L178">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_GET);
<span class="nc" id="L180">              componentCollection.setGetVariables(collectionIds[i]);</span>
<span class="nc" id="L181">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L183">              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="L188" title="1 of 2 branches missed.">            if (collectionIds[i] == null) {</span>
<span class="nc" id="L189">              collectionIds[i] = UUID.randomUUID().toString();</span>
            }
<span class="pc bpc" id="L191" title="1 of 2 branches missed.">            if (fields[i] != null) {</span>
<span class="fc" id="L192">              Set&lt;String&gt; fieldList = new HashSet&lt;&gt;(</span>
<span class="fc" id="L193">                  Arrays.asList(fields[i].split(&quot;,&quot;)));</span>
<span class="fc" id="L194">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_CREATE);
<span class="fc" id="L196">              componentCollection.setCreateVariables(collectionIds[i],</span>
                  fieldList);
<span class="fc" id="L198">              mtasFields.doCollection = true;</span>
<span class="fc" id="L199">              mtasFields.collection.add(componentCollection);</span>
<span class="fc" id="L200">              rb.setNeedDocSet(true);</span>
<span class="fc" id="L201">            } else {</span>
<span class="nc" id="L202">              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="L207" title="1 of 2 branches missed.">            if (posts[i] != null) {</span>
<span class="fc" id="L208">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_POST);
<span class="fc" id="L210">              componentCollection.setPostVariables(collectionIds[i],</span>
<span class="fc" id="L211">                  stringToStringValues(posts[i]));</span>
<span class="fc" id="L212">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L214">              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="L219" title="All 4 branches missed.">            if (urls[i] != null &amp;&amp; collections[i] != null) {</span>
<span class="nc" id="L220">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_IMPORT);
<span class="nc" id="L222">              componentCollection.setImportVariables(collectionIds[i], urls[i],</span>
                  collections[i]);
<span class="nc" id="L224">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L226">              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="L232" title="1 of 2 branches missed.">            if (collectionIds[i] != null) {</span>
<span class="fc" id="L233">              componentCollection = new ComponentCollection(keys[i],</span>
                  ComponentCollection.ACTION_DELETE);
<span class="fc" id="L235">              componentCollection.setDeleteVariables(collectionIds[i]);</span>
<span class="fc" id="L236">              mtasFields.collection.add(componentCollection);</span>
            } else {
<span class="nc" id="L238">              throw new IOException(</span>
                  &quot;no id defined for collection (&quot; + actions[i] + &quot;)&quot;);
            }
            break;
          case ComponentCollection.ACTION_EMPTY:
<span class="nc" id="L243">            componentCollection = new ComponentCollection(keys[i],</span>
                ComponentCollection.ACTION_EMPTY);
<span class="nc" id="L245">            mtasFields.collection.add(componentCollection);</span>
<span class="nc" id="L246">            break;</span>
          default:
<span class="nc" id="L248">            throw new IOException(</span>
                &quot;unrecognized action '&quot; + actions[i] + &quot;' for collection&quot;);
          }
<span class="fc" id="L251">        } else {</span>
<span class="nc" id="L252">          throw new IOException(&quot;no action defined for collection&quot;);</span>
        }
      }
    }
<span class="fc" id="L256">  }</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="L274" title="1 of 2 branches missed.">    if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="pc bpc" id="L275" title="1 of 2 branches missed.">        &amp;&amp; sreq.params.getBool(PARAM_MTAS_COLLECTION, false)) {</span>
<span class="fc bfc" id="L276" 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="L280">        Set&lt;String&gt; keys = MtasSolrResultUtil</span>
<span class="fc" id="L281">            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_COLLECTION);</span>
<span class="fc" id="L282">        sreq.params.remove(PARAM_MTAS_COLLECTION);</span>
<span class="fc bfc" id="L283" title="All 2 branches covered.">        for (String key : keys) {</span>
<span class="fc" id="L284">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_ACTION);
<span class="fc" id="L286">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_ID);
<span class="fc" id="L288">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_FIELD);
<span class="fc" id="L290">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_POST);
<span class="fc" id="L292">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_KEY);
<span class="fc" id="L294">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_URL);
<span class="fc" id="L296">          sreq.params.remove(PARAM_MTAS_COLLECTION + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_COLLECTION_COLLECTION);
<span class="fc" id="L298">        }</span>
      }
    }
<span class="fc" id="L301">  }</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="L313">    MtasSolrCollectionResult data = createMtasSolrCollectionResult(</span>
<span class="fc bfc" id="L314" title="All 2 branches covered.">        componentCollection, encode ? false : true);</span>
    // Create response
<span class="fc" id="L316">    SimpleOrderedMap&lt;Object&gt; mtasCollectionResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="fc" id="L317">    mtasCollectionResponse.add(&quot;key&quot;, componentCollection.key);</span>
<span class="fc bfc" id="L318" title="All 2 branches covered.">    if (encode) {</span>
<span class="fc" id="L319">      mtasCollectionResponse.add(&quot;_encoded_data&quot;,</span>
<span class="fc" id="L320">          MtasSolrResultUtil.encode(data));</span>
    } else {
<span class="fc" id="L322">      mtasCollectionResponse.add(&quot;data&quot;, data);</span>
<span class="fc" id="L323">      MtasSolrResultUtil.rewrite(mtasCollectionResponse, searchComponent);</span>
    }
<span class="fc" id="L325">    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="L351" title="1 of 2 branches missed.">    if (componentCollection != null) {</span>
      // Create response
<span class="fc" id="L353">      MtasSolrCollectionResult data = new MtasSolrCollectionResult(</span>
          componentCollection);
<span class="fc" id="L355">      if (componentCollection.action()</span>
<span class="fc bfc" id="L356" title="All 2 branches covered.">          .equals(ComponentCollection.ACTION_CREATE)) {</span>
<span class="pc bpc" id="L357" title="1 of 4 branches missed.">        if (storeIfRelevant &amp;&amp; componentCollection.version == null) {</span>
<span class="fc" id="L358">          componentCollection.version = searchComponent.getCollectionCache()</span>
<span class="fc" id="L359">              .create(componentCollection.id,</span>
<span class="fc" id="L360">                  componentCollection.values().size(),</span>
<span class="fc" id="L361">                  componentCollection.values());</span>
        }
<span class="fc" id="L363">        data.setCreate(searchComponent.getCollectionCache().now(),</span>
<span class="fc" id="L364">            searchComponent.getCollectionCache().check(componentCollection.id));</span>
<span class="fc" id="L365">      } else if (componentCollection.action()</span>
<span class="fc bfc" id="L366" title="All 2 branches covered.">          .equals(ComponentCollection.ACTION_LIST)) {</span>
        // retrieve and add list to result
<span class="fc" id="L368">        data.setList(searchComponent.getCollectionCache().now(),</span>
<span class="fc" id="L369">            searchComponent.getCollectionCache().list());</span>
<span class="fc" id="L370">      } else if (componentCollection.action()</span>
<span class="fc bfc" id="L371" title="All 2 branches covered.">          .equals(ComponentCollection.ACTION_CHECK)) {</span>
        // retrieve and add status to result
<span class="fc" id="L373">        data.setCheck(searchComponent.getCollectionCache().now(),</span>
<span class="fc" id="L374">            searchComponent.getCollectionCache().check(componentCollection.id));</span>
<span class="fc" id="L375">      } else if (componentCollection.action()</span>
<span class="pc bpc" id="L376" title="1 of 2 branches missed.">          .equals(ComponentCollection.ACTION_GET)) {</span>
        // retrieve and add status to result
<span class="nc" id="L378">        HashSet&lt;String&gt; values = searchComponent.getCollectionCache()</span>
<span class="nc" id="L379">            .getDataById(componentCollection.id);</span>
<span class="nc bnc" id="L380" title="All 2 branches missed.">        if (values != null) {</span>
<span class="nc" id="L381">          data.setGet(searchComponent.getCollectionCache().now(),</span>
<span class="nc" id="L382">              searchComponent.getCollectionCache()</span>
<span class="nc" id="L383">                  .check(componentCollection.id),</span>
              values);
        }
<span class="pc" id="L386">      } else if (componentCollection.action()</span>
<span class="pc bpc" id="L387" title="1 of 2 branches missed.">          .equals(ComponentCollection.ACTION_EMPTY)) {</span>
        // empty
<span class="nc" id="L389">        searchComponent.getCollectionCache().empty();</span>
<span class="fc" id="L390">      } else if (componentCollection.action()</span>
<span class="fc bfc" id="L391" title="All 2 branches covered.">          .equals(ComponentCollection.ACTION_POST)) {</span>
        // store if not already stored
<span class="pc bpc" id="L393" title="1 of 2 branches missed.">        if (componentCollection.version == null) {</span>
<span class="fc" id="L394">          componentCollection.version = searchComponent.getCollectionCache()</span>
<span class="fc" id="L395">              .create(componentCollection.id,</span>
<span class="fc" id="L396">                  componentCollection.values().size(),</span>
<span class="fc" id="L397">                  componentCollection.values());</span>
        }
        // add status to result
<span class="fc" id="L400">        data.setPost(searchComponent.getCollectionCache().now(),</span>
<span class="fc" 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_IMPORT)) {</span>
        // import if not already stored
<span class="nc bnc" id="L405" title="All 2 branches missed.">        if (componentCollection.version == null) {</span>
<span class="nc" id="L406">          componentCollection.version = searchComponent.getCollectionCache()</span>
<span class="nc" id="L407">              .create(componentCollection.id,</span>
<span class="nc" id="L408">                  componentCollection.values().size(),</span>
<span class="nc" id="L409">                  componentCollection.values());</span>
        }
        // add status to result
<span class="nc" id="L412">        data.setImport(searchComponent.getCollectionCache().now(),</span>
<span class="nc" id="L413">            searchComponent.getCollectionCache().check(componentCollection.id));</span>
<span class="fc" id="L414">      } else if (componentCollection.action()</span>
<span class="pc bpc" id="L415" title="1 of 2 branches missed.">          .equals(ComponentCollection.ACTION_DELETE)) {</span>
<span class="fc" id="L416">        searchComponent.getCollectionCache().deleteById(componentCollection.id);</span>
      }
<span class="fc" id="L418">      return data;</span>
    } else {
<span class="nc" id="L420">      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="L437" title="1 of 2 branches missed.">    if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {</span>
<span class="fc bfc" id="L438" 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="L440">        ComponentFields mtasFields = getMtasFields(rb);</span>
<span class="pc bpc" id="L441" title="1 of 2 branches missed.">        if (mtasFields.doCollection) {</span>
<span class="fc bfc" id="L442" title="All 2 branches covered.">          if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {</span>
            // mtas response
<span class="fc" id="L444">            NamedList&lt;Object&gt; mtasResponse = null;</span>
            try {
<span class="fc" id="L446">              mtasResponse = (NamedList&lt;Object&gt;) rb.rsp.getValues().get(&quot;mtas&quot;);</span>
<span class="nc" id="L447">            } catch (ClassCastException e) {</span>
<span class="nc" id="L448">              log.debug(e);</span>
<span class="nc" id="L449">              mtasResponse = null;</span>
<span class="fc" id="L450">            }</span>
<span class="pc bpc" id="L451" title="1 of 2 branches missed.">            if (mtasResponse == null) {</span>
<span class="nc" id="L452">              mtasResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L453">              rb.rsp.add(&quot;mtas&quot;, mtasResponse);</span>
            }
            ArrayList&lt;Object&gt; mtasCollectionResponses;
<span class="pc bpc" id="L456" title="1 of 2 branches missed.">            if (mtasResponse.get(&quot;collection&quot;) != null</span>
<span class="nc bnc" id="L457" title="All 2 branches missed.">                &amp;&amp; mtasResponse.get(&quot;collection&quot;) instanceof ArrayList) {</span>
<span class="nc" id="L458">              mtasCollectionResponses = (ArrayList&lt;Object&gt;) mtasResponse</span>
<span class="nc" id="L459">                  .get(&quot;collection&quot;);</span>
            } else {
<span class="fc" id="L461">              mtasCollectionResponses = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L462">              mtasResponse.add(&quot;collection&quot;, mtasCollectionResponses);</span>
            }
            MtasSolrCollectionResult collectionResult;
<span class="fc bfc" id="L465" title="All 2 branches covered.">            for (ComponentCollection componentCollection : mtasFields.collection) {</span>
              try {
<span class="fc" id="L467">                collectionResult = createMtasSolrCollectionResult(</span>
                    componentCollection, false);
                // Create response
<span class="fc" id="L470">                SimpleOrderedMap&lt;Object&gt; mtasCollectionResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="fc" id="L471">                mtasCollectionResponse.add(&quot;key&quot;, componentCollection.key);</span>
<span class="fc" id="L472">                mtasCollectionResponse.add(&quot;data&quot;, collectionResult);</span>
<span class="fc" id="L473">                mtasCollectionResponses.add(mtasCollectionResponse);</span>
<span class="nc" id="L474">              } catch (IOException e) {</span>
<span class="nc" id="L475">                log.debug(e);</span>
<span class="fc" id="L476">              }</span>
<span class="fc" id="L477">            }</span>
          }
          // decode shard responses
<span class="fc bfc" id="L480" title="All 2 branches covered.">          for (ShardRequest sreq : rb.finished) {</span>
<span class="pc bpc" id="L481" title="1 of 2 branches missed.">            if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="pc bpc" id="L482" title="1 of 2 branches missed.">                &amp;&amp; sreq.params.getBool(PARAM_MTAS_COLLECTION, false)) {</span>
<span class="fc bfc" id="L483" title="All 2 branches covered.">              for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="fc" id="L484">                NamedList&lt;Object&gt; solrShardResponse = shardResponse</span>
<span class="fc" id="L485">                    .getSolrResponse().getResponse();</span>
                try {
<span class="fc" id="L487">                  ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt; data = (ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt;) solrShardResponse</span>
<span class="fc" id="L488">                      .findRecursive(&quot;mtas&quot;, &quot;collection&quot;);</span>
<span class="pc bpc" id="L489" title="1 of 2 branches missed.">                  if (data != null) {</span>
<span class="fc" id="L490">                    MtasSolrResultUtil.decode(data);</span>
<span class="fc bfc" id="L491" title="All 2 branches covered.">                    if (rb.stage &gt; ResponseBuilder.STAGE_EXECUTE_QUERY) {</span>
<span class="fc" id="L492">                      ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt; filteredData = new ArrayList&lt;&gt;();</span>
<span class="fc bfc" id="L493" title="All 2 branches covered.">                      for (SimpleOrderedMap&lt;Object&gt; dataItem : data) {</span>
<span class="pc bpc" id="L494" title="1 of 2 branches missed.">                        if (dataItem.get(&quot;data&quot;) != null &amp;&amp; dataItem</span>
<span class="pc bpc" id="L495" title="1 of 2 branches missed.">                            .get(&quot;data&quot;) instanceof MtasSolrCollectionResult) {</span>
<span class="fc" id="L496">                          MtasSolrCollectionResult collectionResult = (MtasSolrCollectionResult) dataItem</span>
<span class="fc" id="L497">                              .get(&quot;data&quot;);</span>
<span class="fc bfc" id="L498" title="All 2 branches covered.">                          if (rb.stage &lt;= MtasSolrSearchComponent.STAGE_COLLECTION_INIT) {</span>
<span class="fc" id="L499">                            if (!collectionResult.action()</span>
<span class="pc bpc" id="L500" title="1 of 2 branches missed.">                                .equals(ComponentCollection.ACTION_CREATE)</span>
<span class="fc" id="L501">                                &amp;&amp; !collectionResult.action()</span>
<span class="pc bpc" id="L502" title="1 of 2 branches missed.">                                    .equals(ComponentCollection.ACTION_LIST)</span>
<span class="fc" id="L503">                                &amp;&amp; !collectionResult.action()</span>
<span class="pc bpc" id="L504" title="1 of 2 branches missed.">                                    .equals(ComponentCollection.ACTION_CHECK)) {</span>
<span class="fc" id="L505">                              filteredData.add(dataItem);</span>
                            }
<span class="pc bpc" id="L507" title="1 of 2 branches missed.">                          } else if (rb.stage &lt;= MtasSolrSearchComponent.STAGE_COLLECTION_FINISH) {</span>
<span class="fc" id="L508">                            if (!collectionResult.action()</span>
<span class="pc bpc" id="L509" title="1 of 2 branches missed.">                                .equals(ComponentCollection.ACTION_POST)</span>
<span class="nc" id="L510">                                &amp;&amp; !collectionResult.action()</span>
<span class="nc bnc" id="L511" title="All 2 branches missed.">                                    .equals(ComponentCollection.ACTION_IMPORT)</span>
<span class="nc" id="L512">                                &amp;&amp; !collectionResult.action()</span>
<span class="nc bnc" id="L513" title="All 2 branches missed.">                                    .equals(ComponentCollection.ACTION_CHECK)) {</span>
<span class="nc" id="L514">                              filteredData.add(dataItem);</span>
                            }
                          }
<span class="fc" id="L517">                        } else {</span>
<span class="nc" id="L518">                          filteredData.add(dataItem);</span>
                        }
<span class="fc" id="L520">                      }</span>
<span class="fc" id="L521">                      data.clear();</span>
<span class="fc" id="L522">                      data.addAll(filteredData);</span>
                    }
                  }
<span class="nc" id="L525">                } catch (ClassCastException e) {</span>
<span class="nc" id="L526">                  log.debug(e);</span>
                  // shouldn't happen
<span class="fc" id="L528">                }</span>
<span class="fc" id="L529">              }</span>
            }
<span class="fc" id="L531">          }</span>
        }
      }
    }
<span class="fc" id="L535">  }</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="L552">    NamedList&lt;Object&gt; mtasResponse = null;</span>
    try {
<span class="fc" id="L554">      mtasResponse = (NamedList&lt;Object&gt;) rb.rsp.getValues().get(&quot;mtas&quot;);</span>
<span class="nc" id="L555">    } catch (ClassCastException e) {</span>
<span class="nc" id="L556">      log.debug(e);</span>
<span class="nc" id="L557">      mtasResponse = null;</span>
<span class="fc" id="L558">    }</span>
<span class="pc bpc" id="L559" title="1 of 2 branches missed.">    if (mtasResponse != null) {</span>
<span class="fc bfc" id="L560" title="All 2 branches covered.">      if (rb.stage == MtasSolrSearchComponent.STAGE_COLLECTION_INIT) {</span>
        // build index
<span class="fc" id="L562">        Map&lt;String, MtasSolrCollectionResult&gt; index = new HashMap&lt;&gt;();</span>
        ArrayList&lt;Object&gt; mtasResponseCollection;
        try {
<span class="fc" id="L565">          mtasResponseCollection = (ArrayList&lt;Object&gt;) mtasResponse</span>
<span class="fc" id="L566">              .get(&quot;collection&quot;);</span>
<span class="fc bfc" id="L567" title="All 2 branches covered.">          for (Object item : mtasResponseCollection) {</span>
<span class="pc bpc" id="L568" title="1 of 2 branches missed.">            if (item instanceof SimpleOrderedMap) {</span>
<span class="fc" id="L569">              SimpleOrderedMap&lt;Object&gt; itemMap = (SimpleOrderedMap&lt;Object&gt;) item;</span>
<span class="pc bpc" id="L570" title="1 of 2 branches missed.">              if (itemMap.get(&quot;data&quot;) != null</span>
<span class="pc bpc" id="L571" title="1 of 2 branches missed.">                  &amp;&amp; itemMap.get(&quot;data&quot;) instanceof MtasSolrCollectionResult) {</span>
<span class="fc" id="L572">                MtasSolrCollectionResult collectionItem = (MtasSolrCollectionResult) itemMap</span>
<span class="fc" id="L573">                    .get(&quot;data&quot;);</span>
<span class="fc" id="L574">                index.put(collectionItem.id(), collectionItem);</span>
              }
            }
<span class="fc" id="L577">          }</span>
<span class="nc" id="L578">        } catch (ClassCastException e) {</span>
<span class="nc" id="L579">          log.debug(e);</span>
<span class="nc" id="L580">          mtasResponse.remove(&quot;collection&quot;);</span>
<span class="fc" id="L581">        }</span>
        // check and remove previous responses
<span class="fc" id="L583">        Map&lt;String, Set&lt;String&gt;&gt; createPostAfterMissingCheckResult = new HashMap&lt;&gt;();</span>
<span class="fc bfc" id="L584" title="All 2 branches covered.">        for (ShardRequest sreq : rb.finished) {</span>
<span class="pc bpc" id="L585" title="1 of 2 branches missed.">          if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="pc bpc" id="L586" title="1 of 2 branches missed.">              &amp;&amp; sreq.params.getBool(PARAM_MTAS_COLLECTION, false)) {</span>
<span class="fc bfc" id="L587" title="All 2 branches covered.">            for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="fc" id="L588">              NamedList&lt;Object&gt; solrShardResponse = shardResponse</span>
<span class="fc" id="L589">                  .getSolrResponse().getResponse();</span>
              try {
<span class="fc" id="L591">                ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt; data = (ArrayList&lt;SimpleOrderedMap&lt;Object&gt;&gt;) solrShardResponse</span>
<span class="fc" id="L592">                    .findRecursive(&quot;mtas&quot;, &quot;collection&quot;);</span>
<span class="pc bpc" id="L593" title="1 of 2 branches missed.">                if (data != null) {</span>
<span class="fc bfc" id="L594" title="All 2 branches covered.">                  for (SimpleOrderedMap&lt;Object&gt; dataItem : data) {</span>
<span class="pc bpc" id="L595" title="1 of 2 branches missed.">                    if (dataItem.get(&quot;data&quot;) != null &amp;&amp; dataItem</span>
<span class="pc bpc" id="L596" title="1 of 2 branches missed.">                        .get(&quot;data&quot;) instanceof MtasSolrCollectionResult) {</span>
<span class="fc" id="L597">                      MtasSolrCollectionResult dataItemResult = (MtasSolrCollectionResult) dataItem</span>
<span class="fc" id="L598">                          .get(&quot;data&quot;);</span>
<span class="pc bpc" id="L599" title="1 of 2 branches missed.">                      if (index.containsKey(dataItemResult.id())</span>
<span class="fc" id="L600">                          &amp;&amp; index.get(dataItemResult.id()).action()</span>
<span class="fc bfc" id="L601" title="All 2 branches covered.">                              .equals(ComponentCollection.ACTION_CHECK)) {</span>
<span class="fc bfc" id="L602" title="All 2 branches covered.">                        if (dataItemResult.status == null) {</span>
<span class="fc" id="L603">                          if (!createPostAfterMissingCheckResult</span>
<span class="fc bfc" id="L604" title="All 2 branches covered.">                              .containsKey(shardResponse.getShard())) {</span>
<span class="fc" id="L605">                            createPostAfterMissingCheckResult</span>
<span class="fc" id="L606">                                .put(shardResponse.getShard(), new HashSet&lt;&gt;());</span>
                          }
<span class="fc" id="L608">                          createPostAfterMissingCheckResult</span>
<span class="fc" id="L609">                              .get(shardResponse.getShard())</span>
<span class="fc" id="L610">                              .add(dataItemResult.id());</span>
                        }
                      }
                    }
<span class="fc" id="L614">                  }</span>
<span class="fc" id="L615">                  data.clear();</span>
                }
<span class="nc" id="L617">              } catch (ClassCastException e) {</span>
<span class="nc" id="L618">                log.debug(e);</span>
                // shouldn't happen
<span class="fc" id="L620">              }</span>
<span class="fc" id="L621">            }</span>
          }
<span class="fc" id="L623">        }</span>
        // construct new requests
<span class="fc" id="L625">        HashMap&lt;String, ModifiableSolrParams&gt; requestParamList = new HashMap&lt;&gt;();</span>
<span class="fc" id="L626">        int id = 0;</span>
<span class="fc bfc" id="L627" title="All 2 branches covered.">        for (ComponentCollection componentCollection : mtasFields.collection) {</span>
<span class="fc" id="L628">          if (componentCollection.action()</span>
<span class="fc bfc" id="L629" title="All 2 branches covered.">              .equals(ComponentCollection.ACTION_CHECK)) {</span>
<span class="fc bfc" id="L630" title="All 2 branches covered.">            for (String shardAddress : rb.shards) {</span>
<span class="fc bfc" id="L631" title="All 2 branches covered.">              if (createPostAfterMissingCheckResult.containsKey(shardAddress)) {</span>
<span class="fc" id="L632">                if (createPostAfterMissingCheckResult.get(shardAddress)</span>
<span class="pc bpc" id="L633" title="1 of 2 branches missed.">                    .contains(componentCollection.id)) {</span>
<span class="fc" id="L634">                  HashSet&lt;String&gt; values = searchComponent.getCollectionCache()</span>
<span class="fc" id="L635">                      .getDataById(componentCollection.id);</span>
<span class="fc bfc" id="L636" title="All 2 branches covered.">                  if (values != null) {</span>
                    ModifiableSolrParams paramsNewRequest;
<span class="fc bfc" id="L638" title="All 2 branches covered.">                    if (!requestParamList.containsKey(shardAddress)) {</span>
<span class="fc" id="L639">                      paramsNewRequest = new ModifiableSolrParams();</span>
<span class="fc" id="L640">                      requestParamList.put(shardAddress, paramsNewRequest);</span>
                    } else {
<span class="fc" id="L642">                      paramsNewRequest = requestParamList.get(shardAddress);</span>
                    }
<span class="fc" id="L644">                    paramsNewRequest.add(</span>
                        PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                            + NAME_MTAS_COLLECTION_KEY,
                        componentCollection.key);
<span class="fc" id="L648">                    paramsNewRequest.add(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;</span>
                        + NAME_MTAS_COLLECTION_ID, componentCollection.id);
<span class="fc" id="L650">                    paramsNewRequest.add(</span>
                        PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                            + NAME_MTAS_COLLECTION_ACTION,
                        ComponentCollection.ACTION_POST);
<span class="fc" id="L654">                    paramsNewRequest.add(</span>
                        PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                            + NAME_MTAS_COLLECTION_POST,
<span class="fc" id="L657">                        stringValuesToString(values));</span>
<span class="fc" id="L658">                    id++;</span>
                  }
                }
              }
            }
<span class="fc" id="L663">          } else if (componentCollection.action()</span>
<span class="fc bfc" id="L664" title="All 2 branches covered.">              .equals(ComponentCollection.ACTION_CREATE)) {</span>
<span class="pc bpc" id="L665" title="1 of 2 branches missed.">            if (componentCollection.version == null) {</span>
<span class="fc" id="L666">              componentCollection.version = searchComponent.getCollectionCache()</span>
<span class="fc" id="L667">                  .create(componentCollection.id,</span>
<span class="fc" id="L668">                      componentCollection.values().size(),</span>
<span class="fc" id="L669">                      componentCollection.values());</span>
            }
<span class="pc bpc" id="L671" title="1 of 2 branches missed.">            if (index.containsKey(componentCollection.id)) {</span>
<span class="fc" id="L672">              index.get(componentCollection.id).setCreate(</span>
<span class="fc" id="L673">                  searchComponent.getCollectionCache().now(), searchComponent</span>
<span class="fc" id="L674">                      .getCollectionCache().check(componentCollection.id));</span>
            }
<span class="fc bfc" id="L676" title="All 2 branches covered.">            for (String shardAddress : rb.shards) {</span>
              ModifiableSolrParams paramsNewRequest;
<span class="pc bpc" id="L678" title="1 of 2 branches missed.">              if (!requestParamList.containsKey(shardAddress)) {</span>
<span class="fc" id="L679">                paramsNewRequest = new ModifiableSolrParams();</span>
<span class="fc" id="L680">                requestParamList.put(shardAddress, paramsNewRequest);</span>
              } else {
<span class="nc" id="L682">                paramsNewRequest = requestParamList.get(shardAddress);</span>
              }
<span class="fc" id="L684">              paramsNewRequest.add(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;</span>
                  + NAME_MTAS_COLLECTION_KEY, componentCollection.key);
<span class="fc" id="L686">              paramsNewRequest.add(PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;</span>
                  + NAME_MTAS_COLLECTION_ID, componentCollection.id);
<span class="fc" id="L688">              paramsNewRequest.add(</span>
                  PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                      + NAME_MTAS_COLLECTION_ACTION,
                  ComponentCollection.ACTION_POST);
<span class="fc" id="L692">              paramsNewRequest.add(</span>
                  PARAM_MTAS_COLLECTION + &quot;.&quot; + id + &quot;.&quot;
                      + NAME_MTAS_COLLECTION_POST,
<span class="fc" id="L695">                  stringValuesToString(componentCollection.values()));</span>
            }
          }
<span class="fc" id="L698">          id++;</span>
<span class="fc" id="L699">        }</span>
        // add new requests
<span class="fc bfc" id="L701" title="All 2 branches covered.">        for (Entry&lt;String, ModifiableSolrParams&gt; entry : requestParamList</span>
<span class="fc" id="L702">            .entrySet()) {</span>
<span class="fc" id="L703">          ShardRequest newSreq = new ShardRequest();</span>
<span class="fc" id="L704">          newSreq.shards = new String[] { entry.getKey() };</span>
<span class="fc" id="L705">          newSreq.purpose = ShardRequest.PURPOSE_PRIVATE;</span>
<span class="fc" id="L706">          newSreq.params = entry.getValue();</span>
<span class="fc" id="L707">          newSreq.params.add(&quot;q&quot;, &quot;*&quot;);</span>
<span class="fc" id="L708">          newSreq.params.add(&quot;rows&quot;, &quot;0&quot;);</span>
<span class="fc" id="L709">          newSreq.params.add(MtasSolrSearchComponent.PARAM_MTAS,</span>
<span class="fc" id="L710">              rb.req.getOriginalParams()</span>
<span class="fc" id="L711">                  .getParams(MtasSolrSearchComponent.PARAM_MTAS));</span>
<span class="fc" id="L712">          newSreq.params.add(PARAM_MTAS_COLLECTION,</span>
<span class="fc" id="L713">              rb.req.getOriginalParams().getParams(PARAM_MTAS_COLLECTION));</span>
<span class="fc" id="L714">          rb.addRequest(searchComponent, newSreq);</span>
<span class="fc" id="L715">        }</span>
<span class="pc bpc" id="L716" 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="L720">          mtasResponseCollection = (ArrayList&lt;Object&gt;) mtasResponse</span>
<span class="fc" id="L721">              .get(&quot;collection&quot;);</span>
<span class="pc bpc" id="L722" title="1 of 2 branches missed.">          if (mtasResponseCollection != null) {</span>
<span class="fc" id="L723">            MtasSolrResultUtil.rewrite(mtasResponseCollection, searchComponent);</span>
          }
<span class="nc" id="L725">        } catch (ClassCastException e) {</span>
<span class="nc" id="L726">          log.debug(e);</span>
<span class="nc" id="L727">          mtasResponse.remove(&quot;collection&quot;);</span>
<span class="fc" id="L728">        }</span>
      }
    }
<span class="fc" id="L731">  }</span>

  /**
   * Gets the mtas fields.
   *
   * @param rb
   *          the rb
   * @return the mtas fields
   */
  private ComponentFields getMtasFields(ResponseBuilder rb) {
<span class="fc" id="L741">    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="L752">    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="L767">    HashSet&lt;String&gt; stringValues = new HashSet&lt;&gt;();</span>
<span class="fc" id="L768">    JSONParser jsonParser = new JSONParser(stringValue);</span>
<span class="fc" id="L769">    int event = jsonParser.nextEvent();</span>
<span class="pc bpc" id="L770" title="1 of 2 branches missed.">    if (event == JSONParser.ARRAY_START) {</span>
<span class="fc bfc" id="L771" title="All 2 branches covered.">      while ((event = jsonParser.nextEvent()) != JSONParser.ARRAY_END) {</span>
<span class="pc bpc" id="L772" title="1 of 2 branches missed.">        if (jsonParser.getLevel() == 1) {</span>
<span class="pc bpc" id="L773" title="2 of 4 branches missed.">          switch (event) {</span>
          case JSONParser.STRING:
<span class="fc" id="L775">            stringValues.add(jsonParser.getString());</span>
<span class="fc" id="L776">            break;</span>
          case JSONParser.BIGNUMBER:
          case JSONParser.NUMBER:
          case JSONParser.LONG:
<span class="fc" id="L780">            stringValues.add(jsonParser.getNumberChars().toString());</span>
<span class="fc" id="L781">            break;</span>
          case JSONParser.BOOLEAN:
<span class="nc" id="L783">            stringValues.add(Boolean.toString(jsonParser.getBoolean()));</span>
<span class="nc" id="L784">            break;</span>
          default:
            // do nothing
<span class="nc" id="L787">            break;</span>
          }
        }
      }
    } else {
<span class="nc" id="L792">      throw new IOException(&quot;unsupported json structure&quot;);</span>
    }
<span class="fc" id="L794">    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>