From 1c613bf7c33e6bf48ccd3cbe92d72d9214c9c239 Mon Sep 17 00:00:00 2001 From: lingutln Date: Mon, 9 Apr 2012 21:05:21 +0000 Subject: [PATCH] Implemented Ubio Web service integration.(yet to complete reloading functionality) Done by Nikhil. svn path=/; revision=316 --- .../resources/config/application.properties | 3 + .../ie/dcu/apps/ist/actions/OpenAction.java | 1 + .../apps/ist/dialogs/PopUpLabelDialog.java | 2 +- .../src/ie/dcu/apps/ist/labelling/Labels.java | 75 ++++++++++++++++++- .../dcu/apps/ist/views/SegmentationView.java | 56 +++++++++----- .../ie/dcu/segment/SegmentationContext.java | 13 +++- Annotation/src/ie/dcu/swt/SwtUtils.java | 17 +++++ 7 files changed, 143 insertions(+), 24 deletions(-) diff --git a/Annotation/resources/config/application.properties b/Annotation/resources/config/application.properties index 9b65cb4..77372fb 100644 --- a/Annotation/resources/config/application.properties +++ b/Annotation/resources/config/application.properties @@ -30,5 +30,8 @@ ExperimentPanel.button.text.finish=Finish POWebService.TermSearch.URL=http://palea.cgrb.oregonstate.edu/services/PO_web_service.php?request_type=term_search&search_value=&inc_synonyms&branch_filter=plant_anatomy&max=20 POWebService.TermDetail.URL=http://palea.cgrb.oregonstate.edu/services/PO_web_service.php?request_type=term_detail&accession_id= +# UBio Web Service Configuration +UbioWebService.SpeciesTermSearch.URL=http://www.ubio.org/webservices/service.php?function=namebank_search&searchName=&sci=1&vern=1&keyCode=9c5ed3537fb089c0467c42c4d70b3dee71cbf3cd + #Curators names CuratorNamesList=Nikhil Lingutla,Justin Preece,Pankaj Jaiswal,Laurel Cooper,Rajani Raja \ No newline at end of file diff --git a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java index 797723a..051817d 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java @@ -48,6 +48,7 @@ public class OpenAction extends AppAction { else if (name.toLowerCase().endsWith(IMGMAP_EXTENSION)) { // Load Imagemap from Disk + System.out.println("Coming here"); window.setContext(SegmentationContext.loadImageMap(file)); status("Opened segmentation context %s successfully", name); } diff --git a/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java b/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java index 3ee09e5..e5cfb00 100644 --- a/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java +++ b/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java @@ -116,7 +116,7 @@ public class PopUpLabelDialog extends Dialog { { //For removing all previously assigned labels labelCombo.remove(0,labelCombo.getItemCount()-1); - terms = labels.getLabels(labelCombo.getText()); + terms = labels.getLabelsFromJSON(labelCombo.getText()); } int i = 0; for (OntologyTerm term : terms) diff --git a/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java b/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java index f5235d3..ea8732f 100644 --- a/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java +++ b/Annotation/src/ie/dcu/apps/ist/labelling/Labels.java @@ -5,10 +5,20 @@ import ie.dcu.apps.ist.AppWindow; import java.awt.List; import java.io.BufferedReader; import java.io.InputStreamReader; +import java.io.StringReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.parsers.*; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; import org.apache.commons.lang3.StringEscapeUtils; import org.json.JSONArray; @@ -25,7 +35,7 @@ public class Labels * ArrayList containing each Label item * */ - public ArrayList getLabels(String content) { + public ArrayList getLabelsFromJSON(String content) { ArrayList terms = new ArrayList(); // temporary variable for storing each list element in the loop try @@ -67,4 +77,67 @@ public class Labels return terms; } + + + + public Map getLabelsFromXML(String content) { + Map map = new HashMap(); + try + { + String xmlContent = ""; + String encodedContent = URLEncoder.encode(content.toString(),"UTF-8"); + String webServiceURL = AppWindow.props.getProperty("UbioWebService.SpeciesTermSearch.URL"); + webServiceURL = webServiceURL.replace("", encodedContent); + URL url = new URL(webServiceURL); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + // if the response from Web service is 'OK' + if (connection.getResponseCode() == 200) + { + String inputLine; + while ((inputLine = in.readLine()) != null) + { + xmlContent += inputLine; + } + Document doc = loadXMLFromString(xmlContent); + Element docEle = doc.getDocumentElement(); + NodeList nlist = docEle.getElementsByTagName("value"); + if(nlist != null && nlist.getLength() > 0) { + for(int i = 0 ; i < nlist.getLength();i++) { + //get the employee element + Element el = (Element)nlist.item(i); + map.put(getTagValue("namebankID", el),getTagValue("nameString", el)); + } + } + in.close(); + } + else + { + System.out.println("Response error"); + } + } + catch(Exception ex) + { + } + return map; + } + + public static Document loadXMLFromString(String xml) throws Exception + { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(xml)); + return builder.parse(is); + } + + private static String getTagValue(String sTag, Element eElement) { + NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes(); + + Node nValue = (Node) nlList.item(0); + + return nValue.getNodeValue(); + } + + } \ No newline at end of file diff --git a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java index 13b424d..282fab9 100644 --- a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java +++ b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java @@ -16,6 +16,8 @@ import ie.dcu.swt.event.*; import java.lang.reflect.InvocationTargetException; import java.net.*; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; import java.util.logging.*; @@ -75,7 +77,7 @@ public class SegmentationView extends Composite { public static Combo comboLabel,curatorCombo,speciesCombo; - private static Button assign; + private static Button assign,searchSpecies; public static Text collectionId, comment; @@ -113,6 +115,7 @@ public class SegmentationView extends Composite { SetPainter, SetLabel, AssignButton, + SearchSpeciesButton, SetCurator, SegmenterOptions; @@ -240,7 +243,7 @@ public class SegmentationView extends Composite { comboLabel.setToolTipText( getAction(Tool.SetLabel).getToolTipText()); comboLabel.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { - dropdownLabels(e); + dropdownLabelsFromJSON(e,comboLabel); } }); comboLabel.addSelectionListener(new SelectionAdapter() { @@ -273,30 +276,49 @@ public class SegmentationView extends Composite { * For dropping down the labels on pressing the down arrow key just like "Google suggests" functionality. * @param e */ - public void dropdownLabels(KeyEvent e) + public void dropdownLabelsFromJSON(KeyEvent e, Combo combo) { ArrayList terms = new ArrayList(); //For the down arrow functionality if(e.keyCode == 16777218) { - comboLabel.setListVisible(true); + combo.setListVisible(true); } // If key pressed is only a number of character or space. else if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32) { //For removing all previously assigned labels - comboLabel.remove(0,comboLabel.getItemCount()-1); - terms = labels.getLabels(comboLabel.getText()); - assign.setEnabled(!(comboLabel.getText().isEmpty())); + combo.remove(0,combo.getItemCount()-1); + terms = labels.getLabelsFromJSON(combo.getText()); + assign.setEnabled(!(combo.getText().isEmpty())); } int i = 0; for (OntologyTerm term : terms) { // set text for term label - comboLabel.add(term.getFormattedTerm(),i); + combo.add(term.getFormattedTerm(),i); i++; } } + + + /** + * For dropping down the labels on pressing the down arrow key just like "Google suggests" functionality. + * @param e + */ + public void dropdownLabelsFromXML(SelectionEvent e) + { + Map speciesMap = new HashMap(); + speciesMap = labels.getLabelsFromXML(speciesCombo.getText()); + for (String species : speciesMap.values()) + { + speciesCombo.add(species); + } + System.out.println(speciesMap.size()); + searchSpecies.setEnabled(!(speciesCombo.getText().isEmpty())); + } + + public void selectDropdownLabel(SelectionEvent e) { termDetailLookup(); @@ -328,7 +350,7 @@ public class SegmentationView extends Composite { item.setText (0, code.extendedLabel); item.setText (1, ""); } - + for (int i=0; i> 16) & 0xff, (v >> 8) & 0xff, v & 0xff); } + + public static Label spacer(Composite parent) { + Label label = new Label(parent, SWT.NONE); + label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + return label; + } } -- 2.34.1