[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Tue May 4 16:19:37 UTC 2010


gordonp
Tue May  4 12:19:37 EDT 2010
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv6224/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	MobyContentGUI.java MobyContentPane.java 
Log Message:
Refactoring and new code to implement 'for each' peers run on newly wrapped services
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentGUI.java,1.21,1.22 MobyContentPane.java,1.31,1.32
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentGUI.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentGUI.java	2010/03/29 19:55:39	1.21
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentGUI.java	2010/05/04 16:19:37	1.22
@@ -22,6 +22,7 @@
 import org.biomoby.registry.meta.*;
 import org.biomoby.shared.*;
 import org.biomoby.shared.data.*;
+import org.biomoby.shared.parser.MobyTags;
 
 import ca.ucalgary.seahawk.util.*;
 import ca.ucalgary.seahawk.services.MobyClient;
@@ -69,6 +70,9 @@
     public final static String SEAHAWK_NS_PREFIX = "seahawk";
     public final static String SEAHAWK_XPATH_ATTR = "xpath";
 
+    /** if URL starts with this, it's a service input payload spec of the form "url\tproviderURI\tserviceName" */
+    public static final String SERVICE_INPUT_MAGIC = "#!"; 
+
     private int lastClickX = 0;
     private int lastClickY = 0;
     private JTabbedPane tabbedPane;
@@ -777,11 +781,7 @@
 	}
     }
 
-    /**
-     * Called after a service has been created by the wrapping system, with the intention
-     * that the new service should be called and included in the browsing session.
-     */
-    public void serviceWrapped(String providerURI, String serviceName, MobyDataJob sampleData) throws Exception{
+    public MobyService findService(String providerURI, String serviceName) throws Exception{
 	CentralImpl central = getMobyCentralImpl();
 	MobyService[] services = central.findService(new MobyService(serviceName, providerURI)); 
 	if(services == null || services.length == 0){
@@ -792,18 +792,76 @@
 	    throw new Exception("More than one service matching ("+providerURI+","+serviceName+
 				") was found in the registry, something is seriously wrong!");
 	}
+	return services[0];
+    }
 
-	MobyRequest request = new MobyRequest(central);
-	request.setService(services[0]);
-	MobyContentInstance inEnvelope = new MobyContentInstance();
-	inEnvelope.put("test", sampleData);
+    public MobyContentInstance callService(MobyService service, MobyContentInstance inEnvelope) throws Exception{
+	MobyRequest request = new MobyRequest(getMobyCentralImpl());
+	request.setService(service);
 	request.setInput(inEnvelope);
-	MobyContentInstance result = request.invokeService();
-	ByteArrayOutputStream inputXML = new ByteArrayOutputStream();
-	MobyDataUtils.toXMLDocument(inputXML, inEnvelope);
-	URL resultURL = DataUtils.saveOutputData(result, services[0], //for tracking purposes
-						 inEnvelope, central.getRegistryEndpoint());  
+	return request.invokeService();
+    }
 
+    /**
+     * Called after a service has been created by the wrapping system, with the intention
+     * that the new service should be called and included in the browsing session.
+     */
+    public void serviceWrapped(String providerURI, String serviceName, MobyDataJob sampleData) throws Exception{
+	MobyContentInstance inEnvelope = new MobyContentInstance();
+	inEnvelope.put("demo", sampleData);
+	MobyService service = findService(providerURI, serviceName);
+	MobyContentInstance result = callService(service, inEnvelope);
+
+	// If any of the input data had peers, allow the user to invoke the newly created service
+	// on all of its peers.
+	String peerOptionsHTML = "";
+	for(MobyPrimaryData templateData: service.getPrimaryInputs()){
+	    MobyDataInstance data = sampleData.get(templateData.getName());
+	    if(!(data instanceof MobyPrimaryData)){
+		// wierdness
+		logger.warn("Service parameter "+templateData.getName()+" is a primary parameter, but " +
+			    "the sample data provided was of class "+data.getClass().getName());
+		continue;
+	    }
+	    if(data.getUserData() == null){
+		// untraceable for some reason.  The UserData should have been passed along with
+		// the MobyDataInstance from MobyContentPane.getDraggedData(), all the way through 
+		// PBE recorder...
+		logger.warn("Sample MobyDataInstance for new service did not have provenance " +
+			    "data in UserData as expected, skipping peer checking for parameter "+
+			    templateData.getName());
+		continue;
+	    }
+	    // MobyPayloadCreator contains the code to recreate the peer set of the sample data
+	    // as it was the moment the data was dragged into the service wrapping demo.
+	    MobyPayloadCreator srcDataInContext = new MobyPayloadCreator(null, (String) data.getUserData());
+	    MobyContentInstance peerJobs = srcDataInContext.createPayload(templateData.getName());
+	    if(peerJobs != null && peerJobs.size() > 1){
+		String type = ((MobyPrimaryData) data).getDataType().getName();
+		if(type.equals(MobyTags.MOBYOBJECT) && ((MobyPrimaryData) data).getNamespaces().length > 0){
+		    type = ((MobyPrimaryData) data).getNamespaces()[0].getName();
+		}
+		// Create a moby payload input file that the user can use to send all peers 
+		// with the same parameters as the demo
+		URL tempFile = DataUtils.createServiceInputFileForPeers(peerJobs, sampleData);
+		peerOptionsHTML += ("<b><a href=\""+SERVICE_INPUT_MAGIC+tempFile.toString()+"\t"+
+				    providerURI+"\t"+serviceName+
+				    "\">Click here to run <i>" + serviceName + 
+				    "</i> for the demo "+type+"'s peers (" + peerJobs.size() +
+				    " total)</i></a></b><br/>").replaceAll("<", "&lt;");
+	    }
+	}
+	if(peerOptionsHTML.length() != 0){
+	    result.setServiceNotes(peerOptionsHTML);
+	}
+
+	URL resultURL = DataUtils.saveOutputData(result, service, //for tracking purposes
+						 inEnvelope, getMobyCentralImpl().getRegistryEndpoint());  
+
+	loadWrappingPanel(resultURL);
+    }
+
+    private void loadWrappingPanel(URL resultURL){
 	for(int i = 0; i < tabbedPane.getTabCount(); i++){
 	    MobyContentPane pane = (MobyContentPane) tabbedPane.getComponentAt(i);
 	    if(pane.isWrappingService()){
@@ -812,10 +870,9 @@
 		break;
 	    }
 	}	
-	
     }
 
-    /**
+   /**
      * Load a Seahawk browser tab with the data held in the given MobyContentInstance.
      * Note that this methods take a snapshot of the data when it is passed in.  Subsequent
      * changes to the MobyContentInstance will not be reflected in the Seahawk display.

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2010/04/26 16:29:13	1.31
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2010/05/04 16:19:37	1.32
@@ -494,6 +494,7 @@
 	    return;
 	}
 
+	hasFailed = false;
 	setCursor(new Cursor(Cursor.WAIT_CURSOR));
 	try {
 	    // 1000 is initial, unimportant guess as to resulting HTML size
@@ -1098,7 +1099,25 @@
 	    // Internal moby pseudo-URL
 	    if(targetURL == null){
 		String desc = he.getDescription();
-		if(desc.startsWith("#")){
+		if(desc.startsWith(MobyContentGUI.SERVICE_INPUT_MAGIC)){
+		    // Run the input as is on the specified service.  Desc is "#!inputURL\tserviceAuthURI\tserviceName"
+		    String[] runSpec = desc.substring(MobyContentGUI.SERVICE_INPUT_MAGIC.length()).split("\t");
+		    URL inputURL = null;
+		    try{
+			inputURL = new URL(runSpec[0]);
+		    }
+		    catch(Exception e){
+			logger.warn("Could not parse service input file URL "+runSpec[0], e); 
+			return;
+		    }
+		    try{
+			callServiceForInputURL(runSpec[1], runSpec[2], inputURL);
+		    } catch(Exception e){
+			logger.error("Could not call service "+runSpec[2]+" for peer set", e);
+			return;
+		    }
+		}
+		else if(desc.startsWith("#")){
 		    // Anchor hyperlink
 		    editorPane.scrollToReference(desc.substring(1));
 		}
@@ -1127,7 +1146,7 @@
 	    }
 	    
 	}
-	if(he.getEventType() == HyperlinkEvent.EventType.ENTERED){
+	else if(he.getEventType() == HyperlinkEvent.EventType.ENTERED){
 	    overHyperlink = true;
 	    lastHyperlinkHovered = targetURL;
 	    if(isMobyURL(targetURL)){
@@ -1140,8 +1159,11 @@
 	    }
 	    else if(targetURL == null){
 		String desc = he.getDescription();
+		if(desc.startsWith(MobyContentGUI.SERVICE_INPUT_MAGIC)){
+		    status.setText("Click to run service on dataset");
+		}
 		// # start means relative anchor
-		if(desc.startsWith("#")){
+		else if(desc.startsWith("#")){
 		    status.setText("Scroll to section '" + desc.substring(1) + "'");
 		}
 	    }
@@ -1149,12 +1171,22 @@
 		status.setText("Launch external link " + targetURL);
 	    }
 	}
-	if(he.getEventType() == HyperlinkEvent.EventType.EXITED){
+	else if(he.getEventType() == HyperlinkEvent.EventType.EXITED){
 	    overHyperlink = false;
 	    status.setText("");
 	}
     }
 
+    private void callServiceForInputURL(String providerURI, String serviceName, URL inputURL) throws Exception{
+	MobyContentInstance inEnvelope = MobyDataUtils.fromXMLDocument(inputURL);
+	MobyService service = contentGUI.findService(providerURI, serviceName);
+ 	MobyContentInstance result = contentGUI.callService(service, inEnvelope);
+
+	URL resultURL = DataUtils.saveOutputData(result, service, //for tracking purposes
+						 inEnvelope, contentGUI.getMobyCentralImpl().getRegistryEndpoint());  
+	gotoURL(resultURL, true);
+    }
+
     private boolean isLinkEnabled(URL url){
 	String ref = url.getRef();
 	if(ref == null || ref.length() == 0){
@@ -1469,7 +1501,7 @@
     }
 
     protected Document getCurrentDoc(){
-	if(currentDoc == null){  // parse the doc into memory if not already there
+	if(currentDoc == null && getCurrentURL() != null){  // parse the doc into memory if not already there
 	    try{
 		currentDoc = DataUtils.docBuilder.parse(getCurrentURL().openStream());
 	    } catch(Exception e){




More information about the MOBY-guts mailing list