Commit 266fb660 authored by Matija Obreza's avatar Matija Obreza

Historic fixed

parent bdc99921
......@@ -9,7 +9,6 @@ import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
......
......@@ -20,7 +20,13 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
......@@ -31,9 +37,22 @@ import javax.persistence.UniqueConstraint;
*
*/
@Entity
@Table(name = "accession", uniqueConstraints = { @UniqueConstraint(name = "UQ_accession_genus_inst", columnNames = { "instituteId", "taxGenus",
"acceNumb" }) })
@Table(name = "accession", uniqueConstraints = { @UniqueConstraint(name = "UQ_accession_genus_inst", columnNames = { "instituteId", "taxGenus", "acceNumb" }) })
public class Accession extends AccessionData {
public static final List<Accession> EMPTY_LIST = Collections.unmodifiableList(new ArrayList<Accession>());
@Column(name = "storage", nullable = false)
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "accessionstorage", joinColumns = @JoinColumn(name = "accessionId", referencedColumnName = "id"))
@OrderBy("storage")
private List<Integer> stoRage = new ArrayList<Integer>();
public List<Integer> getStoRage() {
return stoRage;
}
public void setStoRage(List<Integer> stoRage) {
this.stoRage = stoRage;
}
}
......@@ -16,30 +16,65 @@
package org.genesys2.server.model.genesys;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.persistence.CollectionTable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OrderBy;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Transient;
import javax.persistence.Version;
import org.genesys2.server.model.IdUUID;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
@MappedSuperclass
public abstract class AccessionData extends AccessionId {
public abstract class AccessionData implements IdUUID, Serializable {
public static final List<AccessionData> EMPTY_LIST = Collections.unmodifiableList(new ArrayList<AccessionData>());
@Id
private Long id;
@Version
private long version = 0;
@CreatedBy
private Long createdBy;
@CreatedDate
@Column(name = "createdDate")
private Date createdDate;
@LastModifiedBy
private Long lastModifiedBy;
@LastModifiedDate
@Column(name = "lastModifiedDate")
private Date lastModifiedDate;
@MapsId
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, optional = false, orphanRemoval = false)
@JoinColumn(name = "id")
private AccessionId accessionId;
@Column(name = "instCode", length = 10, nullable = false)
private String instituteCode;
......@@ -92,12 +127,6 @@ public abstract class AccessionData extends AccessionId {
@Column(name = "taxGenus", nullable = false)
private long taxGenus;
@Column(name = "storage", nullable = false)
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "accessionstorage", joinColumns = @JoinColumn(name = "accessionId"))
@OrderBy("storage")
private List<Integer> stoRage = new ArrayList<Integer>();
@Column(name = "storage", length = 64, nullable = true)
private String storage;
......@@ -235,13 +264,9 @@ public abstract class AccessionData extends AccessionId {
this.taxonomy = taxonomy2;
}
public List<Integer> getStoRage() {
return stoRage;
}
public abstract List<Integer> getStoRage();
public void setStoRage(List<Integer> stoRage) {
this.stoRage = stoRage;
}
public abstract void setStoRage(List<Integer> stoRage);
/**
* Returns {@link #getStoRage()} as MCPD string
......@@ -258,83 +283,79 @@ public abstract class AccessionData extends AccessionId {
protected void setStorage(String storage) {
this.storage = storage;
}
public boolean getHistoric() {
return historic;
}
public void setHistoric(boolean historic) {
this.historic = historic;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public Long getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(Long lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public Date getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(Date lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
public AccessionId getAccessionId() {
return accessionId;
}
public void setAccessionId(AccessionId accessionId) {
this.accessionId = accessionId;
}
@Override
@Transient
public UUID getUuid() {
return accessionId.getUuid();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public String toString() {
return MessageFormat.format("Accession id={0,number,##########} UUID={1}", id, uuid);
}
// public abstract String getAccessionName();
//
// public abstract String getAcquisitionDate();
//
// public abstract String getAcquisitionSource();
//
// public abstract Boolean getAvailability();
//
// public abstract Boolean getInTrust();
//
// public abstract Boolean getMlsStatus();
//
// public abstract FaoInstitute getInstitute();
//
// public abstract void setInstitute(FaoInstitute institute);
//
// public abstract String getStorage();
//
// public abstract List<Integer> getStoRage();
//
// public abstract String getInstituteCode();
//
// public abstract void setAccessionName(String accessionName);
//
// public abstract Taxonomy2 getTaxonomy();
//
// public abstract void setAcquisitionSource(String acquisitionSource);
//
// public abstract void setAcquisitionDate(String acquisitionDate);
//
// public abstract String getOrigin();
//
// protected abstract void setOrigin(String origin);
//
// public abstract Country getCountryOfOrigin();
//
// public abstract void setCountryOfOrigin(Country countryOfOrigin);
//
// public abstract String getDuplSite();
//
// public abstract void setDuplSite(String duplSite);
//
// public abstract Integer getSampleStatus();
//
// public abstract void setSampleStatus(Integer sampleStatus);
//
// public abstract Boolean getInSvalbard();
//
// public abstract void setInSvalbard(Boolean inSvalbard);
//
// public abstract void setInTrust(Boolean inTrust);
//
// public abstract void setAvailability(Boolean availability);
//
// public abstract void setMlsStatus(Boolean mlsStatus);
//
// public abstract long getTaxGenus();
//
// protected abstract void setTaxGenus(long taxGenus);
//
// public abstract void setTaxonomy(Taxonomy2 taxonomy2);
//
// public abstract void setStoRage(List<Integer> stoRage);
//
// protected abstract void setStorage(String storage);
return MessageFormat.format("Accession id={0,number,##########} UUID={1}", accessionId.getId(), getUuid());
}
}
......@@ -16,7 +16,16 @@
package org.genesys2.server.model.genesys;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OrderBy;
import javax.persistence.Table;
/**
......@@ -29,6 +38,12 @@ import javax.persistence.Table;
@Table(name = "accessionhistoric")
public class AccessionHistoric extends AccessionData {
@Column(name = "storage", nullable = false)
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "accessionstorageh", joinColumns = @JoinColumn(name = "accessionId", referencedColumnName = "id"))
@OrderBy("storage")
private List<Integer> stoRage = new ArrayList<Integer>();
public AccessionHistoric() {
}
......@@ -37,4 +52,12 @@ public class AccessionHistoric extends AccessionData {
SelfCopy.copy(accession, this);
}
public List<Integer> getStoRage() {
return stoRage;
}
public void setStoRage(List<Integer> stoRage) {
this.stoRage = stoRage;
}
}
......@@ -32,7 +32,7 @@ public class AccessionTrait extends BusinessModel {
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "accessionId")
private Accession accession;
private AccessionId accession;
@Column(name = "metadataId")
private long metadataId;
......@@ -40,11 +40,11 @@ public class AccessionTrait extends BusinessModel {
@Column(name = "methodId")
private long methodId;
public Accession getAccession() {
public AccessionId getAccession() {
return accession;
}
public void setAccession(Accession accession) {
public void setAccession(AccessionId accession) {
this.accession = accession;
}
......
......@@ -45,7 +45,7 @@ public class AllAccnames extends BusinessModel {
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "accessionId", unique = true, nullable = false, updatable = false)
private Accession accession;
private AccessionId accession;
@Column(name = "names")
@Lob
......@@ -68,11 +68,11 @@ public class AllAccnames extends BusinessModel {
this.version = version;
}
public Accession getAccession() {
public AccessionId getAccession() {
return accession;
}
public void setAccession(Accession accession) {
public void setAccession(AccessionId accession) {
this.accession = accession;
}
......
......@@ -36,7 +36,7 @@ public class GenesysJsonFactory {
final AccessionJson aj = new AccessionJson();
aj.setVersion(accession.getVersion());
aj.setGenesysId(accession.getId());
aj.setGenesysId(accession.getAccessionId().getId());
aj.setInstCode(accession.getInstitute().getCode());
aj.setAcceNumb(accession.getAccessionName());
......
......@@ -31,13 +31,14 @@ public interface AccessionAliasRepository extends JpaRepository<AccessionAlias,
List<AccessionAlias> findByAccession(AccessionId accession);
@Query("select aa from AccessionAlias aa where aa.accession = ?1 and aa.aliasType = ?2")
List<AccessionAlias> findByAccessionAndAliasType(AccessionId accession, int aliasType);
@Modifying
@Query("delete from AccessionAlias aa where aa.accession.id in ( :ids )")
void deleteForAccessions(@Param("ids") Collection<Long> accessionIds);
@Query("select distinct aa.accession from AccessionAlias aa where aa.usedBy=?1 and aa.name=?2 and aa.aliasType=?3 and aa.accession.institute.code=?1")
@Query("select distinct a from Accession a where a.accessionId in (select distinct aa.accession from AccessionAlias aa where aa.usedBy=?1 and aa.name=?2 and aa.aliasType=?3) and a.institute.code=?1")
Accession findAccession(String instCode, String name, int aliasType);
@Query("from AccessionAlias aa where aa.accession.id in ?1")
......
......@@ -22,14 +22,15 @@ import java.util.UUID;
import org.genesys2.server.model.genesys.AccessionHistoric;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface AccessionHistoricRepository extends JpaRepository<AccessionHistoric, Long> {
AccessionHistoric findOneByUuid(UUID uuid);
List<AccessionHistoric> findByInstituteAndAccessionName(FaoInstitute faoInstitute, String acceNumb);
List<AccessionHistoric> findByAccessionName(String acceNumb);
@Query("select a from AccessionHistoric a where a.accessionId.uuid = ?1")
AccessionHistoric findOneByUuid(UUID uuid);
}
/**
* Copyright 2014 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.genesys2.server.persistence.domain;
import org.genesys2.server.model.genesys.AccessionId;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AccessionIdRepository extends JpaRepository<AccessionId, Long> {
}
......@@ -32,4 +32,5 @@ public interface AccessionNameRepository extends JpaRepository<AllAccnames, Long
@Query("delete from AllAccnames an where an.accession.id in ?1")
void deleteForAccessions(Collection<Long> accessionIds);
}
......@@ -110,6 +110,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query(nativeQuery=true, value="delete from accession where id = ?1")
public void deleteActive(long id);
@Query("select a from Accession a where a.accessionId.uuid = ?1")
public Accession findOneByUuid(UUID uuid);
public List<Accession> findByAccessionName(String acceNumb);
......
......@@ -4,6 +4,7 @@ import java.util.List;
import java.util.UUID;
import org.genesys2.server.model.IdUUID;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -11,6 +12,6 @@ public interface ResolverService {
IdUUID forward(UUID uuid);
List<AccessionId> findMatches(FaoInstitute faoInstitute, String acceNumb);
List<AccessionData> findMatches(FaoInstitute faoInstitute, String acceNumb);
}
......@@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
......@@ -204,6 +203,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
LOG.debug("New accession " + dataJson);
accession = new Accession();
accession.setAccessionId(new AccessionId());
accession.setInstitute(institute);
accession.setAccessionName(dataJson.acceNumb);
......@@ -218,7 +218,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
LOG.trace("*** Updating accession " + dataJson);
}
if (accession.getId() == null || useUniqueAcceNumbs && accnJson.get(Api1Constants.Accession.GENUS) != null
if (accession.getAccessionId().getId() == null || useUniqueAcceNumbs && accnJson.get(Api1Constants.Accession.GENUS) != null
|| accnJson.get(Api1Constants.Accession.GENUS_NEW) != null || accnJson.get(Api1Constants.Accession.SPECIES) != null
|| accnJson.get(Api1Constants.Accession.SPAUTHOR) != null || accnJson.get(Api1Constants.Accession.SUBTAXA) != null
|| accnJson.get(Api1Constants.Accession.SUBTAUTHOR) != null) {
......@@ -292,12 +292,12 @@ public class BatchRESTServiceImpl implements BatchRESTService {
value = accnJson.get(Api1Constants.Accession.ACCENAME);
if (value != null) {
acceNames.put(accession, toMcpdArray(accnJson, Api1Constants.Accession.ACCENAME));
acceNames.put(accession.getAccessionId(), toMcpdArray(accnJson, Api1Constants.Accession.ACCENAME));
}
value = accnJson.get(Api1Constants.Accession.OTHERNUMB);
if (value != null) {
otherNumbs.put(accession, toMcpdArray(accnJson, Api1Constants.Accession.OTHERNUMB));
otherNumbs.put(accession.getAccessionId(), toMcpdArray(accnJson, Api1Constants.Accession.OTHERNUMB));
}
value = accnJson.get(Api1Constants.Accession.SAMPSTAT);
......@@ -323,10 +323,10 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (accnJson.has(Api1Constants.Accession.COLL)) {
final ObjectNode collecting = (ObjectNode) accnJson.get(Api1Constants.Accession.COLL);
AccessionCollect accnColl = genesysService.listAccessionCollect(accession);
AccessionCollect accnColl = genesysService.listAccessionCollect(accession.getAccessionId());
if (accnColl == null) {
accnColl = new AccessionCollect();
accnColl.setAccession(accession);
accnColl.setAccession(accession.getAccessionId());
}
value = collecting.get(Api1Constants.Collecting.COLLDATE);
if (value != null) {
......@@ -335,7 +335,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
value = collecting.get(Api1Constants.Collecting.COLLNUMB);
if (value != null) {
accnColl.setCollNumb(StringUtils.defaultIfBlank(value.textValue(), null));
collNumbs.put(accession, toMcpdArray(collecting, Api1Constants.Collecting.COLLNUMB));
collNumbs.put(accession.getAccessionId(), toMcpdArray(collecting, Api1Constants.Collecting.COLLNUMB));
}
value = collecting.get(Api1Constants.Collecting.COLLSRC);
if (value != null) {
......@@ -374,10 +374,10 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (accnJson.has(Api1Constants.Accession.GEO)) {
final ObjectNode geo = (ObjectNode) accnJson.get(Api1Constants.Accession.GEO);
AccessionGeo accnGeo = genesysService.listAccessionGeo(accession);
AccessionGeo accnGeo = genesysService.listAccessionGeo(accession.getAccessionId());
if (accnGeo == null) {
accnGeo = new AccessionGeo();
accnGeo.setAccession(accession);
accnGeo.setAccession(accession.getAccessionId());
}
value = geo.get(Api1Constants.Geo.LATITUDE);
if (value != null) {
......@@ -423,10 +423,10 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
if (accnJson.has(Api1Constants.Accession.BREDCODE) || accnJson.has(Api1Constants.Accession.ANCEST)) {
AccessionBreeding accnBred = genesysService.listAccessionBreeding(accession);
AccessionBreeding accnBred = genesysService.listAccessionBreeding(accession.getAccessionId());
if (accnBred == null) {
accnBred = new AccessionBreeding();
accnBred.setAccession(accession);
accnBred.setAccession(accession.getAccessionId());
}
value = accnJson.get(Api1Constants.Accession.BREDCODE);
if (value != null) {
......@@ -445,10 +445,10 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (accnJson.has(Api1Constants.Accession.DONORCODE) || accnJson.has(Api1Constants.Accession.DONORNUMB)
|| accnJson.has(Api1Constants.Accession.DONORNAME)) {
AccessionExchange accnExch = genesysService.listAccessionExchange(accession);
AccessionExchange accnExch = genesysService.listAccessionExchange(accession.getAccessionId());
if (accnExch == null) {
accnExch = new AccessionExchange();
accnExch.setAccession(accession);
accnExch.setAccession(accession.getAccessionId());
}