1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package jalview.urls; |
23 |
|
|
24 |
|
import static jalview.util.UrlConstants.DB_ACCESSION; |
25 |
|
import static jalview.util.UrlConstants.DELIM; |
26 |
|
import static jalview.util.UrlConstants.SEP; |
27 |
|
import static jalview.util.UrlConstants.SEQUENCE_ID; |
28 |
|
|
29 |
|
import jalview.util.MessageManager; |
30 |
|
import jalview.util.UrlConstants; |
31 |
|
import jalview.util.UrlLink; |
32 |
|
|
33 |
|
import java.util.ArrayList; |
34 |
|
import java.util.HashMap; |
35 |
|
import java.util.Iterator; |
36 |
|
import java.util.List; |
37 |
|
import java.util.Map; |
38 |
|
import java.util.Map.Entry; |
39 |
|
import java.util.StringTokenizer; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@author |
47 |
|
@version |
48 |
|
|
|
|
| 92.4% |
Uncovered Elements: 12 (158) |
Complexity: 43 |
Complexity Density: 0.43 |
|
49 |
|
public class CustomUrlProvider extends UrlProviderImpl |
50 |
|
{ |
51 |
|
|
52 |
|
private static final String SRS_LABEL = "SRS"; |
53 |
|
|
54 |
|
|
55 |
|
private HashMap<String, UrlLink> selectedUrls; |
56 |
|
|
57 |
|
|
58 |
|
private HashMap<String, UrlLink> nonselectedUrls; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
|
65 |
|
|
66 |
|
@param |
67 |
|
|
68 |
|
|
69 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
70 |
43 |
public CustomUrlProvider(String inMenuUrlList, String storedUrlList)... |
71 |
|
{ |
72 |
43 |
try |
73 |
|
{ |
74 |
43 |
selectedUrls = parseUrlStrings(inMenuUrlList); |
75 |
43 |
nonselectedUrls = parseUrlStrings(storedUrlList); |
76 |
|
} catch (Exception ex) |
77 |
|
{ |
78 |
0 |
System.out |
79 |
|
.println(ex.getMessage() + "\nError parsing sequence links"); |
80 |
|
} |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
@param |
87 |
|
|
88 |
|
@param |
89 |
|
|
90 |
|
|
91 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
92 |
2 |
public CustomUrlProvider(Map<String, String> inMenuUrlList,... |
93 |
|
Map<String, String> storedUrlList) |
94 |
|
{ |
95 |
2 |
try |
96 |
|
{ |
97 |
2 |
selectedUrls = parseUrlList(inMenuUrlList); |
98 |
2 |
nonselectedUrls = parseUrlList(storedUrlList); |
99 |
|
} catch (Exception ex) |
100 |
|
{ |
101 |
0 |
System.out |
102 |
|
.println(ex.getMessage() + "\nError parsing sequence links"); |
103 |
|
} |
104 |
|
} |
105 |
|
|
|
|
| 91.3% |
Uncovered Elements: 2 (23) |
Complexity: 7 |
Complexity Density: 0.47 |
|
106 |
86 |
private HashMap<String, UrlLink> parseUrlStrings(String urlStrings)... |
107 |
|
{ |
108 |
|
|
109 |
|
|
110 |
86 |
HashMap<String, UrlLink> urls = new HashMap<>(); |
111 |
|
|
112 |
86 |
StringTokenizer st = new StringTokenizer(urlStrings, SEP); |
113 |
282 |
while (st.hasMoreElements()) |
114 |
|
{ |
115 |
196 |
String name = st.nextToken().trim(); |
116 |
|
|
117 |
196 |
if (!isMiriamId(name)) |
118 |
|
{ |
119 |
|
|
120 |
157 |
String url = st.nextToken(); |
121 |
|
|
122 |
157 |
int rxstart = url.indexOf(DELIM + DB_ACCESSION + DELIM); |
123 |
157 |
if (rxstart == -1) |
124 |
|
{ |
125 |
76 |
rxstart = url.indexOf(DELIM + SEQUENCE_ID + DELIM); |
126 |
|
} |
127 |
157 |
while (rxstart == -1 && url.indexOf("/=" + DELIM) == -1 |
128 |
|
&& st.hasMoreTokens()) |
129 |
|
{ |
130 |
0 |
url = url + SEP + st.nextToken(); |
131 |
|
} |
132 |
157 |
url = url.trim(); |
133 |
157 |
urls.put(name, new UrlLink(name, url, name)); |
134 |
|
} |
135 |
|
} |
136 |
86 |
upgradeOldLinks(urls); |
137 |
86 |
return urls; |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
140 |
4 |
private HashMap<String, UrlLink> parseUrlList(Map<String, String> urlList)... |
141 |
|
{ |
142 |
4 |
HashMap<String, UrlLink> urls = new HashMap<>(); |
143 |
4 |
if (urlList == null) |
144 |
|
{ |
145 |
1 |
return urls; |
146 |
|
} |
147 |
|
|
148 |
3 |
Iterator<Map.Entry<String, String>> it = urlList.entrySet().iterator(); |
149 |
11 |
while (it.hasNext()) |
150 |
|
{ |
151 |
8 |
Map.Entry<String, String> pair = it.next(); |
152 |
8 |
urls.put(pair.getKey(), |
153 |
|
new UrlLink(pair.getKey(), pair.getValue(), pair.getKey())); |
154 |
|
} |
155 |
3 |
upgradeOldLinks(urls); |
156 |
3 |
return urls; |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
162 |
89 |
private void upgradeOldLinks(HashMap<String, UrlLink> urls)... |
163 |
|
{ |
164 |
89 |
boolean upgrade = false; |
165 |
|
|
166 |
89 |
if (urls.containsKey(SRS_LABEL)) |
167 |
|
{ |
168 |
12 |
urls.remove(SRS_LABEL); |
169 |
12 |
upgrade = true; |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
89 |
if (urls.containsKey(UrlConstants.DEFAULT_LABEL)) |
174 |
|
{ |
175 |
|
|
176 |
|
|
177 |
25 |
urls.remove(UrlConstants.DEFAULT_LABEL); |
178 |
25 |
upgrade = true; |
179 |
|
} |
180 |
89 |
if (upgrade) |
181 |
|
{ |
182 |
37 |
UrlLink link = new UrlLink(UrlConstants.DEFAULT_STRING); |
183 |
37 |
link.setLabel(UrlConstants.DEFAULT_LABEL); |
184 |
37 |
urls.put(UrlConstants.DEFAULT_LABEL, link); |
185 |
|
} |
186 |
|
} |
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
188 |
106 |
@Override... |
189 |
|
public List<String> getLinksForMenu() |
190 |
|
{ |
191 |
106 |
List<String> links = new ArrayList<>(); |
192 |
106 |
Iterator<Map.Entry<String, UrlLink>> it = selectedUrls.entrySet() |
193 |
|
.iterator(); |
194 |
370 |
while (it.hasNext()) |
195 |
|
{ |
196 |
264 |
Map.Entry<String, UrlLink> pair = it.next(); |
197 |
264 |
links.add(pair.getValue().toString()); |
198 |
|
} |
199 |
106 |
return links; |
200 |
|
} |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
202 |
22 |
@Override... |
203 |
|
public List<UrlLinkDisplay> getLinksForTable() |
204 |
|
{ |
205 |
22 |
ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<>(); |
206 |
22 |
displayLinks = getLinksForTable(selectedUrls, true); |
207 |
22 |
displayLinks.addAll(getLinksForTable(nonselectedUrls, false)); |
208 |
22 |
return displayLinks; |
209 |
|
} |
210 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
211 |
44 |
private ArrayList<UrlLinkDisplay> getLinksForTable(... |
212 |
|
HashMap<String, UrlLink> urlList, boolean selected) |
213 |
|
{ |
214 |
44 |
return super.getLinksForTable(urlList, null, selected); |
215 |
|
} |
216 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
217 |
47 |
@Override... |
218 |
|
public boolean setPrimaryUrl(String id) |
219 |
|
{ |
220 |
47 |
if (selectedUrls.containsKey(id)) |
221 |
|
{ |
222 |
44 |
primaryUrl = id; |
223 |
|
} |
224 |
3 |
else if (nonselectedUrls.containsKey(id)) |
225 |
|
{ |
226 |
0 |
primaryUrl = id; |
227 |
|
} |
228 |
|
else |
229 |
|
{ |
230 |
3 |
primaryUrl = null; |
231 |
|
} |
232 |
|
|
233 |
47 |
return (primaryUrl != null); |
234 |
|
} |
235 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
236 |
7 |
@Override... |
237 |
|
public String writeUrlsAsString(boolean selected) |
238 |
|
{ |
239 |
7 |
StringBuffer links = new StringBuffer(); |
240 |
7 |
HashMap<String, UrlLink> urls; |
241 |
7 |
if (selected) |
242 |
|
{ |
243 |
4 |
urls = selectedUrls; |
244 |
|
} |
245 |
|
else |
246 |
|
{ |
247 |
3 |
urls = nonselectedUrls; |
248 |
|
} |
249 |
7 |
if (urls.size() > 0) |
250 |
|
{ |
251 |
7 |
for (Entry<String, UrlLink> entry : urls.entrySet()) |
252 |
|
{ |
253 |
22 |
links.append(entry.getValue().toString()); |
254 |
22 |
links.append(SEP); |
255 |
|
} |
256 |
|
|
257 |
|
|
258 |
7 |
links.setLength(links.length() - 1); |
259 |
|
} |
260 |
|
else |
261 |
|
{ |
262 |
0 |
urls.clear(); |
263 |
|
} |
264 |
7 |
return links.toString(); |
265 |
|
} |
266 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
267 |
12 |
@Override... |
268 |
|
public String getPrimaryUrl(String seqid) |
269 |
|
{ |
270 |
12 |
String result = super.getPrimaryUrl(seqid, selectedUrls); |
271 |
12 |
if (result == null) |
272 |
|
{ |
273 |
2 |
result = super.getPrimaryUrl(seqid, nonselectedUrls); |
274 |
|
} |
275 |
12 |
return result; |
276 |
|
} |
277 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
278 |
8 |
@Override... |
279 |
|
public String getPrimaryUrlId() |
280 |
|
{ |
281 |
8 |
return primaryUrl; |
282 |
|
} |
283 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
284 |
0 |
@Override... |
285 |
|
public String getPrimaryTarget(String seqid) |
286 |
|
{ |
287 |
0 |
return selectedUrls.get(primaryUrl).getTarget(); |
288 |
|
} |
289 |
|
|
|
|
| 92% |
Uncovered Elements: 2 (25) |
Complexity: 7 |
Complexity Density: 0.47 |
|
290 |
9 |
@Override... |
291 |
|
public void setUrlData(List<UrlLinkDisplay> links) |
292 |
|
{ |
293 |
9 |
HashMap<String, UrlLink> unselurls = new HashMap<>(); |
294 |
9 |
HashMap<String, UrlLink> selurls = new HashMap<>(); |
295 |
|
|
296 |
9 |
Iterator<UrlLinkDisplay> it = links.iterator(); |
297 |
99 |
while (it.hasNext()) |
298 |
|
{ |
299 |
90 |
UrlLinkDisplay link = it.next(); |
300 |
|
|
301 |
|
|
302 |
90 |
if (!isMiriamId(link.getId())) |
303 |
|
{ |
304 |
|
|
305 |
55 |
if (unselurls.containsKey(link.getId()) |
306 |
|
|| selurls.containsKey(link.getId())) |
307 |
|
{ |
308 |
0 |
throw new IllegalArgumentException(MessageManager.formatMessage( |
309 |
|
"exception.url_cannot_have_duplicate_id", link.getId())); |
310 |
|
} |
311 |
55 |
if (link.getIsSelected()) |
312 |
|
{ |
313 |
37 |
selurls.put(link.getId(), new UrlLink(link.getDescription(), |
314 |
|
link.getUrl(), link.getDescription())); |
315 |
|
} |
316 |
|
else |
317 |
|
{ |
318 |
18 |
unselurls.put(link.getId(), new UrlLink(link.getDescription(), |
319 |
|
link.getUrl(), link.getDescription())); |
320 |
|
} |
321 |
|
|
322 |
55 |
if (link.getIsPrimary()) |
323 |
|
{ |
324 |
8 |
setPrimaryUrl(link.getId()); |
325 |
|
} |
326 |
|
} |
327 |
|
|
328 |
|
} |
329 |
9 |
nonselectedUrls = unselurls; |
330 |
9 |
selectedUrls = selurls; |
331 |
|
} |
332 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
333 |
5 |
@Override... |
334 |
|
public String choosePrimaryUrl() |
335 |
|
{ |
336 |
|
|
337 |
5 |
if ((!nonselectedUrls.containsKey(UrlConstants.DEFAULT_LABEL)) |
338 |
|
&& (!selectedUrls.containsKey(UrlConstants.DEFAULT_LABEL))) |
339 |
|
{ |
340 |
4 |
UrlLink link = new UrlLink(UrlConstants.DEFAULT_STRING); |
341 |
4 |
link.setLabel(UrlConstants.DEFAULT_LABEL); |
342 |
4 |
selectedUrls.put(UrlConstants.DEFAULT_LABEL, link); |
343 |
|
} |
344 |
5 |
primaryUrl = UrlConstants.DEFAULT_LABEL; |
345 |
5 |
return UrlConstants.DEFAULT_LABEL; |
346 |
|
} |
347 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
348 |
38 |
@Override... |
349 |
|
public boolean contains(String id) |
350 |
|
{ |
351 |
38 |
return (selectedUrls.containsKey(id) |
352 |
|
|| nonselectedUrls.containsKey(id)); |
353 |
|
} |
354 |
|
|
355 |
|
} |