Commit 7d897742 authored by Matija Obreza's avatar Matija Obreza
Browse files

Removed referenced 1-to-1 entities from Accession

Introduced AccessionGeo from Environment
Fixed upsert accession REST method
parent 67a4f8f0
-- Add @Id, @Version to acq_collect, ...
ALTER TABLE `acq_breeding` CHANGE COLUMN `version` `version` BIGINT NOT NULL DEFAULT 0,
CHANGE COLUMN `ALIS_Id` `ALIS_Id` BIGINT NOT NULL ,
ADD COLUMN `id` BIGINT NOT NULL AUTO_INCREMENT FIRST ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY (`id`) ,
ADD UNIQUE INDEX `ALIS_Id_UNIQUE` (`ALIS_Id` ASC) ;
ALTER TABLE `acq_collect` CHANGE COLUMN `version` `version` BIGINT NOT NULL DEFAULT 0,
CHANGE COLUMN `ALIS_Id` `ALIS_Id` BIGINT NOT NULL ,
ADD COLUMN `id` BIGINT NOT NULL AUTO_INCREMENT FIRST ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY (`id`) ,
ADD UNIQUE INDEX `ALIS_Id_UNIQUE` (`ALIS_Id` ASC) ;
ALTER TABLE `acq_exchange` CHANGE COLUMN `version` `version` BIGINT NOT NULL DEFAULT 0,
CHANGE COLUMN `ALIS_Id` `ALIS_Id` BIGINT NOT NULL ,
ADD COLUMN `id` BIGINT NOT NULL AUTO_INCREMENT FIRST ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY (`id`) ,
ADD UNIQUE INDEX `ALIS_Id_UNIQUE` (`ALIS_Id` ASC) ;
ALTER TABLE `environment` CHANGE COLUMN `version` `version` BIGINT NOT NULL DEFAULT 0,
CHANGE COLUMN `ALIS_Id` `ALIS_Id` BIGINT NOT NULL ,
ADD COLUMN `id` BIGINT NOT NULL AUTO_INCREMENT FIRST ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY (`id`) ,
ADD UNIQUE INDEX `ALIS_Id_UNIQUE` (`ALIS_Id` ASC) ;
ALTER TABLE `accnames` CHANGE COLUMN `version` `version` BIGINT NOT NULL DEFAULT 0,
CHANGE COLUMN `ALIS_Id` `ALIS_Id` BIGINT NOT NULL ,
ADD COLUMN `id` BIGINT NOT NULL AUTO_INCREMENT FIRST ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY (`id`) ,
ADD UNIQUE INDEX `ALIS_Id_UNIQUE` (`ALIS_Id` ASC) ;
-- Create acq_geo table
create table acq_geo as select id, ALIS_Id, version, LatitudeD as lat, LongitudeD as lng, Altitude as alt from environment;
ALTER TABLE `acq_geo` CHANGE COLUMN `id` `id` BIGINT(20) NOT NULL AUTO_INCREMENT, modify column alt double null, ADD PRIMARY KEY (`id`) ;
-- alter table environment drop column LatitudeD, drop column LongitudeD, drop column Altitude;
ALTER TABLE `accession` DROP COLUMN `dataSource` , CHANGE COLUMN `ACC_Numb_HI` `ACC_Numb_HI` VARCHAR(36) NOT NULL COMMENT 'Accession Number at Holding Institute' , CHANGE COLUMN `Taxon_Code` `Taxon_Code` BIGINT NOT NULL COMMENT 'Taxon Code' , CHANGE COLUMN `Acquisition_Source` `Acquisition_Source` VARCHAR(3) NULL COMMENT 'Acquisition Source Code' , CHANGE COLUMN `Acquisition_Date` `Acquisition_Date` VARCHAR(8) NULL COMMENT 'Acquisition Date' , CHANGE COLUMN `Origin` `Origin` VARCHAR(3) NULL COMMENT 'Country of Origin ISO Code' , CHANGE COLUMN `Dubl_Inst` `Dubl_Inst` VARCHAR(8) NULL COMMENT 'Duplicate Institute' , CHANGE COLUMN `Sample_Status` `Sample_Status` VARCHAR(3) NULL COMMENT 'Sample Status Code' , CHANGE COLUMN `Storage` `Storage` VARCHAR(12) NULL COMMENT 'Storage Type Code' , CHANGE COLUMN `Genuss` `Genuss` VARCHAR(32) NOT NULL ;
......@@ -22,10 +22,6 @@ import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AllAccnames;
import org.genesys2.server.model.genesys.AllAcqBreeding;
import org.genesys2.server.model.genesys.AllAcqCollect;
import org.genesys2.server.model.genesys.AllAcqExchange;
import org.genesys2.server.model.genesys.Taxonomy;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -68,31 +64,31 @@ public class AccessionBridge implements FieldBridge {
if (institute.getCountry() != null)
sd.append(institute.getCountry().getName());
}
AllAccnames accNames = accession.getAccessionNames();
if (accNames != null) {
sd.append(accNames.getOtherIds());
sd.append(accNames.getAccNames());
}
AllAcqBreeding accBreeding = accession.getAccessionBreeding();
if (accBreeding != null) {
sd.append(accBreeding.getPedigree());
sd.append(accBreeding.getBreederCode());
}
AllAcqCollect accCollect = accession.getAccessionCollection();
if (accCollect != null) {
sd.append(accCollect.getCollectSite());
sd.append(accCollect.getCollectorsNumb());
sd.append(accCollect.getCollectingInstitute());
}
AllAcqExchange accExchange = accession.getAccessionExchange();
if (accExchange != null) {
sd.append(accExchange.getDonorInstitute());
sd.append(accExchange.getAccNumbDonor());
}
// AllAccnames accNames = accession.getAccessionNames();
// if (accNames != null) {
// sd.append(accNames.getOtherIds());
// sd.append(accNames.getAccNames());
// }
//
// AllAcqBreeding accBreeding = accession.getAccessionBreeding();
// if (accBreeding != null) {
// sd.append(accBreeding.getPedigree());
// sd.append(accBreeding.getBreederCode());
// }
//
// AllAcqCollect accCollect = accession.getAccessionCollection();
// if (accCollect != null) {
// sd.append(accCollect.getCollectSite());
// sd.append(accCollect.getCollectorsNumb());
// sd.append(accCollect.getCollectingInstitute());
// }
//
// AllAcqExchange accExchange = accession.getAccessionExchange();
// if (accExchange != null) {
// sd.append(accExchange.getDonorInstitute());
// sd.append(accExchange.getAccNumbDonor());
// }
//
LOG.debug("IDX." + name + " = " + sd.toString());
Field field = new Field(name, sd.toString(), luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector());
field.setBoost(luceneOptions.getBoost());
......
......@@ -20,14 +20,12 @@ package org.genesys2.server.model.genesys;
import java.text.MessageFormat;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
......@@ -65,13 +63,6 @@ public class Accession implements java.io.Serializable {
private Boolean availability;
private Boolean mlsStatus;
private String genus;
private String dataSource;
private AllAccnames accessionNames;
private AllAcqBreeding accessionBreeding;
private AllAcqCollect accessionCollection;
private AllAcqExchange accessionExchange;
private AllEnvironment accessionEnvironment;
private SvalbardData svalbardData;
public Accession() {
}
......@@ -253,70 +244,6 @@ public class Accession implements java.io.Serializable {
this.genus = genuss;
}
@OneToOne(optional = true, cascade = { CascadeType.ALL }, mappedBy = "accession")
public AllAccnames getAccessionNames() {
return accessionNames;
}
public void setAccessionNames(AllAccnames accessionNames) {
this.accessionNames = accessionNames;
}
@OneToOne(optional = true, cascade = { CascadeType.ALL }, mappedBy = "accession")
public AllAcqBreeding getAccessionBreeding() {
return accessionBreeding;
}
public void setAccessionBreeding(AllAcqBreeding accessionBreeding) {
this.accessionBreeding = accessionBreeding;
}
@OneToOne(optional = true, cascade = { CascadeType.ALL }, mappedBy = "accession")
public AllAcqCollect getAccessionCollection() {
return accessionCollection;
}
public void setAccessionCollection(AllAcqCollect accessionCollection) {
this.accessionCollection = accessionCollection;
}
@OneToOne(optional = true, cascade = { CascadeType.ALL }, mappedBy = "accession")
public AllAcqExchange getAccessionExchange() {
return accessionExchange;
}
public void setAccessionExchange(AllAcqExchange accessionExchange) {
this.accessionExchange = accessionExchange;
}
@OneToOne(optional = true, cascade = { CascadeType.ALL }, mappedBy = "accession")
public AllEnvironment getAccessionEnvironment() {
return accessionEnvironment;
}
public void setAccessionEnvironment(AllEnvironment accessionEnvironment) {
this.accessionEnvironment = accessionEnvironment;
}
@OneToOne(orphanRemoval = true, cascade = CascadeType.REMOVE, optional = true)
@JoinColumn(name = "id", referencedColumnName = "id")
public SvalbardData getSvalbardData() {
return svalbardData;
}
public void setSvalbardData(SvalbardData svalbardData) {
this.svalbardData = svalbardData;
}
@Column(name = "dataSource", length = 45)
public String getDataSource() {
return dataSource;
}
public void setDataSource(String dataSource) {
this.dataSource = dataSource;
}
@Override
public String toString() {
return MessageFormat.format("Accession id={0,number,#} A={3} inst={1} genus={2}", id, instituteCode, genus, accNumbHi);
......
/**
* Copyright 2013 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.model.genesys;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
@Entity
@Table(name = "acq_geo")
public class AccessionGeo extends BusinessModel {
@Version
private long version = 0;
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "ALIS_Id", unique = true, nullable = false, updatable = false)
private Accession accession;
@Column(name = "lng")
private Double longitude;
@Column(name = "lat")
private Double latitude;
@Column(name = "alt")
private Double altitude;
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
public Accession getAccession() {
return accession;
}
public void setAccession(Accession accession) {
this.accession = accession;
}
public Double getLongitude() {
return this.longitude;
}
public void setLongitude(final Double longitudeD) {
this.longitude = longitudeD;
}
public Double getLatitude() {
return this.latitude;
}
public void setLatitude(final Double latitudeD) {
this.latitude = latitudeD;
}
public Double getAltitude() {
return this.altitude;
}
public void setAltitude(final Double altitude) {
this.altitude = altitude;
}
}
......@@ -16,35 +16,28 @@
package org.genesys2.server.model.genesys;
// Generated Apr 24, 2013 10:08:59 AM by Hibernate Tools 4.0.0
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
/**
* AllAccnames generated by hbm2java
*/
@Entity
@Table(name = "accnames")
public class AllAccnames {
@Id
@Column(name = "ALIS_Id")
private Long id;
public class AllAccnames extends BusinessModel{
@Version
private long version = 0;
@MapsId
@OneToOne(optional = false, fetch = FetchType.LAZY)
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "ALIS_Id", unique = true, nullable = false, updatable = false)
private Accession accession;
......@@ -59,14 +52,6 @@ public class AllAccnames {
public AllAccnames() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public long getVersion() {
return version;
}
......
......@@ -16,35 +16,28 @@
package org.genesys2.server.model.genesys;
// Generated Apr 24, 2013 10:08:59 AM by Hibernate Tools 4.0.0
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
/**
* AllAcqBreeding generated by hbm2java
*/
@Entity
@Table(name = "acq_breeding")
public class AllAcqBreeding {
@Id
@Column(name = "ALIS_Id")
private Long id;
public class AllAcqBreeding extends BusinessModel{
@Version
private long version = 0;
@MapsId
@OneToOne(optional = false, fetch = FetchType.LAZY)
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "ALIS_Id", unique = true, nullable = false, updatable = false)
private Accession accession;
......@@ -58,14 +51,6 @@ public class AllAcqBreeding {
public AllAcqBreeding() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public long getVersion() {
return version;
}
......
......@@ -21,30 +21,25 @@ package org.genesys2.server.model.genesys;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
/**
* AllAcqCollect generated by hbm2java
*/
@Entity
@Table(name = "acq_collect")
public class AllAcqCollect {
@Id
@Column(name = "ALIS_Id")
private Long id;
public class AllAcqCollect extends BusinessModel {
@Version
private long version = 0;
@MapsId
@OneToOne(optional = false, fetch = FetchType.LAZY)
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "ALIS_Id", unique = true, nullable = false, updatable = false)
private Accession accession;
......@@ -61,18 +56,9 @@ public class AllAcqCollect {
@Lob
private String collectSite;
public AllAcqCollect() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public long getVersion() {
return version;
}
......
......@@ -16,34 +16,27 @@
package org.genesys2.server.model.genesys;
// Generated Apr 24, 2013 10:08:59 AM by Hibernate Tools 4.0.0
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
/**
* AllAcqExchange generated by hbm2java
*/
@Entity
@Table(name = "acq_exchange")
public class AllAcqExchange {
@Id
@Column(name = "ALIS_Id")
private Long id;
public class AllAcqExchange extends BusinessModel{
@Version
private long version = 0;
@MapsId
@OneToOne(optional = false, fetch = FetchType.LAZY)
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "ALIS_Id", unique = true, nullable = false, updatable = false)
private Accession accession;
......@@ -56,16 +49,6 @@ public class AllAcqExchange {
public AllAcqExchange() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public long getVersion() {
return version;
}
......
......@@ -16,31 +16,24 @@
package org.genesys2.server.model.genesys;
// Generated Apr 24, 2013 10:08:59 AM by Hibernate Tools 4.0.0
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
@Entity
@Table(name = "environment")
public class AllEnvironment {
@Id
@Column(name = "ALIS_Id")
private Long id;
public class AllEnvironment extends BusinessModel{
@Version
private long version = 0;
@MapsId
@OneToOne(optional = false, fetch = FetchType.LAZY)
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "ALIS_Id", unique = true, nullable = false, updatable = false)
private Accession accession;
......@@ -167,14 +160,6 @@ public class AllEnvironment {
@Column(name = "Altitude")
private Short altitude;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public long getVersion() {
return version;
}
......
......@@ -16,9 +16,12 @@
package org.genesys2.server.persistence.domain;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AllAcqBreeding;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AccessionBreedingRepository extends JpaRepository<AllAcqBreeding, Long> {