package jalview.fts.service.uniprot;
import jalview.bin.Cache;
-import jalview.bin.Jalview;
+import jalview.bin.Instance;
import jalview.fts.api.FTSData;
import jalview.fts.api.FTSDataColumnI;
import jalview.fts.api.FTSRestClientI;
import jalview.fts.core.FTSRestRequest;
import jalview.fts.core.FTSRestResponse;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import java.util.ArrayList;
import java.util.Collection;
{
private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org";
- private static FTSRestClientI instance = null;
+ static
+ {
+ Platform.addJ2SDirectDatabaseCall(DEFAULT_UNIPROT_DOMAIN);
+ }
+
+ public static FTSRestClientI getInstance()
+ {
+ Instance j = Instance.getInstance();
+ return (j.uniprotFTSRestClient == null ? j.uniprotFTSRestClient = new UniProtFTSRestClient()
+ : j.uniprotFTSRestClient);
+ }
public final String uniprotSearchEndpoint;
- public UniProtFTSRestClient()
+ private UniProtFTSRestClient()
{
- super();
uniprotSearchEndpoint = Cache.getDefault("UNIPROT_DOMAIN",
- DEFAULT_UNIPROT_DOMAIN) + "/uniprot/";
+ DEFAULT_UNIPROT_DOMAIN) + "/uniprot/";
}
+ @SuppressWarnings("unchecked")
@Override
public FTSRestResponse executeRequest(FTSRestRequest uniprotRestRequest)
throws Exception
// Java
Client client;
Class<ClientResponse> clientResponseClass;
- if (Jalview.isJS())
+ if (Platform.isJS())
{
// JavaScript only -- coerce types to Java types for Java
client = (Client) (Object) new jalview.javascript.web.Client();
clientResponseClass = (Class<ClientResponse>) (Object) jalview.javascript.web.ClientResponse.class;
}
else
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
{
// Java only
client = Client.create(new DefaultClientConfig());
throw new Exception(errorMessage);
}
- int xTotalResults = Jalview.isJS() ? 1
+ int xTotalResults = Platform.isJS() ? 1
: Integer.valueOf(clientResponse.getHeaders()
.get("X-Total-Results").get(0));
clientResponse = null;
return searchResult;
}
- /**
- * 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
- */
- private String getDataColumnsFieldsAsTabDelimitedString(
- Collection<FTSDataColumnI> dataColumnFields)
- {
- String result = "";
- if (dataColumnFields != null && !dataColumnFields.isEmpty())
- {
- StringBuilder returnedFields = new StringBuilder();
- for (FTSDataColumnI field : dataColumnFields)
- {
- if (field.getName().equalsIgnoreCase("Uniprot Id"))
- {
- returnedFields.append("\t").append("Entry");
- }
- else
- {
- returnedFields.append("\t").append(field.getName());
- }
- }
- returnedFields.deleteCharAt(0);
- result = returnedFields.toString();
- }
- 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
+ // */
+ // private String getDataColumnsFieldsAsTabDelimitedString(
+ // Collection<FTSDataColumnI> dataColumnFields)
+ // {
+ // String result = "";
+ // if (dataColumnFields != null && !dataColumnFields.isEmpty())
+ // {
+ // StringBuilder returnedFields = new StringBuilder();
+ // for (FTSDataColumnI field : dataColumnFields)
+ // {
+ // if (field.getName().equalsIgnoreCase("Uniprot Id"))
+ // {
+ // returnedFields.append("\t").append("Entry");
+ // }
+ // else
+ // {
+ // returnedFields.append("\t").append(field.getName());
+ // }
+ // }
+ // returnedFields.deleteCharAt(0);
+ // result = returnedFields.toString();
+ // }
+ // return result;
+ // }
public static FTSData getFTSData(String tabDelimittedDataStr,
FTSRestRequest request)
};
}
- public static FTSRestClientI getInstance()
- {
- if (instance == null)
- {
- instance = new UniProtFTSRestClient();
- }
- return instance;
- }
-
@Override
public String getColumnDataConfigFileName()
{