SubsetAccessionRef.java
/*
* Copyright 2018 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.genesys.server.model.impl;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.genesys.server.model.genesys.Accession;
import org.genesys.server.model.genesys.AccessionRef;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* The Class SubsetAccessionRef.
*/
@Entity
@Table(name = "subset_accessions", indexes = { @Index(columnList = "subsetId, instCode, acceNumb"), @Index(columnList = "subsetId, genus") }, uniqueConstraints = {
@UniqueConstraint(columnNames = { "subsetId", "instCode", "acceNumb", "genus" }), @UniqueConstraint(columnNames = { "subsetId", "doi" }) })
@Getter
@Setter
@NoArgsConstructor
public class SubsetAccessionRef extends AccessionRef<Subset> {
private static final long serialVersionUID = 5965542485446091921L;
@ManyToOne(cascade = {}, optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "subsetId")
@JsonIgnore
protected Subset list;
/**
* Instantiates a new subset accession ref.
*
* @param ref the ref
*/
public SubsetAccessionRef(AccessionRef<?> ref) {
this.instCode=ref.getInstCode();
this.acceNumb=ref.getAcceNumb();
this.genus=ref.getGenus();
this.species=ref.getSpecies();
this.doi=ref.getDoi();
this.accession = ref.getAccession();
}
/**
* Instantiates a new subset accession ref.
*
* @param accession the accession
*/
public SubsetAccessionRef(Accession accession) {
super(accession);
}
public SubsetAccessionRef(String instCode, String acceNumb, String genus, String doi) {
super(instCode, acceNumb, genus, doi);
}
/**
* Gets the subset.
*
* @return the subset
*/
@Transient
@JsonIgnore
public Subset getSubset() {
return list;
}
/**
* Sets the subset.
*
* @param subset the new subset
*/
public void setSubset(Subset subset) {
this.list = subset;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((list == null) ? 0 : list.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
SubsetAccessionRef other = (SubsetAccessionRef) obj;
if (list == null) {
if (other.list != null)
return false;
} else if (!Objects.equals(list.getId(), other.list.getId()))
return false;
return true;
}
@Override
public boolean canEqual(Object other) {
return other instanceof SubsetAccessionRef;
}
}