JAL-1563 Added Id (Uniprot Id) to the dynamic column config file and changed primary...
[jalview.git] / src / jalview / fts / core / FTSRestClient.java
index eeb7ec6..7a4f72e 100644 (file)
@@ -5,8 +5,9 @@ import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI;
 import jalview.fts.api.FTSRestClientI;
 
 import java.io.BufferedReader;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Objects;
@@ -43,7 +44,10 @@ public abstract class FTSRestClient implements FTSRestClientI
   public void parseDataColumnsConfigFile()
   {
     String fileName = getColumnDataConfigFileName();
-    try (BufferedReader br = new BufferedReader(new FileReader(fileName)))
+    
+    InputStream in = getClass().getResourceAsStream(fileName); 
+    
+    try (BufferedReader br = new BufferedReader(new InputStreamReader(in)))
     {
       String line;
       while ((line = br.readLine()) != null)
@@ -127,7 +131,14 @@ public abstract class FTSRestClient implements FTSRestClientI
               @Override
               public String getCode()
               {
-                return lineData[1];
+                return lineData[1].split("\\|")[0];
+              }
+
+              @Override
+              public String getAltCode()
+              {
+                return lineData[1].split("\\|").length > 1 ? lineData[1]
+                        .split("\\|")[1] : getCode();
               }
 
               @Override
@@ -239,6 +250,13 @@ public abstract class FTSRestClient implements FTSRestClientI
           e.printStackTrace();
         }
       }
+      try
+      {
+        this.primaryKeyColumn = getDataColumnByNameOrCode(primaryKeyColumnCode);
+      } catch (Exception e)
+      {
+        e.printStackTrace();
+      }
     } catch (IOException e)
     {
       e.printStackTrace();
@@ -284,31 +302,6 @@ public abstract class FTSRestClient implements FTSRestClientI
     return result;
   }
 
-  /**
-   * Takes a collection of FTSDataColumnI and converts its 'code' values into a
-   * tab delimited string.
-   * 
-   * @param dataColumnFields
-   *          the collection of FTSDataColumnI to process
-   * @return the generated comma delimited string from the supplied
-   *         FTSDataColumnI collection
-   */
-  public String getDataColumnsFieldsAsTabDelimitedString(
-          Collection<FTSDataColumnI> dataColumnFields)
-  {
-    String result = "";
-    if (dataColumnFields != null && !dataColumnFields.isEmpty())
-    {
-      StringBuilder returnedFields = new StringBuilder();
-      for (FTSDataColumnI field : dataColumnFields)
-      {
-        returnedFields.append("\t").append(field.getName());
-      }
-      returnedFields.deleteCharAt(0);
-      result = returnedFields.toString();
-    }
-    return result;
-  }
 
   @Override
   public Collection<FTSDataColumnI> getAllFTSDataColumns()
@@ -344,6 +337,11 @@ public abstract class FTSRestClient implements FTSRestClientI
   @Override
   public FTSDataColumnI getPrimaryKeyColumn()
   {
+    if (defaulDisplayedDataColumns == null
+            || defaulDisplayedDataColumns.isEmpty())
+    {
+      parseDataColumnsConfigFile();
+    }
     return primaryKeyColumn;
   }
 
@@ -387,11 +385,10 @@ public abstract class FTSRestClient implements FTSRestClientI
 
   protected String getResourceFile(String fileName)
   {
-    ClassLoader classLoader = getClass().getClassLoader();
     String result = "";
     try
     {
-      result = classLoader.getResource(fileName).getFile();
+      result = getClass().getResource(fileName).getFile();
     } catch (Exception e)
     {
       e.printStackTrace();