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

Merge branch '280-bug-cwr-page-500' into 'master'

Resolve "Bug: CWR page 500"

Closes #280

See merge request genesys-pgr/genesys-server!189
parents 195297a8 78739c47
......@@ -151,10 +151,20 @@ public class ElasticQueryBuilder implements Visitor<Void, Void> {
LOG.error("Path ANY for {}={}", pmd.getParent(), value);
root.must(termsQuery(customizedPath(pmd.getParent().toString()), toValue(value)));
} else {
root.must(termsQuery(customizedPath(pmd.getParent().toString() + "." + pmd.getName()), toValue(value)));
root.must(termsQuery(customizedPath(getParentPath(pmd.getParent()) + "." + pmd.getName()), toValue(value)));
}
}
private String getParentPath(Path<?> path) {
String pathValue = path.toString();
if (pathValue.startsWith("any")) {
return getParentPath(path.getMetadata().getParent());
}
return pathValue;
}
private Object toValue(Expression<?> value) {
if (value instanceof Constant<?>) {
Constant<?> cons = (Constant<?>) value;
......
......@@ -43,6 +43,7 @@ import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.ProjectService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.AppliedFiltersConverter;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
......@@ -119,10 +120,10 @@ public class ProjectController extends BaseController {
model.addAttribute("jsonFilter", filters.toString());
try {
model.addAttribute("statisticsCrop", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 5, FilterConstants.CROPS));
model.addAttribute("statisticsGenus", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 5, FilterConstants.TAXONOMY_GENUS));
model.addAttribute("statisticsTaxonomy", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 5, FilterConstants.TAXONOMY_GENUSSPECIES));
model.addAttribute("statisticsOrigCty", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 100, FilterConstants.ORGCTY_ISO3));
model.addAttribute("statisticsCrop", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.CROPS)));
model.addAttribute("statisticsGenus", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUS)));
model.addAttribute("statisticsTaxonomy", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 5, AppliedFiltersConverter.convertTerm(FilterConstants.TAXONOMY_GENUSSPECIES)));
model.addAttribute("statisticsOrigCty", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(filters), 100, AppliedFiltersConverter.convertTerm(FilterConstants.ORGCTY_ISO3)));
} catch (SearchException e) {
LOG.warn(e.getMessage());
}
......
......@@ -15,9 +15,10 @@
*/
package org.genesys2.server.service.filter;
import static org.genesys2.server.model.genesys.QAccession.accession;
import static org.genesys2.server.model.genesys.QAccession.*;
import java.util.Set;
import java.util.UUID;
import org.genesys.blocks.model.filters.NumberFilter;
import org.genesys.blocks.model.filters.StringFilter;
......@@ -83,6 +84,9 @@ public class AccessionFilter extends UuidModelFilter {
public NumberFilter<Double> pdci;
/** acce.lists uuid */
public Set<UUID> list;
/**
* Builds the query.
*
......@@ -143,8 +147,9 @@ public class AccessionFilter extends UuidModelFilter {
if (pdci != null) {
and.and(pdci.buildQuery(accession.accessionId.pdci.score));
}
if (CollectionUtil.isNotEmpty(list)) {
and.and(accession.accessionId.lists.any().uuid.in(list));
}
// TODO Do we have to change this?
if (sgsv != null) {
and.and(accession.accessionId.duplSite.any().eq("NOR051"));
......
package org.genesys2.server.service.filter;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import org.genesys.blocks.model.filters.NumberFilter;
......@@ -220,6 +217,10 @@ public class AppliedFiltersConverter {
f.seqNo = convertNumberFilter(af);
break;
}
case "lists": {
f.list = toUUIDSet(af);
break;
}
default:
throw new RuntimeException("Unhandled Accession filter property=" + filterName);
}
......@@ -392,6 +393,10 @@ public class AppliedFiltersConverter {
return af.getValues().stream().map(fv -> (String) ((LiteralValueFilter) fv).getValue()).collect(Collectors.toSet());
}
private static Set<UUID> toUUIDSet(AppliedFilter af) {
return af.getValues().stream().map(fv -> (UUID) ((LiteralValueFilter) fv).getValue()).collect(Collectors.toSet());
}
private static void apply(InstituteFilter ff, AppliedFilter af) {
String filterName = af.getFilterName();
switch (filterName) {
......
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