Commit ca541237 authored by Matija Obreza's avatar Matija Obreza
Browse files

Accession#taxGenus, #taxSpecies removed, Taxonomy(1) removed

parent f00fad26
......@@ -58,10 +58,6 @@ public class Accession extends VersionedAuditedModel {
@Column(name = "acceNumb", nullable = false, length = 128)
private String accessionName;
// @ManyToOne(cascade = {}, optional = true)
// @JoinColumn(name = "taxonomyId")
// private Taxonomy taxonomy1;
// @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@ManyToOne(cascade = {}, optional = true)
@JoinColumn(name = "taxonomyId2")
......@@ -98,12 +94,6 @@ public class Accession extends VersionedAuditedModel {
@Column(name = "mlsStat")
private Boolean mlsStatus;
@Column(name = "taxGenus", nullable = true)
private Long taxGenus;
@Column(name = "taxSpecies", nullable = true)
private Long taxSpecies;
@Column(name = "storage", nullable = false)
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "accessionstorage", joinColumns = @JoinColumn(name = "accessionId"))
......@@ -241,23 +231,6 @@ public class Accession extends VersionedAuditedModel {
this.mlsStatus = mlsStatus;
}
public long getTaxGenus() {
return taxGenus == null ? -1 : taxGenus.longValue();
}
// TODO Must be long
public void setTaxGenus(Long taxGenus) {
this.taxGenus = taxGenus;
}
public Long getTaxSpecies() {
return taxSpecies;
}
public void setTaxSpecies(Long taxSpecies) {
this.taxSpecies = taxSpecies;
}
public void setTaxonomy(Taxonomy2 taxonomy2) {
this.taxonomy = taxonomy2;
}
......@@ -288,6 +261,6 @@ public class Accession extends VersionedAuditedModel {
@Override
public String toString() {
return MessageFormat.format("Accession id={0,number,#} A={3} inst={1} genus={2}", id, instituteCode, taxGenus, accessionName);
return MessageFormat.format("Accession id={0,number,#} A={3} inst={1} genus={2}", id, instituteCode, "N/A", accessionName);
}
}
/**
* 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.model.genesys;
import java.text.MessageFormat;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.genesys2.server.model.BusinessModel;
@Entity
// Add index on genus, genus+species
@Table(name = "taxonomy", uniqueConstraints = { @UniqueConstraint(columnNames = { "genus", "species" }) })
public class Taxonomy extends BusinessModel {
private static final long serialVersionUID = 8881324404490162933L;
@Column(nullable = false, length = 64)
private String genus;
@Column(nullable = false, length = 64)
private String species;
@Column(name = "taxonName", nullable = false, length = 200)
private String taxonName;
public String getGenus() {
return this.genus;
}
public void setGenus(final String genus) {
this.genus = genus;
}
public String getSpecies() {
return this.species;
}
public void setSpecies(final String species) {
this.species = species;
}
public String getTaxonName() {
return this.taxonName;
}
public void setTaxonName(final String taxonName) {
this.taxonName = taxonName;
}
@Override
public String toString() {
return MessageFormat.format("Tax id={0} genus={1} sp={2}, full={3}", id, genus, species, taxonName);
}
public boolean sameAs(Taxonomy taxonomy) {
return taxonomy == null ? false : taxonomy.getId().equals(id);
}
}
......@@ -39,21 +39,15 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query(countQuery = "select count(*) from accession a where a.institute = ?1")
Page<Accession> findByInstitute(FaoInstitute institute, Pageable pageable);
@Query(countQuery = "select count(*) from accession a where a.taxGenus = ?1")
Page<Accession> findByTaxGenus(long taxonomyId, Pageable pageable);
@Query(countQuery = "select count(*) from accession a where a.taxSpecies = ?1")
Page<Accession> findByTaxSpecies(long taxSpecies, Pageable pageable);
List<Accession> findByInstitute(FaoInstitute institute);
@Query("select count(a) from Accession a where a.institute = ?1")
long countByInstitute(FaoInstitute institute);
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxGenus) from Accession a where a.institute = ?1")
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxonomy.taxGenus) from Accession a where a.institute = ?1")
Page<Object[]> statisticsGenusInInstitute(FaoInstitute institute, Pageable pageable);
@Query(value = "select a.taxSpecies, count(a) from Accession a where a.institute = ?1 group by a.taxSpecies order by count(a) desc", countQuery = "select count(distinct a.taxSpecies) from Accession a where a.institute = ?1")
@Query(value = "select t.taxSpecies, count(a) from Accession a inner join a.taxonomy t where a.institute = ?1 group by t.taxSpecies order by count(a) desc", countQuery = "select count(distinct a.taxonomy.taxSpecies) from Accession a where a.institute = ?1")
Page<Object[]> statisticsSpeciesInInstitute(FaoInstitute institute, Pageable pageable);
// FIXME Slow query
......@@ -123,8 +117,6 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("update Accession a set a.inSvalbard = true where a in ?1")
void setInSvalbard(List<Accession> matching);
Page<Accession> findByInstituteAndTaxSpecies(FaoInstitute institute, long taxSpecies, Pageable pageable);
@Query("select distinct a.institute from Accession a where a.id in ( ?1 )")
List<FaoInstitute> findDistinctInstitutesFor(Set<Long> accessionIds);
......
/**
* 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 java.util.List;
import org.genesys2.server.model.genesys.Taxonomy;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
public interface TaxonomyRepository extends JpaRepository<Taxonomy, Long> {
Taxonomy getByGenusAndSpecies(String genus, String species);
List<Taxonomy> findByGenus(String genus);
Taxonomy getByTaxonName(String fullTaxa);
@Query("select distinct t.genus from Taxonomy t where t.genus like ?1")
List<String> autocompleteGenus(String term, Pageable page);
@Query("select distinct t.taxonName from Taxonomy t where t.taxonName like ?1")
List<String> autocompleteTaxonomy(String term, Pageable page);
@Modifying
@Query("update Accession a set a.taxonomy=?2, a.taxGenus=?3, a.taxSpecies=?4 where a.taxonomy1 = ?1")
int upgrade(Taxonomy t1, Taxonomy2 t2, Long taxGenus, Long taxSpecies);
}
......@@ -108,12 +108,6 @@ public interface GenesysService {
// Page<Object[]> statisticsCropByInstitute(FaoInstitute faoInstitute,
// Pageable pageable);
Page<Accession> listAccessionsByInstituteAndSpecies(FaoInstitute institute, long taxSpecies, Pageable pageable);
Page<Accession> listAccessionsByTaxGenus(long taxGenusId, Pageable pageable);
Page<Accession> listAccessionsByTaxSpecies(long taxSpeciesId, Pageable pageable);
List<Long> listAccessionsIds(Pageable pageable);
Page<Accession> listAccessionsByCrop(Crop crop, Pageable pageable);
......
......@@ -659,8 +659,6 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (!ensuredTaxonomy.sameAs(taxonomy)) {
accession.setTaxonomy(ensuredTaxonomy);
accession.setTaxGenus(ensuredTaxonomy.getTaxGenus());
accession.setTaxSpecies(ensuredTaxonomy.getTaxSpecies());
updated = true;
}
......
......@@ -138,8 +138,11 @@ public class DirectMysqlQuery {
protected DirectMysqlQuery filter(AppliedFilters filters, MethodResolver methodResolver) {
createQuery(whereBuffer, "a.id", filters.get("id"), params);
createQuery(whereBuffer, "a.taxGenus", filters.get("genusId"), params);
createQuery(whereBuffer, "a.taxSpecies", filters.get("speciesId"), params);
{
// FIXME Are these two still used?
createQuery(whereBuffer, "t.taxGenus", filters.get("genusId"), params);
createQuery(whereBuffer, "t.taxSpecies", filters.get("speciesId"), params);
}
createQuery(whereBuffer, "a.acceNumb", filters.get(FilterConstants.ACCENUMB), params);
createQuery(whereBuffer, "a.orgCty", filters.get(FilterConstants.ORGCTY_ISO3), params);
createQuery(whereBuffer, "a.instCode", filters.get(FilterConstants.INSTCODE), params);
......
......@@ -573,21 +573,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return page;
}
@Override
public Page<Accession> listAccessionsByInstituteAndSpecies(FaoInstitute institute, long taxSpecies, Pageable pageable) {
return accessionRepository.findByInstituteAndTaxSpecies(institute, taxSpecies, pageable);
}
@Override
public Page<Accession> listAccessionsByTaxSpecies(long taxSpecies, Pageable pageable) {
return accessionRepository.findByTaxSpecies(taxSpecies, pageable);
}
@Override
public Page<Accession> listAccessionsByTaxGenus(long taxGenusId, Pageable pageable) {
return accessionRepository.findByTaxGenus(taxGenusId, pageable);
}
@Override
public List<Long> listAccessionsIds(Pageable pageable) {
return accessionRepository.listAccessionsIds(pageable);
......
......@@ -240,8 +240,6 @@ public class BatchRESTServiceTest {
assertTrue(accession.getTaxonomy() != null);
final Taxonomy2 tax = accession.getTaxonomy();
System.err.println(tax);
System.err.println(accession.getTaxGenus());
System.err.println(accession.getTaxSpecies());
// Modify taxonomy
json.put("genus", "Hordeum");
......@@ -259,9 +257,6 @@ public class BatchRESTServiceTest {
final Taxonomy2 tax2 = accession.getTaxonomy();
System.err.println(tax2);
assertFalse(tax2.getId().equals(tax.getId()));
System.err.println(accession.getTaxGenus());
System.err.println(accession.getTaxSpecies());
assertFalse(accession.getTaxGenus() == accession.getTaxSpecies());
// test nothing
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment