import eu.etaxonomy.taxeditor.model.ColorResources;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.preference.Resources;
-import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.SuggestParser;
+import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.TermParser;
import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.TerminologyParser;
import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestSearch;
import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestSuggest;
if(searchString.equals(TXT_SEARCH_DEFAULT)){
return;
}
+ String terminology = "";
ISelection selection = composite.getComboTerminologies().getSelection();
Collection<OntologyTermWrapper> wrapperList = new ArrayList<>();
if(selection instanceof IStructuredSelection && !selection.isEmpty()){
- //TODO maybe add support for mutliple terminology selection
+ //TODO maybe add support for multiple terminology selection
Object next = ((IStructuredSelection) selection).iterator().next();
if(next instanceof TerminologyWrapper){
- String response = new RequestSearch(searchString, ((TerminologyWrapper) next).getAcronym()).request();
- if(response==null){
- MessagingUtils.informationDialog(NO_CONNECTION_TITLE, NO_CONNECTION_MESSAGE);
- return;
- }
- wrapperList = SuggestParser.parse(response);
+ terminology =((TerminologyWrapper) next).getAcronym();
+ }
+ String response = new RequestSearch(searchString, terminology).request();
+ if(response==null){
+ MessagingUtils.informationDialog(NO_CONNECTION_TITLE, NO_CONNECTION_MESSAGE);
+ return;
}
+ wrapperList = TermParser.parse(response);
}
else{
String response = new RequestSuggest(searchString).request();
MessagingUtils.informationDialog(NO_CONNECTION_TITLE, NO_CONNECTION_MESSAGE);
return;
}
- wrapperList = SuggestParser.parse(response);
+ wrapperList = TermParser.parse(response);
}
if(wrapperList.isEmpty()){
MessagingUtils.informationDialog(Messages.GfBioTerminologyImportPresenter_NO_RESULTS_TITLE, Messages.GfBioTerminologyImportPresenter_NO_RESULTS_MESSAGE);
LinkedList<HierarchyTermWrapper> wrapperList = new LinkedList<>();
try {
JSONObject jsonResponse = new JSONObject(response);
- JSONArray responseArray = jsonResponse.getJSONArray("results");
+ JSONArray responseArray = ParserUtil.parseResults(jsonResponse);
HierarchyTermWrapper childTerm = null;
for(int i=0;i<responseArray.length();i++){
- JSONObject terminology = responseArray.getJSONObject(i);
- String label = terminology.getString("label");
- String uri = terminology.getString("uri");
+ JSONObject jsonObject = responseArray.getJSONObject(i);
+ String label = ParserUtil.parseLabel(jsonObject);
+ String uri= ParserUtil.parseUri(jsonObject);
HierarchyTermWrapper hierarchyTermWrapper = new HierarchyTermWrapper(uri, label);
wrapperList.add(hierarchyTermWrapper);
if(childTerm!=null){
List<OntologyTermWrapper> wrapperList = new ArrayList<>();
try {
JSONObject jsonResponse = new JSONObject(response);
- JSONArray responseArray = jsonResponse.getJSONArray("results");
+ JSONArray responseArray = ParserUtil.parseResults(jsonResponse);
for(int i=0;i<responseArray.length();i++){
JSONObject jsonObject = responseArray.getJSONObject(i);
- String label = jsonObject.getString("label");
- String uriString = jsonObject.getString("uri");
+ String label = ParserUtil.parseLabel(jsonObject);
+ String uriString = ParserUtil.parseUri(jsonObject);
wrapperList.add(new OntologyTermWrapper(uriString, label, terminology));
}
} catch (JSONException e) {
--- /dev/null
+/**
+* Copyright (C) 2018 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.webimport.termimport.parser;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * @author pplitzner
+ * @since May 31, 2018
+ *
+ */
+public class ParserUtil {
+
+ public static JSONArray parseResults(JSONObject jsonObject) throws JSONException{
+ return jsonObject.getJSONArray("results");
+ }
+
+ public static String parseUri(JSONObject jsonObject) throws JSONException{
+ return jsonObject.getString("uri");
+ }
+
+ public static String parseLabel(JSONObject jsonObject) throws JSONException{
+ return jsonObject.getString("label");
+ }
+
+ public static String parseDescription(JSONObject jsonObject) throws JSONException{
+ return jsonObject.getString("description");
+ }
+
+ public static String parseTerminology(JSONObject jsonObject) throws JSONException {
+ return jsonObject.getString("sourceTerminology");
+ }
+}
import org.json.JSONException;
import org.json.JSONObject;
+import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestTerm;
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
/**
List<OntologyTermWrapper> wrapperList = new ArrayList<>();
try {
JSONObject jsonResponse = new JSONObject(response);
- JSONArray responseArray = jsonResponse.getJSONArray("results");
+ JSONArray responseArray = ParserUtil.parseResults(jsonResponse);
for(int i=0;i<responseArray.length();i++){
- JSONObject terminology = responseArray.getJSONObject(i);
- String label = terminology.getString("label");
- String uri = terminology.getString("uri");
- String sourceTerminology = terminology.getString("sourceTerminology");
- wrapperList.add(new OntologyTermWrapper(uri, label, sourceTerminology));
+ JSONObject jsonObject = responseArray.getJSONObject(i);
+ String label = ParserUtil.parseLabel(jsonObject);
+ String uri= ParserUtil.parseUri(jsonObject);
+ String sourceTerminology = ParserUtil.parseTerminology(jsonObject);
+ String request = new RequestTerm(uri, sourceTerminology).request();
+ //load term description
+ String description = TermParser.parseSingleTerm(request).getDescription();
+ OntologyTermWrapper wrapper = new OntologyTermWrapper(uri, label, sourceTerminology);
+ wrapper.setDescription(description);
+ wrapperList.add(wrapper);
}
} catch (JSONException jsonException) {
jsonException.printStackTrace();
--- /dev/null
+/**
+* Copyright (C) 2018 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.webimport.termimport.parser;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
+
+/**
+ * @author pplitzner
+ * @since May 9, 2018
+ *
+ */
+public class TermParser {
+ public static OntologyTermWrapper parseSingleTerm(String response){
+ try {
+ JSONObject jsonResponse = new JSONObject(response);
+ JSONArray responseArray = ParserUtil.parseResults(jsonResponse);
+ for(int i=0;i<responseArray.length();i++){
+ JSONObject jsonObject = responseArray.getJSONObject(i);
+ return createWrapper(jsonObject);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static Collection<OntologyTermWrapper> parse(String response){
+ List<OntologyTermWrapper> wrapperList = new ArrayList<>();
+ try {
+ JSONObject jsonResponse = new JSONObject(response);
+ JSONArray responseArray = ParserUtil.parseResults(jsonResponse);
+ for(int i=0;i<responseArray.length();i++){
+ JSONObject jsonObject = responseArray.getJSONObject(i);
+ wrapperList.add(createWrapper(jsonObject));
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return wrapperList;
+ }
+
+ private static OntologyTermWrapper createWrapper(JSONObject jsonObject) throws JSONException{
+ String description = ParserUtil.parseDescription(jsonObject);
+ String label = ParserUtil.parseLabel(jsonObject);
+ String uri= ParserUtil.parseUri(jsonObject);
+ String terminology= ParserUtil.parseTerminology(jsonObject);
+ OntologyTermWrapper wrapper = new OntologyTermWrapper(uri, label, terminology);
+ wrapper.setDescription(description);
+ return wrapper;
+ }
+
+}
JSONObject jsonResponse = new JSONObject(response);
JSONArray responseArray = jsonResponse.getJSONArray("results");
for(int i=0;i<responseArray.length();i++){
- JSONObject terminology = responseArray.getJSONObject(i);
- String name = terminology.getString("name");
- String acronym = terminology.getString("acronym");
- String description = terminology.getString("description");
- String uriString = terminology.getString("uri");
- wrapperList.add(new TerminologyWrapper(name, acronym, description, uriString));
+ JSONObject jsonObject = responseArray.getJSONObject(i);
+ String name = jsonObject.getString("name");
+ String acronym = jsonObject.getString("acronym");
+ String description = ParserUtil.parseDescription(jsonObject);
+ String uri = ParserUtil.parseUri(jsonObject);
+ wrapperList.add(new TerminologyWrapper(name, acronym, description, uri));
}
} catch (JSONException e) {
e.printStackTrace();
--- /dev/null
+/**
+* Copyright (C) 2018 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.webimport.termimport.requests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author pplitzner
+ * @since Apr 23, 2018
+ *
+ */
+public class RequestTerm extends AbstractTerminologyServiceRequest{
+
+ private String termUri;
+ private String ontologyLabel;
+
+ public RequestTerm(String termUri, String ontologyLabel) {
+ super();
+ this.termUri = termUri;
+ this.ontologyLabel = ontologyLabel;
+ }
+
+ @Override
+ protected String getServiceUri() {
+ return "term";
+ }
+
+ @Override
+ protected String getTerminologyId() {
+ return ontologyLabel;
+ }
+
+ @Override
+ protected List<RequestParameter> getServiceParameters() {
+ List<RequestParameter> params = new ArrayList<>();
+ params.add(new RequestParameter(TerminologyServiceConstants.ATTR_URI, termUri));
+ return params;
+ }
+
+}