Commit ecd2710c authored by Jérémy Destin's avatar Jérémy Destin
Browse files

fix: Display a no result message when there no germplasm to display on the...

fix: Display a no result message when there no germplasm to display on the germplasm result page. Add test on the method which create the query to get the germplasm list. Rename the method createShouldQuery into createShouldFilterQuery and esShouldFind into germplasmFind. GNP-4309
parent beea973d
......@@ -119,25 +119,10 @@ public class GnpISGermplasmController {
@PostMapping(value = "/search", consumes = APPLICATION_JSON_VALUE)
public GermplasmSearchResponse germplasmSearch(@RequestBody @Valid FaidareGermplasmPOSTShearchCriteria criteria) {
try {
return germplasmService.esShouldFind(criteria);
return germplasmService.germplasmFind(criteria);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
}
/*@ApiOperation("Suggest germplasm document field values")
@PostMapping(value = "/suggest", consumes = APPLICATION_JSON_VALUE)
public LinkedHashSet<String> germplasmSuggest(
@RequestParam String field,
@RequestParam(required = false) String text,
@RequestParam(required = false) Integer fetchSize,
@RequestBody(required = false) @Valid FaidareGermplasmPOSTShearchCriteria criteria)
throws UnsupportedEncodingException {
if (fetchSize == null) {
fetchSize = Integer.MAX_VALUE;
}
return germplasmService.suggest(field, StringFunctions.asUTF8(text), fetchSize, criteria);
}*/
}
......@@ -12,6 +12,6 @@ public interface ESQueryFactory<C> {
*/
QueryBuilder createQuery(C criteria);
QueryBuilder createEsShouldQuery(C criteria);
QueryBuilder createShouldFilterQuery(C criteria);
}
......@@ -56,7 +56,7 @@ public class ESGenericQueryFactory<C> implements ESQueryFactory<C> {
}
@Override
public QueryBuilder createEsShouldQuery(C criteria) {
public QueryBuilder createShouldFilterQuery(C criteria) {
try {
CriteriaMapping voMappingToCriteria = AnnotatedCriteriaMapper.getMapping(criteria.getClass());
DocumentMetadata<?> documentMetadata = voMappingToCriteria.getDocumentMetadata();
......
......@@ -23,7 +23,7 @@ public interface GermplasmRepository
/**
* Find germplasm by criteria with pagination with a should query.
*/
GermplasmSearchResponse esShouldFind(FaidareGermplasmPOSTShearchCriteria germSearCrit);
GermplasmSearchResponse germplasmFind(FaidareGermplasmPOSTShearchCriteria germSearCrit);
/**
* Get germplasm by id.
......
......@@ -94,7 +94,7 @@ public class GermplasmRepositoryImpl implements GermplasmRepository {
@Override
public Iterator<GermplasmVO> scrollAllGermplasm(FaidareGermplasmPOSTShearchCriteria criteria) {
QueryBuilder query = queryFactory.createEsShouldQuery(criteria);
QueryBuilder query = queryFactory.createShouldFilterQuery(criteria);
int fetchSize = criteria.getPageSize().intValue();
return new ESScrollIterator<>(client, requestFactory, parser, GermplasmVO.class, query, fetchSize);
}
......@@ -110,7 +110,7 @@ public class GermplasmRepositoryImpl implements GermplasmRepository {
}
@Override
public GermplasmSearchResponse esShouldFind(FaidareGermplasmPOSTShearchCriteria germplasmSearchCriteria) {
public GermplasmSearchResponse germplasmFind(FaidareGermplasmPOSTShearchCriteria germplasmSearchCriteria) {
try {
// Prepare search request
......
......@@ -17,7 +17,7 @@ public interface GermplasmService {
PaginatedList<GermplasmVO> find(GermplasmSearchCriteria criteria);
GermplasmSearchResponse esShouldFind(FaidareGermplasmPOSTShearchCriteria criteria);
GermplasmSearchResponse germplasmFind(FaidareGermplasmPOSTShearchCriteria criteria);
/*LinkedHashSet<String> suggest(
String criteriaField, String searchText, Integer fetchSize, FaidareGermplasmPOSTShearchCriteria criteria
......
......@@ -111,8 +111,8 @@ public class GermplasmServiceImpl implements GermplasmService {
}
@Override
public GermplasmSearchResponse esShouldFind(FaidareGermplasmPOSTShearchCriteria germplasmSearchCriteria) {
return germplasmRepository.esShouldFind(germplasmSearchCriteria);
public GermplasmSearchResponse germplasmFind(FaidareGermplasmPOSTShearchCriteria germplasmSearchCriteria) {
return germplasmRepository.germplasmFind(germplasmSearchCriteria);
}
@Override
......
......@@ -4,10 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Sets;
import com.google.common.io.CharStreams;
import fr.inra.urgi.faidare.domain.criteria.LocationCriteria;
import fr.inra.urgi.faidare.domain.criteria.ObservationUnitCriteria;
import fr.inra.urgi.faidare.domain.criteria.ProgramCriteria;
import fr.inra.urgi.faidare.domain.criteria.StudySearchCriteria;
import fr.inra.urgi.faidare.domain.criteria.*;
import fr.inra.urgi.faidare.domain.datadiscovery.criteria.DataDiscoveryCriteria;
import fr.inra.urgi.faidare.domain.datadiscovery.criteria.DataDiscoveryCriteriaImpl;
import fr.inra.urgi.faidare.elasticsearch.criteria.annotation.CriteriaForDocument;
......@@ -292,6 +289,28 @@ public class ESGenericQueryFactoryTest {
assertJsonEquals(actualQuery, expectedQuery);
}
@Test
void should_Generate_Filter_Bool_Terms_Query() throws Exception {
FaidareGermplasmPOSTShearchCriteria criteria = new FaidareGermplasmPOSTShearchCriteria();
criteria.setSpecies(newArrayList("Triticum", "Populus"));
criteria.setGenus(newArrayList("Triticum", "Populus"));
criteria.setGenusSpecies(newArrayList("Triticum", "Populus"));
criteria.setBiologicalStatus(newArrayList("Wild"));
ESGenericQueryFactory<FaidareGermplasmPOSTShearchCriteria> queryFactory =
new ESGenericQueryFactory<>();
QueryBuilder query = queryFactory.createShouldFilterQuery(criteria);
String actualQuery = query.toString();
String expectedQuery = readResource("expected/query8.json");
assertJsonEquals(actualQuery, expectedQuery);
}
public static void assertJsonEquals(String json1, String json2) throws IOException {
ObjectMapper mapper = new ObjectMapper();
......
{
"bool" : {
"must" : [
{
"bool" : {
"should" : [
{
"terms" : {
"commonCropName" : [
"Triticum",
"Populus"
],
"boost" : 1.0
}
},
{
"terms" : {
"genusSpeciesSubtaxa" : [
"Triticum",
"Populus"
],
"boost" : 1.0
}
},
{
"terms" : {
"species" : [
"Triticum",
"Populus"
],
"boost" : 1.0
}
},
{
"terms" : {
"genus" : [
"Triticum",
"Populus"
],
"boost" : 1.0
}
},
{
"terms" : {
"subtaxa" : [
"Triticum",
"Populus"
],
"boost" : 1.0
}
},
{
"terms" : {
"taxonSynonyms" : [
"Triticum",
"Populus"
],
"boost" : 1.0
}
},
{
"terms" : {
"genusSpecies" : [
"Triticum",
"Populus"
],
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
],
"filter" : [
{
"terms" : {
"biologicalStatusOfAccessionCode" : [
"Wild"
],
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
......@@ -9,4 +9,4 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="main" />
</component>
</module>
\ No newline at end of file
</module>
......@@ -107,3 +107,12 @@
</div>
</ng-container>
<div *ngIf="germplasm.length == 0"
id="no-results" class="text-center">
<div class="no-result-icon">
<span class="fa fa-meh-o"></span>
</div>
No results.
</div>
......@@ -18,6 +18,11 @@
border-bottom: 1px solid #c2c2c2;
}
.no-result-icon {
font-size: 8rem;
color: $gray-300;
}
.bolder {
font-size: 1.2rem;
font-weight: bold;
......
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