TaxonomyGenus.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.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.Copyable;
import org.gringlobal.compatibility.LookupDisplay;
import org.gringlobal.component.elastic.ElasticLoader;
import org.gringlobal.custom.validation.javax.CodeValueField;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
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 static org.gringlobal.model.community.CommunityCodeValues.CODE_VALUE_LENGTH;
/**
* Auto-generated by:
* org.apache.openjpa.jdbc.meta.ReverseMappingTool$AnnotatedCodeGenerator
*/
@Entity
@Cacheable
@Table(name = "taxonomy_genus")
@Document(indexName = "taxonomygenus")
@JsonIdentityInfo(scope = TaxonomyGenus.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@Getter
@Setter
@NoArgsConstructor
@LookupDisplay(template = "concat(genusName, case when(subgenusName = null) then '' else concat(' subg. ', subgenusName) end," +
" case when(sectionName = null) then '' else concat(' sect. ', sectionName) end, case when(subsectionName = null) then '' else concat(' subsect. ', subsectionName) end," +
" case when(seriesName = null) then '' else concat(' ser. ', seriesName) end, case when(subseriesName = null) then '' else concat(' subser. ', subseriesName) end," +
" case when(genusAuthority = null) then '' when(genusAuthority = '') then '' else concat(' ', genusAuthority) end)"
)
public class TaxonomyGenus extends CooperatorOwnedModel implements Copyable<TaxonomyGenus>, ElasticLoader {
private static final long serialVersionUID = 3054321300424882004L;
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "taxonomy_genus_id", columnDefinition = "int")
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "current_taxonomy_genus_id")
@JsonIgnore
@JsonIdentityInfo(scope = TaxonomyGenus.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIdentityReference(alwaysAsId = true)
private TaxonomyGenus currentTaxonomyGenus;
@Basic
@Column(name = "genus_authority", length = 100)
private String genusAuthority;
@Basic
@Column(name = "genus_name", nullable = false, length = 30)
private String genusName;
@Basic
@Column(name = "hybrid_code", length = CODE_VALUE_LENGTH)
@CodeValueField(value = "GENUS_HYBRID", strict = false)
private String hybridCode;
@Column(name = "grin_genus_id")
private Long grinId;
@Basic
@Column
@Lob
private String note;
@Basic
@Column(name = "qualifying_code", length = CODE_VALUE_LENGTH)
@CodeValueField(value = "TAXONOMY_GENUS_QUALIFIER", strict = false)
private String qualifyingCode;
@Basic
@Column(name = "section_name", length = 30)
private String sectionName;
@Basic
@Column(name = "series_name", length = 30)
private String seriesName;
@Basic
@Column(name = "subgenus_name", length = 30)
private String subgenusName;
@Basic
@Column(name = "subsection_name", length = 30)
private String subsectionName;
@Basic
@Column(name = "subseries_name", length = 30)
private String subseriesName;
@ManyToOne(fetch = FetchType.EAGER, cascade = {})
@JoinColumn(name = "taxonomy_family_id", nullable = false)
@Field(type = FieldType.Object)
@JsonIgnoreProperties({ "ownedBy", "createdBy", "modifiedBy", "typeTaxonomyGenus", "currentTaxonomyFamily", "note" })
private TaxonomyFamily taxonomyFamily;
@Basic
@Column(name = "is_web_visible", nullable = false, length = 1)
private String isWebVisible = "N";
public TaxonomyGenus(final Long id) {
this.id = id;
}
@Override
public void lazyLoad() {
super.lazyLoad();
lazyLoad(this.getCurrentTaxonomyGenus());
lazyLoad(this.getTaxonomyFamily());
}
@Override
public void prepareForIndexing() {
this.lazyLoad();
}
/**
* The complete genus name, including hybrid code
*
* @return full genus name
*/
public String getName() {
return StringUtils.defaultIfBlank(this.hybridCode, "") + this.genusName;
}
@Override
public boolean canEqual(Object other) {
return other instanceof TaxonomyGenus;
}
}