AccessionSource.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 java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.genesys.blocks.model.Copyable;
import org.gringlobal.component.elastic.ElasticTrigger;
import org.gringlobal.custom.validation.javax.CodeValueField;
import org.gringlobal.model.community.CommunityCodeValues;
import org.gringlobal.model.community.IWebVisible;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
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.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.apache.commons.lang3.Strings;
import org.hibernate.Hibernate;
/**
* Auto-generated by:
* org.apache.openjpa.jdbc.meta.ReverseMappingTool$AnnotatedCodeGenerator
*/
@Entity
@Table(name = "accession_source")
@JsonIdentityInfo(scope = AccessionSource.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@Getter
@Setter
@NoArgsConstructor
public class AccessionSource extends CooperatorOwnedModel implements IWebVisible, Copyable<AccessionSource>, ElasticTrigger {
private static final long serialVersionUID = -4505740539246904505L;
/** Accession Source ID. */
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "accession_source_id", columnDefinition = "int")
private Long id;
/** Accession: Reference to the accession described by this source record. */
@NotNull @ManyToOne(fetch = FetchType.LAZY, cascade = {}, optional = false)
@JoinColumn(name = "accession_id", nullable = false)
private Accession accession;
/** Source Type: Indicates how the accession was first obtained. Uses ACCESSION_SOURCE_TYPE vocabulary. */
@Basic
@NotNull @Column(name = "source_type_code", nullable = false, length = CODE_VALUE_LENGTH)
@CodeValueField(CommunityCodeValues.ACCESSION_SOURCE_TYPE)
private String sourceTypeCode;
/** Source Date: Date when the source event occurred. */
@Basic
@Column(name = "source_date")
private Date sourceDate;
/** Source Date Format: Format of the source event date. Uses DATE_FORMAT vocabulary. */
@Basic
@Column(name = "source_date_code", length = CODE_VALUE_LENGTH)
@CodeValueField(CommunityCodeValues.DATE_FORMAT)
private String sourceDateCode;
// Keep this field here
/** Is Origin?: Indicates whether this source event is considered the origin of the accession. */
@Basic
@NotNull @Size(min = 1, max = 1) @Column(name = "is_origin", nullable = false, length = 1)
private String isOrigin = "N";
/** Collecting or Acquisition Source: Collecting or acquisition source. Uses ACCESSION_SOURCE_HABITAT_TYPE vocabulary. */
@Basic
@Column(name = "acquisition_source_code", length = CODE_VALUE_LENGTH)
@CodeValueField(CommunityCodeValues.ACCESSION_SOURCE_HABITAT_TYPE)
private String acquisitionSource;
/** Associated Species: Associated species at the collection locality. */
@Basic
@Column(name = "associated_species")
@Lob
private String associatedSpecies;
/** Collected Form: Form of material collected. Uses GERMPLASM_FORM vocabulary. */
@Basic
@Column(name = "collected_form_code", length = CODE_VALUE_LENGTH)
@CodeValueField(CommunityCodeValues.GERMPLASM_FORM)
private String collectedFormCode;
/** Collector Verbatim Locality: Locality description recorded in a standard format. */
@Basic
@Column(name = "collector_verbatim_locality")
@Lob
private String collectorVerbatimLocality;
/** Elevation (meters): Elevation of the collection site. No decimals; whole numbers only. */
@Basic
@Column(name = "elevation_meters")
private Integer elevationMeters;
/** Environment Description: Description of the biological and physical environment of the locality. */
@Basic
@Column(name = "environment_description")
@Lob
private String environmentDescription;
/** Formatted Locality: Locality description recorded in a standard format. */
@Basic
@Column(name = "formatted_locality")
@Lob
private String formattedLocality;
/** Geography: Reference to the geography of the collection, development, or donation site. */
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "geography_id")
@Field(type = FieldType.Nested)
private Geography geography;
/** Georeference Annotation: Details of the protocol used to determine the coordinates. */
@Basic
@Column(name = "georeference_annotation")
@Lob
private String georeferenceAnnotation;
/** Georeference Datum: Geodetic system upon which the latitude and longitude are based. */
@Basic
@Size(max = 10) @CodeValueField(CommunityCodeValues.GEOREFERENCE_DATUM)
@Column(name = "georeference_datum", length = 10)
private String georeferenceDatum;
/** Georeference Protocol: Code describing how georeferencing was carried out. Uses GEOREFERENCE_PROTOCOL vocabulary. */
@Basic
@Column(name = "georeference_protocol_code", length = CODE_VALUE_LENGTH)
@CodeValueField("GEOREFERENCE_PROTOCOL")
private String georeferenceProtocolCode;
/** Latitude: Decimal latitude of the collection site. Supports decimal values. */
@Basic
private Double latitude;
/** Longitude: Decimal longitude of the collection site. Supports decimal values. */
@Basic
private Double longitude;
/** Uncertainty: Maximum possible error in the georeferenced location. No decimals; whole numbers only. */
@Basic
private Integer uncertainty;
/** Number Plants Sampled: Number of plants sampled to obtain the quantity collected. No decimals; whole numbers only. */
@Basic
@Column(name = "number_plants_sampled")
private Integer numberPlantsSampled;
/** Quantity Collected: Quantity of material collected. Supports decimal values. */
@Basic
@Column(name = "quantity_collected")
private Double quantityCollected;
/** Unit Quantity Collected: Units of the quantity collected. Uses UNIT_OF_QUANTITY vocabulary. */
@Basic
@Column(name = "unit_quantity_collected_code", length = CODE_VALUE_LENGTH)
@CodeValueField(CommunityCodeValues.UNIT_OF_QUANTITY)
private String unitQuantityCollectedCode;
/** Is Web Visible?: Indicates whether information about this source can be shared with external users. */
@Basic
@NotNull @Size(min = 1, max = 1) @Column(name = "is_web_visible", nullable = false, length = 1)
private String isWebVisible = "N";
/** Note: General remarks about the accession source. */
@Basic
@Column
@Lob
private String note;
@JsonIgnore
@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE })
@JoinTable(name = "accession_source_map",
// owner
joinColumns = @JoinColumn(name = "accession_source_id", referencedColumnName = "accession_source_id"),
// target
inverseJoinColumns = @JoinColumn(name = "cooperator_id", referencedColumnName = "cooperator_id"))
private List<Cooperator> cooperators;
@OneToMany(fetch = FetchType.LAZY, cascade = {}, mappedBy = "accessionSource")
@JsonIgnore
private List<SourceDescObservation> sourceDescObservations;
public AccessionSource(final Long id) {
this.id = id;
}
/**
* @return {@code true} if `isOrigin == 'Y'`
*/
@JsonIgnore
@Transient
public boolean isOrigin() {
return Strings.CS.equals("Y", this.isOrigin);
}
@Override
public void lazyLoad() {
super.lazyLoad();
lazyLoad(this.accession, true);
lazyLoad(this.geography);
}
@Override
public Object[] reindexedEntities() {
Hibernate.initialize(this.accession); // assures maybeReindex will work
return new Object[] { this.accession };
}
@Override
public boolean canEqual(Object other) {
return other instanceof AccessionSource;
}
}