Commit 9a9f0cbc authored by Matija Obreza's avatar Matija Obreza

Use Taxonomy2 instead of old Taxonomy

parent 3b99eddf
......@@ -23,7 +23,6 @@ import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.genesys2.server.lucene.genesys.AccessionBridge;
import org.genesys2.server.model.VersionedAuditedModel;
......@@ -33,7 +32,10 @@ import org.hibernate.search.annotations.ClassBridge;
import org.hibernate.search.annotations.Indexed;
@Entity
@Table(name = "accession", uniqueConstraints = { @UniqueConstraint(columnNames = { "instCode", "acceNumb", "genus" }) })
@Table(name = "accession")
// TODO FIXME Reenable
// @Table(name = "accession", uniqueConstraints = {
// @UniqueConstraint(columnNames = { "instCode", "acceNumb", "taxGenus" }) })
@Indexed
@ClassBridge(name = "body", impl = AccessionBridge.class)
public class Accession extends VersionedAuditedModel {
......@@ -54,11 +56,11 @@ public class Accession extends VersionedAuditedModel {
@ManyToOne(cascade = {}, optional = true)
@JoinColumn(name = "taxonomyId")
private Taxonomy taxonomy;
private Taxonomy taxonomy1;
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "taxonomyId2")
private Taxonomy2 taxonomy2;
private Taxonomy2 taxonomy;
@Column(name = "acqSrc", length = 3)
private String acquisitionSource;
......@@ -136,13 +138,13 @@ public class Accession extends VersionedAuditedModel {
}
public Taxonomy getTaxonomy1() {
return this.taxonomy;
return this.taxonomy1;
}
public Taxonomy2 getTaxonomy() {
return this.taxonomy2;
return this.taxonomy;
}
public String getAcquisitionSource() {
return this.acquisitionSource;
}
......@@ -231,7 +233,6 @@ public class Accession extends VersionedAuditedModel {
this.mlsStatus = mlsStatus;
}
public long getTaxGenus() {
return taxGenus;
}
......@@ -249,7 +250,11 @@ public class Accession extends VersionedAuditedModel {
}
public void setTaxonomy(Taxonomy2 taxonomy2) {
this.taxonomy2 = taxonomy2;
this.taxonomy = taxonomy2;
}
public void setTaxonomy1(Taxonomy taxonomy1) {
this.taxonomy1 = taxonomy1;
}
@Override
......
......@@ -38,8 +38,8 @@ 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.genus = ?1")
Page<Accession> findByGenus(String genus, Pageable pageable);
@Query(countQuery = "select count(*) from accession a where a.taxGenus = ?1")
Page<Accession> findByTaxGenus(long taxonomyId, Pageable pageable);
List<Accession> findByInstitute(FaoInstitute institute);
......@@ -53,8 +53,9 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
Page<Object[]> statisticsTaxonomyInInstitute(FaoInstitute institute, Pageable pageable);
// FIXME Slow query
@Query(value = "select ct.crop, count(a) from Accession a inner join a.taxonomy t join t.cropTaxonomies ct where a.institute = ?1 group by ct.crop order by count(a) desc", countQuery = "select count(distinct ct.crop) from Accession a inner join a.taxonomy t join t.cropTaxonomies ct where a.institute = ?1")
Page<Object[]> statisticsCropInInstitute(FaoInstitute institute, Pageable pageable);
// FIXME TOOD taxonomy1!
// @Query(value = "select ct.crop, count(a) from Accession a inner join a.taxonomy1 t join t.cropTaxonomies ct where a.institute = ?1 group by ct.crop order by count(a) desc", countQuery = "select count(distinct ct.crop) from Accession a inner join a.taxonomy t join t.cropTaxonomies ct where a.institute = ?1")
// Page<Object[]> statisticsCropInInstitute(FaoInstitute institute, Pageable pageable);
@Query("select count(a) from Accession a where a.origin = ?1")
long countByOrigin(String isoCode3);
......@@ -65,17 +66,17 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select a from Accession a where a.institute in ( ?1 )")
Page<Accession> findByInstitute(List<FaoInstitute> institutes, Pageable pageable);
@Query("select a from Accession a where a.genus in ( ?1 )")
Page<Accession> findByGenus(List<String> genus, Pageable pageable);
// @Query("select a from Accession a where a.genus in ( ?1 )")
// Page<Accession> findByGenus(List<String> genus, Pageable pageable);
@Query("select a.institute, count(a.id) as total from Accession a where a.genus in ( ?1 ) group by a.institute order by total desc")
List<Object[]> statisticsInstitute(List<String> genus);
// @Query("select a.institute, count(a.id) as total from Accession a where a.genus in ( ?1 ) group by a.institute order by total desc")
// List<Object[]> statisticsInstitute(List<String> genus);
@Query("select a.origin, count(a.id) as total from Accession a where a.genus in ( ?1 ) group by a.origin order by total desc")
List<Object[]> statisticsOrigin(List<String> genus);
// @Query("select a.origin, count(a.id) as total from Accession a where a.genus in ( ?1 ) group by a.origin order by total desc")
// List<Object[]> statisticsOrigin(List<String> genus);
@Query("select a.taxonomy, count(a.id) as total from Accession a where a.genus in ( ?1 ) group by a.taxonomy order by total desc")
List<Object[]> statisticsTaxonomy(List<String> genus);
// @Query("select a.taxonomy, count(a.id) as total from Accession a where a.genus in ( ?1 ) group by a.taxonomy order by total desc")
// List<Object[]> statisticsTaxonomy(List<String> genus);
// List<Accession> findByOrigin(String origin);
......@@ -96,9 +97,10 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select a from Accession a where a.taxonomy in ( ?1 )")
Page<Accession> findByTaxonomy(Collection<Taxonomy> taxonomies, Pageable pageable);
Accession findByInstituteCodeAndAccessionName(String instCode, String acceNumb);
Accession findByInstituteCodeAndAccessionName(String instCode, String accessionName);
Accession findByInstituteCodeAndAccessionNameAndGenus(String holdingInstitute, String accessionName, String genus);
@Query("select a from Accession a inner join a.taxonomy t where a.instituteCode=?1 and a.accessionName=?2 and t.genus=?3")
Accession findOne(String holdingInstitute, String accessionName, String genus);
@Query("select count(a.id) from Accession a where a.id in ( ?1 ) and a.availability = true")
long countAvailable(Set<Long> accessionIds);
......
......@@ -101,7 +101,7 @@ public interface GenesysService {
Page<Object[]> statisticsTaxonomyByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Object[]> statisticsCropByInstitute(FaoInstitute faoInstitute, Pageable pageable);
// Page<Object[]> statisticsCropByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Accession> listAccessionsByInstituteAndTaxonomy(FaoInstitute institute, Taxonomy taxonomy, Pageable pageable);
......
......@@ -84,6 +84,7 @@ import org.genesys2.server.service.AclService;
import org.genesys2.server.service.DatasetService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.HtmlSanitizer;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.TraitService;
import org.genesys2.spring.SecurityContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -130,6 +131,8 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
private MetadataMethodRepository metadataMethodRepository;
@Autowired
private TraitValueRepository traitValueRepository;
@Autowired
private TaxonomyService taxonomyService;
@Autowired
private CropTaxonomyRepository cropTaxonomyRepository;
......@@ -168,7 +171,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
public long countAll() {
return accessionRepository.count();
}
@Override
public long countByInstitute(FaoInstitute institute) {
return accessionRepository.countByInstitute(institute);
......@@ -206,7 +209,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
public List<Accession> listAccessions(List<? extends AccessionIdentifier3> accns) {
List<Accession> result = new ArrayList<Accession>(accns.size());
for (AccessionIdentifier3 aid3 : accns) {
Accession accn = accessionRepository.findByInstituteCodeAndAccessionNameAndGenus(aid3.getHoldingInstitute(), aid3.getAccessionName(),
Accession accn = accessionRepository.findOne(aid3.getHoldingInstitute(), aid3.getAccessionName(),
aid3.getGenus());
// Including null's
result.add(accn);
......@@ -222,9 +225,8 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override
public Accession getAccession(AccessionIdentifier3 aid3) {
return accessionRepository.findByInstituteCodeAndAccessionNameAndGenus(aid3.getHoldingInstitute(), aid3.getAccessionName(), aid3.getGenus());
return accessionRepository.findOne(aid3.getHoldingInstitute(), aid3.getAccessionName(), aid3.getGenus());
}
@Override
public Accession getAccession(String instCode, String acceNumb) {
......@@ -233,7 +235,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override
public Accession getAccession(String instCode, String acceNumb, String genus) {
return accessionRepository.findByInstituteCodeAndAccessionNameAndGenus(instCode, acceNumb, genus);
return accessionRepository.findOne(instCode, acceNumb, genus);
}
@Override
......@@ -364,11 +366,6 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
return accessionRepository.statisticsTaxonomyInInstitute(institute, pageable);
}
@Override
public Page<Object[]> statisticsCropByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsCropInInstitute(institute, pageable);
}
@Override
public Page<Accession> listAccessionsByInstituteAndTaxonomy(FaoInstitute institute, Taxonomy taxonomy, Pageable pageable) {
return accessionRepository.findByInstituteAndTaxonomy(institute, taxonomy, pageable);
......@@ -381,7 +378,8 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override
public Page<Accession> listAccessionsByGenus(String genus, Pageable pageable) {
return accessionRepository.findByGenus(genus, pageable);
long taxGenusId = taxonomyService.getTaxonomy2Id(genus);
return accessionRepository.findByTaxGenus(taxGenusId, pageable);
}
@Override
......@@ -416,7 +414,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
public List<Parameter> listTraits() {
return parameterRepository.findAll(new Sort(new Order(Direction.ASC, "id")));
}
@Override
public Page<Parameter> listTraits(Pageable pageable) {
return parameterRepository.findAll(pageable);
......@@ -446,7 +444,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
public List<Method> listMethods() {
return methodRepository.findAll(new Sort(new Order(Direction.ASC, "id")));
}
@Override
public Page<Method> listMethods(Pageable pageable) {
return methodRepository.findAll(pageable);
......@@ -532,7 +530,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
svalbardRepository.deleteForAccessions(accessionIds);
accessionRepository.delete(toDelete);
updateAccessionCount(institute);
}
}
......@@ -616,11 +614,11 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = false)
public ParameterCategory addCategory(String name, String i18n) {
public ParameterCategory addCategory(String name, String i18n) {
ParameterCategory category = new ParameterCategory();
category.setName(name);
category.setNameL(i18n);
parameterCategoryRepository.save(category);
parameterCategoryRepository.save(category);
return category;
}
......@@ -628,33 +626,27 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = true)
public ParameterCategory getCategory(String name) {
ParameterCategory category =
parameterCategoryRepository.findByName(name);
ParameterCategory category = parameterCategoryRepository.findByName(name);
return category;
}
@Override
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = false)
public Parameter addParameter(
String rdfUri,
Crop crop, String category,
String title, String i18n
) {
public Parameter addParameter(String rdfUri, Crop crop, String category, String title, String i18n) {
Parameter parameter = new Parameter();
parameter.setRdfUri(StringUtils.defaultIfBlank(rdfUri, null));
parameter.setCrop(crop);
parameter.setCrop(crop);
// In an ideal world, we should search for category by URI, not name...
ParameterCategory parameterCategory =
parameterCategoryRepository.findByName(category);
ParameterCategory parameterCategory = parameterCategoryRepository.findByName(category);
parameter.setCategory(parameterCategory);
parameter.setTitle(title);
parameter.setI18n(StringUtils.defaultIfBlank(i18n, null));
parameterRepository.save(parameter);
return parameter;
......@@ -664,12 +656,17 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = true)
public Parameter getParameter(String rdfUri) {
if(rdfUri == null || rdfUri.isEmpty() )
return null ;
Parameter parameter =
parameterRepository.findByRdfUri(rdfUri) ; // assumes that crop x title is unique(?)
if (rdfUri == null || rdfUri.isEmpty())
return null;
Parameter parameter = parameterRepository.findByRdfUri(rdfUri); // assumes
// that
// crop
// x
// title
// is
// unique(?)
return parameter;
}
......@@ -677,21 +674,22 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = true)
public Parameter getParameter(Crop crop, String title) {
Parameter parameter =
parameterRepository.findByCropAndTitle(crop, title) ; // assumes that crop x title is unique(?)
Parameter parameter = parameterRepository.findByCropAndTitle(crop, title); // assumes
// that
// crop
// x
// title
// is
// unique(?)
return parameter;
}
@Override
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = false)
public Method addMethod(
String rdfUri, String description, String i18n, String unit,
String fieldName, int fieldType, Integer fieldSize,
String options, String range,
Parameter parameter
) {
public Method addMethod(String rdfUri, String description, String i18n, String unit, String fieldName, int fieldType, Integer fieldSize, String options,
String range, Parameter parameter) {
Method method = new Method();
method.setRdfUri(StringUtils.defaultIfBlank(rdfUri, null));
......@@ -700,12 +698,12 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
method.setUnit(StringUtils.defaultIfBlank(StringUtils.trimToNull(unit), null));
method.setFieldName(StringUtils.trimToNull(fieldName));
method.setFieldType(fieldType);
if (fieldType == 0) {
// Will throw NPE if not provided!
method.setFieldSize(fieldSize.toString());
}
method.setOptions(StringUtils.defaultIfBlank(StringUtils.trimToNull(options), null));
method.setRange(StringUtils.defaultIfBlank(StringUtils.trimToNull(range), null));
method.setParameter(parameter);
......@@ -722,26 +720,23 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = true)
public Method getMethod(String rdfUri) {
if(rdfUri == null || rdfUri.isEmpty() )
return null ;
Method method =
methodRepository.findByRdfUri(rdfUri) ;
if (rdfUri == null || rdfUri.isEmpty())
return null;
Method method = methodRepository.findByRdfUri(rdfUri);
return method;
}
@Override
public Method getMethod(String description, Parameter parameter) {
if(description == null || description.isEmpty() )
return null ;
Method method =
methodRepository.findByMethodAndParameter(description,parameter) ;
if (description == null || description.isEmpty())
return null;
Method method = methodRepository.findByMethodAndParameter(description, parameter);
return method;
}
......
......@@ -100,6 +100,7 @@ public class WiewsController extends BaseController {
// model.addAttribute("statisticsCrop",
// genesysService.statisticsCropByInstitute(faoInstitute, new
// PageRequest(0, 30)));
model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute, new PageRequest(0, 30)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsTaxonomyByInstitute(faoInstitute, new PageRequest(0, 30)));
......
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