added approved column to organizations table
This commit is contained in:
parent
f1c39ee6df
commit
8666648c46
|
@ -219,7 +219,7 @@ public class OrganizationController {
|
||||||
@PathVariable final int size,
|
@PathVariable final int size,
|
||||||
final Authentication authentication) {
|
final Authentication authentication) {
|
||||||
if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForCountry(code, authentication.getName())) {
|
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 {
|
} else {
|
||||||
throw new RuntimeException("User not authorized");
|
throw new RuntimeException("User not authorized");
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ public class OrganizationController {
|
||||||
@PathVariable final int size,
|
@PathVariable final int size,
|
||||||
final Authentication authentication) {
|
final Authentication authentication) {
|
||||||
return UserInfo.isSuperAdmin(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));
|
: organizationSimpleViewRepository.findByTypeForUser(type, authentication.getName(), PageRequest.of(page, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ public class BrowseEntry implements Serializable {
|
||||||
private static final long serialVersionUID = 8854955977257064470L;
|
private static final long serialVersionUID = 8854955977257064470L;
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
private int count;
|
private int approved;
|
||||||
|
private int pending;
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return value;
|
return value;
|
||||||
|
@ -20,12 +21,20 @@ public class BrowseEntry implements Serializable {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
public int getApproved() {
|
||||||
return count;
|
return approved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCount(final int count) {
|
public void setApproved(final int approved) {
|
||||||
this.count = count;
|
this.approved = approved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPending() {
|
||||||
|
return pending;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPending(final int pending) {
|
||||||
|
this.pending = pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import com.vladmihalcea.hibernate.type.array.StringArrayType;
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "organizations_simple_view")
|
@Table(name = "organizations_simple_view")
|
||||||
@TypeDefs({
|
@TypeDefs({
|
||||||
@TypeDef(name = "string-array", typeClass = StringArrayType.class)
|
@TypeDef(name = "string-array", typeClass = StringArrayType.class)
|
||||||
})
|
})
|
||||||
public class OrganizationSimpleView implements Serializable, Comparable<OrganizationSimpleView> {
|
public class OrganizationSimpleView implements Serializable, Comparable<OrganizationSimpleView> {
|
||||||
|
|
||||||
|
@ -46,19 +46,24 @@ public class OrganizationSimpleView implements Serializable, Comparable<Organiza
|
||||||
@Column(name = "acronyms", columnDefinition = "text[]")
|
@Column(name = "acronyms", columnDefinition = "text[]")
|
||||||
private String[] acronyms;
|
private String[] acronyms;
|
||||||
|
|
||||||
|
@Column(name = "approved")
|
||||||
|
private boolean approved = false;
|
||||||
|
|
||||||
public OrganizationSimpleView() {}
|
public OrganizationSimpleView() {}
|
||||||
|
|
||||||
public OrganizationSimpleView(final String id) {
|
public OrganizationSimpleView(final String id) {
|
||||||
this.id = 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.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.city = city;
|
this.city = city;
|
||||||
this.country = country;
|
this.country = country;
|
||||||
this.acronyms = acronyms;
|
this.acronyms = acronyms;
|
||||||
|
this.approved = approved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -109,6 +114,14 @@ public class OrganizationSimpleView implements Serializable, Comparable<Organiza
|
||||||
this.acronyms = acronyms;
|
this.acronyms = acronyms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isApproved() {
|
||||||
|
return approved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApproved(final boolean approved) {
|
||||||
|
this.approved = approved;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id);
|
return Objects.hash(id);
|
||||||
|
|
|
@ -12,18 +12,18 @@ import eu.dnetlib.organizations.model.view.OrganizationSimpleView;
|
||||||
public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<OrganizationSimpleView, String> {
|
public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<OrganizationSimpleView, String> {
|
||||||
|
|
||||||
// SEARCH
|
// 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);
|
Page<OrganizationSimpleView> search(@Param("text") String text, Pageable pageable);
|
||||||
|
|
||||||
// SEARCH FOR USER
|
// 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> 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);
|
Page<OrganizationSimpleView> findByTypeForUser(String type, String name, Pageable pageable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,31 +269,35 @@ public class DatabaseUtils {
|
||||||
|
|
||||||
// BROWSE BY COUNTRY
|
// BROWSE BY COUNTRY
|
||||||
public List<BrowseEntry> browseCountries() {
|
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));
|
return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
// BROWSE BY COUNTRY FOR USER
|
// BROWSE BY COUNTRY FOR USER
|
||||||
public List<BrowseEntry> browseCountriesForUser(final String email) {
|
public List<BrowseEntry> browseCountriesForUser(final String email) {
|
||||||
final String sql =
|
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);
|
return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class), email);
|
||||||
}
|
}
|
||||||
|
|
||||||
// BROWSE BY ORG TYPE
|
// BROWSE BY ORG TYPE
|
||||||
public List<BrowseEntry> browseTypes() {
|
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));
|
return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
// BROWSE BY ORG TYPE FOR USER
|
// BROWSE BY ORG TYPE FOR USER
|
||||||
public List<BrowseEntry> browseTypesForUser(final String email) {
|
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 "
|
+ "from organizations o "
|
||||||
+ "left outer join user_countries uc on (uc.country = o.country) "
|
+ "left outer join user_countries uc on (uc.country = o.country) "
|
||||||
+ "where uc.email=? "
|
+ "where uc.email=? "
|
||||||
+ "group by o.type "
|
+ "group by o.type "
|
||||||
+ "order by count desc;";
|
+ "order by approved desc;";
|
||||||
return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class), email);
|
return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class), email);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,8 @@ CREATE TABLE organizations (
|
||||||
created_by text,
|
created_by text,
|
||||||
creation_date timestamp with time zone DEFAULT now(),
|
creation_date timestamp with time zone DEFAULT now(),
|
||||||
modified_by text,
|
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_type_idx ON organizations(type);
|
||||||
CREATE INDEX organizations_country_idx ON organizations(country);
|
CREATE INDEX organizations_country_idx ON organizations(country);
|
||||||
|
@ -206,6 +207,7 @@ CREATE VIEW organizations_simple_view AS SELECT
|
||||||
org.type,
|
org.type,
|
||||||
org.city,
|
org.city,
|
||||||
org.country,
|
org.country,
|
||||||
|
org.approved,
|
||||||
array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms
|
array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms
|
||||||
FROM
|
FROM
|
||||||
organizations org
|
organizations org
|
||||||
|
@ -215,7 +217,8 @@ GROUP BY
|
||||||
org.name,
|
org.name,
|
||||||
org.type,
|
org.type,
|
||||||
org.city,
|
org.city,
|
||||||
org.country;
|
org.country,
|
||||||
|
org.approved;
|
||||||
|
|
||||||
CREATE VIEW users_view AS SELECT
|
CREATE VIEW users_view AS SELECT
|
||||||
u.email,
|
u.email,
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
<thead class="thead-light">
|
<thead class="thead-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{field}}</th>
|
<th>{{field}}</th>
|
||||||
<th class="text-right">#</th>
|
<th class="text-right"># approved</th>
|
||||||
|
<th class="text-right"># pending</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="e in entries">
|
<tr ng-repeat="e in entries">
|
||||||
<td><a href="#!{{resultsBasePath}}/0/50/{{e.value}}">{{e.value}}</a></td>
|
<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>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -35,10 +35,11 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<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">
|
<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="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>
|
<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>
|
||||||
<td class="col-4"><img ng-src="resources/images/flags/{{o.country}}.gif" /> {{o.city}}, {{o.country}}</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>
|
<td class="col-1 text-center">{{o.acronyms.join()}}</td>
|
||||||
|
|
Loading…
Reference in New Issue