package org.pharmgkb.pharmcat.reporter.model;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import org.apache.commons.lang3.StringUtils;


/**
 * @author Lester Carter
 * @author Ryan Whaley
 */
public class PharmcatException {
  private static final int sf_rowLength = 9;

  public PharmcatException(@Nonnull String row) throws RuntimeException {
    String[] fields = row.split("\\t");

    if (fields.length < sf_rowLength) {
      throw new RuntimeException("Row not of expected length "+sf_rowLength);
    }

    m_name = fields[0];
    m_exceptionType = fields[8];
    m_message = fields[9];
    m_version = fields[10];

    m_matches = new MatchLogic();
    m_matches.setGene(fields[1]);
    m_matches.setHapsCalled(parseList(fields[2]));
    m_matches.setHapsMissing(parseList(fields[3]));
    m_matches.setVariantsMissing(parseList(fields[4]));
    m_matches.setDips(parseList(fields[5]));
    m_matches.setDrugs(parseList(fields[6]));
  }

  @Expose
  @SerializedName("rule_name")
  private String m_name;
  @Expose
  @SerializedName("version")
  private String m_version;
  @Expose
  @SerializedName("matches")
  private MatchLogic m_matches;
  @Expose
  @SerializedName("exception_type")
  private String m_exceptionType;
  @Expose
  @SerializedName("message")
  private String m_message;

  public String getName() {
    return m_name;
  }

  public void setName(String rule_name) {
    m_name = rule_name;
  }

  public String getVersion() {
    return m_version;
  }

  public void setVersion(String version) {
    m_version = version;
  }

  public MatchLogic getMatches() {
    return m_matches;
  }

  public void setMatches(MatchLogic matches) {
    m_matches = matches;
  }

  public String getExceptionType() {
    return m_exceptionType;
  }

  public void setExceptionType(String exceptionType) {
    m_exceptionType = exceptionType;
  }

  public String getMessage() {
    return m_message;
  }

  public void setMessage(String message) {
    m_message = message;
  }

  @Override
  public String toString() {
    return getName();
  }

  private static List<String> parseList(String value) {
    if (StringUtils.isBlank(value)) {
      return new ArrayList<>();
    }

    return ImmutableList.copyOf(Splitter.on(",").trimResults().split(value));
  }
}

package org.pharmgkb.pharmcat.reporter.model;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import org.apache.commons.lang3.StringUtils;


/**
 * @author Lester Carter
 * @author Ryan Whaley
 */
public class PharmcatException {
  private static final int sf_rowLength = 11;

  public PharmcatException(@Nonnull String row) throws RuntimeException {
    String[] fields = row.split("\\t");

    if (fields.length < sf_rowLength) {
      throw new RuntimeException("Row not of expected length "+sf_rowLength);
    }

    m_name = fields[0];

    m_matches = new MatchLogic();
    m_matches.setGene(fields[1]);
    m_matches.setHapsCalled(parseList(fields[2]));
    m_matches.setHapsMissing(parseList(fields[3]));
    m_matches.setVariantsMissing(parseList(fields[4]));
    m_matches.setDips(parseList(fields[5]));
    m_matches.setDrugs(parseList(fields[6]));

    m_exceptionType = fields[8];
    m_message = fields[9];
    m_version = fields[10];
  }

  @Expose
  @SerializedName("rule_name")
  private String m_name;
  @Expose
  @SerializedName("version")
  private String m_version;
  @Expose
  @SerializedName("matches")
  private MatchLogic m_matches;
  @Expose
  @SerializedName("exception_type")
  private String m_exceptionType;
  @Expose
  @SerializedName("message")
  private String m_message;

  public String getName() {
    return m_name;
  }

  public void setName(String rule_name) {
    m_name = rule_name;
  }

  public String getVersion() {
    return m_version;
  }

  public void setVersion(String version) {
    m_version = version;
  }

  public MatchLogic getMatches() {
    return m_matches;
  }

  public void setMatches(MatchLogic matches) {
    m_matches = matches;
  }

  public String getExceptionType() {
    return m_exceptionType;
  }

  public void setExceptionType(String exceptionType) {
    m_exceptionType = exceptionType;
  }

  public String getMessage() {
    return m_message;
  }

  public void setMessage(String message) {
    m_message = message;
  }

  @Override
  public String toString() {
    return getName();
  }

  private static List<String> parseList(String value) {
    if (StringUtils.isBlank(value)) {
      return new ArrayList<>();
    }

    return ImmutableList.copyOf(Splitter.on(",").trimResults().split(value));
  }
}

Update exception row length.