<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasSolrCollectionResult.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.solr.handler.component.util</a> > <span class="el_source">MtasSolrCollectionResult.java</span></div><h1>MtasSolrCollectionResult.java</h1><pre class="source lang-java linenums">package mtas.solr.handler.component.util; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import org.apache.solr.common.util.SimpleOrderedMap; import mtas.codec.util.CodecComponent.ComponentCollection; import mtas.solr.handler.component.MtasSolrSearchComponent; /** * The Class MtasSolrCollectionResult. */ public class MtasSolrCollectionResult implements Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** The values. */ private HashSet<String> values; /** The id. */ private String id; /** The action. */ private String action; /** The now. */ private Long now; /** The list. */ private List<SimpleOrderedMap<Object>> list; /** The status. */ public SimpleOrderedMap<Object> status; /** The component collection. */ <span class="fc" id="L43"> private transient ComponentCollection componentCollection = null;</span> /** * Instantiates a new mtas solr collection result. * * @param componentCollection the component collection * @throws IOException Signals that an I/O exception has occurred. */ public MtasSolrCollectionResult(ComponentCollection componentCollection) <span class="fc" id="L52"> throws IOException {</span> <span class="fc" id="L53"> this.componentCollection = componentCollection;</span> <span class="pc bpc" id="L54" title="1 of 2 branches missed."> if (componentCollection != null) {</span> <span class="fc" id="L55"> action = componentCollection.action();</span> <span class="fc" id="L56"> id = null;</span> <span class="fc" id="L57"> values = null;</span> <span class="fc" id="L58"> now = null;</span> <span class="fc" id="L59"> list = null;</span> <span class="pc bpc" id="L60" title="16 of 30 branches missed."> switch (action) {</span> case ComponentCollection.ACTION_CREATE: <span class="fc" id="L62"> values = componentCollection.values();</span> <span class="fc" id="L63"> id = componentCollection.id;</span> <span class="fc" id="L64"> break;</span> case ComponentCollection.ACTION_CHECK: case ComponentCollection.ACTION_GET: case ComponentCollection.ACTION_DELETE: <span class="fc" id="L68"> id = componentCollection.id;</span> <span class="fc" id="L69"> break;</span> case ComponentCollection.ACTION_POST: case ComponentCollection.ACTION_IMPORT: <span class="fc" id="L72"> id = componentCollection.id;</span> <span class="fc" id="L73"> values = componentCollection.values();</span> <span class="fc" id="L74"> break;</span> case ComponentCollection.ACTION_LIST: case ComponentCollection.ACTION_EMPTY: // do nothing <span class="fc" id="L78"> break;</span> default: <span class="pc" id="L80"> throw new IOException("action " + action + " not allowed");</span> } } else { <span class="nc" id="L83"> throw new IOException("no componentCollection available");</span> } <span class="fc" id="L85"> }</span> /** * Sets the list. * * @param now the now * @param list the list * @throws IOException Signals that an I/O exception has occurred. */ public void setList(long now, List<SimpleOrderedMap<Object>> list) throws IOException { <span class="pc bpc" id="L96" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_LIST)) {</span> <span class="fc" id="L97"> this.now = now;</span> <span class="fc" id="L98"> this.list = list;</span> } else { <span class="nc" id="L100"> throw new IOException("not allowed with action '" + action + "'");</span> } <span class="fc" id="L102"> }</span> /** * Sets the check. * * @param now the now * @param status the status * @throws IOException Signals that an I/O exception has occurred. */ public void setCheck(long now, SimpleOrderedMap<Object> status) throws IOException { <span class="pc bpc" id="L113" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_CHECK)) {</span> <span class="fc" id="L114"> this.now = now;</span> <span class="fc" id="L115"> this.status = status;</span> } else { <span class="nc" id="L117"> throw new IOException("not allowed with action '" + action + "'");</span> } <span class="fc" id="L119"> }</span> /** * Sets the get. * * @param now the now * @param status the status * @param stringValues the string values * @throws IOException Signals that an I/O exception has occurred. */ public void setGet(long now, SimpleOrderedMap<Object> status, HashSet<String> stringValues) throws IOException { <span class="nc bnc" id="L131" title="All 2 branches missed."> if (action.equals(ComponentCollection.ACTION_GET)) {</span> <span class="nc" id="L132"> this.now = now;</span> <span class="nc" id="L133"> this.status = status;</span> <span class="nc" id="L134"> this.values = stringValues;</span> } else { <span class="nc" id="L136"> throw new IOException("not allowed with action '" + action + "'");</span> } <span class="nc" id="L138"> }</span> /** * Sets the post. * * @param now the now * @param status the status * @throws IOException Signals that an I/O exception has occurred. */ public void setPost(long now, SimpleOrderedMap<Object> status) throws IOException { <span class="pc bpc" id="L149" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_POST)) {</span> <span class="fc" id="L150"> this.now = now;</span> <span class="fc" id="L151"> this.status = status;</span> } else { <span class="nc" id="L153"> throw new IOException("not allowed with action '" + action + "'");</span> } <span class="fc" id="L155"> }</span> /** * Sets the import. * * @param now the now * @param status the status * @throws IOException Signals that an I/O exception has occurred. */ public void setImport(long now, SimpleOrderedMap<Object> status) throws IOException { <span class="nc bnc" id="L166" title="All 2 branches missed."> if (action.equals(ComponentCollection.ACTION_IMPORT)) {</span> <span class="nc" id="L167"> this.now = now;</span> <span class="nc" id="L168"> this.status = status;</span> } else { <span class="nc" id="L170"> throw new IOException("not allowed with action '" + action + "'");</span> } <span class="nc" id="L172"> }</span> /** * Sets the create. * * @param now the now * @param status the status * @throws IOException Signals that an I/O exception has occurred. */ public void setCreate(long now, SimpleOrderedMap<Object> status) throws IOException { <span class="pc bpc" id="L183" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_CREATE)) {</span> <span class="fc" id="L184"> this.now = now;</span> <span class="fc" id="L185"> this.status = status;</span> } else { <span class="nc" id="L187"> throw new IOException("not allowed with action '" + action + "'");</span> } <span class="fc" id="L189"> }</span> /** * Id. * * @return the string */ public String id() { <span class="fc" id="L197"> return id;</span> } /** * Action. * * @return the string */ public String action() { <span class="fc" id="L206"> return action;</span> } /** * Rewrite. * * @param searchComponent the search component * @return the simple ordered map * @throws IOException Signals that an I/O exception has occurred. */ public SimpleOrderedMap<Object> rewrite( MtasSolrSearchComponent searchComponent) throws IOException { <span class="fc" id="L218"> SimpleOrderedMap<Object> response = new SimpleOrderedMap<>();</span> Iterator<Entry<String, Object>> it; <span class="pc bpc" id="L220" title="11 of 24 branches missed."> switch (action) {</span> case ComponentCollection.ACTION_LIST: <span class="fc" id="L222"> response.add("now", now);</span> <span class="fc" id="L223"> response.add("list", list);</span> <span class="fc" id="L224"> break;</span> case ComponentCollection.ACTION_CREATE: case ComponentCollection.ACTION_POST: case ComponentCollection.ACTION_IMPORT: <span class="pc bpc" id="L228" title="2 of 4 branches missed."> if (componentCollection != null && status != null) {</span> <span class="fc" id="L229"> it = status.iterator();</span> <span class="fc bfc" id="L230" title="All 2 branches covered."> while (it.hasNext()) {</span> <span class="fc" id="L231"> Entry<String, Object> entry = it.next();</span> <span class="fc" id="L232"> response.add(entry.getKey(), entry.getValue());</span> <span class="fc" id="L233"> }</span> } break; case ComponentCollection.ACTION_CHECK: <span class="fc bfc" id="L237" title="All 2 branches covered."> if (status != null) {</span> <span class="fc" id="L238"> it = status.iterator();</span> <span class="fc bfc" id="L239" title="All 2 branches covered."> while (it.hasNext()) {</span> <span class="fc" id="L240"> Entry<String, Object> entry = it.next();</span> <span class="fc" id="L241"> response.add(entry.getKey(), entry.getValue());</span> <span class="fc" id="L242"> }</span> } break; case ComponentCollection.ACTION_GET: <span class="nc bnc" id="L246" title="All 2 branches missed."> if (status != null) {</span> <span class="nc" id="L247"> it = status.iterator();</span> <span class="nc bnc" id="L248" title="All 2 branches missed."> while (it.hasNext()) {</span> <span class="nc" id="L249"> Entry<String, Object> entry = it.next();</span> <span class="nc" id="L250"> response.add(entry.getKey(), entry.getValue());</span> <span class="nc" id="L251"> }</span> } <span class="nc bnc" id="L253" title="All 2 branches missed."> if (values != null) {</span> <span class="nc" id="L254"> response.add("values", values);</span> } break; default: break; } <span class="fc" id="L260"> return response;</span> } /** * Merge. * * @param newItem the new item * @throws IOException Signals that an I/O exception has occurred. */ public void merge(MtasSolrCollectionResult newItem) throws IOException { <span class="pc bpc" id="L270" title="2 of 4 branches missed."> if (action != null && newItem.action != null) {</span> <span class="fc bfc" id="L271" title="All 2 branches covered."> if (action.equals(ComponentCollection.ACTION_CREATE)</span> <span class="fc bfc" id="L272" title="All 2 branches covered."> && newItem.action.equals(ComponentCollection.ACTION_CREATE)) {</span> <span class="fc" id="L273"> values.addAll(newItem.values);</span> <span class="pc bpc" id="L274" title="3 of 6 branches missed."> if (id != null && (newItem.id == null || !newItem.id.equals(id))) {</span> <span class="nc" id="L275"> id = null;</span> } <span class="fc bfc" id="L277" title="All 2 branches covered."> } else if (action.equals(ComponentCollection.ACTION_LIST)) {</span> <span class="pc bpc" id="L278" title="1 of 2 branches missed."> if (list != null) {</span> <span class="fc" id="L279"> HashMap<String, SimpleOrderedMap<Object>> index = new HashMap<>();</span> <span class="fc bfc" id="L280" title="All 2 branches covered."> for (SimpleOrderedMap<Object> item : list) {</span> <span class="pc bpc" id="L281" title="2 of 4 branches missed."> if (item.get("id") != null && item.get("id") instanceof String) {</span> <span class="fc" id="L282"> index.put((String) item.get("id"), item);</span> <span class="fc bfc" id="L283" title="All 2 branches covered."> if (item.get("shards") == null</span> <span class="pc bpc" id="L284" title="1 of 2 branches missed."> || !(item.get("shards") instanceof List)) {</span> <span class="fc" id="L285"> item.add("shards", new ArrayList<>());</span> } } <span class="fc" id="L288"> }</span> <span class="fc bfc" id="L289" title="All 2 branches covered."> for (SimpleOrderedMap<Object> item : newItem.list) {</span> <span class="pc bpc" id="L290" title="2 of 4 branches missed."> if (item.get("id") != null && item.get("id") instanceof String) {</span> <span class="fc" id="L291"> String id = (String) item.get("id");</span> <span class="pc bpc" id="L292" title="1 of 2 branches missed."> if (index.containsKey(id)) {</span> <span class="fc" id="L293"> SimpleOrderedMap<Object> indexItem = index.get(id);</span> List<SimpleOrderedMap<Object>> shards; <span class="pc bpc" id="L295" title="1 of 2 branches missed."> if (indexItem.get("shards") != null</span> <span class="pc bpc" id="L296" title="1 of 2 branches missed."> && indexItem.get("shards") instanceof List) {</span> <span class="fc" id="L297"> shards = (List<SimpleOrderedMap<Object>>) indexItem</span> <span class="fc" id="L298"> .get("shards");</span> } else { <span class="nc" id="L300"> shards = new ArrayList<>();</span> <span class="nc" id="L301"> indexItem.add("shards", shards);</span> } <span class="fc" id="L303"> shards.add(item);</span> } } <span class="fc" id="L306"> }</span> <span class="fc" id="L307"> }</span> <span class="fc bfc" id="L308" title="All 2 branches covered."> } else if (action.equals(ComponentCollection.ACTION_CHECK)</span> <span class="fc bfc" id="L309" title="All 2 branches covered."> || action.equals(ComponentCollection.ACTION_POST)</span> <span class="pc bpc" id="L310" title="1 of 2 branches missed."> || action.equals(ComponentCollection.ACTION_IMPORT)</span> <span class="fc bfc" id="L311" title="All 2 branches covered."> || action.equals(ComponentCollection.ACTION_CREATE)</span> <span class="pc bpc" id="L312" title="1 of 2 branches missed."> || action.equals(ComponentCollection.ACTION_GET)) {</span> <span class="pc bpc" id="L313" title="1 of 4 branches missed."> if (status != null && status.get("id") != null</span> <span class="pc bpc" id="L314" title="1 of 2 branches missed."> && status.get("id") instanceof String) {</span> <span class="fc" id="L315"> String id = (String) status.get("id");</span> <span class="pc bpc" id="L316" title="1 of 2 branches missed."> if (id.equals(newItem.id)) {</span> List<SimpleOrderedMap<Object>> shards; <span class="fc bfc" id="L318" title="All 2 branches covered."> if (status.get("shards") != null</span> <span class="pc bpc" id="L319" title="1 of 2 branches missed."> && status.get("shards") instanceof List) {</span> <span class="fc" id="L320"> shards = (List<SimpleOrderedMap<Object>>) status.get("shards");</span> } else { <span class="fc" id="L322"> shards = new ArrayList<>();</span> <span class="fc" id="L323"> status.add("shards", shards);</span> } <span class="fc bfc" id="L325" title="All 2 branches covered."> if (newItem.status != null) {</span> <span class="pc bpc" id="L326" title="1 of 2 branches missed."> if (action.equals(ComponentCollection.ACTION_GET)) {</span> <span class="nc" id="L327"> newItem.status.add("values", newItem.values);</span> } <span class="fc" id="L329"> shards.add(newItem.status);</span> } } <span class="fc" id="L332"> }</span> } else { <span class="fc" id="L334"> throw new IOException("not allowed for action '" + action + "'");</span> } } <span class="fc" id="L337"> }</span> /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { <span class="nc" id="L346"> StringBuilder text = new StringBuilder("");</span> <span class="nc" id="L347"> text.append(MtasSolrCollectionResult.class.getSimpleName() + "[");</span> <span class="nc" id="L348"> text.append(action + ", ");</span> <span class="nc" id="L349"> text.append(id + ", ");</span> <span class="nc bnc" id="L350" title="All 2 branches missed."> if (componentCollection != null) {</span> <span class="nc" id="L351"> text.append(componentCollection.version + ", ");</span> <span class="nc bnc" id="L352" title="All 2 branches missed."> } else if (status != null) {</span> <span class="nc" id="L353"> text.append(status.get("version") + ", ");</span> } else { <span class="nc" id="L355"> text.append("null, ");</span> } <span class="nc bnc" id="L357" title="All 2 branches missed."> text.append((values != null) ? values.size() : "null");</span> <span class="nc" id="L358"> text.append("]");</span> <span class="nc" id="L359"> return text.toString();</span> } } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>