Revision c1bd0764
Added by Patrick Plitzner about 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/webimport/termimport/GfBioTerminologyImportPresenter.java | ||
---|---|---|
38 | 38 |
import org.eclipse.swt.events.KeyEvent; |
39 | 39 |
import org.eclipse.swt.events.SelectionAdapter; |
40 | 40 |
import org.eclipse.swt.events.SelectionEvent; |
41 |
import org.json.JSONException; |
|
41 | 42 |
|
42 | 43 |
import eu.etaxonomy.cdm.common.CdmUtils; |
43 | 44 |
import eu.etaxonomy.taxeditor.l10n.Messages; |
44 | 45 |
import eu.etaxonomy.taxeditor.model.ColorResources; |
45 | 46 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
46 | 47 |
import eu.etaxonomy.taxeditor.preference.Resources; |
48 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; |
|
47 | 49 |
import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.TermParser; |
48 | 50 |
import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.TerminologyParser; |
49 | 51 |
import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestSearch; |
... | ... | |
185 | 187 |
@Override |
186 | 188 |
protected IStatus run(IProgressMonitor monitor) { |
187 | 189 |
String response = new RequestTerminologies().request(); |
188 |
availableOntologies = TerminologyParser.parse(response); |
|
190 |
try { |
|
191 |
availableOntologies = TerminologyParser.parse(response); |
|
192 |
} catch (JSONException e) { |
|
193 |
MessagingUtils.errorDialog("Loading ontologies failed", this, "Ontologies could not be found", TaxeditorStorePlugin.PLUGIN_ID, e, false); |
|
194 |
e.printStackTrace(); |
|
195 |
} |
|
189 | 196 |
return Status.OK_STATUS; |
190 | 197 |
} |
191 | 198 |
}; |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/webimport/termimport/parser/TerminologyParser.java | ||
---|---|---|
24 | 24 |
* |
25 | 25 |
*/ |
26 | 26 |
public class TerminologyParser { |
27 |
public static Collection<TerminologyWrapper> parse(String response){ |
|
27 |
public static Collection<TerminologyWrapper> parse(String response) throws JSONException{
|
|
28 | 28 |
List<TerminologyWrapper> wrapperList = new ArrayList<>(); |
29 |
try { |
|
30 |
JSONObject jsonResponse = new JSONObject(response); |
|
31 |
JSONArray responseArray = jsonResponse.getJSONArray("results"); |
|
32 |
for(int i=0;i<responseArray.length();i++){ |
|
33 |
JSONObject jsonObject = responseArray.getJSONObject(i); |
|
34 |
String name = jsonObject.getString("name"); |
|
35 |
String acronym = jsonObject.getString("acronym"); |
|
36 |
String description = ParserUtil.parseDescription(jsonObject); |
|
37 |
String uri = ParserUtil.parseUri(jsonObject); |
|
38 |
wrapperList.add(new TerminologyWrapper(name, acronym, description, uri)); |
|
39 |
} |
|
40 |
} catch (JSONException e) { |
|
41 |
e.printStackTrace(); |
|
29 |
JSONObject jsonResponse = new JSONObject(response); |
|
30 |
JSONArray responseArray = jsonResponse.getJSONArray("results"); |
|
31 |
for(int i=0;i<responseArray.length();i++){ |
|
32 |
JSONObject jsonObject = responseArray.getJSONObject(i); |
|
33 |
String name = jsonObject.getString("name"); |
|
34 |
String acronym = jsonObject.getString("acronym"); |
|
35 |
String description = ParserUtil.parseDescription(jsonObject); |
|
36 |
String uri = ParserUtil.parseUri(jsonObject); |
|
37 |
wrapperList.add(new TerminologyWrapper(name, acronym, description, uri)); |
|
42 | 38 |
} |
43 | 39 |
return wrapperList; |
44 | 40 |
} |
Also available in: Unified diff
Show error message when loading ontologies fails