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 |
|
|
28 |
|
import jalview.util.JSONUtils; |
29 |
|
import jalview.util.UrlLink; |
30 |
|
|
31 |
|
import java.io.FileReader; |
32 |
|
import java.io.IOException; |
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.StringTokenizer; |
39 |
|
|
40 |
|
import org.json.simple.parser.ParseException; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@author |
48 |
|
@version |
49 |
|
|
|
|
| 85.3% |
Uncovered Elements: 16 (109) |
Complexity: 29 |
Complexity Density: 0.44 |
|
50 |
|
public class IdentifiersUrlProvider extends UrlProviderImpl |
51 |
|
{ |
52 |
|
|
53 |
|
private static final String LOCAL_KEY = "Local"; |
54 |
|
|
55 |
|
private static final String ID_ORG_KEY = "identifiers.org"; |
56 |
|
|
57 |
|
|
58 |
|
private HashMap<String, UrlLink> urls; |
59 |
|
|
60 |
|
|
61 |
|
private ArrayList<String> selectedUrls; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
63 |
41 |
public IdentifiersUrlProvider(String cachedUrlList)... |
64 |
|
{ |
65 |
41 |
urls = readIdentifiers(IdOrgSettings.getDownloadLocation()); |
66 |
41 |
selectedUrls = new ArrayList<>(); |
67 |
41 |
checkSelectionMatchesUrls(cachedUrlList); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
|
75 |
|
@return |
76 |
|
|
|
|
| 71% |
Uncovered Elements: 9 (31) |
Complexity: 6 |
Complexity Density: 0.26 |
|
77 |
41 |
@SuppressWarnings("unchecked")... |
78 |
|
private HashMap<String, UrlLink> readIdentifiers(String idFileName) |
79 |
|
{ |
80 |
|
|
81 |
41 |
HashMap<String, UrlLink> idData = new HashMap<>(); |
82 |
|
|
83 |
41 |
String errorMessage = null; |
84 |
41 |
try |
85 |
|
{ |
86 |
|
|
87 |
|
|
88 |
41 |
FileReader reader = new FileReader(idFileName); |
89 |
41 |
String key = ""; |
90 |
41 |
Map<String, Object> obj = (Map<String, Object>) JSONUtils |
91 |
|
.parse(reader); |
92 |
41 |
if (obj.containsKey(ID_ORG_KEY)) |
93 |
|
{ |
94 |
0 |
key = ID_ORG_KEY; |
95 |
|
} |
96 |
41 |
else if (obj.containsKey(LOCAL_KEY)) |
97 |
|
{ |
98 |
41 |
key = LOCAL_KEY; |
99 |
|
} |
100 |
|
else |
101 |
|
{ |
102 |
0 |
jalview.bin.Console.outPrintln( |
103 |
|
"Unexpected key returned from identifiers jalview service"); |
104 |
0 |
return idData; |
105 |
|
} |
106 |
|
|
107 |
41 |
List<Object> jsonarray = (List<Object>) obj.get(key); |
108 |
|
|
109 |
|
|
110 |
15061 |
for (int i = 0; i < jsonarray.size(); i++) |
111 |
|
{ |
112 |
15020 |
Map<String, Object> item = (Map<String, Object>) jsonarray.get(i); |
113 |
|
|
114 |
15020 |
String url = (String) item.get("url") + "/" + DELIM + DB_ACCESSION |
115 |
|
+ DELIM; |
116 |
15020 |
UrlLink link = new UrlLink((String) item.get("name"), url, |
117 |
|
(String) item.get("prefix")); |
118 |
15020 |
idData.put((String) item.get("id"), link); |
119 |
|
} |
120 |
|
} catch (IOException | ParseException e) |
121 |
|
{ |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
0 |
errorMessage = e.toString(); |
130 |
0 |
idData.clear(); |
131 |
|
} |
132 |
|
|
133 |
41 |
if (errorMessage != null) |
134 |
|
{ |
135 |
0 |
jalview.bin.Console.errPrintln("IdentifiersUrlProvider: cannot read " |
136 |
|
+ idFileName + ": " + errorMessage); |
137 |
|
} |
138 |
41 |
return idData; |
139 |
|
} |
140 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
141 |
41 |
private void checkSelectionMatchesUrls(String cachedUrlList)... |
142 |
|
{ |
143 |
41 |
StringTokenizer st = new StringTokenizer(cachedUrlList, SEP); |
144 |
307 |
while (st.hasMoreElements()) |
145 |
|
{ |
146 |
266 |
String id = st.nextToken(); |
147 |
|
|
148 |
266 |
if (isMiriamId(id)) |
149 |
|
{ |
150 |
|
|
151 |
44 |
if (urls.containsKey(id)) |
152 |
|
{ |
153 |
44 |
selectedUrls.add(id); |
154 |
|
} |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
41 |
setPrimaryUrl(primaryUrl); |
160 |
|
} |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
162 |
79 |
@Override... |
163 |
|
public boolean setPrimaryUrl(String id) |
164 |
|
{ |
165 |
79 |
if (urls.containsKey(id)) |
166 |
|
{ |
167 |
2 |
primaryUrl = id; |
168 |
|
} |
169 |
|
else |
170 |
|
{ |
171 |
77 |
primaryUrl = null; |
172 |
|
} |
173 |
|
|
174 |
79 |
return urls.containsKey(id); |
175 |
|
} |
176 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
177 |
5 |
@Override... |
178 |
|
public String writeUrlsAsString(boolean selected) |
179 |
|
{ |
180 |
5 |
if (!selected) |
181 |
|
{ |
182 |
2 |
return ""; |
183 |
|
} |
184 |
|
|
185 |
3 |
StringBuffer links = new StringBuffer(); |
186 |
3 |
if (!selectedUrls.isEmpty()) |
187 |
|
{ |
188 |
3 |
for (String k : selectedUrls) |
189 |
|
{ |
190 |
9 |
links.append(k); |
191 |
9 |
links.append(SEP); |
192 |
|
} |
193 |
|
|
194 |
3 |
links.setLength(links.length() - 1); |
195 |
|
} |
196 |
3 |
return links.toString(); |
197 |
|
} |
198 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
199 |
104 |
@Override... |
200 |
|
public List<String> getLinksForMenu() |
201 |
|
{ |
202 |
104 |
List<String> links = new ArrayList<>(); |
203 |
104 |
for (String key : selectedUrls) |
204 |
|
{ |
205 |
15 |
links.add(urls.get(key).toStringWithTarget()); |
206 |
|
} |
207 |
104 |
return links; |
208 |
|
} |
209 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
21 |
@Override... |
211 |
|
public List<UrlLinkDisplay> getLinksForTable() |
212 |
|
{ |
213 |
21 |
return super.getLinksForTable(urls, selectedUrls, false); |
214 |
|
} |
215 |
|
|
|
|
| 85% |
Uncovered Elements: 3 (20) |
Complexity: 6 |
Complexity Density: 0.6 |
|
216 |
9 |
@Override... |
217 |
|
public void setUrlData(List<UrlLinkDisplay> links) |
218 |
|
{ |
219 |
9 |
selectedUrls = new ArrayList<>(); |
220 |
|
|
221 |
9 |
Iterator<UrlLinkDisplay> it = links.iterator(); |
222 |
99 |
while (it.hasNext()) |
223 |
|
{ |
224 |
90 |
UrlLinkDisplay link = it.next(); |
225 |
|
|
226 |
|
|
227 |
90 |
if (isMiriamId(link.getId())) |
228 |
|
{ |
229 |
|
|
230 |
35 |
if (urls.containsKey(link.getId())) |
231 |
|
{ |
232 |
35 |
if (link.getIsSelected()) |
233 |
|
{ |
234 |
26 |
selectedUrls.add(link.getId()); |
235 |
|
} |
236 |
35 |
if (link.getIsPrimary()) |
237 |
|
{ |
238 |
0 |
setPrimaryUrl(link.getId()); |
239 |
|
} |
240 |
|
} |
241 |
|
} |
242 |
|
} |
243 |
|
} |
244 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
245 |
7 |
@Override... |
246 |
|
public String getPrimaryUrl(String seqid) |
247 |
|
{ |
248 |
7 |
return super.getPrimaryUrl(seqid, urls); |
249 |
|
} |
250 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
251 |
5 |
@Override... |
252 |
|
public String getPrimaryUrlId() |
253 |
|
{ |
254 |
5 |
return primaryUrl; |
255 |
|
} |
256 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
257 |
0 |
@Override... |
258 |
|
public String getPrimaryTarget(String seqid) |
259 |
|
{ |
260 |
0 |
return null; |
261 |
|
} |
262 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
263 |
1 |
@Override... |
264 |
|
public String choosePrimaryUrl() |
265 |
|
{ |
266 |
1 |
return null; |
267 |
|
} |
268 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
269 |
37 |
@Override... |
270 |
|
public boolean contains(String id) |
271 |
|
{ |
272 |
37 |
return (urls.containsKey(id)); |
273 |
|
} |
274 |
|
} |