diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java index af78fadb..d3ed7a36 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java @@ -219,7 +219,7 @@ public class OrganizationController { @PathVariable final int size, final Authentication authentication) { if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForCountry(code, authentication.getName())) { - return organizationSimpleViewRepository.findByCountry(code, PageRequest.of(page, size)); + return organizationSimpleViewRepository.findByCountryOrderByName(code, PageRequest.of(page, size)); } else { throw new RuntimeException("User not authorized"); } @@ -231,7 +231,7 @@ public class OrganizationController { @PathVariable final int size, final Authentication authentication) { return UserInfo.isSuperAdmin(authentication) - ? organizationSimpleViewRepository.findByType(type, PageRequest.of(page, size)) + ? organizationSimpleViewRepository.findByTypeOrderByName(type, PageRequest.of(page, size)) : organizationSimpleViewRepository.findByTypeForUser(type, authentication.getName(), PageRequest.of(page, size)); } diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/BrowseEntry.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/BrowseEntry.java index 8895f1c1..c77259fb 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/BrowseEntry.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/BrowseEntry.java @@ -10,7 +10,8 @@ public class BrowseEntry implements Serializable { private static final long serialVersionUID = 8854955977257064470L; private String value; - private int count; + private int approved; + private int pending; public String getValue() { return value; @@ -20,12 +21,20 @@ public class BrowseEntry implements Serializable { this.value = value; } - public int getCount() { - return count; + public int getApproved() { + return approved; } - public void setCount(final int count) { - this.count = count; + public void setApproved(final int approved) { + this.approved = approved; + } + + public int getPending() { + return pending; + } + + public void setPending(final int pending) { + this.pending = pending; } } diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/view/OrganizationSimpleView.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/view/OrganizationSimpleView.java index 8c44b87f..a7a71eda 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/view/OrganizationSimpleView.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/view/OrganizationSimpleView.java @@ -17,7 +17,7 @@ import com.vladmihalcea.hibernate.type.array.StringArrayType; @Entity @Table(name = "organizations_simple_view") @TypeDefs({ - @TypeDef(name = "string-array", typeClass = StringArrayType.class) + @TypeDef(name = "string-array", typeClass = StringArrayType.class) }) public class OrganizationSimpleView implements Serializable, Comparable { @@ -46,19 +46,24 @@ public class OrganizationSimpleView implements Serializable, Comparable { // SEARCH - @Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) where idx.txt @@ plainto_tsquery(:text)", nativeQuery = true) + @Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) where idx.txt @@ plainto_tsquery(:text) order by o.name", nativeQuery = true) Page search(@Param("text") String text, Pageable pageable); // SEARCH FOR USER - @Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) left outer join user_countries uc on (uc.country = o.country) where idx.txt @@ plainto_tsquery(:text) and uc.email = :email", nativeQuery = true) + @Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) left outer join user_countries uc on (uc.country = o.country) where idx.txt @@ plainto_tsquery(:text) and uc.email = :email order by o.name", nativeQuery = true) Page searchForUser(@Param("text") String text, @Param("email") String email, Pageable pageable); - Page findByCountry(String country, Pageable pageable); + Page findByCountryOrderByName(String country, Pageable pageable); - Page findByType(String type, Pageable pageable); + Page findByTypeOrderByName(String type, Pageable pageable); - @Query(value = "select o.* from organizations_simple_view o left outer join user_countries uc on (uc.country = o.country) where uc.email = ?2 and o.type = ?1", nativeQuery = true) + @Query(value = "select o.* from organizations_simple_view o left outer join user_countries uc on (uc.country = o.country) where uc.email = ?2 and o.type = ?1 order by o.name", nativeQuery = true) Page findByTypeForUser(String type, String name, Pageable pageable); } diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java index c25c7276..58d84c19 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java @@ -269,31 +269,35 @@ public class DatabaseUtils { // BROWSE BY COUNTRY public List browseCountries() { - final String sql = "select country as value, count(*) as count from organizations group by country order by count desc"; + final String sql = + "select country as value, sum(case when approved then 1 else 0 end) as approved, sum(case when approved then 0 else 1 end) as pending from organizations group by country order by approved desc;"; return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class)); } // BROWSE BY COUNTRY FOR USER public List browseCountriesForUser(final String email) { final String sql = - "select o.country as value, count(o.country) as count from user_countries uc left outer join organizations o on (uc.country = o.country) where uc.email=? group by o.country order by count desc"; + "select o.country as value, sum(case when approved then 1 else 0 end) as approved, sum(case when approved then 0 else 1 end) as pending from user_countries uc left outer join organizations o on (uc.country = o.country) where uc.email=? group by o.country order by approved desc"; return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class), email); } // BROWSE BY ORG TYPE public List browseTypes() { - final String sql = "select type as value, count(*) as count from organizations group by type order by count desc"; + final String sql = + "select type as value, sum(case when approved then 1 else 0 end) as approved, sum(case when approved then 0 else 1 end) as pending from organizations group by type order by approved desc"; return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class)); } // BROWSE BY ORG TYPE FOR USER public List browseTypesForUser(final String email) { - final String sql = "select o.type as value, count(o.type) as count " + final String sql = "select o.type as value, " + + "sum(case when approved then 1 else 0 end) as approved, " + + "sum(case when approved then 0 else 1 end) as pending " + "from organizations o " + "left outer join user_countries uc on (uc.country = o.country) " + "where uc.email=? " + "group by o.type " - + "order by count desc;"; + + "order by approved desc;"; return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class), email); } diff --git a/apps/dnet-orgs-database-application/src/main/resources/sql/schema.sql b/apps/dnet-orgs-database-application/src/main/resources/sql/schema.sql index 25537692..f1faea15 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/sql/schema.sql +++ b/apps/dnet-orgs-database-application/src/main/resources/sql/schema.sql @@ -81,7 +81,8 @@ CREATE TABLE organizations ( created_by text, creation_date timestamp with time zone DEFAULT now(), modified_by text, - modification_date timestamp with time zone DEFAULT now() + modification_date timestamp with time zone DEFAULT now(), + approved boolean NOT NULL DEFAULT false ); CREATE INDEX organizations_type_idx ON organizations(type); CREATE INDEX organizations_country_idx ON organizations(country); @@ -206,6 +207,7 @@ CREATE VIEW organizations_simple_view AS SELECT org.type, org.city, org.country, + org.approved, array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms FROM organizations org @@ -215,7 +217,8 @@ GROUP BY org.name, org.type, org.city, - org.country; + org.country, + org.approved; CREATE VIEW users_view AS SELECT u.email, diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/browse.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/browse.html index 71d535cd..c012c2bf 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/browse.html +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/browse.html @@ -2,13 +2,15 @@ {{field}} - # + # approved + # pending {{e.value}} - {{e.count}} + {{e.approved}} + {{e.pending}} diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/parts/org_results.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/parts/org_results.html index 5ea9857d..9037c156 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/parts/org_results.html +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/parts/org_results.html @@ -35,10 +35,11 @@ - + {{o.name}} {{o.name}} + pending {{o.city}}, {{o.country}} {{o.acronyms.join()}}