<commit_before>/*
 *    Copyright 2016 West Coast Informatics, LLC
 */
package com.wci.umls.server.jpa.content;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.hibernate.envers.Audited;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Fields;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.Store;

import com.wci.umls.server.helpers.ConfigUtility;
import com.wci.umls.server.jpa.helpers.MapValueToCsvBridge;
import com.wci.umls.server.model.content.Atom;
import com.wci.umls.server.model.content.AtomRelationship;
import com.wci.umls.server.model.content.AtomSubsetMember;
import com.wci.umls.server.model.content.ComponentHistory;
import com.wci.umls.server.model.content.Definition;
import com.wci.umls.server.model.workflow.WorkflowStatus;

/**
 * JPA and JAXB enabled implementation of {@link Atom}.
 */
@Entity
// @UniqueConstraint here is being used to create an index, not to enforce
// uniqueness
@Table(name = "atoms", uniqueConstraints = {
    @UniqueConstraint(columnNames = {
        "terminologyId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "conceptId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "codeId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "descriptorId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "lexicalClassId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "stringClassId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "lowerNameHash", "conceptId", "terminology", "version", "id"
    })
})
@Audited
@XmlRootElement(name = "atom")
public class AtomJpa extends AbstractComponentHasAttributes implements Atom {

  /** The definitions. */
  @OneToMany(targetEntity = DefinitionJpa.class)
  @IndexedEmbedded(targetElement = DefinitionJpa.class)
  private List<Definition> definitions = null;

  /** The members. */
  @OneToMany(mappedBy = "member", targetEntity = AtomSubsetMemberJpa.class)
  private List<AtomSubsetMember> members = null;

  /** The relationships. */
  @OneToMany(mappedBy = "from", targetEntity = AtomRelationshipJpa.class)
  private List<AtomRelationship> relationships = null;

  /** The component histories. */
  @OneToMany(targetEntity = ComponentHistoryJpa.class)
  private List<ComponentHistory> componentHistories = null;

  /** The concept terminology id map. */
  @ElementCollection(fetch = FetchType.EAGER)
  // consider this: @Fetch(sFetchMode.JOIN)
  @Column(nullable = false)
  Map<String, String> conceptTerminologyIds;

  /** The alternate terminology ids. */
  @ElementCollection(fetch = FetchType.EAGER)
  // consider this: @Fetch(FetchMode.JOIN)
  @Column(nullable = true)
  private Map<String, String> alternateTerminologyIds;

  /** The code id. */
  @Column(nullable = false)
  private String codeId;

  /** The descriptor id. */
  @Column(nullable = false)
  private String descriptorId;

  /** The concept id. */
  @Column(nullable = false)
  private String conceptId;

  /** The language. */
  @Column(nullable = false)
  private String language;

  /** The lexical class id. */
  @Column(nullable = false)
  private String lexicalClassId;

  /** The string class id. */
  @Column(nullable = false)
  private String stringClassId;

  /** The lower name hash. */
  @Column(nullable = false)
  private String lowerNameHash;

  /** The name. */
  @Column(nullable = false, length = 4000)
  private String name;

  /** The term type. */
  @Column(nullable = false)
  private String termType;

  /** The workflow status. */
  @Enumerated(EnumType.STRING)
  @Column(nullable = false)
  private WorkflowStatus workflowStatus;

  /**
   * Instantiates an empty {@link AtomJpa}.
   */
  public AtomJpa() {
    // do nothing
  }

  /**
   * Instantiates a {@link AtomJpa} from the specified parameters.
   *
   * @param atom the atom
   */<commit_msg>NE-52: allow lowerNameHash to be null<commit_after>/*
 *    Copyright 2016 West Coast Informatics, LLC
 */
package com.wci.umls.server.jpa.content;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.hibernate.envers.Audited;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Fields;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.Store;

import com.wci.umls.server.helpers.ConfigUtility;
import com.wci.umls.server.jpa.helpers.MapValueToCsvBridge;
import com.wci.umls.server.model.content.Atom;
import com.wci.umls.server.model.content.AtomRelationship;
import com.wci.umls.server.model.content.AtomSubsetMember;
import com.wci.umls.server.model.content.ComponentHistory;
import com.wci.umls.server.model.content.Definition;
import com.wci.umls.server.model.workflow.WorkflowStatus;

/**
 * JPA and JAXB enabled implementation of {@link Atom}.
 */
@Entity
// @UniqueConstraint here is being used to create an index, not to enforce
// uniqueness
@Table(name = "atoms", uniqueConstraints = {
    @UniqueConstraint(columnNames = {
        "terminologyId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "conceptId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "codeId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "descriptorId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "lexicalClassId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "stringClassId", "terminology", "version", "id"
    }), @UniqueConstraint(columnNames = {
        "lowerNameHash", "conceptId", "terminology", "version", "id"
    })
})
@Audited
@XmlRootElement(name = "atom")
public class AtomJpa extends AbstractComponentHasAttributes implements Atom {

  /** The definitions. */
  @OneToMany(targetEntity = DefinitionJpa.class)
  @IndexedEmbedded(targetElement = DefinitionJpa.class)
  private List<Definition> definitions = null;

  /** The members. */
  @OneToMany(mappedBy = "member", targetEntity = AtomSubsetMemberJpa.class)
  private List<AtomSubsetMember> members = null;

  /** The relationships. */
  @OneToMany(mappedBy = "from", targetEntity = AtomRelationshipJpa.class)
  private List<AtomRelationship> relationships = null;

  /** The component histories. */
  @OneToMany(targetEntity = ComponentHistoryJpa.class)
  private List<ComponentHistory> componentHistories = null;

  /** The concept terminology id map. */
  @ElementCollection(fetch = FetchType.EAGER)
  // consider this: @Fetch(sFetchMode.JOIN)
  @Column(nullable = false)
  Map<String, String> conceptTerminologyIds;

  /** The alternate terminology ids. */
  @ElementCollection(fetch = FetchType.EAGER)
  // consider this: @Fetch(FetchMode.JOIN)
  @Column(nullable = true)
  private Map<String, String> alternateTerminologyIds;

  /** The code id. */
  @Column(nullable = false)
  private String codeId;

  /** The descriptor id. */
  @Column(nullable = false)
  private String descriptorId;

  /** The concept id. */
  @Column(nullable = false)
  private String conceptId;

  /** The language. */
  @Column(nullable = false)
  private String language;

  /** The lexical class id. */
  @Column(nullable = false)
  private String lexicalClassId;

  /** The string class id. */
  @Column(nullable = false)
  private String stringClassId;

  /** The lower name hash. */
  @Column(nullable = true)
  private String lowerNameHash;

  /** The name. */
  @Column(nullable = false, length = 4000)
  private String name;

  /** The term type. */
  @Column(nullable = false)
  private String termType;

  /** The workflow status. */
  @Enumerated(EnumType.STRING)
  @Column(nullable = false)
  private WorkflowStatus workflowStatus;

  /**
   * Instantiates an empty {@link AtomJpa}.
   */
  public AtomJpa() {
    // do nothing
  }

  /**
   * Instantiates a {@link AtomJpa} from the specified parameters.
   *
   * @param atom the atom
   */
{'fraction_non_alphanumeric': 0.12629812231196896, 'fraction_numerical': 0.0018881779083184727, 'mean_word_length': 4.371267605633803, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7321686', 'n_tokens_mistral': 2952, 'n_tokens_neox': 2882, 'n_words': 645}