- ClientConfig clientConfig = new DefaultClientConfig();
- Client client = Client.create(clientConfig);
-
- @SuppressWarnings("unchecked")
- // String wantedFields =
- // getUniProtDocFieldsAsCommaDelimitedString((Collection<UniProtDocField>)
- // uniportRestRequest
- // .getWantedFields());
- int responseSize = (uniportRestRequest.getResponseSize() == 0) ? DEFAULT_RESPONSE_SIZE
- : uniportRestRequest.getResponseSize();
-
- WebResource webResource = null;
-
- webResource = client.resource(UNIPROT_SEARCH_ENDPOINT)
- .queryParam("format", "tab")
- // .queryParam("columns", wantedFields)
- .queryParam("limit", String.valueOf(responseSize))
- .queryParam("query", "name:filaggrin");
- // Execute the REST request
- ClientResponse clientResponse = webResource
- .accept(MediaType.TEXT_PLAIN).get(ClientResponse.class);
- String responseString = clientResponse.getEntity(String.class);
- String[] results = responseString.split("\n");
- for (String result : results)
+ try
+ {
+ ClientConfig clientConfig = new DefaultClientConfig();
+ Client client = Client.create(clientConfig);
+
+ String wantedFields = getDataColumnsFieldsAsCommaDelimitedString(
+ uniportRestRequest.getWantedFields());
+ int responseSize = (uniportRestRequest.getResponseSize() == 0)
+ ? getDefaultResponsePageSize()
+ : uniportRestRequest.getResponseSize();
+
+ int offSet = uniportRestRequest.getOffSet();
+ String query;
+ if (isAdvancedQuery(uniportRestRequest.getSearchTerm()))
+ {
+ query = uniportRestRequest.getSearchTerm();
+ }
+ else
+ {
+ query = uniportRestRequest.getFieldToSearchBy()
+ .equalsIgnoreCase("Search All")
+ ? uniportRestRequest.getSearchTerm()
+ + " or mnemonic:"
+ + uniportRestRequest.getSearchTerm()
+ : uniportRestRequest.getFieldToSearchBy() + ":"
+ + uniportRestRequest.getSearchTerm();
+ }
+
+ WebResource webResource = null;
+ webResource = client.resource(uniprotSearchEndpoint)
+ .queryParam("format", "tab")
+ .queryParam("columns", wantedFields)
+ .queryParam("limit", String.valueOf(responseSize))
+ .queryParam("offset", String.valueOf(offSet))
+ .queryParam("sort", "score").queryParam("query", query);
+ // Execute the REST request
+ ClientResponse clientResponse = webResource
+ .accept(MediaType.TEXT_PLAIN).get(ClientResponse.class);
+ String uniProtTabDelimittedResponseString = clientResponse
+ .getEntity(String.class);
+ // Make redundant objects eligible for garbage collection to conserve
+ // memory
+ // System.out.println(">>>>> response : "
+ // + uniProtTabDelimittedResponseString);
+ if (clientResponse.getStatus() != 200)
+ {
+ String errorMessage = getMessageByHTTPStatusCode(
+ clientResponse.getStatus(), "Uniprot");
+ throw new Exception(errorMessage);
+
+ }
+ int xTotalResults = Integer.valueOf(
+ clientResponse.getHeaders().get("X-Total-Results").get(0));
+ clientResponse = null;
+ client = null;
+ return parseUniprotResponse(uniProtTabDelimittedResponseString,
+ uniportRestRequest, xTotalResults);
+ } catch (Exception e)