Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
211adb58
Commit
211adb58
authored
Mar 23, 2022
by
Artem Hrybeniuk
Browse files
Networks with accession filter
parent
e75cd782
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/model/impl/PGRFANetwork.java
View file @
211adb58
...
...
@@ -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
;
}
}
src/main/java/org/genesys2/server/service/filter/AccessionFilter.java
View file @
211adb58
...
...
@@ -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
);
}
}
src/main/java/org/genesys2/server/service/impl/PGRFANetworkServiceImpl.java
View file @
211adb58
...
...
@@ -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
();
}
...
...
src/main/resources/liquibase/liquibase-changeLog.yml
View file @
211adb58
...
...
@@ -7734,4 +7734,15 @@ databaseChangeLog:
sql
:
update descriptorlist set firstPublishedDate = lastModifiedDate where state =
1
-
sql
:
comment
:
Sets firstPublishedDate = lastModifiedDate to descriptors
sql
:
update descriptor set firstPublishedDate = lastModifiedDate where state = 1
\ No newline at end of file
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
src/test/java/org/genesys/test/simpletest/AccessionFilterTest.java
View file @
211adb58
...
...
@@ -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"
));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment