added a default limit in suggestion pages
This commit is contained in:
parent
db18cb601c
commit
19bc482244
|
@ -86,20 +86,16 @@ public class OrganizationController extends AbstractDnetController {
|
|||
@PostMapping("/save")
|
||||
public List<String> save(@RequestBody final OrganizationView org, final Authentication authentication) {
|
||||
|
||||
if (StringUtils.isBlank(org.getName())) {
|
||||
throw new RuntimeException("Missing field: name");
|
||||
} else if (StringUtils.isBlank(org.getCountry())) {
|
||||
throw new RuntimeException("Missing field: country");
|
||||
} else if (StringUtils.isBlank(org.getType())) {
|
||||
throw new RuntimeException("Missing field: type");
|
||||
} else if (UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
final String orgId =
|
||||
if (StringUtils.isBlank(org.getName())) { throw new RuntimeException("Missing field: name"); }
|
||||
if (StringUtils.isBlank(org.getCountry())) { throw new RuntimeException("Missing field: country"); }
|
||||
if (StringUtils.isBlank(org.getType())) { throw new RuntimeException("Missing field: type"); }
|
||||
if (UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
final String orgId =
|
||||
databaseUtils.insertOrUpdateOrganization(org, UserInfo.getEmail(authentication), UserInfo.isSimpleUser(authentication));
|
||||
return Arrays.asList(orgId);
|
||||
} else {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
return Arrays.asList(orgId);
|
||||
}
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
|
@ -115,11 +111,11 @@ public class OrganizationController extends AbstractDnetController {
|
|||
suggestionInfoViewByCountryRepository.findAll().forEach(info::add);
|
||||
} else if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
||||
userCountryRepository.getCountriesForUser(UserInfo.getEmail(authentication))
|
||||
.stream()
|
||||
.map(suggestionInfoViewByCountryRepository::findById)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.forEach(info::add);
|
||||
.stream()
|
||||
.map(suggestionInfoViewByCountryRepository::findById)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.forEach(info::add);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
@ -129,29 +125,26 @@ public class OrganizationController extends AbstractDnetController {
|
|||
final OrganizationView org = organizationViewRepository.findById(id).get();
|
||||
|
||||
if (UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
return org;
|
||||
} else {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
|
||||
@GetMapping("/conflicts")
|
||||
public List<OrganizationConflict> conflicts(@RequestParam final String id, final Authentication authentication) {
|
||||
if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(id, UserInfo.getEmail(authentication))) {
|
||||
return databaseUtils.listConflictsForId(id);
|
||||
} else {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
|
||||
@GetMapping("/duplicates")
|
||||
public List<OpenaireDuplicateView> duplicates(@RequestParam final String id, final Authentication authentication) {
|
||||
if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(id, UserInfo.getEmail(authentication))) {
|
||||
return listDuplicates(id);
|
||||
} else {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
|
||||
private List<OpenaireDuplicateView> listDuplicates(final String id) {
|
||||
|
@ -159,45 +152,47 @@ public class OrganizationController extends AbstractDnetController {
|
|||
}
|
||||
|
||||
@GetMapping("/conflicts/byCountry/{country}")
|
||||
public Collection<Set<OrganizationConflict>> findConflictsByCountry(@PathVariable final String country, final Authentication authentication) {
|
||||
public Collection<Set<OrganizationConflict>> findConflictsByCountry(@PathVariable final String country,
|
||||
@RequestParam(required = false, defaultValue = "1000") final int limit,
|
||||
final Authentication authentication) {
|
||||
|
||||
if (UserInfo.isSuperAdmin(authentication)) {
|
||||
return groupConflicts(conflictGroupViewRepository.findByCountry1OrCountry2(country, country).stream());
|
||||
} else if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
||||
final Stream<ConflictGroupView> list = userCountryRepository.getCountriesForUser(UserInfo.getEmail(authentication))
|
||||
.stream()
|
||||
.filter(country::equalsIgnoreCase)
|
||||
.map(c -> conflictGroupViewRepository.findByCountry1OrCountry2(c, c).stream())
|
||||
.findFirst()
|
||||
.orElse(Stream.empty());
|
||||
return groupConflicts(list);
|
||||
} else {
|
||||
throw new RuntimeException("User not authorized");
|
||||
return groupConflicts(conflictGroupViewRepository.findByCountry1OrCountry2(country, country, PageRequest.of(0, limit)).stream());
|
||||
}
|
||||
if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
||||
final Stream<ConflictGroupView> list = userCountryRepository.getCountriesForUser(UserInfo.getEmail(authentication))
|
||||
.stream()
|
||||
.filter(country::equalsIgnoreCase)
|
||||
.map(c -> conflictGroupViewRepository.findByCountry1OrCountry2(c, c, PageRequest.of(0, limit)).stream())
|
||||
.findFirst()
|
||||
.orElse(Stream.empty());
|
||||
return groupConflicts(list);
|
||||
}
|
||||
throw new RuntimeException("User not authorized");
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/duplicates/byCountry/{country}")
|
||||
public Iterable<DuplicateGroupView> findDuplicatesByCountry(@PathVariable final String country, final Authentication authentication) {
|
||||
public Iterable<DuplicateGroupView> findDuplicatesByCountry(@PathVariable final String country,
|
||||
@RequestParam(required = false, defaultValue = "1000") final int limit,
|
||||
final Authentication authentication) {
|
||||
|
||||
if (UserInfo.isSuperAdmin(authentication)) {
|
||||
return duplicateGroupViewRepository.findByCountry(country);
|
||||
} else if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
||||
if (UserInfo.isSuperAdmin(authentication)) { return duplicateGroupViewRepository.findByCountry(country, PageRequest.of(0, limit)); }
|
||||
if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
||||
return userCountryRepository.getCountriesForUser(UserInfo.getEmail(authentication))
|
||||
.stream()
|
||||
.filter(country::equalsIgnoreCase)
|
||||
.map(duplicateGroupViewRepository::findByCountry)
|
||||
.findFirst()
|
||||
.orElse(new ArrayList<DuplicateGroupView>());
|
||||
} else {
|
||||
throw new RuntimeException("User not authorized");
|
||||
.stream()
|
||||
.filter(country::equalsIgnoreCase)
|
||||
.map(c -> duplicateGroupViewRepository.findByCountry(c, PageRequest.of(0, limit)))
|
||||
.findFirst()
|
||||
.orElse(new ArrayList<DuplicateGroupView>());
|
||||
}
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
|
||||
@GetMapping(value = "/duplicates/byCountry/{country}/csv", produces = "text/csv")
|
||||
public void findDuplicatesByCountryCSV(@PathVariable final String country, final HttpServletResponse res, final Authentication authentication)
|
||||
throws IOException {
|
||||
final Iterable<DuplicateGroupView> list = findDuplicatesByCountry(country, authentication);
|
||||
throws IOException {
|
||||
final Iterable<DuplicateGroupView> list = findDuplicatesByCountry(country, Integer.MAX_VALUE, authentication);
|
||||
CSVConverter.writeCSV(res.getOutputStream(), list, DuplicateGroupView.class, "id", "name", "city", "country", "numberOfDuplicates");
|
||||
}
|
||||
|
||||
|
@ -219,148 +214,130 @@ public class OrganizationController extends AbstractDnetController {
|
|||
if (simrels.isEmpty()) { return new ArrayList<>(); }
|
||||
|
||||
final boolean b = UserInfo.isSuperAdmin(authentication)
|
||||
|| simrels.stream()
|
||||
.map(OpenaireDuplicate::getLocalId)
|
||||
.distinct()
|
||||
.allMatch(id -> userCountryRepository.verifyAuthorizationForId(id, UserInfo.getEmail(authentication)));
|
||||
|| simrels.stream()
|
||||
.map(OpenaireDuplicate::getLocalId)
|
||||
.distinct()
|
||||
.allMatch(id -> userCountryRepository.verifyAuthorizationForId(id, UserInfo.getEmail(authentication)));
|
||||
|
||||
if (b) {
|
||||
databaseUtils.saveDuplicates(simrels, UserInfo.getEmail(authentication));
|
||||
return listDuplicates(simrels.get(0).getLocalId());
|
||||
} else {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
|
||||
@GetMapping("/search/{page}/{size}")
|
||||
public Page<OrganizationSimpleView> search(@PathVariable final int page,
|
||||
@PathVariable final int size,
|
||||
@RequestParam final String q,
|
||||
@RequestParam(required = false, defaultValue = "") final String status,
|
||||
final Authentication authentication) {
|
||||
@PathVariable final int size,
|
||||
@RequestParam final String q,
|
||||
@RequestParam(required = false, defaultValue = "") final String status,
|
||||
final Authentication authentication) {
|
||||
|
||||
if (status.equals(SPECIAL_STATUS_FOR_CANDIDATE_DUP)) {
|
||||
if (SPECIAL_STATUS_FOR_CANDIDATE_DUP.equals(status)) {
|
||||
return UserInfo.isSuperAdmin(authentication)
|
||||
? organizationSimpleViewRepository.searchCandidateDuplicates(q, PageRequest.of(page, size))
|
||||
: organizationSimpleViewRepository.searchCandidateDuplicatesForUser(q, UserInfo.getEmail(authentication), PageRequest.of(page, size));
|
||||
? organizationSimpleViewRepository.searchCandidateDuplicates(q, PageRequest.of(page, size))
|
||||
: organizationSimpleViewRepository.searchCandidateDuplicatesForUser(q, UserInfo.getEmail(authentication), PageRequest.of(page, size));
|
||||
}
|
||||
final List<String> statuses;
|
||||
if (StringUtils.isNotBlank(status)) {
|
||||
statuses = Arrays.asList(status.split(","));
|
||||
} else if (UserInfo.isSimpleUser(authentication)) {
|
||||
statuses = Arrays.asList(OrganizationStatus.approved.toString());
|
||||
} else {
|
||||
final List<String> statuses;
|
||||
if (StringUtils.isNotBlank(status)) {
|
||||
statuses = Arrays.asList(status.split(","));
|
||||
} else if (UserInfo.isSimpleUser(authentication)) {
|
||||
statuses = Arrays.asList(OrganizationStatus.approved.toString());
|
||||
} else {
|
||||
statuses = Arrays.asList(OrganizationStatus.approved.toString(), OrganizationStatus.suggested.toString());
|
||||
}
|
||||
statuses = Arrays.asList(OrganizationStatus.approved.toString(), OrganizationStatus.suggested.toString());
|
||||
}
|
||||
|
||||
return UserInfo.isSuperAdmin(authentication)
|
||||
return UserInfo.isSuperAdmin(authentication)
|
||||
? organizationSimpleViewRepository.search(q, statuses, PageRequest.of(page, size))
|
||||
: organizationSimpleViewRepository.searchForUser(q, UserInfo.getEmail(authentication), statuses, PageRequest.of(page, size));
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/byCountry/{status}/{code}/{page}/{size}")
|
||||
public Page<OrganizationSimpleView> findByCountry(@PathVariable final String status,
|
||||
@PathVariable final String code,
|
||||
@PathVariable final int page,
|
||||
@PathVariable final int size,
|
||||
final Authentication authentication) {
|
||||
if (UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(code, UserInfo.getEmail(authentication))) {
|
||||
if (status.equalsIgnoreCase("all")) {
|
||||
return organizationSimpleViewRepository.findByCountryOrderByName(code, PageRequest.of(page, size));
|
||||
} else {
|
||||
return organizationSimpleViewRepository.findByCountryAndStatusOrderByName(code, status, PageRequest.of(page, size));
|
||||
}
|
||||
} else {
|
||||
@PathVariable final String code,
|
||||
@PathVariable final int page,
|
||||
@PathVariable final int size,
|
||||
final Authentication authentication) {
|
||||
if (!UserInfo.isSuperAdmin(authentication) && !userCountryRepository.verifyAuthorizationForCountry(code, UserInfo.getEmail(authentication))) {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
if ("all".equalsIgnoreCase(status)) { return organizationSimpleViewRepository.findByCountryOrderByName(code, PageRequest.of(page, size)); }
|
||||
return organizationSimpleViewRepository.findByCountryAndStatusOrderByName(code, status, PageRequest.of(page, size));
|
||||
}
|
||||
|
||||
@GetMapping("/byCountry/{status}/{code}")
|
||||
public Iterable<OrganizationSimpleView> findOrgsByStatusAndCountry(@PathVariable final String status,
|
||||
@PathVariable final String code,
|
||||
final Authentication authentication) {
|
||||
if (UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(code, UserInfo.getEmail(authentication))) {
|
||||
if (status.equalsIgnoreCase("all")) {
|
||||
return organizationSimpleViewRepository.findByCountryOrderByName(code);
|
||||
} else {
|
||||
return organizationSimpleViewRepository.findByCountryAndStatusOrderByName(code, status);
|
||||
}
|
||||
} else {
|
||||
public List<OrganizationSimpleView> findOrgsByStatusAndCountry(@PathVariable final String status,
|
||||
@PathVariable final String code,
|
||||
@RequestParam(required = false, defaultValue = "1000") final int limit,
|
||||
final Authentication authentication) {
|
||||
if (!UserInfo.isSuperAdmin(authentication) && !userCountryRepository.verifyAuthorizationForCountry(code, UserInfo.getEmail(authentication))) {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
if ("all".equalsIgnoreCase(status)) { return organizationSimpleViewRepository.findByCountryOrderByName(code, PageRequest.of(0, limit)).getContent(); }
|
||||
return organizationSimpleViewRepository.findByCountryAndStatusOrderByName(code, status, PageRequest.of(0, limit)).getContent();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/byCountry/{status}/{code}/csv", produces = "text/csv")
|
||||
public void findOrgsByStatusAndCountryCSV(@PathVariable final String status,
|
||||
@PathVariable final String code,
|
||||
final HttpServletResponse res,
|
||||
final Authentication authentication) throws IOException {
|
||||
final Iterable<OrganizationSimpleView> list = findOrgsByStatusAndCountry(status, code, authentication);
|
||||
@PathVariable final String code,
|
||||
final HttpServletResponse res,
|
||||
final Authentication authentication) throws IOException {
|
||||
final Iterable<OrganizationSimpleView> list = findOrgsByStatusAndCountry(status, code, Integer.MAX_VALUE, authentication);
|
||||
CSVConverter.writeCSV(res
|
||||
.getOutputStream(), list, OrganizationSimpleView.class, "id", "name", "type", "city", "country", "acronyms", "urls", "status", "nSimilarDups", "nSuggestedDups", "nDifferentDups");
|
||||
.getOutputStream(), list, OrganizationSimpleView.class, "id", "name", "type", "city", "country", "acronyms", "urls", "status", "nSimilarDups", "nSuggestedDups", "nDifferentDups");
|
||||
}
|
||||
|
||||
@GetMapping("/byType/{status}/{type}/{page}/{size}")
|
||||
public Page<OrganizationSimpleView> findByType(@PathVariable final String status,
|
||||
@PathVariable final String type,
|
||||
@PathVariable final int page,
|
||||
@PathVariable final int size,
|
||||
final Authentication authentication) {
|
||||
@PathVariable final String type,
|
||||
@PathVariable final int page,
|
||||
@PathVariable final int size,
|
||||
final Authentication authentication) {
|
||||
|
||||
if (UserInfo.isSuperAdmin(authentication)) {
|
||||
if (status.equalsIgnoreCase("all")) {
|
||||
return organizationSimpleViewRepository.findByTypeOrderByName(type, PageRequest.of(page, size));
|
||||
} else {
|
||||
return organizationSimpleViewRepository.findByTypeAndStatusOrderByName(type, status, PageRequest.of(page, size));
|
||||
}
|
||||
} else {
|
||||
if (status.equalsIgnoreCase("all")) {
|
||||
return organizationSimpleViewRepository.findByTypeForUser(type, UserInfo.getEmail(authentication), PageRequest.of(page, size));
|
||||
} else {
|
||||
return organizationSimpleViewRepository
|
||||
.findByTypeAndStatusForUser(type, status, UserInfo.getEmail(authentication), PageRequest.of(page, size));
|
||||
}
|
||||
if ("all".equalsIgnoreCase(status)) { return organizationSimpleViewRepository.findByTypeOrderByName(type, PageRequest.of(page, size)); }
|
||||
return organizationSimpleViewRepository.findByTypeAndStatusOrderByName(type, status, PageRequest.of(page, size));
|
||||
}
|
||||
if ("all".equalsIgnoreCase(status)) {
|
||||
return organizationSimpleViewRepository.findByTypeForUser(type, UserInfo.getEmail(authentication), PageRequest.of(page, size));
|
||||
}
|
||||
return organizationSimpleViewRepository
|
||||
.findByTypeAndStatusForUser(type, status, UserInfo.getEmail(authentication), PageRequest.of(page, size));
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/browse/countries")
|
||||
public List<BrowseEntry> browseCountries(final Authentication authentication) {
|
||||
return UserInfo.isSuperAdmin(authentication)
|
||||
? databaseUtils.browseCountries()
|
||||
: databaseUtils.browseCountriesForUser(UserInfo.getEmail(authentication));
|
||||
? databaseUtils.browseCountries()
|
||||
: databaseUtils.browseCountriesForUser(UserInfo.getEmail(authentication));
|
||||
}
|
||||
|
||||
@GetMapping("/browse/types")
|
||||
public List<BrowseEntry> browseOrganizationTypes(final Authentication authentication) {
|
||||
return UserInfo.isSuperAdmin(authentication)
|
||||
? databaseUtils.browseTypes()
|
||||
: databaseUtils.browseTypesForUser(UserInfo.getEmail(authentication));
|
||||
? databaseUtils.browseTypes()
|
||||
: databaseUtils.browseTypesForUser(UserInfo.getEmail(authentication));
|
||||
}
|
||||
|
||||
@PostMapping("/conflicts/fix/similar")
|
||||
public List<String> fixConflictSim(final Authentication authentication, @RequestBody final List<String> ids) {
|
||||
if (ids.size() > 1 && UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForId(ids.get(0), UserInfo.getEmail(authentication))) {
|
||||
|| userCountryRepository.verifyAuthorizationForId(ids.get(0), UserInfo.getEmail(authentication))) {
|
||||
final String newOrgId = databaseUtils.fixConflictSimilars(ids, UserInfo.getEmail(authentication));
|
||||
return Arrays.asList(newOrgId);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@PostMapping("/conflicts/fix/different")
|
||||
public List<String> fixConflictDiff(final Authentication authentication, @RequestBody final List<String> ids) {
|
||||
if (ids.size() > 1 && UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForId(ids.get(0), UserInfo.getEmail(authentication))) {
|
||||
|| userCountryRepository.verifyAuthorizationForId(ids.get(0), UserInfo.getEmail(authentication))) {
|
||||
databaseUtils.fixConflictDifferents(ids, UserInfo.getEmail(authentication));
|
||||
return ids;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@GetMapping("/note")
|
||||
|
@ -368,11 +345,10 @@ public class OrganizationController extends AbstractDnetController {
|
|||
final OrganizationView org = organizationViewRepository.findById(id).get();
|
||||
|
||||
if (UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
return noteRepository.findById(id).orElse(new Note(id, "", null, null));
|
||||
} else {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
|
||||
@PostMapping("/note")
|
||||
|
@ -381,20 +357,17 @@ public class OrganizationController extends AbstractDnetController {
|
|||
|
||||
final OrganizationView org = organizationViewRepository.findById(orgId).get();
|
||||
|
||||
if (UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
|
||||
if (StringUtils.isNotBlank(note.getNote())) {
|
||||
note.setModifiedBy(UserInfo.getEmail(authentication));
|
||||
note.setModificationDate(OffsetDateTime.now());
|
||||
return noteRepository.save(note);
|
||||
} else {
|
||||
noteRepository.deleteById(orgId);
|
||||
return new Note(orgId, "", null, null);
|
||||
}
|
||||
} else {
|
||||
if (!UserInfo.isSuperAdmin(authentication)
|
||||
&& !userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
if (StringUtils.isNotBlank(note.getNote())) {
|
||||
note.setModifiedBy(UserInfo.getEmail(authentication));
|
||||
note.setModificationDate(OffsetDateTime.now());
|
||||
return noteRepository.save(note);
|
||||
}
|
||||
noteRepository.deleteById(orgId);
|
||||
return new Note(orgId, "", null, null);
|
||||
}
|
||||
|
||||
@GetMapping("/journal")
|
||||
|
@ -402,11 +375,10 @@ public class OrganizationController extends AbstractDnetController {
|
|||
final OrganizationView org = organizationViewRepository.findById(id).get();
|
||||
|
||||
if (UserInfo.isSuperAdmin(authentication)
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
|| userCountryRepository.verifyAuthorizationForCountry(org.getCountry(), UserInfo.getEmail(authentication))) {
|
||||
return journalEntryRepository.findByOrgIdOrderByDateDesc(id);
|
||||
} else {
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
throw new RuntimeException("User not authorized");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.dnetlib.organizations.repository.readonly;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import eu.dnetlib.organizations.model.view.ConflictGroupView;
|
||||
|
@ -10,6 +11,6 @@ import eu.dnetlib.organizations.model.view.ConflictGroupViewPK;
|
|||
@Repository
|
||||
public interface ConflictGroupViewRepository extends ReadOnlyRepository<ConflictGroupView, ConflictGroupViewPK> {
|
||||
|
||||
List<ConflictGroupView> findByCountry1OrCountry2(String country1, String country2);
|
||||
List<ConflictGroupView> findByCountry1OrCountry2(String country1, String country2, Pageable page);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.dnetlib.organizations.repository.readonly;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import eu.dnetlib.organizations.model.view.DuplicateGroupView;
|
||||
|
@ -9,5 +10,5 @@ import eu.dnetlib.organizations.model.view.DuplicateGroupView;
|
|||
@Repository
|
||||
public interface DuplicateGroupViewRepository extends ReadOnlyRepository<DuplicateGroupView, String> {
|
||||
|
||||
List<DuplicateGroupView> findByCountry(String country);
|
||||
List<DuplicateGroupView> findByCountry(String country, Pageable page);
|
||||
}
|
||||
|
|
|
@ -15,60 +15,56 @@ public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<Org
|
|||
|
||||
// SEARCH
|
||||
@Query(value = "SELECT \n"
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'is_similar') AS n_similar_dups,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'suggested') AS n_suggested_dups,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'is_different') AS n_different_dups\n"
|
||||
+ "FROM org_index_search idx "
|
||||
+ " JOIN organizations org ON (idx.id = org.id) \n"
|
||||
+ " LEFT OUTER JOIN acronyms a ON org.id = a.id\n"
|
||||
+ " LEFT OUTER JOIN urls u ON org.id = u.id\n"
|
||||
+ " LEFT OUTER JOIN oa_duplicates d1 ON org.id = d1.local_id\n"
|
||||
+ "WHERE org.status in :statuses AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'is_similar') AS n_similar_dups,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'suggested') AS n_suggested_dups,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'is_different') AS n_different_dups\n"
|
||||
+ "FROM org_index_search idx "
|
||||
+ " JOIN organizations org ON (idx.id = org.id) \n"
|
||||
+ " LEFT OUTER JOIN acronyms a ON org.id = a.id\n"
|
||||
+ " LEFT OUTER JOIN urls u ON org.id = u.id\n"
|
||||
+ " LEFT OUTER JOIN oa_duplicates d1 ON org.id = d1.local_id\n"
|
||||
+ "WHERE org.status in :statuses AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
Page<OrganizationSimpleView> search(@Param("text") String text, @Param("statuses") List<String> statuses, Pageable pageable);
|
||||
|
||||
// SEARCH FOR USER
|
||||
@Query(value = "SELECT\n"
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'is_similar' ) AS n_similar_dups,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'suggested' ) AS n_suggested_dups,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'is_different') AS n_different_dups\n"
|
||||
+ "FROM org_index_search idx\n"
|
||||
+ " JOIN organizations org ON (idx.id = org.id)\n"
|
||||
+ " LEFT OUTER JOIN acronyms a ON (org.id = a.id)\n"
|
||||
+ " LEFT OUTER JOIN urls u ON (org.id = u.id)\n"
|
||||
+ " LEFT OUTER JOIN oa_duplicates d1 ON (org.id = d1.local_id)\n"
|
||||
+ " LEFT OUTER JOIN user_countries uc ON (uc.country = org.country) \n"
|
||||
+ "WHERE uc.email = :email AND org.status IN :statuses AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'is_similar' ) AS n_similar_dups,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'suggested' ) AS n_suggested_dups,\n"
|
||||
+ " count(DISTINCT d1.oa_original_id) FILTER (WHERE d1.reltype = 'is_different') AS n_different_dups\n"
|
||||
+ "FROM org_index_search idx\n"
|
||||
+ " JOIN organizations org ON (idx.id = org.id)\n"
|
||||
+ " LEFT OUTER JOIN acronyms a ON (org.id = a.id)\n"
|
||||
+ " LEFT OUTER JOIN urls u ON (org.id = u.id)\n"
|
||||
+ " LEFT OUTER JOIN oa_duplicates d1 ON (org.id = d1.local_id)\n"
|
||||
+ " LEFT OUTER JOIN user_countries uc ON (uc.country = org.country) \n"
|
||||
+ "WHERE uc.email = :email AND org.status IN :statuses AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
Page<OrganizationSimpleView> searchForUser(@Param("text") String text,
|
||||
@Param("email") String email,
|
||||
@Param("statuses") List<String> statuses,
|
||||
Pageable pageable);
|
||||
@Param("email") String email,
|
||||
@Param("statuses") List<String> statuses,
|
||||
Pageable pageable);
|
||||
|
||||
Page<OrganizationSimpleView> findByCountryOrderByName(String country, Pageable pageable);
|
||||
|
||||
Iterable<OrganizationSimpleView> findByCountryOrderByName(String code);
|
||||
|
||||
Iterable<OrganizationSimpleView> findByCountryAndStatusOrderByName(String code, String status);
|
||||
|
||||
Page<OrganizationSimpleView> findByCountryAndStatusOrderByName(String code, String status, Pageable pageable);
|
||||
|
||||
Page<OrganizationSimpleView> findByTypeOrderByName(String type, Pageable pageable);
|
||||
|
@ -83,51 +79,51 @@ public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<Org
|
|||
|
||||
// SEARCH FOR VALID DUPLICATE CANDIDATES
|
||||
@Query(value = "SELECT\n"
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " NULL AS n_similar_dups,\n"
|
||||
+ " NULL AS n_suggested_dups,\n"
|
||||
+ " NULL AS n_different_dups\n"
|
||||
+ "FROM org_index_search idx\n"
|
||||
+ " JOIN organizations org ON (idx.id = org.id) \n"
|
||||
+ " LEFT OUTER JOIN acronyms a ON (org.id = a.id)\n"
|
||||
+ " LEFT OUTER JOIN urls u ON (org.id = u.id)\n"
|
||||
+ " LEFT OUTER JOIN oa_duplicates d2 ON (org.id = d2.oa_original_id)\n"
|
||||
+ "WHERE org.status = 'raw' AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "HAVING not('is_similar' = ANY(array_agg(d2.reltype)))\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " NULL AS n_similar_dups,\n"
|
||||
+ " NULL AS n_suggested_dups,\n"
|
||||
+ " NULL AS n_different_dups\n"
|
||||
+ "FROM org_index_search idx\n"
|
||||
+ " JOIN organizations org ON (idx.id = org.id) \n"
|
||||
+ " LEFT OUTER JOIN acronyms a ON (org.id = a.id)\n"
|
||||
+ " LEFT OUTER JOIN urls u ON (org.id = u.id)\n"
|
||||
+ " LEFT OUTER JOIN oa_duplicates d2 ON (org.id = d2.oa_original_id)\n"
|
||||
+ "WHERE org.status = 'raw' AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "HAVING not('is_similar' = ANY(array_agg(d2.reltype)))\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
Page<OrganizationSimpleView> searchCandidateDuplicates(@Param("text") String text, Pageable pageable);
|
||||
|
||||
// SEARCH FOR VALID DUPLICATE CANDIDATES FOR USER
|
||||
@Query(value = "SELECT\n"
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " NULL AS n_similar_dups,\n"
|
||||
+ " NULL AS n_suggested_dups,\n"
|
||||
+ " NULL AS n_different_dups\n"
|
||||
+ "FROM org_index_search idx\n"
|
||||
+ " JOIN organizations org ON (idx.id = org.id) \n"
|
||||
+ " LEFT OUTER JOIN acronyms a ON (org.id = a.id)\n"
|
||||
+ " LEFT OUTER JOIN urls u ON (org.id = u.id)\n"
|
||||
+ " LEFT OUTER JOIN oa_duplicates d2 ON (org.id = d2.oa_original_id)\n"
|
||||
+ " LEFT OUTER JOIN user_countries uc ON (uc.country = org.country)\n"
|
||||
+ "WHERE org.status = 'raw' AND uc.email = :email AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "HAVING not('is_similar' = ANY(array_agg(d2.reltype)))\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " NULL AS n_similar_dups,\n"
|
||||
+ " NULL AS n_suggested_dups,\n"
|
||||
+ " NULL AS n_different_dups\n"
|
||||
+ "FROM org_index_search idx\n"
|
||||
+ " JOIN organizations org ON (idx.id = org.id) \n"
|
||||
+ " LEFT OUTER JOIN acronyms a ON (org.id = a.id)\n"
|
||||
+ " LEFT OUTER JOIN urls u ON (org.id = u.id)\n"
|
||||
+ " LEFT OUTER JOIN oa_duplicates d2 ON (org.id = d2.oa_original_id)\n"
|
||||
+ " LEFT OUTER JOIN user_countries uc ON (uc.country = org.country)\n"
|
||||
+ "WHERE org.status = 'raw' AND uc.email = :email AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "HAVING not('is_similar' = ANY(array_agg(d2.reltype)))\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
Page<OrganizationSimpleView> searchCandidateDuplicatesForUser(@Param("text") String text, @Param("email") String email, Pageable pageable);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue