JAL-3829 proof in principle 3d-beacons sequence fetcher - still some TODOs !
[jalview.git] / src / jalview / fts / service / threedbeacons / TDBeaconsFTSRestClient.java
index 655b960..e956461 100644 (file)
@@ -32,7 +32,7 @@ import jalview.util.Platform;
 public class TDBeaconsFTSRestClient extends FTSRestClient
 {
   private static final String DEFAULT_THREEDBEACONS_DOMAIN = 
-          "https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons-hub-api/uniprot/";
+          "https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
   
   private static FTSRestClientI instance = null;
   
@@ -47,8 +47,7 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
   {
     try
     {
-      String query = tdbRestRequest.getFieldToSearchBy()
-              + tdbRestRequest.getSearchTerm();
+      String query = tdbRestRequest.getSearchTerm();
       Client client;
       Class<ClientResponse> clientResponseClass;
       if (Platform.isJS())
@@ -151,32 +150,24 @@ public class TDBeaconsFTSRestClient extends FTSRestClient
       {
         jsonObj = (Map<String, Object>) JSONUtils.parse(tdbJsonResponseString);
       }
-      //System.out.println(jsonObj);
       
       Object uniprot_entry = jsonObj.get("uniprot_entry"); 
-      System.out.println(uniprot_entry);
-      
-      Long seqLength = (Long) ((Map<String, Object>) jsonObj.get("uniprot_entry")).get("sequence_length");
-      System.out.println("seqLenght :" + seqLength);
-      
-      result = new ArrayList<>();
+      // TODO: decide if anything from uniprot_entry needs to be reported via the FTSRestResponse object
+      // Arnaud added seqLength = (Long) ((Map<String, Object>) jsonObj.get("uniprot_entry")).get("sequence_length");
+
       List<Object> structures = (List<Object>) jsonObj.get("structures");
-    //Map<String, Object> tdbResponse = (Map<String, Object>) jsonObj.get("structures");
+      result = new ArrayList<>();
       
       int numFound = 0;
-      for (Iterator<Object> strucIter = structures.iterator(); strucIter
-              .hasNext();)
+      for (Iterator<Object> strucIter = structures.iterator(); strucIter.hasNext();)
       {
         Map<String, Object> structure = (Map<String, Object>) strucIter.next();
         result.add(getFTSData(structure, tdbRestRequest));
         numFound++;
-        //System.out.println(structure);
       }
       
-      System.out.println("1 : " + structures.get(1));
       searchResult.setNumberOfItemsFound(numFound); 
       searchResult.setSearchSummary(result);
-      searchResult.setSequenceLength(seqLength);
         
     } catch (ParseException e)
     {
@@ -194,15 +185,17 @@ private static FTSData getFTSData(Map<String, Object> tdbJsonStructure,
     Collection<FTSDataColumnI> displayFields = tdbRequest.getWantedFields();
     int colCounter = 0;
     summaryRowData = new Object[displayFields.size()];
+    
     for (FTSDataColumnI field : displayFields) {
       String fieldData = (tdbJsonStructure.get(field.getCode()) == null) ? " " 
               : tdbJsonStructure.get(field.getCode()).toString();
+      // System.out.println("Field : " + field + "  Data : " + fieldData);
       if (field.isPrimaryKeyColumn())
       {
         primaryKey = fieldData;
         summaryRowData[colCounter++] = primaryKey;
       }
-      else if (fieldData == null || fieldData.isEmpty())
+      else if (fieldData == null || fieldData.trim().isEmpty())
       {
         summaryRowData[colCounter++] = null;
       }
@@ -219,8 +212,8 @@ private static FTSData getFTSData(Map<String, Object> tdbJsonStructure,
                                           : fieldData;
         } catch (Exception e)
         {
-          e.printStackTrace();
-          System.out.println("offending value:" + fieldData);
+          //e.printStackTrace();
+          System.out.println("offending value:" + fieldData + fieldData);
         }
       }
     }