Commit 7d873476 authored by Matija Obreza's avatar Matija Obreza Committed by Maxym Borodenko
Browse files

Dropped CropTaxonomy

Drop
parent a3c3f044
......@@ -24,13 +24,10 @@ import org.genesys2.server.exception.AuthorizationException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -74,10 +71,8 @@ public class CropsController extends ApiBaseController {
/**
* Add a crop
* @return
*
* @return
* @throws ValidationException
*/
@RequestMapping(value = { "/save" }, method = { RequestMethod.PUT, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Crop saveCrop(@RequestBody Crop cropJson) {
......@@ -159,47 +154,4 @@ public class CropsController extends ApiBaseController {
return cropService.getCropRules(crop);
}
/**
* Get crop taxonomies /crops/{shortName}/taxa
* @return
*
* @return
* @throws AuthorizationException
*/
@RequestMapping(value = "/{shortName}/taxa", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<CropTaxonomy> getCropTaxa(@PathVariable("shortName") String shortName) throws AuthorizationException {
LOG.info("Getting crop taxa {}", shortName);
final Crop crop = cropService.getCrop(shortName);
final Page<CropTaxonomy> cropTaxa = cropService.getCropTaxonomies(crop, PageRequest.of(0, 50));
return cropTaxa;
}
/**
* Rebuild taxonomy-crop lists
*
* @return
* @throws AuthorizationException
*/
@RequestMapping(value = "/rebuild", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public void rebuild() {
cropService.rebuildTaxonomies();
}
/**
* Rebuild taxonomy-crop lists
*
* @return
* @throws AuthorizationException
*/
@RequestMapping(value = "{shortName}/rebuild", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public void rebuildCrop(@PathVariable("shortName") String shortName) {
LOG.info("Updating crop rules for {}", shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null)
throw new NotFoundElement("No crop " + shortName);
cropService.rebuildTaxonomies(crop);
}
}
......@@ -29,15 +29,12 @@ import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.CropService.CropDetails;
import org.genesys2.spring.CSVMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -238,45 +235,6 @@ public class CropsController extends ApiBaseController {
return cropService.getCropRules(crop);
}
/**
* Get crop taxonomies /crops/{shortName}/taxa
*
* @return
*/
@RequestMapping(value = "/{shortName}/taxa", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<CropTaxonomy> getCropTaxa(@PathVariable("shortName") String shortName) {
LOG.info("Getting crop taxa {}", shortName);
final Crop crop = cropService.getCrop(shortName);
return cropService.getCropTaxonomies(crop, PageRequest.of(0, 50));
}
/**
* Rebuild taxonomy-crop lists
*
* @return
*/
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping(value = "/rebuild", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public void rebuild() {
cropService.rebuildTaxonomies();
}
/**
* Rebuild taxonomy-crop lists
*
* @return
*/
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping(value = "{shortName}/rebuild", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public void rebuildCrop(@PathVariable("shortName") String shortName) {
LOG.info("Updating crop rules for {}", shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null)
throw new NotFoundElement("No crop " + shortName);
cropService.rebuildTaxonomies(crop);
}
/**
* Link accession#cropName with crop
*
......
......@@ -20,8 +20,9 @@ import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import org.genesys.blocks.model.JsonViews;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.exception.DetailedConstraintViolationException;
......@@ -29,14 +30,11 @@ import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -48,8 +46,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.ConstraintViolationException;
import javax.validation.Valid;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.Api;
@RestController("cropApi2")
@RequestMapping(value = { CropsController.CONTROLLER_URL})
......@@ -201,45 +200,6 @@ public class CropsController extends ApiBaseController {
return cropService.getCropRules(crop);
}
/**
* Get crop taxonomies /crops/{shortName}/taxa
*
* @return
*/
@RequestMapping(value = "/{shortName}/taxa", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public Page<CropTaxonomy> getCropTaxa(@PathVariable("shortName") String shortName) {
LOG.info("Getting crop taxa {}", shortName);
final Crop crop = cropService.getCrop(shortName);
return cropService.getCropTaxonomies(crop, PageRequest.of(0, 50));
}
/**
* Rebuild taxonomy-crop lists
*
* @return
*/
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping(value = "/rebuild", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public void rebuild() {
cropService.rebuildTaxonomies();
}
/**
* Rebuild taxonomy-crop lists
*
* @return
*/
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping(value = "{shortName}/rebuild", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public void rebuildCrop(@PathVariable("shortName") String shortName) {
LOG.info("Updating crop rules for {}", shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null)
throw new NotFoundElement("No crop " + shortName);
cropService.rebuildTaxonomies(crop);
}
/**
* Link accession#cropName with crop
*
......
......@@ -17,7 +17,6 @@
package org.genesys2.server.model.genesys;
import java.text.MessageFormat;
import java.util.List;
import javax.persistence.Cacheable;
import javax.persistence.Column;
......@@ -26,7 +25,6 @@ import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Transient;
......@@ -35,14 +33,12 @@ import javax.persistence.UniqueConstraint;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.model.GlobalVersionedAuditedModel;
import org.genesys2.server.model.grin.TaxonomySpecies;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.model.json.Api1Constants;
import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
......@@ -94,11 +90,6 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
@JsonInclude
private String genusSpecies;
@JsonIgnore
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "taxonomy")
private List<CropTaxonomy> cropTaxonomies;
@ManyToOne(cascade = {}, fetch = FetchType.EAGER, optional = true)
@JoinColumn(name = "grinTaxonomySpecies")
@JsonProperty(access = Access.READ_ONLY)
......@@ -237,14 +228,6 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
this.taxSpecies = taxSpecies;
}
public List<CropTaxonomy> getCropTaxonomies() {
return cropTaxonomies;
}
public void setCropTaxonomies(List<CropTaxonomy> cropTaxonomies) {
this.cropTaxonomies = cropTaxonomies;
}
@Override
public String toString() {
return MessageFormat.format("Tax id={0} taxonName={1} genus={2} sp={3} spauthor={4} subtaxa={5} subtauthor={6}", getId(), getTaxonName(), genus, species,
......
/**
* 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.impl;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.genesys.blocks.model.BasicModel;
import org.genesys2.server.model.genesys.Taxonomy2;
@Entity
@Table(name = "croptaxonomy")
public class CropTaxonomy extends BasicModel {
private static final long serialVersionUID = 8973799991421179782L;
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "cropId")
private Crop crop;
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "taxonomyId")
private Taxonomy2 taxonomy;
public Crop getCrop() {
return crop;
}
public void setCrop(Crop crop) {
this.crop = crop;
}
public Taxonomy2 getTaxonomy() {
return taxonomy;
}
public void setTaxonomy(Taxonomy2 taxonomy) {
this.taxonomy = taxonomy;
}
}
......@@ -61,7 +61,6 @@ import org.genesys2.server.persistence.kpi.ExecutionRepository;
import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CountryNamesUpdater;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoRegionService;
......@@ -139,9 +138,6 @@ public class AdminController {
@Autowired
private TaxonomyService taxonomyService;
@Autowired
private CropService cropService;
@Autowired
private DatasetService datasetService;
......@@ -444,13 +440,6 @@ public class AdminController {
return "redirect:/admin/";
}
@RequestMapping(value = "/taxonomy", method = RequestMethod.POST, params = { "action=taxonomy-rebuild" })
public String rebuild() {
LOG.info("Rebuilding taxonomies");
cropService.rebuildTaxonomies();
return "redirect:/admin/";
}
@RequestMapping(value = "/taxonomy", method = RequestMethod.POST, params = { "action=taxonomy-cleanup" })
public String cleanupTaxonomies() {
taxonomyService.cleanupTaxonomies();
......
/**
* 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;
import java.util.List;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface CropTaxonomyRepository extends JpaRepository<CropTaxonomy, Long> {
/**
* Returns all
*
* @param crop
* @return
*/
List<CropTaxonomy> findByCrop(Crop crop);
Page<CropTaxonomy> findByCrop(Crop crop, Pageable pageable);
@Query("select distinct t from CropTaxonomy ct inner join ct.taxonomy t where ct.crop = ?1")
List<Taxonomy2> findTaxonomiesByCrop(Crop crop);
@Query("select distinct ct.crop from CropTaxonomy ct where ct.taxonomy= ?1")
List<Crop> findCropsByTaxonomy(Taxonomy2 taxonomy);
@Query("select ct from CropTaxonomy ct where ct.taxonomy= ?1")
List<CropTaxonomy> findByTaxonomy(Taxonomy2 taxonomy);
}
......@@ -21,7 +21,6 @@ import java.util.List;
import java.util.Set;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Crop;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
......@@ -33,15 +32,9 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long>, Que
@Query("select distinct t.genus from Taxonomy2 t where t.genus like ?1")
List<String> autocompleteGenus(String term, Pageable page);
@Query("select distinct t.genus from Taxonomy2 t join t.cropTaxonomies ct where t.genus like ?1 and ct.crop = ?2")
List<String> autocompleteGenusByCrop(String term, Crop crop, Pageable page);
@Query("select distinct t.species from Taxonomy2 t where t.species like ?1")
List<String> autocompleteSpecies(String term, Pageable page);
@Query("select distinct t.species from Taxonomy2 t join t.cropTaxonomies ct where t.species like ?1 and ct.crop = ?2")
List<String> autocompleteSpeciesByCrop(String term, Crop crop, Pageable page);
@Query("select distinct t.species from Taxonomy2 t where t.species like ?1 and t.genus in (?2)")
List<String> autocompleteSpeciesByGenus(String term, List<String> genus, Pageable page);
......@@ -51,9 +44,6 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long>, Que
@Query("select distinct t.subtaxa from Taxonomy2 t where t.subtaxa like ?1")
List<String> autocompleteSubtaxa(String string, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t join t.cropTaxonomies ct where t.subtaxa like ?1 and ct.crop = ?2")
List<String> autocompleteSubtaxaByCrop(String string, Crop crop, Pageable page);
@Query("select distinct t.subtaxa from Taxonomy2 t where t.subtaxa like ?1 and t.genus in (?2)")
List<String> autocompleteSubtaxaByGenus(String string, List<String> genus, Pageable page);
......@@ -72,13 +62,10 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long>, Que
List<Taxonomy2> findByGenusAndSpeciesAndSubtaxa(String genus, String species, String subtaxa);
@Query(nativeQuery = true, value = "SELECT ct.taxonomyId FROM croptaxonomy ct " +
"UNION ALL SELECT t2.taxGenus FROM taxonomy2 t2 " +
@Query(nativeQuery = true, value = "SELECT t2.taxGenus FROM taxonomy2 t2 " +
"UNION ALL SELECT t3.taxSpecies FROM taxonomy2 t3 " +
"UNION ALL SELECT a.taxonomyId2 FROM accession a " +
"UNION ALL SELECT a2.taxGenus FROM accession a2 " +
"UNION ALL SELECT ah.taxGenus FROM accessionhistoric ah " +
"UNION ALL SELECT ah2.taxonomyId2 FROM accessionhistoric ah2;")
"UNION ALL SELECT ah2.taxonomyId2 FROM accession_historic ah2;")
Set<BigInteger> findTaxonomyReferencedIds();
@Query("select t.id from Taxonomy2 t")
......
......@@ -22,6 +22,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.validation.Valid;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.catalog.model.dataset.Dataset;
......@@ -30,11 +32,9 @@ import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.model.impl.DiversityTree;
import org.genesys2.server.model.impl.Subset;
import org.springframework.data.domain.Page;
......@@ -43,8 +43,6 @@ import org.springframework.data.domain.Pageable;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonView;
import javax.validation.Valid;
public interface CropService {
Crop getCrop(String shortName);
......@@ -59,16 +57,8 @@ public interface CropService {
List<Crop> list(Locale locale);
List<Crop> getCrops(Taxonomy2 taxonomy2);
Article updateBlurb(Crop crop, String title, String summary, String textBody, Locale locale) throws CRMException;
void rebuildTaxonomies();
void rebuildTaxonomies(Crop crop);
Page<CropTaxonomy> getCropTaxonomies(Crop crop, Pageable pageable);
/**
* Add a {@link Crop} to the system
*
......@@ -115,13 +105,6 @@ public interface CropService {
*/
Crop delete(Crop crop);
/**
* Insert Taxonomy2 into correct CropTaxonomy lists
*
* @param taxonomy
*/
void updateCropTaxonomyLists(Taxonomy2 taxonomy);
/**
* Get crops
*/
......
......@@ -100,8 +100,6 @@ public interface GenesysService {
List<Long> listAccessionsIds(Pageable pageable);
Page<Accession> listAccessionsByCrop(Crop crop, Pageable pageable);
Page<Accession> listAccessionsByOrganization(PGRFANetwork network, Pageable pageable);
void updateAccessionCountryRefs();
......
......@@ -19,19 +19,20 @@ package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.service.filter.TaxonomyFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
public interface TaxonomyService {
List<String> autocompleteGenus(String term,Crop crop);
List<String> autocompleteGenus(String term);
List<String> autocompleteSpecies(String term, Crop crop, List<String> genus);
List<String> autocompleteSpecies(String term, List<String> genus);
List<String> autocompleteTaxonomy(String term);
List<String> autocompleteSubtaxa(String term, List<String> genus, List<String> species);
long getTaxonomy2Id(String genus);
long getTaxonomy2Id(String genus, String species);
......@@ -54,7 +55,6 @@ public interface TaxonomyService {
Taxonomy2 internalEnsure(String genus, String species, String spAuthor, String subtaxa, String subtAuthor) throws InterruptedException;
List<String> autocompleteSubtaxa(String ac, Crop crop, List<String> genus, List<String> species);
void cleanupTaxonomies();
......
......@@ -467,7 +467,7 @@ public class AccessionServiceImpl implements AccessionService {
}
}
} else if (AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS).equalsIgnoreCase(field)) {
final List<String> genusList = taxonomyService.autocompleteGenus(text, null);
final List<String> genusList = taxonomyService.autocompleteGenus(text);
try {
termResult = elasticsearchService.termStatisticsAuto(Accession.class, suggestionFilter, 20000,AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS));
} catch (SearchException e) {
......
......@@ -21,16 +21,12 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;