fix hibernate, dependencies, empty query
This commit is contained in:
parent
1e3654808a
commit
c8b5ca96d2
|
@ -33,8 +33,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.thymeleaf.extras</groupId>
|
<groupId>org.thymeleaf.extras</groupId>
|
||||||
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
|
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
|
||||||
<version>3.0.4.RELEASE</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
|
@ -43,7 +42,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.vladmihalcea</groupId>
|
<groupId>com.vladmihalcea</groupId>
|
||||||
<artifactId>hibernate-types-52</artifactId>
|
<artifactId>hibernate-types-52</artifactId>
|
||||||
<version>2.3.5</version>
|
<version>2.9.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JAXB API, java.xml.bind module -->
|
<!-- JAXB API, java.xml.bind module -->
|
||||||
|
|
|
@ -30,17 +30,19 @@ public class MainApplication {
|
||||||
log.info("Initializing SWAGGER...");
|
log.info("Initializing SWAGGER...");
|
||||||
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
.select()
|
.select()
|
||||||
.apis(RequestHandlerSelectors.any())
|
.apis(RequestHandlerSelectors.any())
|
||||||
.paths(p -> p.startsWith("/api/"))
|
.paths(p -> p.startsWith("/api/"))
|
||||||
.build().apiInfo(new ApiInfoBuilder()
|
.build()
|
||||||
.title("D-Net Organizations Service APIs")
|
.apiInfo(new ApiInfoBuilder()
|
||||||
.description("APIs documentation")
|
.title("D-Net Organizations Service APIs")
|
||||||
.version("1.1")
|
.description("APIs documentation")
|
||||||
.contact(ApiInfo.DEFAULT_CONTACT)
|
.version("1.1")
|
||||||
.license("Apache 2.0")
|
.contact(ApiInfo.DEFAULT_CONTACT)
|
||||||
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
|
.license("Apache 2.0")
|
||||||
.build());
|
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
|
||||||
|
.build());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ public class OrganizationController {
|
||||||
|
|
||||||
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||||||
public List<String> save(@RequestBody final OrganizationView org, final Authentication authentication) {
|
public List<String> save(@RequestBody final OrganizationView org, final Authentication authentication) {
|
||||||
|
|
||||||
if (StringUtils.isBlank(org.getName())) {
|
if (StringUtils.isBlank(org.getName())) {
|
||||||
throw new RuntimeException("Missing field: name");
|
throw new RuntimeException("Missing field: name");
|
||||||
} else if (StringUtils.isBlank(org.getCountry())) {
|
} else if (StringUtils.isBlank(org.getCountry())) {
|
||||||
|
@ -100,11 +101,11 @@ public class OrganizationController {
|
||||||
suggestionInfoViewByCountryRepository.findAll().forEach(info::add);
|
suggestionInfoViewByCountryRepository.findAll().forEach(info::add);
|
||||||
} else if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
} else if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
||||||
userCountryRepository.getCountriesForUser(authentication.getName())
|
userCountryRepository.getCountriesForUser(authentication.getName())
|
||||||
.stream()
|
.stream()
|
||||||
.map(suggestionInfoViewByCountryRepository::findById)
|
.map(suggestionInfoViewByCountryRepository::findById)
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.forEach(info::add);
|
.forEach(info::add);
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@ -147,11 +148,11 @@ public class OrganizationController {
|
||||||
return groupConflicts(conflictGroupViewRepository.findByCountry1OrCountry2(country, country).stream());
|
return groupConflicts(conflictGroupViewRepository.findByCountry1OrCountry2(country, country).stream());
|
||||||
} else if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
} else if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
||||||
final Stream<ConflictGroupView> list = userCountryRepository.getCountriesForUser(authentication.getName())
|
final Stream<ConflictGroupView> list = userCountryRepository.getCountriesForUser(authentication.getName())
|
||||||
.stream()
|
.stream()
|
||||||
.filter(country::equalsIgnoreCase)
|
.filter(country::equalsIgnoreCase)
|
||||||
.map(c -> conflictGroupViewRepository.findByCountry1OrCountry2(c, c).stream())
|
.map(c -> conflictGroupViewRepository.findByCountry1OrCountry2(c, c).stream())
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(Stream.empty());
|
.orElse(Stream.empty());
|
||||||
return groupConflicts(list);
|
return groupConflicts(list);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("User not authorized");
|
throw new RuntimeException("User not authorized");
|
||||||
|
@ -166,11 +167,11 @@ public class OrganizationController {
|
||||||
return duplicateGroupViewRepository.findByCountry(country);
|
return duplicateGroupViewRepository.findByCountry(country);
|
||||||
} else if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
} else if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
||||||
return userCountryRepository.getCountriesForUser(authentication.getName())
|
return userCountryRepository.getCountriesForUser(authentication.getName())
|
||||||
.stream()
|
.stream()
|
||||||
.filter(country::equalsIgnoreCase)
|
.filter(country::equalsIgnoreCase)
|
||||||
.map(duplicateGroupViewRepository::findByCountry)
|
.map(duplicateGroupViewRepository::findByCountry)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(new ArrayList<DuplicateGroupView>());
|
.orElse(new ArrayList<DuplicateGroupView>());
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("User not authorized");
|
throw new RuntimeException("User not authorized");
|
||||||
}
|
}
|
||||||
|
@ -193,10 +194,10 @@ public class OrganizationController {
|
||||||
public List<OpenaireDuplicate> duplicates(@RequestBody final List<OpenaireDuplicate> simrels, final Authentication authentication) {
|
public List<OpenaireDuplicate> duplicates(@RequestBody final List<OpenaireDuplicate> simrels, final Authentication authentication) {
|
||||||
|
|
||||||
final boolean b = UserInfo.isSuperAdmin(authentication)
|
final boolean b = UserInfo.isSuperAdmin(authentication)
|
||||||
|| simrels.stream()
|
|| simrels.stream()
|
||||||
.map(OpenaireDuplicate::getLocalId)
|
.map(OpenaireDuplicate::getLocalId)
|
||||||
.distinct()
|
.distinct()
|
||||||
.allMatch(id -> userCountryRepository.verifyAuthorizationForId(id, authentication.getName()));
|
.allMatch(id -> userCountryRepository.verifyAuthorizationForId(id, authentication.getName()));
|
||||||
|
|
||||||
if (b) {
|
if (b) {
|
||||||
return openaireDuplicateRepository.saveAll(simrels);
|
return openaireDuplicateRepository.saveAll(simrels);
|
||||||
|
@ -207,19 +208,19 @@ public class OrganizationController {
|
||||||
|
|
||||||
@RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.GET)
|
@RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.GET)
|
||||||
public Page<OrganizationSimpleView> search(@PathVariable final int page,
|
public Page<OrganizationSimpleView> search(@PathVariable final int page,
|
||||||
@PathVariable final int size,
|
@PathVariable final int size,
|
||||||
@RequestParam final String q,
|
@RequestParam final String q,
|
||||||
final Authentication authentication) {
|
final Authentication authentication) {
|
||||||
return UserInfo.isSuperAdmin(authentication)
|
return UserInfo.isSuperAdmin(authentication)
|
||||||
? organizationSimpleViewRepository.findByNameContainingIgnoreCase(q, PageRequest.of(page, size))
|
? organizationSimpleViewRepository.findByNameContainingIgnoreCase(q, PageRequest.of(page, size))
|
||||||
: organizationSimpleViewRepository.findByNameForUser(q, authentication.getName(), PageRequest.of(page, size));
|
: organizationSimpleViewRepository.findByNameForUser(q, authentication.getName(), PageRequest.of(page, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/byCountry/{code}/{page}/{size}", method = RequestMethod.GET)
|
@RequestMapping(value = "/byCountry/{code}/{page}/{size}", method = RequestMethod.GET)
|
||||||
public Page<OrganizationSimpleView> findByCountry(@PathVariable final String code,
|
public Page<OrganizationSimpleView> findByCountry(@PathVariable final String code,
|
||||||
@PathVariable final int page,
|
@PathVariable final int page,
|
||||||
@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.findByCountry(code, PageRequest.of(page, size));
|
||||||
} else {
|
} else {
|
||||||
|
@ -229,26 +230,26 @@ public class OrganizationController {
|
||||||
|
|
||||||
@RequestMapping(value = "/byType/{type}/{page}/{size}", method = RequestMethod.GET)
|
@RequestMapping(value = "/byType/{type}/{page}/{size}", method = RequestMethod.GET)
|
||||||
public Page<OrganizationSimpleView> findByType(@PathVariable final String type,
|
public Page<OrganizationSimpleView> findByType(@PathVariable final String type,
|
||||||
@PathVariable final int page,
|
@PathVariable final int page,
|
||||||
@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.findByType(type, PageRequest.of(page, size))
|
||||||
: organizationSimpleViewRepository.findByTypeForUser(type, authentication.getName(), PageRequest.of(page, size));
|
: organizationSimpleViewRepository.findByTypeForUser(type, authentication.getName(), PageRequest.of(page, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/browse/countries", method = RequestMethod.GET)
|
@RequestMapping(value = "/browse/countries", method = RequestMethod.GET)
|
||||||
public List<BrowseEntry> browseCountries(final Authentication authentication) {
|
public List<BrowseEntry> browseCountries(final Authentication authentication) {
|
||||||
return UserInfo.isSuperAdmin(authentication)
|
return UserInfo.isSuperAdmin(authentication)
|
||||||
? organizationSimpleViewRepository.browseCountries()
|
? databaseUtils.browseCountries()
|
||||||
: organizationSimpleViewRepository.browseCountriesForUser(authentication.getName());
|
: databaseUtils.browseCountriesForUser(authentication.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/browse/types", method = RequestMethod.GET)
|
@RequestMapping(value = "/browse/types", method = RequestMethod.GET)
|
||||||
public List<BrowseEntry> browseOrganizationTypes(final Authentication authentication) {
|
public List<BrowseEntry> browseOrganizationTypes(final Authentication authentication) {
|
||||||
return UserInfo.isSuperAdmin(authentication)
|
return UserInfo.isSuperAdmin(authentication)
|
||||||
? organizationSimpleViewRepository.browseTypes()
|
? databaseUtils.browseTypes()
|
||||||
: organizationSimpleViewRepository.browseTypesForUser(authentication.getName());
|
: databaseUtils.browseTypesForUser(authentication.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/conflicts/fix/{masterId}", method = RequestMethod.POST)
|
@RequestMapping(value = "/conflicts/fix/{masterId}", method = RequestMethod.POST)
|
||||||
|
@ -256,10 +257,10 @@ public class OrganizationController {
|
||||||
if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(masterId, authentication.getName())) {
|
if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(masterId, authentication.getName())) {
|
||||||
|
|
||||||
return otherIds.stream()
|
return otherIds.stream()
|
||||||
.filter(id -> UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(id, authentication.getName()))
|
.filter(id -> UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(id, authentication.getName()))
|
||||||
.map(id -> databaseUtils.makeRelation(masterId, id, RelationType.Merges))
|
.map(id -> databaseUtils.makeRelation(masterId, id, RelationType.Merges))
|
||||||
.flatMap(List::stream)
|
.flatMap(List::stream)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
|
|
@ -1,9 +1,31 @@
|
||||||
package eu.dnetlib.organizations.model.utils;
|
package eu.dnetlib.organizations.model.utils;
|
||||||
|
|
||||||
public interface BrowseEntry {
|
import java.io.Serializable;
|
||||||
|
|
||||||
String getValue();
|
public class BrowseEntry implements Serializable {
|
||||||
|
|
||||||
int getCount();
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 8854955977257064470L;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(final String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(final int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package eu.dnetlib.organizations.repository.readonly;
|
package eu.dnetlib.organizations.repository.readonly;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import eu.dnetlib.organizations.model.utils.BrowseEntry;
|
|
||||||
import eu.dnetlib.organizations.model.view.OrganizationSimpleView;
|
import eu.dnetlib.organizations.model.view.OrganizationSimpleView;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@ -20,29 +17,8 @@ public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<Org
|
||||||
@Query(value = "select o.* from organizations_simple_view o left outer join user_countries uc on (uc.country = o.country) where o.name ilike %:text% and uc.email = :email", nativeQuery = true)
|
@Query(value = "select o.* from organizations_simple_view o left outer join user_countries uc on (uc.country = o.country) where o.name ilike %:text% and uc.email = :email", nativeQuery = true)
|
||||||
Page<OrganizationSimpleView> findByNameForUser(String text, String email, Pageable pageable);
|
Page<OrganizationSimpleView> findByNameForUser(String text, String email, Pageable pageable);
|
||||||
|
|
||||||
// BROWSE BY COUNTRY
|
|
||||||
@Query(value = "select country as value, count(*) as count from organizations group by country order by count desc", nativeQuery = true)
|
|
||||||
List<BrowseEntry> browseCountries();
|
|
||||||
|
|
||||||
// BROWSE BY COUNTRY FOR USER
|
|
||||||
@Query(value = "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=?1 group by o.country order by count desc", nativeQuery = true)
|
|
||||||
List<BrowseEntry> browseCountriesForUser(String email);
|
|
||||||
|
|
||||||
Page<OrganizationSimpleView> findByCountry(String country, Pageable pageable);
|
Page<OrganizationSimpleView> findByCountry(String country, Pageable pageable);
|
||||||
|
|
||||||
// BROWSE BY ORG TYPE
|
|
||||||
@Query(value = "select type as value, count(*) as count from organizations group by type order by count desc", nativeQuery = true)
|
|
||||||
List<BrowseEntry> browseTypes();
|
|
||||||
|
|
||||||
// BROWSE BY ORG TYPE FOR USER
|
|
||||||
@Query(value = "select o.type as value, count(o.type) as count "
|
|
||||||
+ "from organizations o "
|
|
||||||
+ "left outer join user_countries uc on (uc.country = o.country) "
|
|
||||||
+ "where uc.email=?1 "
|
|
||||||
+ "group by o.type "
|
|
||||||
+ "order by count desc;", nativeQuery = true)
|
|
||||||
List<BrowseEntry> browseTypesForUser(String email);
|
|
||||||
|
|
||||||
Page<OrganizationSimpleView> findByType(String type, Pageable pageable);
|
Page<OrganizationSimpleView> findByType(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", nativeQuery = true)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import javax.transaction.Transactional;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
@ -31,6 +32,7 @@ import eu.dnetlib.organizations.model.Relationship;
|
||||||
import eu.dnetlib.organizations.model.Url;
|
import eu.dnetlib.organizations.model.Url;
|
||||||
import eu.dnetlib.organizations.model.User;
|
import eu.dnetlib.organizations.model.User;
|
||||||
import eu.dnetlib.organizations.model.UserCountry;
|
import eu.dnetlib.organizations.model.UserCountry;
|
||||||
|
import eu.dnetlib.organizations.model.utils.BrowseEntry;
|
||||||
import eu.dnetlib.organizations.model.view.OrganizationView;
|
import eu.dnetlib.organizations.model.view.OrganizationView;
|
||||||
import eu.dnetlib.organizations.model.view.UserView;
|
import eu.dnetlib.organizations.model.view.UserView;
|
||||||
import eu.dnetlib.organizations.repository.AcronymRepository;
|
import eu.dnetlib.organizations.repository.AcronymRepository;
|
||||||
|
@ -68,7 +70,12 @@ public class DatabaseUtils {
|
||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
public enum VocabularyTable {
|
public enum VocabularyTable {
|
||||||
languages, countries, org_types, id_types, rel_types, simrel_types
|
languages,
|
||||||
|
countries,
|
||||||
|
org_types,
|
||||||
|
id_types,
|
||||||
|
rel_types,
|
||||||
|
simrel_types
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -79,10 +86,10 @@ public class DatabaseUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
final Organization org = new Organization(update ? orgView.getId() : null,
|
final Organization org = new Organization(update ? orgView.getId() : null,
|
||||||
orgView.getName(),
|
orgView.getName(),
|
||||||
orgView.getType(),
|
orgView.getType(),
|
||||||
orgView.getLat(), orgView.getLng(),
|
orgView.getLat(), orgView.getLng(),
|
||||||
orgView.getCity(), orgView.getCountry());
|
orgView.getCity(), orgView.getCountry());
|
||||||
|
|
||||||
final String orgId = organizationRepository.save(org).getId();
|
final String orgId = organizationRepository.save(org).getId();
|
||||||
|
|
||||||
|
@ -139,7 +146,7 @@ public class DatabaseUtils {
|
||||||
userCountryRepository.deleteByEmail(userView.getEmail());
|
userCountryRepository.deleteByEmail(userView.getEmail());
|
||||||
if (userView.getCountries() != null) {
|
if (userView.getCountries() != null) {
|
||||||
userCountryRepository
|
userCountryRepository
|
||||||
.saveAll(Arrays.stream(userView.getCountries()).map(c -> new UserCountry(userView.getEmail(), c)).collect(Collectors.toList()));
|
.saveAll(Arrays.stream(userView.getCountries()).map(c -> new UserCountry(userView.getEmail(), c)).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,13 +215,13 @@ public class DatabaseUtils {
|
||||||
|
|
||||||
private List<String> findExistingGroupsForRel(final OpenaireConflict w, final Map<String, Set<String>> groups) {
|
private List<String> findExistingGroupsForRel(final OpenaireConflict w, final Map<String, Set<String>> groups) {
|
||||||
return groups.entrySet()
|
return groups.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(e -> {
|
.filter(e -> {
|
||||||
return e.getValue().contains(w.getId1()) || e.getValue().contains(w.getId2());
|
return e.getValue().contains(w.getId1()) || e.getValue().contains(w.getId2());
|
||||||
})
|
})
|
||||||
.map(e -> e.getKey())
|
.map(e -> e.getKey())
|
||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToGroup(final Map<String, Set<String>> groups, final String gid, final OpenaireConflict w) {
|
private void addToGroup(final Map<String, Set<String>> groups, final String gid, final OpenaireConflict w) {
|
||||||
|
@ -236,4 +243,36 @@ public class DatabaseUtils {
|
||||||
|
|
||||||
return Arrays.asList(r1, r2);
|
return Arrays.asList(r1, r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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";
|
||||||
|
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";
|
||||||
|
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";
|
||||||
|
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 "
|
||||||
|
+ "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;";
|
||||||
|
return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class), email);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ orgsModule.directive('selectOrgModal', function($http) {
|
||||||
|
|
||||||
scope.search = function(text, page, size) {
|
scope.search = function(text, page, size) {
|
||||||
scope.searchOrgs = {};
|
scope.searchOrgs = {};
|
||||||
|
|
||||||
$http.get('api/organizations/search/' + page + '/' + size + '?q=' + text).then(function successCallback(res) {
|
$http.get('api/organizations/search/' + page + '/' + size + '?q=' + text).then(function successCallback(res) {
|
||||||
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
||||||
scope.searchValue = text;
|
scope.searchValue = text;
|
||||||
|
@ -438,14 +439,21 @@ orgsModule.controller('newOrgCtrl', function ($scope, $http, $routeParams, $loca
|
||||||
orgsModule.controller('searchCtrl', function ($scope, $location) {
|
orgsModule.controller('searchCtrl', function ($scope, $location) {
|
||||||
$scope.searchText = '';
|
$scope.searchText = '';
|
||||||
$scope.search = function() {
|
$scope.search = function() {
|
||||||
$location.url('/searchResults/0/50/' + encodeURIComponent(encodeURIComponent($scope.searchText)));
|
if ($scope.searchText) {
|
||||||
|
$location.url('/searchResults/0/50/' + encodeURIComponent(encodeURIComponent($scope.searchText)));
|
||||||
|
} else {
|
||||||
|
$location.url('/searchResults/0/50/_');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams, $location) {
|
orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams, $location) {
|
||||||
$scope.searchText = decodeURIComponent($routeParams.text);
|
$scope.searchText = '';
|
||||||
|
if ($routeParams.text != '_') {
|
||||||
|
$scope.searchText = decodeURIComponent($routeParams.text);
|
||||||
|
}
|
||||||
$scope.orgs = {};
|
$scope.orgs = {};
|
||||||
|
|
||||||
$http.get('api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.searchText).then(function successCallback(res) {
|
$http.get('api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.searchText).then(function successCallback(res) {
|
||||||
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
||||||
$scope.orgs = res.data;
|
$scope.orgs = res.data;
|
||||||
|
@ -454,11 +462,19 @@ orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.prev = function() {
|
$scope.prev = function() {
|
||||||
$location.url('/searchResults/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
|
if ($scope.searchText) {
|
||||||
|
$location.url('/searchResults/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
|
||||||
|
} else {
|
||||||
|
$location.url('/searchResults/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/_');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.next = function() {
|
$scope.next = function() {
|
||||||
$location.url('/searchResults/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
|
if ($scope.searchText) {
|
||||||
|
$location.url('/searchResults/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
|
||||||
|
} else {
|
||||||
|
$location.url('/searchResults/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/_');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.3.1.RELEASE</version>
|
<version>2.3.2.RELEASE</version>
|
||||||
<relativePath />
|
<relativePath />
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue