Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
45
Issues
45
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
b37efc7f
Commit
b37efc7f
authored
Apr 10, 2019
by
Maxym Borodenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accession filters autocomplete
parent
c40f004d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
17 deletions
+59
-17
src/main/java/org/genesys2/server/service/impl/AccessionServiceImpl.java
...rg/genesys2/server/service/impl/AccessionServiceImpl.java
+59
-17
No files found.
src/main/java/org/genesys2/server/service/impl/AccessionServiceImpl.java
View file @
b37efc7f
...
...
@@ -43,16 +43,19 @@ import org.genesys2.server.model.genesys.AccessionData;
import
org.genesys2.server.model.genesys.AccessionId
;
import
org.genesys2.server.model.genesys.QAccession
;
import
org.genesys2.server.model.impl.AccessionIdentifier3
;
import
org.genesys2.server.model.impl.Country
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.genesys2.server.model.impl.Subset
;
import
org.genesys2.server.persistence.AccessionRepository
;
import
org.genesys2.server.service.AccessionService
;
import
org.genesys2.server.service.ElasticsearchService
;
import
org.genesys2.server.service.FilterConstants
;
import
org.genesys2.server.service.GeoService
;
import
org.genesys2.server.service.InstituteService
;
import
org.genesys2.server.service.SubsetService
;
import
org.genesys2.server.service.TaxonomyService
;
import
org.genesys2.server.service.filter.AccessionFilter
;
import
org.genesys2.server.service.filter.AppliedFiltersConverter
;
import
org.genesys2.server.service.impl.GenesysFilterServiceImpl.LabelValue
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -111,6 +114,9 @@ public class AccessionServiceImpl implements AccessionService {
@Autowired
private
TaxonomyService
taxonomyService
;
@Autowired
private
GeoService
geoService
;
private
static
final
int
LOAD_CHUNK_SIZE
=
200
;
private
<
T
extends
AccessionData
>
T
lazyLoad
(
T
accession
)
{
...
...
@@ -379,11 +385,11 @@ public class AccessionServiceImpl implements AccessionService {
}
final
List
<
LabelValue
<
String
>>
completed
=
new
ArrayList
<>();
if
(
FilterConstants
.
INSTCODE
.
equalsIgnoreCase
(
field
))
{
ElasticsearchService
.
TermResult
termResult
=
null
;
if
(
AppliedFiltersConverter
.
convertTerm
(
FilterConstants
.
INSTCODE
).
equalsIgnoreCase
(
field
))
{
final
List
<
FaoInstitute
>
faoInst
=
instituteService
.
autocomplete
(
text
);
ElasticsearchService
.
TermResult
termResult
=
null
;
try
{
termResult
=
elasticsearchService
.
termStatisticsAuto
(
Accession
.
class
,
suggestionFilter
,
20000
,
FilterConstants
.
INSTCODE
);
termResult
=
elasticsearchService
.
termStatisticsAuto
(
Accession
.
class
,
suggestionFilter
,
20000
,
AppliedFiltersConverter
.
convertTerm
(
FilterConstants
.
INSTCODE
)
);
}
catch
(
SearchException
e
)
{
LOG
.
error
(
"Error occurred during search"
,
e
);
}
...
...
@@ -391,38 +397,74 @@ public class AccessionServiceImpl implements AccessionService {
if
(
termResult
!=
null
&&
!
termResult
.
getTerms
().
isEmpty
())
{
for
(
FaoInstitute
inst
:
faoInst
)
{
String
label
=
inst
.
getCode
()
+
", "
+
inst
.
getFullName
();
for
(
ElasticsearchService
.
Term
term
:
termResult
.
getTerms
())
{
if
(
term
.
getTerm
().
equalsIgnoreCase
(
inst
.
getCode
())
&&
term
.
getCount
()
>
0
)
{
label
=
label
.
concat
(
" ("
+
term
.
getCount
()
+
")"
);
completed
.
add
(
new
LabelValue
<>(
inst
.
getCode
(),
label
));
break
;
}
LabelValue
<
String
>
suggestion
=
getSuggestion
(
termResult
.
getTerms
(),
label
,
inst
.
getCode
());
if
(
suggestion
!=
null
)
{
completed
.
add
(
suggestion
);
}
}
}
}
else
if
(
FilterConstants
.
TAXONOMY_GENUS
.
equalsIgnoreCase
(
field
))
{
}
else
if
(
AppliedFiltersConverter
.
convertTerm
(
FilterConstants
.
TAXONOMY_GENUS
)
.
equalsIgnoreCase
(
field
))
{
final
List
<
String
>
genusList
=
taxonomyService
.
autocompleteGenus
(
text
,
null
);
ElasticsearchService
.
TermResult
termResult
=
null
;
try
{
termResult
=
elasticsearchService
.
termStatisticsAuto
(
Accession
.
class
,
suggestionFilter
,
20000
,
FilterConstants
.
TAXONOMY_GENUS
);
termResult
=
elasticsearchService
.
termStatisticsAuto
(
Accession
.
class
,
suggestionFilter
,
20000
,
AppliedFiltersConverter
.
convertTerm
(
FilterConstants
.
TAXONOMY_GENUS
)
);
}
catch
(
SearchException
e
)
{
LOG
.
error
(
"Error occurred during search"
,
e
);
}
if
(
termResult
!=
null
&&
!
termResult
.
getTerms
().
isEmpty
())
{
for
(
String
genus
:
genusList
)
{
for
(
ElasticsearchService
.
Term
term
:
termResult
.
getTerms
())
{
if
(
term
.
getTerm
().
equalsIgnoreCase
(
genus
)
&&
term
.
getCount
()
>
0
)
{
completed
.
add
(
new
LabelValue
<>(
genus
,
genus
.
concat
(
" ("
+
term
.
getCount
()
+
")"
)));
break
;
}
LabelValue
<
String
>
suggestion
=
getSuggestion
(
termResult
.
getTerms
(),
genus
,
genus
);
if
(
suggestion
!=
null
)
{
completed
.
add
(
suggestion
);
}
}
}
}
else
if
(
AppliedFiltersConverter
.
convertTerm
(
FilterConstants
.
ORGCTY_ISO3
).
equalsIgnoreCase
(
field
))
{
final
List
<
Country
>
countries
=
geoService
.
autocomplete
(
text
);
try
{
termResult
=
elasticsearchService
.
termStatisticsAuto
(
Accession
.
class
,
suggestionFilter
,
20000
,
AppliedFiltersConverter
.
convertTerm
(
FilterConstants
.
ORGCTY_ISO3
));
}
catch
(
SearchException
e
)
{
LOG
.
error
(
"Error occurred during search"
,
e
);
}
completed
.
addAll
(
getCountrySuggestions
(
termResult
,
countries
));
}
else
if
(
AppliedFiltersConverter
.
convertTerm
(
FilterConstants
.
INSTITUTE_COUNTRY_ISO3
).
equalsIgnoreCase
(
field
))
{
final
List
<
Country
>
countries
=
geoService
.
autocomplete
(
text
);
try
{
termResult
=
elasticsearchService
.
termStatisticsAuto
(
Accession
.
class
,
suggestionFilter
,
20000
,
AppliedFiltersConverter
.
convertTerm
(
FilterConstants
.
INSTITUTE_COUNTRY_ISO3
));
}
catch
(
SearchException
e
)
{
LOG
.
error
(
"Error occurred during search"
,
e
);
}
completed
.
addAll
(
getCountrySuggestions
(
termResult
,
countries
));
}
return
completed
;
}
private
List
<
LabelValue
<
String
>>
getCountrySuggestions
(
ElasticsearchService
.
TermResult
termResult
,
List
<
Country
>
countries
)
{
final
List
<
LabelValue
<
String
>>
result
=
new
ArrayList
<>();
if
(
termResult
!=
null
&&
!
termResult
.
getTerms
().
isEmpty
())
{
for
(
Country
c
:
countries
)
{
String
label
=
c
.
getCode3
()
+
", "
+
c
.
getName
();
LabelValue
<
String
>
suggestion
=
getSuggestion
(
termResult
.
getTerms
(),
label
,
c
.
getCode3
());
if
(
suggestion
!=
null
)
{
result
.
add
(
suggestion
);
}
}
}
return
result
;
}
private
LabelValue
<
String
>
getSuggestion
(
List
<
ElasticsearchService
.
Term
>
terms
,
String
label
,
String
value
)
{
for
(
ElasticsearchService
.
Term
term
:
terms
)
{
if
(
term
.
getTerm
().
equalsIgnoreCase
(
value
)
&&
term
.
getCount
()
>
0
)
{
label
=
label
.
concat
(
" ("
+
term
.
getCount
()
+
")"
);
return
new
LabelValue
<>(
value
,
label
);
}
}
return
null
;
}
@Override
public
Map
<
String
,
ElasticsearchService
.
TermResult
>
getSuggestions
(
AccessionFilter
filter
)
throws
SearchException
,
IOException
{
Map
<
String
,
ElasticsearchService
.
TermResult
>
suggestionRes
=
new
HashMap
<>(
suggestions
.
size
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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