import jalview.ws.uimodel.PDBSearchRequest;
import jalview.ws.uimodel.PDBSearchResponse;
-import jalview.ws.uimodel.PDBSummaryListModel;
-import jalview.ws.uimodel.PDBSummaryListModel.PDBDocField;
+import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
import java.util.ArrayList;
import java.util.Iterator;
String responseSize = (request.getResponseSize() == 0) ? "200" : String
.valueOf(request.getResponseSize());
+ String sortParam = (request.getSortTarget() == null || request
+ .getSortTarget().trim().isEmpty()) ? ""
+ : (request
+ .getSortTarget() + (request.isAscending() ? " asc" : " desc"));
+
WebResource webResource = client.resource(pdbSearchEndpoint)
.queryParam("wt", "json").queryParam("fl", wantedFields)
.queryParam("rows", responseSize)
- .queryParam("q", query);
+ .queryParam("q", query)
+ .queryParam("sort", sortParam);
ClientResponse clientResponse = webResource.accept(
MediaType.APPLICATION_JSON).get(ClientResponse.class);
String responseString = clientResponse.getEntity(String.class);
if (clientResponse.getStatus() != 200)
{
+ if (clientResponse.getStatus() == 400)
+ {
+ throw new RuntimeException(parseException(responseString));
+ }
+ else
+ {
throw new RuntimeException("Failed : HTTP error code : "
+ clientResponse.getStatus());
+ }
}
// System.out.println("--------------> " + responseString);
return parseResponse(responseString, request.getWantedFields());
}
+ private String parseException(String jsonResponse)
+ {
+ String errorMessage = "RunTime error";
+ try
+ {
+ JSONParser jsonParser = new JSONParser();
+ JSONObject jsonObj = (JSONObject) jsonParser.parse(jsonResponse);
+ JSONObject errorResponse = (JSONObject) jsonObj.get("error");
+ errorMessage = errorResponse.get("msg").toString();
+
+ JSONObject responseHeader = (JSONObject) jsonObj
+ .get("responseHeader");
+ errorMessage += responseHeader.get("params").toString();
+ } catch (ParseException e)
+ {
+ e.printStackTrace();
+ }
+ return errorMessage;
+ }
+
+ @SuppressWarnings("unchecked")
private PDBSearchResponse parseResponse(String jsonResponse,
List<PDBDocField> wantedFields)
{
PDBSearchResponse searchResult = new PDBSearchResponse();
- List<PDBSummaryListModel> result = null;
+ List<PDBResponseSummary> result = null;
try
{
JSONParser jsonParser = new JSONParser();
.valueOf(pdbResponse.get("numFound").toString());
if (numFound > 0)
{
- result = new ArrayList<PDBSummaryListModel>();
+ result = new ArrayList<PDBResponseSummary>();
JSONArray docs = (JSONArray) pdbResponse.get("docs");
for (Iterator<JSONObject> docIter = docs.iterator(); docIter
.hasNext();)
JSONObject doc = docIter.next();
// if (doc.get("molecule_sequence") != null)
// {
- result.add(new PDBSummaryListModel(doc, wantedFields));
+ result.add(searchResult.new PDBResponseSummary(doc, wantedFields));
// }
}
searchResult.setItemsFound(numFound);
}
+ public enum PDBDocField
+ {
+ PDB_ID("PDB Id", "pdb_id"), TITLE("Title", "title"), MOLECULE_NAME(
+ "Molecule", "molecule_name"), MOLECULE_TYPE("Molecule Type",
+ "molecule_type"), MOLECULE_SEQUENCE("Sequence",
+ "molecule_sequence"), UNIPROT_FEATURES("Uniprot Features",
+ "uniprot_features"), PFAM_ACCESSION("PFAM Accession",
+ "pfam_accession"), INTERPRO_ACCESSION("InterPro Accession",
+ "interpro_accession"), UNIPROT_ACCESSION("UniProt Accession",
+ "uniprot_accession"), R_FACTOR("R Factor", "r_factor"), RESOLUTION(
+ "Resolution", "resolution"), DATA_QUALITY("Data Quality",
+ "data_quality"), OVERALL_QUALITY("Overall Quality",
+ "overall_quality"), POLYMER_COUNT("Polymer Count",
+ "number_of_polymers"), PROTEIN_CHAIN_COUNT(
+ "Protein Chain Count", "number_of_protein_chains"), BOUND_MOLECULE_COUNT(
+ "Bound Molecule Count", "number_of_bound_molecules"), POLYMER_RESIDUE_COUNT(
+ "Polymer Residue Count", "number_of_polymer_residues"), UNIPROT_COVERAGE(
+ "UniProt Coverage", "uniprot_coverage"), GENUS("GENUS", "genus"), GENE_NAME(
+ "Gene Name", "gene_name"), ALL("ALL", "text");
+
+ private String name;
+
+ private String code;
+
+ PDBDocField(String name, String code)
+ {
+ this.name = name;
+ this.code = code;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getCode()
+ {
+ return code;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+ }
}