2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 package jalview.ws.uimodel;
24 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
26 import java.util.Collection;
27 import java.util.Objects;
29 import javax.swing.table.DefaultTableModel;
31 import org.json.simple.JSONObject;
34 * Represents the response model produced by the PDBRestClient upon successful
35 * execution of a given request
40 public class PDBRestResponse
42 private int numberOfItemsFound;
44 private String responseTime;
46 private Collection<PDBResponseSummary> searchSummary;
48 public int getNumberOfItemsFound()
50 return numberOfItemsFound;
53 public void setNumberOfItemsFound(int itemFound)
55 this.numberOfItemsFound = itemFound;
58 public String getResponseTime()
63 public void setResponseTime(String responseTime)
65 this.responseTime = responseTime;
68 public Collection<PDBResponseSummary> getSearchSummary()
73 public void setSearchSummary(Collection<PDBResponseSummary> searchSummary)
75 this.searchSummary = searchSummary;
80 * Convenience method to obtain a Table model for a given summary List and
84 * the PDBRestRequest object which holds useful information for
85 * creating a table model
86 * @param summariesList
87 * the summary list which contains the data for populating the
89 * @return the table model which was dynamically generated
91 public static DefaultTableModel getTableModel(PDBRestRequest request,
92 Collection<PDBResponseSummary> summariesList)
94 DefaultTableModel tableModel = new DefaultTableModel();
96 if (request.getAssociatedSequence() != null)
98 tableModel.addColumn("Sequence"); // Create sequence column header if
99 // exists in the request
101 for (PDBDocField field : request.getWantedFields())
103 tableModel.addColumn(field.getName()); // Create sequence column header if
104 // exists in the request
107 for (PDBResponseSummary res : summariesList)
109 tableModel.addRow(res.getSummaryData()); // Populate table rows with
116 * Model for a unique response summary
121 public class PDBResponseSummary
123 private String pdbId;
125 private String[] summaryRowData;
127 private String associatedSequence;
129 public PDBResponseSummary(JSONObject doc, PDBRestRequest request)
131 Collection<PDBDocField> diplayFields = request.getWantedFields();
132 String associatedSeq = request.getAssociatedSequence();
134 summaryRowData = new String[(associatedSeq != null) ? diplayFields
135 .size() + 1 : diplayFields.size()];
136 if (associatedSeq != null)
138 this.associatedSequence = (associatedSeq.length() > 18) ? associatedSeq
139 .substring(0, 18) : associatedSeq;
140 summaryRowData[0] = associatedSequence;
144 for (PDBDocField field : diplayFields)
146 String fieldData = (doc.get(field.getCode()) == null) ? "" : doc
147 .get(field.getCode()).toString();
148 if (field.equals(PDBDocField.PDB_ID)
149 && doc.get(PDBDocField.PDB_ID.getCode()) != null)
151 this.pdbId = fieldData;
152 summaryRowData[colCounter++] = this.pdbId;
156 summaryRowData[colCounter++] = fieldData;
161 public String getPdbId()
166 public void setPdbId(String pdbId)
171 public String[] getSummaryData()
173 return summaryRowData;
176 public void setSummaryData(String[] summaryData)
178 this.summaryRowData = summaryData;
182 public String toString()
184 StringBuilder summaryFieldValues = new StringBuilder();
185 for (String summaryField : summaryRowData)
187 summaryFieldValues.append(summaryField).append("\t");
189 return summaryFieldValues.toString();
193 public int hashCode()
195 return Objects.hash(this.pdbId, this.toString());
199 public boolean equals(Object that)
201 if (!(that instanceof PDBResponseSummary))
205 PDBResponseSummary another = (PDBResponseSummary) that;
206 return this.toString().equals(another.toString());