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