diff --git a/dspace-api/src/main/java/org/dspace/content/authority/SHERPARoMEOJournalTitle.java b/dspace-api/src/main/java/org/dspace/content/authority/SHERPARoMEOJournalTitle.java index da5c743c5b07..418000e51e2a 100644 --- a/dspace-api/src/main/java/org/dspace/content/authority/SHERPARoMEOJournalTitle.java +++ b/dspace-api/src/main/java/org/dspace/content/authority/SHERPARoMEOJournalTitle.java @@ -59,7 +59,37 @@ public Choices getMatches(String text, int start, int limit, String locale) { @Override public Choices getBestMatch(String text, String locale) { - return getMatches(text, 0, 1, locale); + // punt if there is no query text + if (text == null || text.trim().length() == 0) { + return new Choices(true); + } + int limit = 10; + SHERPAService sherpaService = new DSpace().getSingletonService(SHERPAService.class); + SHERPAResponse sherpaResponse = sherpaService.performRequest("publication", "title", + "equals", text, 0, limit); + Choices result; + if (CollectionUtils.isNotEmpty(sherpaResponse.getJournals())) { + List list = sherpaResponse + .getJournals().stream() + .map(sherpaJournal -> new Choice(sherpaJournal.getIssns().get(0), + sherpaJournal.getTitles().get(0), sherpaJournal.getTitles().get(0))) + .collect(Collectors.toList()); + int total = sherpaResponse.getJournals().size(); + + int confidence; + if (list.isEmpty()) { + confidence = Choices.CF_NOTFOUND; + } else if (list.size() == 1) { + confidence = Choices.CF_UNCERTAIN; + } else { + confidence = Choices.CF_AMBIGUOUS; + } + result = new Choices(list.toArray(new Choice[list.size()]), 0, total, confidence, + total > limit); + } else { + result = new Choices(false); + } + return result; } @Override diff --git a/dspace-api/src/main/java/org/dspace/content/authority/SHERPARoMEOPublisher.java b/dspace-api/src/main/java/org/dspace/content/authority/SHERPARoMEOPublisher.java index 0f93dff49879..d1001ce5dba8 100644 --- a/dspace-api/src/main/java/org/dspace/content/authority/SHERPARoMEOPublisher.java +++ b/dspace-api/src/main/java/org/dspace/content/authority/SHERPARoMEOPublisher.java @@ -60,7 +60,38 @@ public Choices getMatches(String text, int start, int limit, String locale) { @Override public Choices getBestMatch(String text, String locale) { - return getMatches(text, 0, 1, locale); + // punt if there is no query text + if (text == null || text.trim().length() == 0) { + return new Choices(true); + } + int limit = 10; + SHERPAService sherpaService = new DSpace().getSingletonService(SHERPAService.class); + SHERPAPublisherResponse sherpaResponse = sherpaService.performPublisherRequest("publisher", "name", + "equals", text, 0, limit); + Choices result; + if (CollectionUtils.isNotEmpty(sherpaResponse.getPublishers())) { + List list = sherpaResponse + .getPublishers().stream() + .map(sherpaPublisher -> + new Choice(sherpaPublisher.getIdentifier(), + sherpaPublisher.getName(), sherpaPublisher.getName())) + .collect(Collectors.toList()); + int total = sherpaResponse.getPublishers().size(); + + int confidence; + if (list.isEmpty()) { + confidence = Choices.CF_NOTFOUND; + } else if (list.size() == 1) { + confidence = Choices.CF_UNCERTAIN; + } else { + confidence = Choices.CF_AMBIGUOUS; + } + result = new Choices(list.toArray(new Choice[list.size()]), 0, total, confidence, + total > limit); + } else { + result = new Choices(false); + } + return result; } @Override