Commit 211adb58 authored by Artem Hrybeniuk's avatar Artem Hrybeniuk
Browse files

Networks with accession filter

parent e75cd782
......@@ -57,6 +57,9 @@ public class PGRFANetwork extends AuditedVersionedModel {
@OrderBy("code")
private List<FaoInstitute> members = new ArrayList<FaoInstitute>();
@Column(name = "accessionFilter")
private String accessionFilter;
public String getSlug() {
return slug;
}
......@@ -80,4 +83,12 @@ public class PGRFANetwork extends AuditedVersionedModel {
public void setMembers(List<FaoInstitute> members) {
this.members = members;
}
public String getAccessionFilter() {
return accessionFilter;
}
public void setAccessionFilter(String accessionFilter) {
this.accessionFilter = accessionFilter;
}
}
......@@ -22,6 +22,8 @@ import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.querydsl.core.types.dsl.BooleanExpression;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -607,4 +609,12 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
public Map<String, String> remappedProperties() {
return REMAPPED_PROPERTIES;
}
public static AccessionFilter fromJson(String json) throws JsonProcessingException {
if (StringUtils.isBlank(json)) {
return new AccessionFilter();
}
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, AccessionFilter.class);
}
}
......@@ -23,6 +23,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
......@@ -160,11 +161,18 @@ public class PGRFANetworkServiceImpl implements PGRFANetworkService {
@Override
public Map<String, ElasticsearchService.TermResult> overview(String slug) throws SearchException {
AccessionFilter filterWithNetwork = new AccessionFilter();
filterWithNetwork.networks = Sets.newHashSet(slug);
var network = networkRepository.findBySlug(slug);
var accessionFilter = new AccessionFilter();
try {
accessionFilter = AccessionFilter.fromJson(network.getAccessionFilter());
} catch (JsonProcessingException e) {
LOG.error("Exception in parsing json filter: {}", network.getAccessionFilter(), e);
}
accessionFilter.networks = Sets.newHashSet(slug);
if (elasticsearchService != null) {
return elasticsearchService.termStatisticsAuto(Accession.class, filterWithNetwork, 10, terms.toArray(new String[] {}));
return elasticsearchService.termStatisticsAuto(Accession.class, accessionFilter, 10, terms.toArray(new String[] {}));
}
return Map.of();
}
......
......@@ -7735,3 +7735,14 @@ databaseChangeLog:
- sql:
comment: Sets firstPublishedDate = lastModifiedDate to descriptors
sql: update descriptor set firstPublishedDate = lastModifiedDate where state = 1
- changeSet:
id: 1648043998325-1
author: ahrybeniuk
changes:
- addColumn:
columns:
- column:
name: accessionFilter
type: varchar(500)
tableName: organization
\ No newline at end of file
......@@ -5,7 +5,9 @@ import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.util.Set;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Sets;
import org.genesys2.server.component.elastic.ElasticQueryBuilder;
import org.genesys2.server.service.filter.AccessionFilter;
......@@ -110,4 +112,19 @@ public class AccessionFilterTest {
assertThat("historic value should stay null", afCopy2.historic, nullValue());
assertThat(afCopy2.crop, hasItems("apple"));
}
@Test
public void testAccessionFilterFromJson() throws JsonProcessingException {
String json = "{ \"crop\": [ \"banana\" ] }";
AccessionFilter af = AccessionFilter.fromJson(json);
assertThat(af.historic, is(false));
assertThat(af.crop, hasItem("banana"));
json = "{\"taxonomy\":{\"genus\":[\"Musa\"]}}";
af = AccessionFilter.fromJson(json);
assertThat(af.taxonomy, is(notNullValue()));
assertThat(af.taxonomy.genus, hasItem("Musa"));
}
}
Supports Markdown
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