Commit 0b20469a authored by Matija Obreza's avatar Matija Obreza

Autocomplete institutes and countries from database

parent a8792b3f
...@@ -61,6 +61,9 @@ public interface CountryRepository extends JpaRepository<Country, Long> { ...@@ -61,6 +61,9 @@ public interface CountryRepository extends JpaRepository<Country, Long> {
@Query("select distinct c from Country c where c.nameL like :pattern") @Query("select distinct c from Country c where c.nameL like :pattern")
List<Country> findWithI18N(@Param("pattern") String pattern); List<Country> findWithI18N(@Param("pattern") String pattern);
@Query("select distinct c from Country c where c.code3 like ?1 or c.code2 like ?1 or c.name like ?1 or c.nameL like ?1")
List<Country> autocomplete(String ac, Pageable pageable);
// @Query("select distinct c from Country c where c.region in ( ?1 )") // @Query("select distinct c from Country c where c.region in ( ?1 )")
// List<Country> findByRegions(List<Region> regions); // List<Country> findByRegions(List<Region> regions);
} }
...@@ -61,4 +61,7 @@ public interface FaoInstituteRepository extends JpaRepository<FaoInstitute, Long ...@@ -61,4 +61,7 @@ public interface FaoInstituteRepository extends JpaRepository<FaoInstitute, Long
@Query("update FaoInstitute fi set accessionCount=(select count(a) from Accession a where a.institute = :institute ) where fi=:institute") @Query("update FaoInstitute fi set accessionCount=(select count(a) from Accession a where a.institute = :institute ) where fi=:institute")
void updateInstituteAccessionCount(@Param("institute") FaoInstitute institute); void updateInstituteAccessionCount(@Param("institute") FaoInstitute institute);
@Query("select distinct fi from FaoInstitute fi where fi.code like ?1 or fi.fullName like ?1 or fi.acronym like ?1")
List<FaoInstitute> autocomplete(String string, Pageable pageable);
} }
...@@ -117,4 +117,6 @@ public interface GeoService { ...@@ -117,4 +117,6 @@ public interface GeoService {
String filteredKml(String jsonFilter); String filteredKml(String jsonFilter);
List<Country> autocomplete(String ac);
} }
...@@ -64,4 +64,6 @@ public interface InstituteService { ...@@ -64,4 +64,6 @@ public interface InstituteService {
List<FaoInstitute> listMyInstitutes(Sort sort); List<FaoInstitute> listMyInstitutes(Sort sort);
List<FaoInstitute> autocomplete(String ac);
} }
...@@ -45,6 +45,7 @@ import org.genesys2.server.persistence.domain.TraitValueRepository; ...@@ -45,6 +45,7 @@ import org.genesys2.server.persistence.domain.TraitValueRepository;
import org.genesys2.server.service.GenesysFilterService; import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.DataType; import org.genesys2.server.service.GenesysFilterService.GenesysFilter.DataType;
import org.genesys2.server.service.GenesysFilterService.GenesysFilter.FilterType; import org.genesys2.server.service.GenesysFilterService.GenesysFilter.FilterType;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService; import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.SearchService; import org.genesys2.server.service.SearchService;
import org.genesys2.server.service.TaxonomyService; import org.genesys2.server.service.TaxonomyService;
...@@ -84,6 +85,9 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -84,6 +85,9 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
@Autowired @Autowired
private TraitService traitService; private TraitService traitService;
@Autowired
private GeoService geoService;
// @PersistenceContext // @PersistenceContext
// private EntityManager entityManager; // private EntityManager entityManager;
...@@ -244,12 +248,12 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -244,12 +248,12 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
final List<LabelValue<String>> completed = new ArrayList<LabelValue<String>>(); final List<LabelValue<String>> completed = new ArrayList<LabelValue<String>>();
if ("instCode".equalsIgnoreCase(filter)) { if ("instCode".equalsIgnoreCase(filter)) {
final List<FaoInstitute> faoInst = searchService.autocomplete(ac, FaoInstitute.class); final List<FaoInstitute> faoInst = instituteService.autocomplete(ac);
for (final FaoInstitute inst : faoInst) { for (final FaoInstitute inst : faoInst) {
completed.add(new LabelValue<String>(inst.getCode(), inst.getCode() + ", " + inst.getFullName())); completed.add(new LabelValue<String>(inst.getCode(), inst.getCode() + ", " + inst.getFullName()));
} }
} else if ("country".equalsIgnoreCase(filter)) { } else if ("country".equalsIgnoreCase(filter)) {
final List<Country> countries = searchService.autocomplete(ac, Country.class); final List<Country> countries = geoService.autocomplete(ac);
for (final Country c : countries) { for (final Country c : countries) {
completed.add(new LabelValue<String>(c.getCode3(), c.getCode3() + ", " + c.getName())); completed.add(new LabelValue<String>(c.getCode3(), c.getCode3() + ", " + c.getName()));
} }
......
...@@ -39,6 +39,7 @@ import org.genesys2.server.persistence.domain.ITPGRFAStatusRepository; ...@@ -39,6 +39,7 @@ import org.genesys2.server.persistence.domain.ITPGRFAStatusRepository;
import org.genesys2.server.service.ContentService; import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.GeoService; import org.genesys2.server.service.GeoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -130,7 +131,7 @@ public class GeoServiceImpl implements GeoService { ...@@ -130,7 +131,7 @@ public class GeoServiceImpl implements GeoService {
/** /**
* Check if we have a country that has * Check if we have a country that has
* *
* @param name * @param name
* in i18n * in i18n
* @param countryString * @param countryString
...@@ -160,7 +161,7 @@ public class GeoServiceImpl implements GeoService { ...@@ -160,7 +161,7 @@ public class GeoServiceImpl implements GeoService {
/** /**
* Get current country based on ISO3 code. Follow replacedBy where possible. * Get current country based on ISO3 code. Follow replacedBy where possible.
* *
* @param code3 * @param code3
* @return * @return
*/ */
...@@ -310,11 +311,11 @@ public class GeoServiceImpl implements GeoService { ...@@ -310,11 +311,11 @@ public class GeoServiceImpl implements GeoService {
* countryInfo.getRefnameId() != null) { * countryInfo.getRefnameId() != null) {
* country.setRefnameId(countryInfo.getRefnameId()); * country.setRefnameId(countryInfo.getRefnameId());
* countryRepository.save(country); } * countryRepository.save(country); }
* *
* // if country name is not the same if * // if country name is not the same if
* (StringUtils.isNotBlank(countryInfo.getName()) && * (StringUtils.isNotBlank(countryInfo.getName()) &&
* !countryInfo.getName().equals(country.getName())) { * !countryInfo.getName().equals(country.getName())) {
* *
* LOG.info("Updating country name from: " + country.getName() + * LOG.info("Updating country name from: " + country.getName() +
* " to: " + countryInfo.getName()); * " to: " + countryInfo.getName());
* country.setName(countryInfo.getName()); * country.setName(countryInfo.getName());
...@@ -410,4 +411,9 @@ public class GeoServiceImpl implements GeoService { ...@@ -410,4 +411,9 @@ public class GeoServiceImpl implements GeoService {
public String filteredKml(String jsonFilter) { public String filteredKml(String jsonFilter) {
return null; return null;
} }
@Override
public List<Country> autocomplete(String term) {
return countryRepository.autocomplete("%" + term + "%", new PageRequest(0, 10));
}
} }
...@@ -212,4 +212,9 @@ public class InstituteServiceImpl implements InstituteService { ...@@ -212,4 +212,9 @@ public class InstituteServiceImpl implements InstituteService {
return instituteRepository.findByIds(oids, sort); return instituteRepository.findByIds(oids, sort);
} }
@Override
public List<FaoInstitute> autocomplete(String term) {
return instituteRepository.autocomplete("%" + term + "%", new PageRequest(0, 10));
}
} }
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