[MOBY-guts] biomoby commit

senger@ebi.ac.uk senger at pub.open-bio.org
Tue Nov 25 13:18:11 UTC 2003


senger
Tue Nov 25 08:18:10 EST 2003
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv19385/src/main/org/biomoby/client

Modified Files:
	CentralImpl.java GraphsServlet.java Graphviz.java 
Log Message:
added buglist for graphs; code cleaning

moby-live/Java/src/main/org/biomoby/client CentralImpl.java,1.5,1.6 GraphsServlet.java,1.3,1.4 Graphviz.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java	2003/11/24 18:45:25	1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java	2003/11/25 13:18:10	1.6
@@ -1093,7 +1093,8 @@
      *   </Relationship>
      * </Relationships>
      *************************************************************************/
-    public String[] getServiceTypeRelationships (String serviceTypeName)
+    public String[] getServiceTypeRelationships (String serviceTypeName,
+						 boolean expand)
 	throws MobyException {
 	String result =
 	    (String)doCall ("Relationships",
@@ -1101,7 +1102,7 @@
 				"<Relationship>" +
 				"<serviceType>" + serviceTypeName + "</serviceType>" +
 				"<relationshipType>" + Central.ISA + "</relationshipType>" +
-				"<expandRelationship>1</expandRelationship>" +
+				"<expandRelationship>" + (expand ? "1" : "0") + "</expandRelationship>" +
 				"</Relationship>"
 			    });
 

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/GraphsServlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/GraphsServlet.java	2003/11/09 01:52:28	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/GraphsServlet.java	2003/11/25 13:18:10	1.4
@@ -21,7 +21,8 @@
 
 
 /**
- * A servlet making graphs of Moby services and Moby data types.  <P>
+ * A servlet making graphs of Moby service instances, Moby data types,
+ * and Moby service types.  <P>
  *
  * @author <A HREF="mailto:senger at ebi.ac.uk">Martin Senger</A>
  * @version $Id$
@@ -119,6 +120,7 @@
     // these are filled in the static initializer
     static String[] supportedTypesForData;
     static String[] supportedTypesForServices;
+    static String[] supportedTypesForServiceTypes;
     static Hashtable contentTypes;
     static Hashtable displayNamesForTypes;
 
@@ -137,6 +139,7 @@
     boolean verbose = false;
     MobyDataType[] dataTypes;
     MobyService[] services;
+    MobyServiceType[] serviceTypes;
     long lastRead = -1;         // in millis
     long refreshInterval = -1;  // in millis
 
@@ -166,6 +169,8 @@
 	    T_PNG, T_GIF, T_JPG, T_PS, T_SVG, T_VRML, T_MIF, /* T_IMAP, T_CMAP, */
 	    T_HPGL, T_PCL, T_FIG, T_DOT, T_CANON, T_PLAIN, T_RDF
 	};
+	supportedTypesForServiceTypes = supportedTypesForData;
+
 	displayNamesForTypes = new Hashtable();
 	displayNamesForTypes.put (T_PNG,   "PNG - Portable Network Graphics");
 	displayNamesForTypes.put (T_GIF,   "GIF Bitmap image");
@@ -298,8 +303,8 @@
 	    worker.doGraphDataTypes (req, res);
 	else if (exists (req, ACTION_JOB_SERVI))
 	    worker.doGraphServices (req, res);
-// 	else if (exists (req, ACTION_JOB_SERVT))
-// 	    worker.doGraphServiceTypes (req, res);
+ 	else if (exists (req, ACTION_JOB_SERVT))
+ 	    worker.doGraphServiceTypes (req, res);
 	else
 	    worker.doEntryPage (req, res);
     }
@@ -543,6 +548,30 @@
 			    h.submit (" Create Graph of Data Types ", ACTION_JOB_DATA)));
 	out.println (h.end (BLOCKQUOTE));
 
+	// ---------------------------------------------
+	out.println (h.gen (H3, "Graph of service types"));
+	// ---------------------------------------------
+	out.println (start (BLOCKQUOTE));
+
+	labels = null;
+	values = null;
+	synchronized (supportedTypesForServiceTypes) {
+	    labels = new String [supportedTypesForServiceTypes.length];
+	    values = new String [supportedTypesForServiceTypes.length];
+	    for (int i = 0; i < supportedTypesForServiceTypes.length; i++) {
+		labels[i] = (String)displayNamesForTypes.get (supportedTypesForServiceTypes[i]);
+		values[i] = supportedTypesForServiceTypes[i];
+	    }
+	}
+	selected.clear();
+	selected.put (T_PNG, "1");
+
+	out.println ("Select output type: ");
+	out.println (h.list (OUTPUT_TYPE_SERVT, labels, values, selected));
+ 	out.println (h.gen (P,
+			    h.submit (" Create Graph of Service Types ", ACTION_JOB_SERVT)));
+	out.println (h.end (BLOCKQUOTE));
+
 	// -------------------------------------------------------------
 	out.println (h.gen (H3, "Additional visualization properties"));
 	// -------------------------------------------------------------
@@ -657,39 +686,13 @@
 		}
 
 		// create the real graphs (or an RDF representation)
-		String graph;
 		if (wantedOutputType.equals (T_RDF)) {
-		    graph = RDF.createServicesGraph (edges, props);
+		    String graph = RDF.createServicesGraph (edges, props);
 		    cache.setContents (id, graph.getBytes());
 
 		} else {
-		    graph = Graphviz.createServicesGraph (edges, props);
-
-		    // where is the 'dot' program
-		    String dotProg = "dot";
-		    String dotPath = (String)initParams.get (DOT_PATH);
-		    if (dotPath != null)
-			dotProg = dotPath + System.getProperty ("file.separator") + dotProg;
-
-		    // depending on the cache implementation we may ask
-		    // 'dot' to produce output to its standard output, or
-		    // to write to a file
-		    if (cache.supportsFilenames()) {
-
-			// note that this filename represents a not-yet-existing file
-			String filename = cache.getFilename (id);
-
-			// call 'dot' to create a real graph in a 'filename'
-			executeDot (dotProg, graph, wantedOutputType, filename);
-
-		    } else {
-
-			// call 'dot' to return a real graph as byte array
-			byte[] graphBytes = executeDot (dotProg, graph, wantedOutputType);
-			if (graphBytes == null || graphBytes.length == 0)
-			    throw new MobyException ("An empty graph. Strange.");
-			cache.setContents (id, graphBytes);
-		    }
+		    createGraph (id, wantedOutputType,
+				 Graphviz.createServicesGraph (edges, props));
 		}
 	    }
 	    res.sendRedirect (res.encodeRedirectURL (cache.getURL (id)));
@@ -737,34 +740,56 @@
 	    if (! cache.exists (id)) {
 		// create a dot definition of the graph
 		log ("Creating a graph of the data types...\n");
-		String dotGraph = Graphviz.createDataTypesGraph (dataTypes, props);
-
-
-		// where is the 'dot' program
-		String dotProg = "dot";
-		String dotPath = (String)initParams.get (DOT_PATH);
-		if (dotPath != null)
-		    dotProg = dotPath + System.getProperty ("file.separator") + dotProg;
-
-		// depending on the cache implementation we may ask
-		// 'dot' to produce output to its standard output, or
-		// to write to a file
-		if (cache.supportsFilenames()) {
+		createGraph (id, wantedOutputType,
+			     Graphviz.createDataTypesGraph (dataTypes, props));
+	    }
+	    res.sendRedirect (res.encodeRedirectURL (cache.getURL (id)));
+	
+	} catch (MobyException e) {
+	    error (res, res.SC_SERVICE_UNAVAILABLE, e);
+	    return;
+	}
+    }
 
-                    // note that this filename represents a not-yet-existing file
-		    String filename = cache.getFilename (id);
+    /*************************************************************************
+     * Create and return a graph of Moby service types.
+     *************************************************************************/
+    protected void doGraphServiceTypes (HttpServletRequest req, HttpServletResponse res)
+	throws ServletException, IOException {
 
-		    // call 'dot' to create a real graph in a 'filename'
-		    executeDot (dotProg, dotGraph, wantedOutputType, filename);
+	// check if the output type is supported
+	String wantedOutputType = getString (req, OUTPUT_TYPE_SERVT);
+	if (wantedOutputType == null)
+	    wantedOutputType = T_PNG;
+	boolean supported = false;
+	for (int i = 0; i < supportedTypesForServiceTypes.length; i++) {
+	    if (supportedTypesForServiceTypes[i].equals (wantedOutputType)) {
+		supported = true;
+		break;
+	    }
+	}
+	if (! supported) {
+	    error (res, res.SC_SERVICE_UNAVAILABLE,
+		   new MobyException ("Unrecognized output type '" + wantedOutputType + "'."));
+	    return;
+	}
 
-		} else {
+	// collect visualization properties
+	Properties props = new Properties();
+	String rankdir = getString (req, RANKDIR);
+	if (rankdir != null)
+	    props.put (Graphviz.PROP_RANKDIR, rankdir);
 
-		    // call 'dot' to return a real graph as byte array
-		    byte[] graph = executeDot (dotProg, dotGraph, wantedOutputType);
-		    if (graph == null || graph.length == 0)
-			throw new MobyException ("An empty graph. Strange.");
-		    cache.setContents (id, graph);
-		}
+	try {
+	    // perhaps we have the same graph in the cache already
+	    props.entrySet().toArray();
+	    String id = cache.createId (endpoint, GRAPH_SERVT,
+					wantedOutputType, lastRead, props);
+	    if (! cache.exists (id)) {
+		// create a dot definition of the graph
+		log ("Creating a graph of the services types...\n");
+		createGraph (id, wantedOutputType,
+			     Graphviz.createServiceTypesGraph (serviceTypes, props));
 	    }
 	    res.sendRedirect (res.encodeRedirectURL (cache.getURL (id)));
 	
@@ -777,9 +802,44 @@
     /********************************************************************
      *
      ********************************************************************/
+    protected void createGraph (String id,
+				String wantedOutputType,
+				String graph)
+	throws MobyException, IOException {
+
+	// where is the 'dot' program
+	String dotProg = "dot";
+	String dotPath = (String)initParams.get (DOT_PATH);
+	if (! UUtils.isEmpty (dotPath))
+	    dotProg = dotPath + System.getProperty ("file.separator") + dotProg;
+
+	// depending on the cache implementation we may ask
+	// 'dot' to produce output to its standard output, or
+	// to write to a file
+	if (cache.supportsFilenames()) {
+
+	    // note that this filename represents a not-yet-existing file
+	    String filename = cache.getFilename (id);
+
+	    // call 'dot' to create a real graph in a 'filename'
+	    executeDot (dotProg, graph, wantedOutputType, filename);
+
+	} else {
+
+	    // call 'dot' to return a real graph as byte array
+	    byte[] graphBytes = executeDot (dotProg, graph, wantedOutputType);
+	    if (graphBytes == null || graphBytes.length == 0)
+		throw new MobyException ("An empty graph. Strange.");
+	    cache.setContents (id, graphBytes);
+	}
+    }
+
+    /********************************************************************
+     *
+     ********************************************************************/
     protected void readRegistryIfNeeded()
 	throws MobyException {
-	if (dataTypes == null || services == null) {
+	if (dataTypes == null || services == null || serviceTypes == null) {
 	    readRegistry();
 	    return;
 	}
@@ -827,6 +887,22 @@
 	    dataTypes = new MobyDataType [v.size()];
 	    v.copyInto (dataTypes);
 
+	    // read all services types and their relationships
+	    v.clear();
+	    log ("Asking for all service types...\n");
+	    types = registry.getServiceTypes();
+	    for (Iterator it = types.entrySet().iterator(); it.hasNext(); ) {
+		Map.Entry entry = (Map.Entry)it.next();
+		String typeName = (String)entry.getKey();
+		log ("Processing service type " + typeName + "...\n");
+		MobyServiceType serviceType = new MobyServiceType (typeName);
+		serviceType.setDescription ((String)entry.getKey());
+		serviceType.setParentNames (registry.getServiceTypeRelationships (typeName, false));
+		v.addElement (serviceType);
+	    }
+	    serviceTypes = new MobyServiceType [v.size()];
+	    v.copyInto (serviceTypes);
+
 	    // read all services
 	    v.clear();
 	    log ("Asking for all service names...\n");
@@ -1024,7 +1100,7 @@
 	    h.gen (HR) + h.gen (DIV, ALIGN, "right",
 				h.gen (FONT, SIZE, "-2",
 				       h.gen (ADDRESS, contact) +
-				       "Last modified: " + UUtils.formatDate()));
+				       "Page created: " + UUtils.formatDate()));
     }
 
     /*************************************************************************

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/Graphviz.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/Graphviz.java	2003/10/17 13:13:34	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/Graphviz.java	2003/11/25 13:18:10	1.2
@@ -157,6 +157,44 @@
     }
 
     /*************************************************************************
+     * Creates a graph connecting 'serviceTypes' using their ISA
+     * relationship.  <p>
+     *
+     * @param servicesTypes represent nodes in the created graph
+     * @param props are some properties that can influence how the
+     * graph will look like; see the property names elswhere in this
+     * API what properties are understood
+     *
+     * @return a string with all definitions as understood by 'dot'
+     * program (from the graphviz package); this string can be saved
+     * in a '.dot' file that can be passed to a dot program to produce
+     * graphs in many available formats
+     *
+     *************************************************************************/
+    static public String createServiceTypesGraph (MobyServiceType[] serviceTypes,
+						  Properties props) {
+
+	StringBuffer buf = new StringBuffer();
+	buf.append ("digraph MobyServicesTypes {\n");
+	buf.append ("\trankdir=" + props.getProperty (PROP_RANKDIR, "LR") + ";\n");
+	buf.append ("\tedge [dir=back,arrowtail=empty];\n");
+	for (int t = 0; t < serviceTypes.length; t++) {
+	    MobyServiceType type = serviceTypes[t];
+	    String name = Utils.pureName (type.getName());
+	    String[] parents = type.getParentNames();
+	    for (int i = 0; i < parents.length; i++) {
+		buf.append ("\t");
+		buf.append (trName (Utils.pureName (parents[i])).toLowerCase());
+		buf.append (" -> ");
+		buf.append (trName (name).toLowerCase());
+		buf.append (";\n");
+	    }
+	}
+	buf.append ("}\n");
+	return new String (buf);
+    }
+
+    /*************************************************************************
      * Append 'value' to 'buf'. If it is not the first value there, it
      * prefix it by a comma.
      *************************************************************************/




More information about the MOBY-guts mailing list