*/
package eu.etaxonomy.taxeditor.view.webimport.termimport;
-import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
/**
*/
public class GfBioTerminologyImportComposite extends Composite{
private TreeViewer treeTermHierarchy;
- private ComboViewer comboOntologies;
+ private Text txtSearch;
+ private Button btnSearch;
public GfBioTerminologyImportComposite(Composite parent, int style) {
super(parent, style);
- setLayout(new GridLayout(1, false));
+ setLayout(new GridLayout(2, false));
- comboOntologies = new ComboViewer(this, SWT.NONE);
- Combo combo = comboOntologies.getCombo();
- combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ txtSearch = new Text(this, SWT.BORDER);
+ txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- treeTermHierarchy = new TreeViewer(this, SWT.BORDER);
- Tree tree = treeTermHierarchy.getTree();
- tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ btnSearch = new Button(this, SWT.NONE);
+ btnSearch.setText("Search");
+
+ treeTermHierarchy = new TreeViewer(this, SWT.BORDER);
+ Tree tree = treeTermHierarchy.getTree();
+ GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
+ gd_tree.widthHint = 423;
+ tree.setLayoutData(gd_tree);
}
public TreeViewer getTreeTermHierarchy() {
return treeTermHierarchy;
}
- public ComboViewer getComboOntologies() {
- return comboOntologies;
+ public Button getBtnSearch() {
+ return btnSearch;
+ }
+ public Text getTxtSearch() {
+ return txtSearch;
}
}
*/
package eu.etaxonomy.taxeditor.view.webimport.termimport;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.ComboViewer;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestTerminologies;
-import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.TerminologyServiceConstants;
+import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.SuggestParser;
+import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestSuggest;
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
-import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.TerminologyWrapper;
/**
* @author pplitzner
* @since Apr 23, 2018
*
*/
-public class GfBioTerminologyImportPresenter implements ISelectionChangedListener {
+public class GfBioTerminologyImportPresenter implements SelectionListener, KeyListener {
private GfBioTerminologyImportComposite composite;
- private OntologyTermContentProvider contentProvider;
- /**
- * @param composite
- */
public GfBioTerminologyImportPresenter(GfBioTerminologyImportComposite composite) {
super();
this.composite = composite;
- String response = new RequestTerminologies().request();
+ //text search
+ composite.getBtnSearch().addSelectionListener(this);
+ composite.getTxtSearch().addKeyListener(this);
+ //tree results
+ composite.getTreeTermHierarchy().setContentProvider(new OntologyTermContentProvider());
+ composite.getTreeTermHierarchy().setLabelProvider(new OntologyTermLabelProvider());
+ }
+
+ private void search(){
+ String searchString = composite.getTxtSearch().getText();
+ String response = new RequestSuggest(searchString).request();
if(response==null){
MessagingUtils.informationDialog("Web service unavailable", "Could not retrieve data from web service");
return;
}
- //fetch terminology list via web service
- List<TerminologyWrapper> wrapperList = new ArrayList<>();
- try {
- 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));
- }
- } catch (JSONException e) {
- e.printStackTrace();
+ Collection<OntologyTermWrapper> wrapperList = SuggestParser.parse(response);
+ composite.getTreeTermHierarchy().setInput(wrapperList);
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if(e.widget==composite.getBtnSearch()){
+ search();
}
- //combo
- ComboViewer comboOntologies = composite.getComboOntologies();
- comboOntologies.setLabelProvider(new TerminologyLabelProvider());
- comboOntologies.setContentProvider(new ArrayContentProvider());
- comboOntologies.setInput(wrapperList);
- comboOntologies.addSelectionChangedListener(this);
+ }
- contentProvider = new OntologyTermContentProvider();
- composite.getTreeTermHierarchy().setContentProvider(contentProvider);
- composite.getTreeTermHierarchy().setLabelProvider(new OntologyTermLabelProvider());
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
}
- /**
- * {@inheritDoc}
- */
@Override
- public void selectionChanged(SelectionChangedEvent event) {
- //get root elements of selected ontology
- //FIXME: this service endpoint does not exist yet
- //so we use the root element of the PO for all selections
- String selectedOntology = "PO";
- contentProvider.setOntologyLabel(selectedOntology);
- Collection<OntologyTermWrapper> termWrappers = new HashSet<>();
- termWrappers.add(new OntologyTermWrapper(TerminologyServiceConstants.PO_ROOT_ELEMENT, "plant anatomical entity"));
- composite.getTreeTermHierarchy().setInput(termWrappers);
+ public void keyPressed(KeyEvent e) {
+ if(e.keyCode==SWT.CR){
+ search();
+ }
}
+ @Override
+ public void keyReleased(KeyEvent e) {
+
+ }
}
import java.util.Collection;
import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestNarrower;
+import eu.etaxonomy.taxeditor.view.webimport.termimport.parser.OntologyTermParser;
+import eu.etaxonomy.taxeditor.view.webimport.termimport.requests.RequestBroader;
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
/**
*/
public class OntologyTermContentProvider implements ITreeContentProvider {
- private String ontologyLabel;
-
@Override
public Object[] getElements(Object inputElement) {
Collection<Object> elements = new ArrayList<>();
@Override
public Object[] getChildren(Object parentElement) {
- Collection<OntologyTermWrapper> wrapperList = new ArrayList<>();
if(parentElement instanceof OntologyTermWrapper){
- String parentUri = ((OntologyTermWrapper) parentElement).getUri();
- String response = new RequestNarrower(parentUri, ontologyLabel).request();
- try {
- JSONObject jsonResponse = new JSONObject(response);
- JSONArray responseArray = jsonResponse.getJSONArray("results");
- for(int i=0;i<responseArray.length();i++){
- JSONObject terminology = responseArray.getJSONObject(i);
- String label = terminology.getString("label");
- String uriString = terminology.getString("uri");
- wrapperList.add(new OntologyTermWrapper(uriString, label));
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
+ OntologyTermWrapper wrapper = (OntologyTermWrapper) parentElement;
+ String response = new RequestBroader(wrapper.getUri(), wrapper.getSourceTerminology()).request();
+ Collection<OntologyTermWrapper> broader = OntologyTermParser.parse(response, ((OntologyTermWrapper) parentElement).getSourceTerminology());
+ return broader.toArray();
}
- return wrapperList.toArray();
+ return null;
}
@Override
return true;
}
- public void setOntologyLabel(String ontologyLabel) {
- this.ontologyLabel = ontologyLabel;
- }
-
}
@Override
public String getText(Object element) {
if(element instanceof OntologyTermWrapper){
- return ((OntologyTermWrapper) element).getLabel();
+ OntologyTermWrapper wrapper = (OntologyTermWrapper) element;
+ return wrapper.getSourceTerminology()+": "+wrapper.getLabel();
}
return super.getText(element);
}
+++ /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;
-
-import org.eclipse.jface.viewers.LabelProvider;
-
-import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.TerminologyWrapper;
-
-/**
- * @author pplitzner
- * @since Apr 23, 2018
- *
- */
-public class TerminologyLabelProvider extends LabelProvider {
-
- @Override
- public String getText(Object element) {
- if(element instanceof TerminologyWrapper){
- return ((TerminologyWrapper) element).getName();
- }
- return super.getText(element);
- }
-}
--- /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.Collection;
+import java.util.LinkedList;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.HierarchyTermWrapper;
+
+/**
+ * @author pplitzner
+ * @since May 9, 2018
+ *
+ */
+public class HierarchyParser {
+ public static Collection<HierarchyTermWrapper> parse(String response){
+ LinkedList<HierarchyTermWrapper> wrapperList = new LinkedList<>();
+ try {
+ JSONObject jsonResponse = new JSONObject(response);
+ JSONArray responseArray = jsonResponse.getJSONArray("results");
+ 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");
+ HierarchyTermWrapper hierarchyTermWrapper = new HierarchyTermWrapper(uri, label);
+ wrapperList.add(hierarchyTermWrapper);
+ if(childTerm!=null){
+ childTerm.setParentTerm(hierarchyTermWrapper);
+ }
+ childTerm = hierarchyTermWrapper;
+ }
+ } catch (JSONException jsonException) {
+ jsonException.printStackTrace();
+ }
+ return wrapperList;
+ }
+
+}
--- /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 OntologyTermParser {
+ public static Collection<OntologyTermWrapper> parse(String response, String terminology){
+ List<OntologyTermWrapper> wrapperList = new ArrayList<>();
+ try {
+ JSONObject jsonResponse = new JSONObject(response);
+ JSONArray responseArray = jsonResponse.getJSONArray("results");
+ for(int i=0;i<responseArray.length();i++){
+ JSONObject jsonObject = responseArray.getJSONObject(i);
+ String label = jsonObject.getString("label");
+ String uriString = jsonObject.getString("uri");
+ wrapperList.add(new OntologyTermWrapper(uriString, label, terminology));
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return wrapperList;
+ }
+
+}
--- /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 SuggestParser {
+ public static Collection<OntologyTermWrapper> parse(String response){
+ List<OntologyTermWrapper> wrapperList = new ArrayList<>();
+ try {
+ JSONObject jsonResponse = new JSONObject(response);
+ JSONArray responseArray = jsonResponse.getJSONArray("results");
+ 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));
+ }
+ } catch (JSONException jsonException) {
+ jsonException.printStackTrace();
+ }
+ return wrapperList;
+ }
+
+}
List<RequestParameter> serviceParameters = getServiceParameters();
if(serviceParameters!=null){
- uriString += "?";
+ uriString += "?format=json&";
StringBuilder params = new StringBuilder();
serviceParameters.forEach(param->params.append(param.key+"="+param.value+"&"));
uriString += params.toString();
}
URL url = new URL(uriString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setRequestProperty("format", "json");
- conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
--- /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 RequestBroader extends AbstractTerminologyServiceRequest{
+
+ private String termUri;
+ private String ontologyLabel;
+
+ public RequestBroader(String termUri, String ontologyLabel) {
+ super();
+ this.termUri = termUri;
+ this.ontologyLabel = ontologyLabel;
+ }
+
+ @Override
+ protected String getServiceUri() {
+ return TerminologyServiceConstants.BROADER_SERVICE_URL;
+ }
+
+ @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;
+ }
+
+}
--- /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 RequestHierarchy extends AbstractTerminologyServiceRequest{
+
+ private String termUri;
+
+ public RequestHierarchy(String termUri) {
+ super();
+ this.termUri = termUri;
+ }
+
+ @Override
+ protected String getServiceUri() {
+ return TerminologyServiceConstants.HIERARCHY_SERVICE_URL;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getTerminologyId() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<RequestParameter> getServiceParameters() {
+ List<RequestParameter> params = new ArrayList<>();
+ params.add(new RequestParameter(TerminologyServiceConstants.ATTR_URI, termUri));
+ return params;
+ }
+
+}
return TerminologyServiceConstants.NARROWER_SERVICE_URL;
}
- /**
- * {@inheritDoc}
- */
@Override
protected String getTerminologyId() {
return ontologyLabel;
}
- /**
- * {@inheritDoc}
- */
@Override
protected List<RequestParameter> getServiceParameters() {
List<RequestParameter> params = new ArrayList<>();
- params.add(new RequestParameter(TerminologyServiceConstants.ATR_URI, termUri));
+ params.add(new RequestParameter(TerminologyServiceConstants.ATTR_URI, termUri));
return params;
}
--- /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 RequestSuggest extends AbstractTerminologyServiceRequest{
+
+ private String suggestString;
+
+ public RequestSuggest(String suggestString) {
+ super();
+ this.suggestString = suggestString;
+ }
+
+ @Override
+ protected String getServiceUri() {
+ return TerminologyServiceConstants.SUGGEST_SERVICE_URL;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getTerminologyId() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<RequestParameter> getServiceParameters() {
+ List<RequestParameter> params = new ArrayList<>();
+ params.add(new RequestParameter(TerminologyServiceConstants.ATTR_QUERY, suggestString));
+ params.add(new RequestParameter(TerminologyServiceConstants.ATTR_LIMIT, "20"));
+ return params;
+ }
+
+}
public static final String SERVICE_URL = "https://dev-gfbio.bgbm.org/api/terminologies/";
public static final String NARROWER_SERVICE_URL = "narrower";
+ public static final String BROADER_SERVICE_URL = "broader";
+ public static final String SUGGEST_SERVICE_URL = "suggest";
+ public static final String HIERARCHY_SERVICE_URL = "hierarchy";
public static final String TERM_SERVICE_URL = "term";
- public static final String ATR_URI = "uri";
+
+ public static final String ATTR_QUERY = "query";
+ public static final String ATTR_URI = "uri";
+ public static final String ATTR_LIMIT = "limit";
public static final String PO_ROOT_ELEMENT = "http://purl.obolibrary.org/obo/PO_0025131";
}
--- /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.wrapper;
+
+/**
+ * @author pplitzner
+ * @since Apr 23, 2018
+ *
+ */
+public class HierarchyTermWrapper extends TermWrapper{
+
+ private HierarchyTermWrapper parentTerm;
+ public HierarchyTermWrapper(String uri, String label) {
+ super(uri, label);
+ }
+ public HierarchyTermWrapper getParentTerm() {
+ return parentTerm;
+ }
+ public void setParentTerm(HierarchyTermWrapper parentTerm) {
+ this.parentTerm = parentTerm;
+ }
+}
* @since Apr 23, 2018
*
*/
-public class OntologyTermWrapper {
+public class OntologyTermWrapper extends TermWrapper{
- private String uri;
- private String label;
- public OntologyTermWrapper(String uri, String label) {
- this.uri = uri;
- this.label = label;
+ private String sourceTerminology;
+ public OntologyTermWrapper(String uri, String label, String sourceTerminology) {
+ super(uri, label);
+ this.sourceTerminology = sourceTerminology;
}
- public String getUri() {
- return uri;
+ public String getSourceTerminology() {
+ return sourceTerminology;
}
- public String getLabel() {
- return label;
- }
-
}
--- /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.wrapper;
+
+/**
+ * @author pplitzner
+ * @since May 9, 2018
+ *
+ */
+public class TermWrapper {
+ private String uri;
+ private String label;
+ public TermWrapper(String uri, String label) {
+ this.uri = uri;
+ this.label = label;
+ }
+ public String getUri() {
+ return uri;
+ }
+ public String getLabel() {
+ return label;
+ }
+}