TaxonomyFamily.java

/*
 * Copyright 2019 Global Crop Diversity Trust
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.gringlobal.model;

import javax.persistence.*;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.genesys.blocks.model.Copyable;

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;

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

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

/**
 * 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;

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

	@Column(name = "grin_family_id")
	private Long grinId;

	@Basic
	@Column(name = "alternate_name", length = 25)
	private String alternateName;

	@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;

	@Basic
	@Column(name = "family_authority", length = 100)
	private String familyAuthority;

	@Basic
	@Column(name = "family_name", nullable = false, length = 25)
	private String familyName;

	@Basic
	@Column
	@Lob
	private String note;

	@Basic
	@Column(name = "subfamily_name", length = 25)
	private String subfamilyName;

	@Basic
	@Column(name = "subtribe_name", length = 25)
	private String subtribeName;

	@Basic
	@Column(name = "suprafamily_rank_code", length = CODE_VALUE_LENGTH)
	@CodeValueField(value = "TAXONOMY_SUPRAFAMILY", strict = false)
	private String suprafamilyRankCode;

	@Basic
	@Column(name = "suprafamily_rank_name", length = 100)
	private String suprafamilyRankName;

	@Basic
	@Column(name = "tribe_name", length = 25)
	private String tribeName;

	@ManyToOne(fetch = FetchType.LAZY, cascade = {})
	@JoinColumn(name = "type_taxonomy_genus_id")
	@JsonIgnoreProperties({ "taxonomyFamily" })
	private TaxonomyGenus typeTaxonomyGenus;

	@Basic
	@Column(name = "family_type_code", length = CODE_VALUE_LENGTH)
	@CodeValueField(value = "TAXONOMY_FAMILY_TYPE", strict = false)
	private String familyTypeCode;

	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;
	}
}