X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=blobdiff_plain;f=src%2Fjalview%2Ffts%2Fservice%2Funiprot%2FUniprotFTSPanel.java;h=68a56962f661d6a3210c924c0e32d7419b9cbb36;hp=182e29b311018cf3e9adc741df0893f3a022b9de;hb=1114062d7c3034db3387f46a860c0e334206ce49;hpb=3da878124135ff033f42d19d8733891b09e953cd diff --git a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java index 182e29b..68a5696 100644 --- a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java +++ b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java @@ -21,6 +21,13 @@ package jalview.fts.service.uniprot; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +import javax.help.HelpSetException; + +import jalview.bin.Console; import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; import jalview.fts.core.FTSRestRequest; @@ -31,12 +38,6 @@ import jalview.gui.Help.HelpId; import jalview.gui.SequenceFetcher; import jalview.util.MessageManager; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -import javax.help.HelpSetException; - @SuppressWarnings("serial") public class UniprotFTSPanel extends GFTSPanel { @@ -69,10 +70,19 @@ public class UniprotFTSPanel extends GFTSPanel @Override public void searchAction(boolean isFreshSearch) { + searchAction(null, isFreshSearch); + } + + public void searchAction(String cursor, boolean isFreshSearch) + { mainFrame.requestFocusInWindow(); if (isFreshSearch) { offSet = 0; + UniProtFTSRestClient c = UniProtFTSRestClient.getInstance(); + c.clearCursors(); + c.setCursorPage(0); + c.setCursor(0, ""); } new Thread() { @@ -97,12 +107,12 @@ public class UniprotFTSPanel extends GFTSPanel request.setSearchTerm(searchTerm); request.setOffSet(offSet); request.setWantedFields(wantedFields); - FTSRestClientI uniProtRestClient = UniProtFTSRestClient + UniProtFTSRestClient uniProtRestClient = UniProtFTSRestClient .getInstance(); FTSRestResponse resultList; try { - resultList = uniProtRestClient.executeRequest(request); + resultList = uniProtRestClient.executeRequest(request, cursor); } catch (Exception e) { setErrorMessage(e.getMessage()); @@ -130,18 +140,18 @@ public class UniprotFTSPanel extends GFTSPanel : MessageManager.getString("label.result"); if (isPaginationEnabled() && resultSetCount > 0) { - updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result - + " " - + totalNumberformatter - .format(Integer.valueOf(offSet + 1)) - + " to " - + totalNumberformatter - .format(Integer + updateSearchFrameTitle( + defaultFTSFrameTitle + " - " + result + " " + + totalNumberformatter + .format(Integer.valueOf(offSet + 1)) + + " to " + + totalNumberformatter.format(Integer .valueOf(offSet + resultSetCount)) - + " of " - + totalNumberformatter - .format(Integer.valueOf(totalResultSetCount)) - + " " + " (" + (endTime - startTime) + " milli secs)"); + + " of " + + totalNumberformatter.format( + Integer.valueOf(totalResultSetCount)) + + " " + " (" + (endTime - startTime) + + " milli secs)"); } else { @@ -268,4 +278,72 @@ public class UniprotFTSPanel extends GFTSPanel e1.printStackTrace(); } } + + /* + * 2022-07-20 bsoares + * The new Uniprot API has a strange pagination process described at + * https://www.uniprot.org/help/pagination + * When a successful request returns results, with more results past the size + * limit, the response sends a "Link" header with a URL containing the a "cursor" + * parameter with an opaque string that refers to the next page of results. + * These are store as nextCursor in the UniProtFTSRestClient along with the currCursor. + * When navigation across pages occurs these should be swapped around. + */ + @Override + public void refreshPaginatorState() + { + UniProtFTSRestClient c = UniProtFTSRestClient.getInstance(); + setNextPageButtonEnabled(c.getNextCursor() != null); + setPrevPageButtonEnabled(c.getPrevCursor() != null); + } + + @Override + public void prevPageAction() + { + updatePaginatorCart(); + UniProtFTSRestClient c = UniProtFTSRestClient.getInstance(); + String prevCursor = c.getPrevCursor(); + if (prevCursor != null) + { + if (offSet >= pageLimit) + { + offSet -= pageLimit; + } + else + { + // not sure what's happening if we get here though it wouldn't surprise + // me + Console.warn( + "UniprotFTSPanel: prevCursor exists but offset < pageLimit. This probably shouldn't be happening."); + } + c.setPrevCursorPage(); + searchAction(prevCursor, false); + } + else + { + refreshPaginatorState(); + } + } + + @Override + public void nextPageAction() + { + UniProtFTSRestClient c = UniProtFTSRestClient.getInstance(); + String nextCursor = c.getNextCursor(); + if (nextCursor != null) + { + offSet += pageLimit; + c.setNextCursorPage(); + searchAction(nextCursor, false); + } + else + { + refreshPaginatorState(); + } + } + + public String getDbName() + { + return "UniProt"; + } }