TaxonomyFamily.java

/*
 * Copyright 2026 Global Crop Diversity Trust
 * Licensed under the Apache License, Version 2.0
 * See LICENSE file in project root folder or http://www.apache.org/licenses/LICENSE-2.0
 */

package org.gringlobal.model;

import static org.gringlobal.model.community.CommunityCodeValues.CODE_VALUE_LENGTH;

import javax.persistence.*;

import org.genesys.blocks.model.Copyable;

import org.gringlobal.compatibility.LookupDisplay;
import org.gringlobal.custom.validation.javax.CodeValueField;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

/**
 * Auto-generated by:
 * org.apache.openjpa.jdbc.meta.ReverseMappingTool$AnnotatedCodeGenerator
 */
@Entity
@Cacheable
@Table(name = "taxonomy_family")
@JsonIdentityInfo(scope = TaxonomyFamily.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@Getter
@Setter
@NoArgsConstructor
@LookupDisplay(template = "concat(familyName, case when(subfamilyName = null) then '' else concat(' subfam. ', subfamilyName) end," +
	" case when(tribe_name = null) then '' else concat(' tr. ', tribe_name) end, case when(subtribeName = null) then '' else concat(' subtr. ', subtribeName) end)")
public class TaxonomyFamily extends CooperatorOwnedModel implements Copyable<TaxonomyFamily>{

	private static final long serialVersionUID = 3373830137037007643L;

	/** Taxonomy Family ID. */
	@Id
	@JsonIgnore
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "taxonomy_family_id", columnDefinition = "int")
	private Long id;

	/** Family: The taxonomic family name. */
	@Basic
	@Column(name = "family_name", nullable = false, length = 25)
	private String familyName;

	/** Alternate Family Name: The authorized alternative family name. */
	@Basic
	@Column(name = "alternate_name", length = 25)
	private String alternateName;

	/** TaxonomyFamily: Reference to the accepted extended family described by this taxonomy family. */
	@ManyToOne(fetch = FetchType.LAZY, cascade = {})
	@JoinColumn(name = "current_taxonomy_family_id")
	@JsonIdentityReference(alwaysAsId = true)
	@JsonIdentityInfo(scope = TaxonomyFamily.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
	private TaxonomyFamily currentTaxonomyFamily;

	/** Family Authority: The author for the family name. */
	@Basic
	@Column(name = "family_authority", length = 100)
	private String familyAuthority;

	/** Family Type: The type of taxonomic family. Uses TAXONOMY_FAMILY_TYPE vocabulary. */
	@Basic
	@Column(name = "family_type_code", length = CODE_VALUE_LENGTH)
	@CodeValueField(value = "TAXONOMY_FAMILY_TYPE", strict = false)
	private String familyTypeCode;

	/** GRIN Taxonomy Family ID: The id of this name in USDA GRIN Taxonomy. */
	@Column(name = "grin_family_id")
	private Long grinId;

	/** Subfamily: The name for a subfamily division of the family. */
	@Basic
	@Column(name = "subfamily_name", length = 25)
	private String subfamilyName;

	/** Subtribe: The name for a subtribe division of the family. */
	@Basic
	@Column(name = "subtribe_name", length = 25)
	private String subtribeName;

	/** Suprafamily Rank: The suprafamily rank. Serves to group families. The chosen rank depends on desired family groupings. Uses TAXONOMY_SUPRAFAMILY vocabulary. */
	@Basic
	@Column(name = "suprafamily_rank_code", length = CODE_VALUE_LENGTH)
	@CodeValueField(value = "TAXONOMY_SUPRAFAMILY", strict = false)
	private String suprafamilyRankCode;

	/** Suprafamily Rank Name: The suprafamily name at the chosen suprafamily rank. */
	@Basic
	@Column(name = "suprafamily_rank_name", length = 100)
	private String suprafamilyRankName;

	/** Tribe: The name for a tribe division of the family. */
	@Basic
	@Column(name = "tribe_name", length = 25)
	private String tribeName;

	/** TaxonomyGenus: Reference to the type genus described by this taxonomy family. */
	@ManyToOne(fetch = FetchType.LAZY, cascade = {})
	@JoinColumn(name = "type_taxonomy_genus_id")
	@JsonIgnoreProperties({ "taxonomyFamily" })
	private TaxonomyGenus typeTaxonomyGenus;

	/** Note: Generic comments about the taxonomic family. */
	@Basic
	@Column
	@Lob
	private String note;

	public TaxonomyFamily(final Long id) {
		this.id = id;
	}

	@JsonProperty
	public Long getId() {
		return id;
	}

	public void setId(final Long id) {
		this.id = id;
	}

	@Override
	public void lazyLoad() {
		super.lazyLoad();
		lazyLoad(this.getCurrentTaxonomyFamily());
		lazyLoad(this.getTypeTaxonomyGenus());
	}

	@Override
	public boolean canEqual(Object other) {
		return other instanceof TaxonomyFamily;
	}
}