Commit 978e0f56 authored by Matija Obreza's avatar Matija Obreza

TaxonomySpecies: Fixed filtering

parent 531c585b
......@@ -29,6 +29,7 @@ import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.filter.TaxonomyExtraFilter;
import org.genesys2.server.service.filter.TaxonomyFilter;
import org.genesys2.server.service.filter.TaxonomySpeciesFilter;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
......@@ -98,10 +99,11 @@ public class TaxonomyController extends ApiBaseController {
* @param page the page
* @param filter the filter
* @return the page
* @throws SearchException
*/
@PostMapping(value = "/grin-species", produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<TaxonomySpecies> listSpecies(final Pagination page, @RequestBody final TaxonomySpeciesFilter filter) {
return new FilteredPage<>(filter, taxonomyService.listSpecies(filter, page.toPageRequest(100, Sort.Direction.ASC, "id")));
public FilteredPage<TaxonomySpecies> listSpecies(final Pagination page, @RequestBody final TaxonomySpeciesFilter filter) throws SearchException {
return new FilteredPage<>(filter, taxonomyService.listSpecies(filter, page.toPageRequest(100, Sort.Direction.ASC, "genusSpecies", "subtaxa")));
}
/**
......
......@@ -28,6 +28,7 @@ import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.filter.TaxonomyExtraFilter;
import org.genesys2.server.service.filter.TaxonomyFilter;
import org.genesys2.server.service.filter.TaxonomySpeciesFilter;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
......@@ -97,10 +98,11 @@ public class TaxonomyController extends ApiBaseController {
* @param page the page
* @param filter the filter
* @return the page
* @throws SearchException
*/
@PostMapping(value = "/grin-species", produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<TaxonomySpecies> listSpecies(final Pagination page, @RequestBody final TaxonomySpeciesFilter filter) {
return new FilteredPage<>(filter, taxonomyService.listSpecies(filter, page.toPageRequest(100, Sort.Direction.ASC, "id")));
public FilteredPage<TaxonomySpecies> listSpecies(final Pagination page, @RequestBody final TaxonomySpeciesFilter filter) throws SearchException {
return new FilteredPage<>(filter, taxonomyService.listSpecies(filter, page.toPageRequest(100, Sort.Direction.ASC, "genusSpecies", "subtaxa")));
}
/**
......
......@@ -82,6 +82,7 @@ public class TaxonomySpecies extends CooperatorOwnedModel implements IGrinSpecie
@JsonIdentityInfo(scope = TaxonomySpecies.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIdentityReference(alwaysAsId = true)
@Field(index = false, type = FieldType.Long)
@JsonIgnoreProperties({ "currentTaxonomySpecies", "taxonomyGenus" })
private TaxonomySpecies currentTaxonomySpecies;
@Basic
......
......@@ -25,6 +25,7 @@ import org.genesys2.server.model.grin.TaxonomySpecies;
import org.genesys2.server.service.filter.TaxonomyExtraFilter;
import org.genesys2.server.service.filter.TaxonomyFilter;
import org.genesys2.server.service.filter.TaxonomySpeciesFilter;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -52,7 +53,7 @@ public interface TaxonomyService {
Page<Taxonomy2Info> list(TaxonomyExtraFilter filter, Pageable page);
Page<TaxonomySpecies> listSpecies(TaxonomySpeciesFilter filter, Pageable page);
Page<TaxonomySpecies> listSpecies(TaxonomySpeciesFilter filter, Pageable page) throws SearchException;
Taxonomy2 setGrinSpecies(long taxonomy2Id, Long customGrinSpeciesId);
......
......@@ -60,7 +60,7 @@ public class TaxonomySpeciesFilter extends CooperatorOwnedModelFilter<TaxonomySp
public List<Predicate> collectPredicates(final QTaxonomySpecies taxonomySpecies) {
final List<Predicate> predicates = super.collectPredicates(taxonomySpecies, taxonomySpecies._super);
if (CollectionUtils.isNotEmpty(genus)) {
predicates.add(taxonomySpecies.genusSpecies.in(genus));
predicates.add(taxonomySpecies.taxonomyGenus.name.in(genus));
}
if (CollectionUtils.isNotEmpty(species)) {
predicates.add(taxonomySpecies.speciesName.in(species));
......
......@@ -30,6 +30,7 @@ import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.persistence.Taxonomy2Repository;
import org.genesys2.server.persistence.grin.TaxonomyGenusRepository;
import org.genesys2.server.persistence.grin.TaxonomySpeciesRepository;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.filter.TaxonomyExtraFilter;
import org.genesys2.server.service.filter.TaxonomyFilter;
......@@ -72,6 +73,9 @@ public class TaxonomyServiceImpl implements TaxonomyService {
@Autowired
private JPAQueryFactory jpaQueryFactory;
@Autowired
private ElasticsearchService elasticsearchService;
@Override
public Taxonomy2 get(Long id) {
return taxonomy2Repository.findById(id).orElse(null);
......@@ -246,10 +250,13 @@ public class TaxonomyServiceImpl implements TaxonomyService {
}
@Override
public Page<TaxonomySpecies> listSpecies(TaxonomySpeciesFilter filter, Pageable page) {
public Page<TaxonomySpecies> listSpecies(TaxonomySpeciesFilter filter, Pageable page) throws SearchException {
final BooleanBuilder predicate = new BooleanBuilder();
if (filter != null) {
predicate.and(filter.buildPredicate());
if (filter.isFulltextQuery()) {
return elasticsearchService.findAll(TaxonomySpecies.class, filter, page);
}
}
Page<TaxonomySpecies> res = grinSpeciesRepository.findAll(predicate, page);
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
......
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