[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Fri Jul 9 00:21:53 UTC 2004


mwilkinson
Thu Jul  8 20:21:53 EDT 2004
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv5633/MOBY

Modified Files:
	Central.pm Config.pm dbConfig.pm service_instance.pm 
Log Message:
more refactoring of code to get SQL out of mobycentral.  Also created two new subroutines for Martin and Ben to add their XSD-generating code such that the WSDL from MOBY Central will be valid

moby-live/Perl/MOBY Central.pm,1.131,1.132 Config.pm,1.3,1.4 dbConfig.pm,1.2,1.3 service_instance.pm,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Central.pm,v
retrieving revision 1.131
retrieving revision 1.132
diff -u -r1.131 -r1.132
--- /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2004/06/24 22:32:38	1.131
+++ /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2004/07/09 00:21:53	1.132
@@ -1942,15 +1942,16 @@
 
 sub retrieveService { 
 	my ($pkg,  $payload) = @_;
+    # the payload here is actually the full XML from the findService call above...
 	#return "<Services>NOT YET IMPLEMENTED</Services>";
-	my ($AuthURI, $serviceName) = &_retrieveServicePayload($payload);
+	my ($AuthURI, $serviceName, $InputXML, $OutputXML, $SecondaryXML) = &_retrieveServicePayload($payload);
 	unless ($AuthURI && $serviceName){return "<Services/>"}
 	my $SI = MOBY::service_instance->new(authority_uri => $AuthURI, servicename => $serviceName);
 	my $wsdls;
     return "<Service/>" unless ($SI);
 	
     if ($SI->category eq 'moby'){
-	    my $wsdl = &_getServiceWSDL($SI);
+	    my $wsdl = &_getServiceWSDL($SI, $InputXML, $OutputXML, $SecondaryXML);
 	    if ($wsdl){
 	        $wsdls .= "<Service><![CDATA[$wsdl]]></Service>\n";
 	    }
@@ -1976,7 +1977,27 @@
 		$serviceName = $x->item($n)->getAttributeNode("serviceName");  # may or may not have a name
 		if ($serviceName){$serviceName = $serviceName->getValue()}
 	}
-	return ($authURI, $serviceName);	
+
+	my $INPUT = $doc->getElementsByTagName("Input");
+    my $InputXML = "";
+    if ($INPUT->item(0)){
+        $InputXML = $INPUT->item(0)->toString;
+	}
+
+	my $OUTPUT = $doc->getElementsByTagName("Output");
+    my $OutputXML = "";
+    if ($OUTPUT->item(0)){
+        $OutputXML = $OUTPUT->item(0)->toString;
+	}
+
+	my $SECONDARY = $doc->getElementsByTagName("Output");
+    my $SecondaryXML = "";
+    if ($SECONDARY->item(0)){
+        $SecondaryXML = $SECONDARY->item(0)->toString;
+	}
+
+	return ($authURI, $serviceName, $InputXML, $OutputXML, $SecondaryXML);
+    
 }
 
 
@@ -2571,7 +2592,7 @@
 
 
 sub _getServiceWSDL {
-	my ($SI) = @_;
+	my ($SI, $InputXML, $OutputXML, $SecondaryXML) = @_;
 	# the lines below causes no end of grief.  It is now in a variable.	
 	#open (WSDL, "./MOBY/Central_WSDL_SandR.wsdl") || die "can't open WSDL file for search and replace\n";
 	#my $wsdl = join "", (<WSDL>);
@@ -2586,8 +2607,13 @@
 	my $URL = $SI->url;
 	my $IN = "NOT_YET_DEFINED_INPUTS";
 	my $OUT = "NOT_YET_DEFINED_OUTPUTS";
-	my $INxsd = "<NOT_YET_IMPLEMENTED_INPUT_XSD/>";
-	my $OUTxsd="<NOT_YET_IMPLEMENTED_OUTPUT_XSD/>";
+    
+    my $INxsd = &_getInputXSD($InputXML, $SecondaryXML);
+    my $OUTxsd = &_getOutputXSD($OutputXML);
+	
+    $INxsd ||= "<NOT_YET_IMPLEMENTED_INPUT_XSD/>";
+	$OUTxsd ||="<NOT_YET_IMPLEMENTED_OUTPUT_XSD/>";
+    
     $wsdl =~ s/MOBY__SERVICE__NAME__/$serviceName/g;  # replace all of the goofy portbindingpottype crap
     $wsdl =~ s/\<\!\-\-\s*MOBY__SERVICE__DESCRIPTION\s*\-\-\>/Authority: $AuthURI  -  $desc/g;  # add a sensible description
     $wsdl =~ s/MOBY__SERVICE__URL/$URL/g;  # the URL to the service
@@ -3045,6 +3071,125 @@
 END
 
 
+=head2 _getInputXSD
+
+  name    : _getInputXSD($InputXML, $SecondaryXML)
+  function: to get an XSD describing the input to a MOBY Service,
+            e.g. to use in a WSDL document
+  args    : (see _serviceListResponse code above for full details of XML)
+           $InputXML - the <Input>...</Input> block of a findService
+           response message
+           
+           $SecondaryXML - the <secondaryArticles>...<sescondaryArticles>
+           fragment of a findService response message
+           
+  returns :  XSD fragment of XML (should not return an XML header!)
+  notes   : the structure of an Input block is as follows:
+           <Input>
+              <!-- one or more Simple or Collection articles -->
+           </Input>
+           
+           the structure of a secondaryArticle block is as follows:
+           <sescondaryArticles>
+              <!-- one or more Parameter blocks -->
+           </secondaryArticles>
+           
+
+=over
+
+=item *  Simple
+
+         <Simple articleName="NameOfArticle">
+           <objectType>ObjectOntologyTerm</objectType>
+           <Namespace>NamespaceTerm</Namespace>
+           <Namespace>...</Namespace><!-- one or more... -->
+         </Simple>
+
+=item *  Collection note that articleName of the contained Simple objects is not required, and is ignored.
+
+        
+         <Collection articleName="NameOfArticle">
+            <Simple>......</Simple> <!-- Simple parameter type structure -->
+            <Simple>......</Simple> <!-- DIFFERENT Simple parameter type
+                                      (used only when multiple Object Classes
+                                      appear in a collection) -->
+         </Collection>
+
+=item *  Secondary
+
+        
+          <Parameter articleName="NameOfArticle">
+                <datatype>INT|FLOAT|STRING</datatype>
+                <default>...</default> <!-- any/all of these -->
+                <max>...</max>         <!-- ... -->
+                <min>...</min>         <!-- ... -->
+                <enum>...<enum>        <!-- ... -->
+                <enum>...<enum>        <!-- ... -->
+          </Parameter>
+
+=back
+
+=cut
+
+ 
+sub _getInputXSD {
+    my ($Input, $Secondary) =@_;
+    my $XSD;
+    
+    
+    return $XSD;
+}
+
+=head2 _getOuputXSD
+
+  name    : _getOutputXSD($OutputXML)
+  function: to get an XSD describing the output from a MOBY Service
+            e.g. to use in a WSDL document
+  args    : (see _serviceListResponse code above for full details)
+           $InputXML - the <Input>...</Input> block of a findService
+           response message
+           
+           $SecondaryXML - the <secondaryArticles>...<sescondaryArticles>
+           fragment of a findService response message
+           
+  returns :  XSD fragment of XML (should not return an XML header!)
+  notes   : the structure of an Output block is as follows:
+           <Input>
+              <!-- one or more Simple or Collection articles -->
+           </Input>
+
+=over
+
+=item *  Simple
+
+         <Simple articleName="NameOfArticle">
+           <objectType>ObjectOntologyTerm</objectType>
+           <Namespace>NamespaceTerm</Namespace>
+           <Namespace>...</Namespace><!-- one or more... -->
+         </Simple>
+
+=item *  Collection note that articleName of the contained Simple objects is not required, and is ignored.
+
+        
+         <Collection articleName="NameOfArticle">
+            <Simple>......</Simple> <!-- Simple parameter type structure -->
+            <Simple>......</Simple> <!-- DIFFERENT Simple parameter type
+                                      (used only when multiple Object Classes
+                                       appear in a collection) -->
+         </Collection>
+
+=back
+
+=cut
+
+sub _getOutputXSD {
+    my ($Output) =@_;
+    my $XSD;
+    
+    
+    return $XSD;
+}
+
 
 1;
 

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Config.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Perl/MOBY/Config.pm	2004/06/24 22:32:38	1.3
+++ /home/repository/moby/moby-live/Perl/MOBY/Config.pm	2004/07/09 00:21:53	1.4
@@ -74,7 +74,7 @@
     }
 
     my $file = $ENV{MOBY_CENTRAL_CONFIG};
-	$file || die "can't open MOBY Configuration file $!\n";
+	(-e $file) || die "can't open MOBY Configuration file $!\n";
     
 	chomp $file;
     if ((-e $file) && (!(-d $file))){
@@ -106,27 +106,22 @@
 	
 	if ($self->{"${source}Adaptor"}){return $self->{"${source}Adaptor"}};  # read from cache
 
-    my $username = $self->$source->{username};  # $self->source returns a MOBY::dbConfig object
+    my $username = $self->$source->{username};  # $self->$source returns a MOBY::dbConfig object
     my $password = $self->$source->{password};
     my $port = $self->$source->{port};
     my $dbname = $self->$source->{dbname};
     my $url = $self->$source->{url};
 	my $adaptor = $self->$source->{adaptor};
-	my $sourcetype = $self->$source->{sourcetype};
 	
 	eval "require $adaptor";
 	return undef if $@;
-	eval "require $sourcetype";
-	return undef if $@;
 	
-	my $ADAPTOR = $adaptor->new(  # by default, this is queryapi
-								source => $source,
+	my $ADAPTOR = $adaptor->new(  # by default, this is queryapi::mysql
 								username => $username,
 								password => $password,
 								port => $port,
 								dbname => $dbname,
 								url => $url,
-								sourcetype => $sourcetype,
 							   );
 	if ($ADAPTOR){
 		$self->{"${source}Adaptor"} = $ADAPTOR;  # cache it

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/dbConfig.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Perl/MOBY/dbConfig.pm	2004/06/29 16:23:59	1.2
+++ /home/repository/moby/moby-live/Perl/MOBY/dbConfig.pm	2004/07/09 00:21:53	1.3
@@ -18,8 +18,7 @@
 				   dbname		=>  [undef,			'read/write'],
 				   port			=>  [undef,			'read/write'],
 				   proxy		=>	[undef,			'read/write'],
-				   adaptor		=> 	["MOBY::Adaptor::moby::queryapi",			'read/write'],
-				   sourcetype	=> 	["MOBY::Adaptor::moby::queryapi::mysql",			'read/write'],
+				   adaptor		=> 	["MOBY::Adaptor::moby::queryapi::mysql",			'read/write'],
 				   url			=>	[undef,			'read/write'],
                    section      =>  [undef,         'read/write'],
                     );
@@ -44,7 +43,7 @@
     sub _standard_keys {
 	keys %_attr_data;
     }
-    # List of names of all specified object attributes
+
     sub database_title {
 		my ($self, $val) = @_;
 		$self->section_title($val) if $val;

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/service_instance.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Perl/MOBY/service_instance.pm	2004/06/24 22:32:38	1.5
+++ /home/repository/moby/moby-live/Perl/MOBY/service_instance.pm	2004/07/09 00:21:53	1.6
@@ -8,6 +8,7 @@
 use MOBY::central_db_connection;
 use MOBY::OntologyServer;
 use MOBY::authority;
+use MOBY::Config;
 
 #@ISA = qw(MOBY::central_db_connection);  # can't do this yet...
 
@@ -74,14 +75,6 @@
                     description   => [undef,      'read/write'],
                     registry		=> ['MOBY_Central', 		'read/write'],
                     test      => [0,      'read/write'],  # toggles create or test_existence behaviour
-                    
-                    username => ["mobycentral",         'read/write'],
-                    password => ["mobycentral",         'read/write'],        
-                    dbname => ["mobycentral",       'read/write'],
-                    host => ["localhost",         'read/write'],
-                    port => [3306,         'read/write'],
-                    dbh => [undef,      'read/write'],
-
 				);
 
    #_____________________________________________________________
@@ -147,14 +140,23 @@
         (defined $val) && ($self->{description} = $val);
         return $self->{description}
     }
+	
+	sub dbh {
+		$CONFIG ||=MOBY::Config->new;  # exported by Config.pm
+		my $adaptor = $CONFIG->getDataAdaptor(datasource => 'mobycentral')->dbh;
+	}
+	sub adaptor {
+		$CONFIG ||=MOBY::Config->new;  # exported by Config.pm
+		my $adaptor = $CONFIG->getDataAdaptor(datasource => 'mobycentral');
+	}
 }
 
-sub _dbh {
-    my ($self) = @_;
-    
-    my $central_connect = MOBY::central_db_connection->new();
-	$self->dbh($central_connect->dbh);
-}
+#sub _dbh {
+#    my ($self) = @_;
+#    
+#    my $central_connect = MOBY::central_db_connection->new();
+#	$self->dbh($central_connect->dbh);
+#}
 
 sub new {
 	my ($caller, %args) = @_;
@@ -186,13 +188,15 @@
     return undef unless $self->authority_uri;
     return undef unless $self->servicename;
     
-    $self->_dbh();
-    return undef unless $self->dbh;
-    my $dbh = $self->dbh;
+    #$self->_dbh();
+    #return undef unless $self->dbh;
+    #my $dbh = $self->dbh;
 
     if ($self->test){ return $self->service_instance_exists}
 
-    $self->authority($self->_get_authority());
+    $self->authority($self->_get_authority());  # this might not be necessary - it simply converts auth_uri to auth_id and v.v.?
+												# it actually is necessary for the moment.  We need to put the logic of determining
+												# service id into the mysql.pm module!!
     
     if ($self->service_type){
         my $OE = MOBY::OntologyServer->new(ontology => 'service');
@@ -201,54 +205,43 @@
         ($self->service_type =~ /urn:lsid/)?$self->service_type_uri($self->service_type):$self->service_type_uri($servicetypeURI);
     }
     
-    my ($serviceid, $category, $name, $typeURI, $authid,$url,$email,$authoritative,$desc) = $dbh->selectrow_array( # does this service already exist?
-        q{select
-          service_instance_id,
-          category,
-          serviceName,
-          service_type_uri,
-          authority_id,
-          url,
-          contact_email,
-          authoritative,
-          description 
-          from service_instance where servicename=? and authority_id=?},
-        undef,($self->servicename, $self->authority->authority_id));
+	my $existing_service = $self->adaptor->query_service_instance (servicename => $self->servicename, authURI => $self->authority_uri);
+	
+
     
-    if ((defined $serviceid)  # if it exists, you are not allowed to have passed anything other than service name and authorityURI
+    if (($existing_service)  # if it exists, you are not allowed to have passed anything other than service name and authorityURI
         && ((defined $self->category)
         || (defined $self->service_type)
         || (defined $self->url)
         || (defined $self->contact_email)
         || (defined $self->description))){
             return -1;  # no no no, not alowed to do that!  I will not give you an object
-    } elsif (defined $serviceid){    # if service exists, then instantiate it from the database retrieval we just did
-        $self->service_instance_id($serviceid);
-        $self->category($category);
-        $self->service_type($typeURI);
-        $self->url($url);
-        $self->contact_email($email);
-        $self->description($desc);
-        $self->authority($self->_get_authority);
+    } elsif ($existing_service){    # if service exists, then instantiate it from the database retrieval we just did
+        $self->service_instance_id($existing_service->{'serviceid'});
+        $self->category($existing_service->{'category'});
+        $self->service_type($existing_service->{'servicetype'});
+        $self->url($existing_service->{'url'});
+        $self->contact_email($existing_service->{'email'});
+        $self->description($existing_service->{'desc'});
+        $self->authority($existing_service->{'authURI'});
         $self->{__exists__} = 1;  # this service already existed
-    } elsif (!(defined $serviceid)  # if it doesn't exist
+    } elsif (!($existing_service)  # if it doesn't exist
             && (defined $self->category)  # and you have given me things I need to create it
             && (defined $self->service_type)
             && (defined $self->url)
             && (defined $self->contact_email)
             && (defined $self->description))
             {   # then create it de novo if we have enough information
-        $dbh->do(q{insert into service_instance (category, servicename, service_type_uri, authority_id, url, contact_email, authoritative, description) values (?,?,?,?,?,?,?,?)},
-             undef,
-             $self->category,
-             $self->servicename,
-             $self->service_type_uri,
-             $self->authority->authority_id,
-             $self->url,
-             $self->contact_email,
-             $self->authoritative,
-             $self->description);
-        $self->service_instance_id($dbh->{mysql_insertid});
+		my $id = $self->adaptor->insert_service_instance(
+														category => $self->category,
+														servicename => $self->servicename,
+														service_type_uri => $self->service_type_uri,
+														authority_id => $self->authority_id,
+														url => $self->url,
+														contact_email => $self->contact_email,
+														authoritative => $self->authoritative,
+														description => $self->description);        
+        $self->service_instance_id($id);
         $self->{__exists__} = 1;  # this service now exists
     } else {  # if it doesn't exist, and you havne't given me anyting I need to create it, then bail out
         return undef;
@@ -263,6 +256,8 @@
     unless ($self->{__exists__}){
         return undef
     }
+	$CONFIG ||=MOBY::Config->new;
+	
     $dbh->do(q{delete from service_instance where service_instance_id = ?},undef,$self->service_instance_id);
     $dbh->do(q{delete from simple_input where service_instance_id = ?},undef,$self->service_instance_id);
     $dbh->do(q{delete from simple_output where service_instance_id = ?},undef,$self->service_instance_id);
@@ -299,7 +294,7 @@
 }
     
     
-sub _get_authority {
+sub _get_authority {  # there's somethign fishy here... the authority.pm object already knows about authority_id and authorty_uri, doens't it?
     my ($self) = @_;
     my $dbh = $self->dbh;
     my $authority;




More information about the MOBY-guts mailing list