Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.fts.service.uniprot

File UniprotFTSPanel.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

22
86
12
1
271
220
28
0.33
7.17
12
2.33

Classes

Class Line # Actions
UniprotFTSPanel 41 86 28
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21   
22    package jalview.fts.service.uniprot;
23   
24    import jalview.fts.api.FTSDataColumnI;
25    import jalview.fts.api.FTSRestClientI;
26    import jalview.fts.core.FTSRestRequest;
27    import jalview.fts.core.FTSRestResponse;
28    import jalview.fts.core.GFTSPanel;
29    import jalview.gui.Help;
30    import jalview.gui.Help.HelpId;
31    import jalview.gui.SequenceFetcher;
32    import jalview.util.MessageManager;
33   
34    import java.util.HashMap;
35    import java.util.HashSet;
36    import java.util.Map;
37   
38    import javax.help.HelpSetException;
39   
40    @SuppressWarnings("serial")
 
41    public class UniprotFTSPanel extends GFTSPanel
42    {
43   
44    private static String defaultFTSFrameTitle = MessageManager
45    .getString("label.uniprot_sequence_fetcher");
46   
47    private static Map<String, Integer> tempUserPrefs = new HashMap<>();
48   
49    private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS";
50   
51    private static final String UNIPROT_AUTOSEARCH = "FTS.UNIPROT.AUTOSEARCH";
52   
53    /**
54    * Constructor given an (optional) sequence fetcher panel to revert to on
55    * clicking the 'Back' button
56    *
57    * @param fetcher
58    */
 
59  0 toggle public UniprotFTSPanel(SequenceFetcher fetcher)
60    {
61  0 super(fetcher);
62  0 pageLimit = UniProtFTSRestClient.getInstance()
63    .getDefaultResponsePageSize();
64  0 this.seqFetcher = fetcher;
65  0 this.progressIndicator = (fetcher == null) ? null
66    : fetcher.getProgressIndicator();
67    }
68   
 
69  0 toggle @Override
70    public void searchAction(boolean isFreshSearch)
71    {
72  0 mainFrame.requestFocusInWindow();
73  0 if (isFreshSearch)
74    {
75  0 offSet = 0;
76    }
77  0 new Thread()
78    {
 
79  0 toggle @Override
80    public void run()
81    {
82  0 reset();
83  0 String searchInput = getTypedText();
84  0 if (searchInput.length() > 0)
85    {
86  0 setSearchInProgress(true);
87  0 long startTime = System.currentTimeMillis();
88  0 searchInput = getTypedText();
89  0 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
90    .getSelectedItem()).getAltCode();
91  0 wantedFields = UniProtFTSRestClient.getInstance()
92    .getAllDefaultDisplayedFTSDataColumns();
93  0 String searchTerm = decodeSearchTerm(searchInput, searchTarget);
94   
95  0 FTSRestRequest request = new FTSRestRequest();
96  0 request.setFieldToSearchBy(searchTarget);
97  0 request.setSearchTerm(searchTerm);
98  0 request.setOffSet(offSet);
99  0 request.setWantedFields(wantedFields);
100  0 FTSRestClientI uniProtRestClient = UniProtFTSRestClient
101    .getInstance();
102  0 FTSRestResponse resultList;
103  0 try
104    {
105  0 resultList = uniProtRestClient.executeRequest(request);
106    } catch (Exception e)
107    {
108  0 setErrorMessage(e.getMessage());
109  0 checkForErrors();
110  0 setSearchInProgress(false);
111  0 return;
112    }
113   
114  0 if (resultList.getSearchSummary() != null
115    && resultList.getSearchSummary().size() > 0)
116    {
117  0 getResultTable().setModel(FTSRestResponse.getTableModel(request,
118    resultList.getSearchSummary()));
119  0 FTSRestResponse.configureTableColumn(getResultTable(),
120    wantedFields, tempUserPrefs);
121  0 getResultTable().setVisible(true);
122    }
123   
124  0 long endTime = System.currentTimeMillis();
125  0 totalResultSetCount = resultList.getNumberOfItemsFound();
126  0 resultSetCount = resultList.getSearchSummary() == null ? 0
127    : resultList.getSearchSummary().size();
128  0 String result = (resultSetCount > 0)
129    ? MessageManager.getString("label.results")
130    : MessageManager.getString("label.result");
131  0 if (isPaginationEnabled() && resultSetCount > 0)
132    {
133  0 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
134    + " "
135    + totalNumberformatter
136    .format(Integer.valueOf(offSet + 1))
137    + " to "
138    + totalNumberformatter
139    .format(Integer
140    .valueOf(offSet + resultSetCount))
141    + " of "
142    + totalNumberformatter
143    .format(Integer.valueOf(totalResultSetCount))
144    + " " + " (" + (endTime - startTime) + " milli secs)");
145    }
146    else
147    {
148  0 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
149    + resultSetCount + " " + result + " ("
150    + (endTime - startTime) + " milli secs)");
151    }
152  0 setSearchInProgress(false);
153  0 refreshPaginatorState();
154  0 updateSummaryTableSelections();
155    }
156  0 txt_search.updateCache();
157    }
158    }.start();
159   
160    }
161   
 
162  0 toggle public String decodeSearchTerm(String enteredText, String targetField)
163    {
164  0 int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0
165    : targetField.length() + 1;
166  0 String searchTarget = targetField.equalsIgnoreCase("Search All") ? ""
167    : targetField + ":";
168  0 String foundSearchTerms = enteredText;
169  0 StringBuilder foundSearchTermsBuilder = new StringBuilder();
170  0 if (enteredText.contains(";"))
171    {
172  0 String[] searchTerms = enteredText.split(";");
173  0 for (String searchTerm : searchTerms)
174    {
175  0 foundSearchTermsBuilder.append(searchTarget).append(searchTerm)
176    .append(" OR ");
177    }
178  0 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
179  0 foundSearchTerms = foundSearchTermsBuilder.toString();
180  0 if (foundSearchTerms.contains(" OR "))
181    {
182  0 foundSearchTerms = foundSearchTerms.substring(searchTargetLength,
183    endIndex);
184    }
185    }
186  0 return foundSearchTerms;
187    }
188   
 
189  0 toggle @Override
190    public boolean isPaginationEnabled()
191    {
192  0 return true;
193    }
194   
 
195  0 toggle @Override
196    public void okAction()
197    {
198  0 disableActionButtons();
199  0 StringBuilder selectedIds = new StringBuilder();
200  0 HashSet<String> selectedIdsSet = new HashSet<>();
201  0 int primaryKeyColIndex = 0;
202  0 try
203    {
204  0 primaryKeyColIndex = getFTSRestClient()
205    .getPrimaryKeyColumIndex(wantedFields, false);
206    } catch (Exception e)
207    {
208  0 e.printStackTrace();
209    }
210  0 int[] selectedRows = getResultTable().getSelectedRows();
211  0 for (int summaryRow : selectedRows)
212    {
213  0 String idStr = getResultTable()
214    .getValueAt(summaryRow, primaryKeyColIndex).toString();
215  0 selectedIdsSet.add(idStr);
216    }
217  0 selectedIdsSet.addAll(paginatorCart);
218  0 for (String selectedId : selectedIdsSet)
219    {
220  0 selectedIds.append(selectedId).append(";");
221    }
222   
223  0 String ids = selectedIds.toString();
224  0 seqFetcher.setQuery(ids);
225  0 Thread worker = new Thread(seqFetcher);
226  0 worker.start();
227  0 delayAndEnableActionButtons();
228    }
229   
 
230  0 toggle @Override
231    public FTSRestClientI getFTSRestClient()
232    {
233  0 return UniProtFTSRestClient.getInstance();
234    }
235   
 
236  0 toggle @Override
237    public String getFTSFrameTitle()
238    {
239  0 return defaultFTSFrameTitle;
240    }
241   
 
242  0 toggle @Override
243    public Map<String, Integer> getTempUserPrefs()
244    {
245  0 return tempUserPrefs;
246    }
247   
 
248  0 toggle @Override
249    public String getCacheKey()
250    {
251  0 return UNIPROT_FTS_CACHE_KEY;
252    }
253   
 
254  0 toggle @Override
255    public String getAutosearchPreference()
256    {
257  0 return UNIPROT_AUTOSEARCH;
258    }
259   
 
260  0 toggle @Override
261    protected void showHelp()
262    {
263  0 try
264    {
265  0 Help.showHelpWindow(HelpId.UniprotFts);
266    } catch (HelpSetException e1)
267    {
268  0 e1.printStackTrace();
269    }
270    }
271    }