added approved column to organizations table

This commit is contained in:
Michele Artini 2020-10-01 16:30:32 +02:00
parent f1c39ee6df
commit 8666648c46
8 changed files with 56 additions and 24 deletions

View File

@ -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));
}

View File

@ -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;
}
}

View File

@ -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<OrganizationSimpleView> {
@ -46,19 +46,24 @@ public class OrganizationSimpleView implements Serializable, Comparable<Organiza
@Column(name = "acronyms", columnDefinition = "text[]")
private String[] acronyms;
@Column(name = "approved")
private boolean approved = false;
public OrganizationSimpleView() {}
public OrganizationSimpleView(final String id) {
this.id = id;
}
public OrganizationSimpleView(final String id, final String name, final String type, final String city, final String country, final String[] acronyms) {
public OrganizationSimpleView(final String id, final String name, final String type, final String city, final String country, final String[] acronyms,
final boolean approved) {
this.id = id;
this.name = name;
this.type = type;
this.city = city;
this.country = country;
this.acronyms = acronyms;
this.approved = approved;
}
public String getId() {
@ -109,6 +114,14 @@ public class OrganizationSimpleView implements Serializable, Comparable<Organiza
this.acronyms = acronyms;
}
public boolean isApproved() {
return approved;
}
public void setApproved(final boolean approved) {
this.approved = approved;
}
@Override
public int hashCode() {
return Objects.hash(id);

View File

@ -12,18 +12,18 @@ import eu.dnetlib.organizations.model.view.OrganizationSimpleView;
public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<OrganizationSimpleView, String> {
// 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<OrganizationSimpleView> 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<OrganizationSimpleView> searchForUser(@Param("text") String text, @Param("email") String email, Pageable pageable);
Page<OrganizationSimpleView> findByCountry(String country, Pageable pageable);
Page<OrganizationSimpleView> findByCountryOrderByName(String country, Pageable pageable);
Page<OrganizationSimpleView> findByType(String type, Pageable pageable);
Page<OrganizationSimpleView> 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<OrganizationSimpleView> findByTypeForUser(String type, String name, Pageable pageable);
}

View File

@ -269,31 +269,35 @@ public class DatabaseUtils {
// BROWSE BY COUNTRY
public List<BrowseEntry> 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<BrowseEntry> 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<BrowseEntry> 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<BrowseEntry> 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);
}

View File

@ -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,

View File

@ -2,13 +2,15 @@
<thead class="thead-light">
<tr>
<th>{{field}}</th>
<th class="text-right">#</th>
<th class="text-right"># approved</th>
<th class="text-right"># pending</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="e in entries">
<td><a href="#!{{resultsBasePath}}/0/50/{{e.value}}">{{e.value}}</a></td>
<td class="text-right">{{e.count}}</td>
<td class="text-right">{{e.approved}}</td>
<td class="text-right">{{e.pending}}</td>
</tr>
</tbody>
</table>

View File

@ -35,10 +35,11 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="o in orgs.content" class="d-flex">
<tr ng-repeat="o in orgs.content" class="d-flex" ng-class="{'table-warning' : !o.approved }">
<td class="col-6">
<a ng-if="mode == 'select-modal'" href="javascript:void(0)" title="select" ng-click="selectOrg(o)" data-dismiss="modal">{{o.name}}</a>
<a ng-if="mode != 'select-modal'" href="#!/edit/0/{{o.id}}" title="{{o.id}}">{{o.name}}</a>
<span class="badge badge-warning" ng-if="!o.approved">pending</span>
</td>
<td class="col-4"><img ng-src="resources/images/flags/{{o.country}}.gif" /> {{o.city}}, {{o.country}}</td>
<td class="col-1 text-center">{{o.acronyms.join()}}</td>