From e2c95a076f6ac8fae4922781e8008bae5513d6aa Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 31 Mar 2022 14:06:04 +0100 Subject: [PATCH] =?utf8?q?JAL-3985=20split=20PDB=20id=20queries=20into=20mul?= =?utf8?q?tiple=20queries=20so=20server=20doesn=E2=80=99t=20414?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../ThreeDBStructureChooserQuerySource.java | 88 ++++++++++++++------ 1 file changed, 62 insertions(+), 26 deletions(-) diff --git a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java index 9e4ee21..175ad77 100644 --- a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java +++ b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java @@ -195,7 +195,7 @@ public class ThreeDBStructureChooserQuerySource lastTdbRequest = tdbRequest; if (resultList != null) { // Query the PDB and add additional metadata - FTSRestResponse pdbResponse = fetchStructuresMetaDataFor( + List pdbResponse = fetchStructuresMetaDataFor( getPDBQuerySource(), resultList); resultList = joinResponses(resultList, pdbResponse); @@ -266,7 +266,7 @@ public class ThreeDBStructureChooserQuerySource { // tdb returns custom object TDB_FTSData row = (TDB_FTSData) _row; - String provider = (String) row.getProvider(); + String provider = row.getProvider(); FilterOption providerOpt = new FilterOption( "3DB Provider - " + provider, FILTER_SOURCE_PREFIX + provider, VIEWS_FILTER, false, this); @@ -472,8 +472,9 @@ public class ThreeDBStructureChooserQuerySource * @return */ - public String buildPDBFTSQueryFor(FTSRestResponse upResponse) + public List buildPDBFTSQueryFor(FTSRestResponse upResponse) { + List ftsQueries = new ArrayList(); Set pdbIds = new HashSet(); int idx_modelId = getLastFTSRequest().getFieldIndex("Model id"); int idx_provider = getLastFTSRequest().getFieldIndex("Provider"); @@ -486,7 +487,25 @@ public class ThreeDBStructureChooserQuerySource pdbIds.add(id); } } - return String.join(" OR ", pdbIds).toString(); + StringBuilder sb = new StringBuilder(); + for (String pdbId : pdbIds) + { + if (sb.length() > 2500) + { + ftsQueries.add(sb.toString()); + sb.setLength(0); + } + if (sb.length() > 0) + { + sb.append(" OR "); + } + sb.append(pdbId); + } + if (sb.length() > 0) + { + ftsQueries.add(sb.toString()); + } + return ftsQueries; } /** @@ -496,34 +515,48 @@ public class ThreeDBStructureChooserQuerySource * @param upResponse * @return FTSRestResponse via PDBStructureChooserQuerySource */ - public FTSRestResponse fetchStructuresMetaDataFor( + public List fetchStructuresMetaDataFor( PDBStructureChooserQuerySource pdbquery, FTSRestResponse upResponse) throws Exception { - - String pdb_Query = buildPDBFTSQueryFor(upResponse); - if (pdb_Query.length() == 0) + List pdb_Queries = buildPDBFTSQueryFor(upResponse); + if (pdb_Queries.size() == 0) { return null; } - FTSRestResponse resultList; - FTSRestRequest pdbRequest = new FTSRestRequest(); - pdbRequest.setAllowEmptySeq(false); - pdbRequest.setResponseSize(500); - pdbRequest.setFieldToSearchBy("("); - // pdbRequest.setFieldToSortBy("pdb_id"); - pdbRequest.setWantedFields( - pdbquery.getDocFieldPrefs().getStructureSummaryFields()); - pdbRequest.setSearchTerm(pdb_Query + ")"); + List results = new ArrayList(); + + for (String pdb_Query : pdb_Queries) + { + FTSRestResponse resultList; + FTSRestRequest pdbRequest = new FTSRestRequest(); + pdbRequest.setAllowEmptySeq(false); + pdbRequest.setResponseSize(500); + pdbRequest.setFieldToSearchBy("("); + // pdbRequest.setFieldToSortBy("pdb_id"); + pdbRequest.setWantedFields( + pdbquery.getDocFieldPrefs().getStructureSummaryFields()); + pdbRequest.setSearchTerm(pdb_Query + ")"); + + // handle exceptions like server errors here - means the threedbeacons + // discovery isn't broken by issues to do with the PDBe SOLR api + try + { + resultList = pdbquery.executePDBFTSRestRequest(pdbRequest); + results.add(resultList); + lastPdbRequest = pdbRequest; + } catch (Exception ex) + { + Console.error("PDBFTSQuery failed", ex); + } - resultList = pdbquery.executePDBFTSRestRequest(pdbRequest); + } - lastPdbRequest = pdbRequest; - return resultList; + return results; } public FTSRestResponse joinResponses(FTSRestResponse upResponse, - FTSRestResponse pdbResponse) + List pdbResponses) { boolean hasPdbResp = lastPdbRequest != null; @@ -548,13 +581,16 @@ public class ThreeDBStructureChooserQuerySource } else { - for (final FTSData pdbrow : pdbResponse.getSearchSummary()) + for (final FTSRestResponse pdbResponse : pdbResponses) { - String pdbid = (String) pdbrow.getSummaryData()[pdbIdx]; - if (id.equalsIgnoreCase(pdbid)) + for (final FTSData pdbrow : pdbResponse.getSearchSummary()) { - row.getSummaryData()[tdbTitle_idx] = pdbrow - .getSummaryData()[pdbTitle_idx]; + String pdbid = (String) pdbrow.getSummaryData()[pdbIdx]; + if (id.equalsIgnoreCase(pdbid)) + { + row.getSummaryData()[tdbTitle_idx] = pdbrow + .getSummaryData()[pdbTitle_idx]; + } } } } -- 1.7.10.2