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 uniportRestRequest)
+ public FTSRestResponse executeRequest(FTSRestRequest uniprotRestRequest)
throws Exception
{
try
{
String wantedFields = getDataColumnsFieldsAsCommaDelimitedString(
- uniportRestRequest.getWantedFields());
- int responseSize = (uniportRestRequest.getResponseSize() == 0)
+ uniprotRestRequest.getWantedFields());
+ int responseSize = (uniprotRestRequest.getResponseSize() == 0)
? getDefaultResponsePageSize()
- : uniportRestRequest.getResponseSize();
+ : uniprotRestRequest.getResponseSize();
- int offSet = uniportRestRequest.getOffSet();
+ int offSet = uniprotRestRequest.getOffSet();
String query;
- if (isAdvancedQuery(uniportRestRequest.getSearchTerm()))
+ if (isAdvancedQuery(uniprotRestRequest.getSearchTerm()))
{
- query = uniportRestRequest.getSearchTerm();
+ query = uniprotRestRequest.getSearchTerm();
}
else
{
- query = uniportRestRequest.getFieldToSearchBy()
+ query = uniprotRestRequest.getFieldToSearchBy()
.equalsIgnoreCase("Search All")
- ? uniportRestRequest.getSearchTerm()
+ ? uniprotRestRequest.getSearchTerm()
+ " or mnemonic:"
- + uniportRestRequest.getSearchTerm()
- : uniportRestRequest.getFieldToSearchBy() + ":"
- + uniportRestRequest.getSearchTerm();
+ + uniprotRestRequest.getSearchTerm()
+ : uniprotRestRequest.getFieldToSearchBy() + ":"
+ + uniprotRestRequest.getSearchTerm();
}
// BH 2018 the trick here is to coerce the classes in Javascript to be
// Java
Client client;
Class<ClientResponse> clientResponseClass;
- if (/** @j2sNative true || */
- false)
+ 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;
client = null;
return parseUniprotResponse(uniProtTabDelimittedResponseString,
- uniportRestRequest, xTotalResults);
+ uniprotRestRequest, xTotalResults);
} catch (Exception e)
{
String exceptionMsg = e.getMessage();
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()
{