dsm browse api

This commit is contained in:
Michele Artini 2023-11-24 08:38:34 +01:00
parent c625ba627b
commit a76a22cbf1
2 changed files with 15 additions and 9 deletions

View File

@ -39,28 +39,28 @@ public interface SimpleDsWithApisRepository extends ReadOnlyRepository<SimpleDsW
@Query(value = "select * from dsm_datasources_view where ? = ANY(hidden_actives)", nativeQuery = true)
Page<SimpleDsWithApis> findByActive(Boolean active, Pageable pageable);
@Query(value = "select type as term, type as name, count(*) as total from dsm_datasources_view group by type order by total desc", nativeQuery = true)
@Query(value = "select type as term, type as name, count(*) as total from dsm_datasources_view group by type", nativeQuery = true)
List<BrowseTerm> browseTermsForType();
@Query(value = "select collectedfrom as term, collectedfrom as name, count(*) as total from dsm_datasources_view group by collectedfrom order by total desc", nativeQuery = true)
@Query(value = "select collectedfrom as term, collectedfrom as name, count(*) as total from dsm_datasources_view group by collectedfrom", nativeQuery = true)
List<BrowseTerm> browseTermsForCollectedFrom();
@Query(value = "select c as term, c as name, count(*) as total from (select unnest(hidden_compliances) as c from dsm_datasources_view) as t group by c order by total desc", nativeQuery = true)
@Query(value = "select c as term, c as name, count(*) as total from (select unnest(hidden_compliances) as c from dsm_datasources_view) as t group by c", nativeQuery = true)
List<BrowseTerm> browseTermsForCompliance();
@Query(value = "select c as term, c as name, count(*) as total from (select unnest(hidden_countries) as c from dsm_datasources_view) as t group by c order by total desc", nativeQuery = true)
@Query(value = "select c as term, c as name, count(*) as total from (select unnest(hidden_countries) as c from dsm_datasources_view) as t group by c", nativeQuery = true)
List<BrowseTerm> browseTermsForCountry();
@Query(value = "select c as term, c as name, count(*) as total from (select unnest(hidden_protocols) as c from dsm_datasources_view) as t group by c order by total desc", nativeQuery = true)
@Query(value = "select c as term, c as name, count(*) as total from (select unnest(hidden_protocols) as c from dsm_datasources_view) as t group by c", nativeQuery = true)
List<BrowseTerm> browseTermsForProtocol();
@Query(value = "select c as term, c as name, count(*) as total from (select unnest(hidden_actives) as c from dsm_datasources_view) as t group by c order by total desc", nativeQuery = true)
@Query(value = "select c as term, c as name, count(*) as total from (select unnest(hidden_actives) as c from dsm_datasources_view) as t group by c", nativeQuery = true)
List<BrowseTerm> browseTermsForActive();
@Query(value = "select consenttermsofuse as term, consenttermsofuse as name, count(*) as total from dsm_datasources_view group by consenttermsofuse order by total desc", nativeQuery = true)
@Query(value = "select consenttermsofuse as term, consenttermsofuse as name, count(*) as total from dsm_datasources_view group by consenttermsofuse", nativeQuery = true)
List<BrowseTerm> browseTermsForConsenttermsofuse();
@Query(value = "select fulltextdownload as term, fulltextdownload as name, count(*) as total from dsm_datasources_view group by fulltextdownload order by total desc", nativeQuery = true)
@Query(value = "select fulltextdownload as term, fulltextdownload as name, count(*) as total from dsm_datasources_view group by fulltextdownload", nativeQuery = true)
List<BrowseTerm> browseTermsForFulltextdownload();
}

View File

@ -7,6 +7,7 @@ import java.sql.Timestamp;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -432,7 +433,7 @@ public class DsmService {
@Transactional
@Cacheable("brosable_terms")
public List<BrowseTerm> browseTerm(final DsmBrowsableFields f) {
return switch (f) {
final List<BrowseTerm> list = switch (f) {
case type -> simpleDsWithApisRepository.browseTermsForType();
case collectedfrom -> simpleDsWithApisRepository.browseTermsForCollectedFrom();
case compliance -> simpleDsWithApisRepository.browseTermsForCompliance();
@ -443,6 +444,11 @@ public class DsmService {
case fulltextdownload -> simpleDsWithApisRepository.browseTermsForFulltextdownload();
default -> throw new RuntimeException("not implemeted");
};
return list.stream()
.filter(t -> StringUtils.isNotBlank(t.getName()))
.sorted(Comparator.comparing(BrowseTerm::getTotal))
.toList();
}
public Page<SimpleDsWithApis> searchByField(final DsmBrowsableFields f, final String value, final int page, final int size) {