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 { ...@@ -57,6 +57,9 @@ public class PGRFANetwork extends AuditedVersionedModel {
@OrderBy("code") @OrderBy("code")
private List<FaoInstitute> members = new ArrayList<FaoInstitute>(); private List<FaoInstitute> members = new ArrayList<FaoInstitute>();
@Column(name = "accessionFilter")
private String accessionFilter;
public String getSlug() { public String getSlug() {
return slug; return slug;
} }
...@@ -80,4 +83,12 @@ public class PGRFANetwork extends AuditedVersionedModel { ...@@ -80,4 +83,12 @@ public class PGRFANetwork extends AuditedVersionedModel {
public void setMembers(List<FaoInstitute> members) { public void setMembers(List<FaoInstitute> members) {
this.members = 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; ...@@ -22,6 +22,8 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; 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 com.querydsl.core.types.dsl.BooleanExpression;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -607,4 +609,12 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> ...@@ -607,4 +609,12 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
public Map<String, String> remappedProperties() { public Map<String, String> remappedProperties() {
return REMAPPED_PROPERTIES; 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; ...@@ -23,6 +23,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.genesys2.server.exception.InvalidApiUsageException; import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement; import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
...@@ -160,11 +161,18 @@ public class PGRFANetworkServiceImpl implements PGRFANetworkService { ...@@ -160,11 +161,18 @@ public class PGRFANetworkServiceImpl implements PGRFANetworkService {
@Override @Override
public Map<String, ElasticsearchService.TermResult> overview(String slug) throws SearchException { public Map<String, ElasticsearchService.TermResult> overview(String slug) throws SearchException {
AccessionFilter filterWithNetwork = new AccessionFilter(); var network = networkRepository.findBySlug(slug);
filterWithNetwork.networks = Sets.newHashSet(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) { 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(); return Map.of();
} }
......
...@@ -7734,4 +7734,15 @@ databaseChangeLog: ...@@ -7734,4 +7734,15 @@ databaseChangeLog:
sql: update descriptorlist set firstPublishedDate = lastModifiedDate where state = 1 sql: update descriptorlist set firstPublishedDate = lastModifiedDate where state = 1
- sql: - sql:
comment: Sets firstPublishedDate = lastModifiedDate to descriptors comment: Sets firstPublishedDate = lastModifiedDate to descriptors
sql: update descriptor set firstPublishedDate = lastModifiedDate where state = 1 sql: update descriptor set firstPublishedDate = lastModifiedDate where state = 1
\ No newline at end of file
- 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.*; ...@@ -5,7 +5,9 @@ import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException; import java.io.IOException;
import java.util.Set;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.genesys2.server.component.elastic.ElasticQueryBuilder; import org.genesys2.server.component.elastic.ElasticQueryBuilder;
import org.genesys2.server.service.filter.AccessionFilter; import org.genesys2.server.service.filter.AccessionFilter;
...@@ -110,4 +112,19 @@ public class AccessionFilterTest { ...@@ -110,4 +112,19 @@ public class AccessionFilterTest {
assertThat("historic value should stay null", afCopy2.historic, nullValue()); assertThat("historic value should stay null", afCopy2.historic, nullValue());
assertThat(afCopy2.crop, hasItems("apple")); 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