blib/lib/MOBY/Client/Central.pm

filter: Statementstmt 68.2% 43 / 63 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 78.9% 15 / 19 Podpod n/a totaltotal 62.3% 58 / 93 CC 6 SCAR 17.3
CC
6
Cov
60%
Connection
20.0
_accessible
12.0
_default_for
2.0
CRAP 5.6
« blib/lib/MOBY/Adaptor/moby/DataAccessI.pm ↑ Summary blib/lib/auto/share/dist/MOBY/scripts/CloneCentralDatabases.pl »
1 #$Id: Central.pm,v 1.8 2009/03/31 21:19:36 kawas Exp $
2 package MOBY::Client::Central;
3 4 ▶use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 #use SOAP::Lite + trace; # for debugging
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use MOBY::MobyXMLConstants;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use MOBY::Client::ServiceInstance;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use MOBY::Client::Registration;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use MOBY::Client::SimpleArticle;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use MOBY::Client::CollectionArticle;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use MOBY::Client::SecondaryArticle;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use MOBY::Client::OntologyServer;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use vars qw($AUTOLOAD @ISA $MOBY_server $MOBY_uri);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 ▶use vars qw /$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 $VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /: (\d+)\.(\d+)/;
20  
21 =head1 NAME
22  
23 MOBY::Client::Central - a client side wrapper for MOBY Central
24  
25 =cut
26  
27 =head1 SYNOPSIS
28  
29 use MOBY::Client::Central;
30 my $Central = MOBY::Client::Central->new();
31  
32 my ($Services, $REG) = $Central->findService(
33 input =>[
34 [DNASequence => ['NCBI_gi', 'NCBI_Acc']],
35 ],
36 expandObjects => 1
37 );
38 unless ($Services){
39 print "Service discovery failed with the following errror: ";
40 print $REG->message;
41 end
42 }
43 foreach my $SERVICE(@{$Services}){
44 print "Service Name: ", $SERVICE->name, "\n";
45 print "Service Provider: ", $SERVICE->authority,"\n";
46  
47 }
48  
49 =cut
50  
51 =head1 DESCRIPTION
52  
53 Client side "wrapper" for communicating with
54 the MOBY::Central registry.
55  
56 Used to do various read-only transactions with MOBY-Central. Parses
57 MOBY::Central XML output into Perlish lists, hashes, and objects. This should
58 be sufficient for most or all MOBY Client activities written in Perl.
59  
60  
61 =cut
62  
63  
64 =head1 AUTHORS
65  
66 Mark Wilkinson (markw@illuminae.com)
67  
68 BioMOBY Project: http://www.biomoby.org
69  
70  
71 =cut
72  
73 =head1 METHODS
74  
75  
76  
77 =head2 new
78  
79 Usage : my $MOBY = MOBY::Client::Central->new(Registries => \%regrefs)
80 Function : connect to one or more MOBY-Central
81 registries for searching
82 Returns : MOBY::Client::Central object
83  
84 ENV & PROXY : you can set environment variables to change the defaults.
85 By default, a call to 'new' will initialize MOBY::Client::Central
86 to connect to the default MOBY Central registry. The location of
87 this registry can be determined by examining the redirect from:
88 http://biomoby.org/mobycentral
89 If you wish to chose another registry by default, or if you need
90 to set up additional connection details (e.g. PROXY) then you may
91 set the following environment variables to whatever you
92 require:
93 MOBY_SERVER (default http://moby.ucalgary.ca/moby/MOBY-Central.pl)
94 MOBY_URI (default http://moby.ucalgary.ca/MOBY/Central)
95 MOBY_PROXY (no default)
96  
97 Args : user_agent - optional. The name of your software application
98 Registries - optional.
99 - takes the form
100 {$NAME1 => {
101 URL => $URL,
102 URI => $URI,
103 PROXY => $proxy_server},
104 $NAME2 => {
105 URL => $URL,
106 URI => $URI,
107 PROXY => $proxy_server},
108 }
109 - by default this becomes
110 {mobycentral => {
111 URL => 'http://moby.ucalgary.ca/moby/MOBY-Central.pl',
112 URI => 'http://moby.ucalgary.ca/MOBY/Central'}
113 }
114 Discussion: Each registry must have a different
115 NAME. If you have more than one
116 registry with the same NAME, only
117 one will be used. You can NAME them
118 however you please - this is for
119 internal reference only. You will
120 make subsequent calls on one or more
121 of these registries by NAME, or by
122 default on all registries.
123 Notes : BE CAREFUL WITH OBJECT/SERVICE
124 REGISTRATION!! YOU WILL REGISTER
125 IN EVERY MOBY-CENTRAL YOU HAVE
126 NAMED! If you do not host a MOBY::Central
127 database locally, or don't know
128 better,then don't use any arguments
129 at all, and everything should work
130  
131  
132 =cut
133  
134 my $debug = 0;
135 if ($debug) {
136 open( OUT, ">/tmp/CentralLogOut.txt" )
137 || die "cant open logfile CentralLogOut.txt $!\n";
138 close OUT;
139 }
140 {
141  
142 # Encapsulated:
143 # DATA
144 #___________________________________________________________
145 #ATTRIBUTES
146 my %_attr_data = # DEFAULT ACCESSIBILITY
147 (
148 Connections => [ undef, 'read/write' ],
149 default_MOBY_servername => [ 'mobycentral', 'read/write' ],
150 default_MOBY_server => [ '', 'read/write'],
151 default_MOBY_uri => [ 'http://biomoby.org/MOBY/Central', 'read/write' ],
152 default_MOBY_proxy => [ undef, 'read/write' ],
153 default_MOBY_type => [ 'soap', 'read/write' ],
154 Registries => [ undef, 'read/write' ],
155 multiple_registries => [ undef, 'read/write' ],
156 user_agent => [ "MOBY-Client-Central", 'read/write'],
157
158  
159 # SWITCH TO THESE FOR A LOCAL MOBY CENTRAL REGISTRY
160 #default_MOBY_server => ['http://localhost/cgi-bin/MOBY-Central.pl', 'read/write'],
161 #default_MOBY_uri => ['http://localhost/MOBY/Central', 'read/write'],
162 );
163  
164 #_____________________________________________________________
165 # METHODS, to operate on encapsulated class data
166 # Is a specified object attribute accessible in a given mode
167 0 ▶ sub _accessible {
Subroutine _accessible: not called CC=3 SCAR=24.8
168 0 my ( $self, $attr, $mode ) = @_;
169 0 ▶ return 0 unless ( $mode && $_attr_data{$attr} );
Branch: 1 branch
BranchTrueFalseTotal
unless $mode and $_attr_data{$attr} 0 0 0
Condition0%0/3
$mode and $_attr_data{$attr}
!ll&&!rl&&r
000
MC/DC0%0/2
$mode and $_attr_data{$attr}
$mode $_attr_data{$attr}
Truth table0%0/3
A and B
A= $modeB= $_attr_data{$attr}
ABresult
0X0
100
111
170 0 $_attr_data{$attr}[1] =~ /$mode/;
171 }
172  
173 # Classwide default value for a specified object attribute
174 0 ▶ sub _default_for {
Subroutine _default_for: not called CC=1 SCAR=6.9
175 0 my ( $self, $attr ) = @_;
176 0 $_attr_data{$attr}[0];
177 }
178  
179 # List of names of all specified object attributes
180 0 ▶ sub _standard_keys {
Subroutine _standard_keys: not called CC=1 SCAR=6.9
181 0 keys %_attr_data;
182 }
183  
184 0 ▶ sub Connection {
Subroutine Connection: not called CC=4 SCAR=30.0
185 0 my ( $self, $desired ) = @_;
186 0 ▶ if ($desired) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desired) { } 0 0 0
187 0 my @registries = @{$self->Connections};
188 0 foreach (@registries){
189 0 my ( $name, $type, $connect ) = @{$_};
190 0 ▶ return ( $type, $connect ) if $name eq $desired;
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $desired 0 0 0
191 }
192 }
193 else {
194 0 my ( $name, $type, $connect ) = @{ $self->Connections->[0] };
195 0 return ( $type, $connect );
196 }
197 0 return ( undef, undef );
198 }
199 }
200  
201 sub _call {
202  
203 # this method replaces the former calls directly
204 # to teh SOAP_Connection, to give more flexibility
205 # in how that call is made
206 # most subroutines in here do the following:
207 # $return = $self->SOAP_connection->call(registerObjectClass => ($message))->paramsall;
208 # or $payload = $self->SOAP_connection($reg)->call('Relationships' => ($m))->paramsall;
209 # so intercept that and figure out if we are actually making a SOAP call or not
210 # and determine which registry it is
211 my ( $self, $reg, $method, @params ) = @_;
212 $reg = $self->default_MOBY_servername if $reg eq "default";
213 $reg = $self->default_MOBY_servername if !$reg;
214 my ( $type, $connect ) = $self->Connection($reg);
215 return "<result>EXECUTION ERROR - registry $reg not found</result>"
216 unless ( $type && $connect );
217 my $param = join "", @params; # must be a single message!
218 if ( lc($type) eq "get" ) {
219  
220 #print STDERR "executing CGI call\n";
221 4 ▶ use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
222 my $ua = LWP::UserAgent->new;
223 $ua->agent($self->user_agent);
224 0 ▶ use CGI;
Subroutine BEGIN: called CC=1 SCAR=2.6
225 $param =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
226 my $paramstring = "?action=$method";
227 $paramstring .= ";payload=$param" if $param;
228 my $req = HTTP::Request->new( GET => $connect . $paramstring );
229 my $res = $ua->request($req);
230 if ( $res->is_success ) {
231 return $res->content;
232 }
233 else {
234 return
235 "<result>EXECUTION ERROR - unsuccessful call to MOBY Central registry named '$reg'</result>";
236 }
237 }
238 else {
239  
240 #print STDERR "executing SOAP call\n";
241 my @payload = $connect->call( $method => SOAP::Data->type('string' => $param ) )->paramsall;
242 return @payload;
243 }
244 }
245  
246 sub new {
247 my ( $caller, %args ) = @_;
248 my $caller_is_obj = ref($caller);
249 return $caller if $caller_is_obj;
250 my $class = $caller_is_obj || $caller;
251 my $proxy;
252 my $self = bless {}, $class;
253 foreach my $attrname ( $self->_standard_keys ) {
254 if ( exists $args{$attrname} ) {
255 $self->{$attrname} = $args{$attrname};
256 }
257 elsif ($caller_is_obj) {
258 $self->{$attrname} = $caller->{$attrname};
259 }
260 else {
261 $self->{$attrname} = $self->_default_for($attrname);
262 }
263 }
264 $self->Connections( [] ); # initialize;
265
266 do {
267 my ($central, $ontologyserver) = _getDefaultCentral();
268 $self->default_MOBY_server($central) if $central;
269 } unless $ENV{MOBY_SERVER};
270  
271 # if user has set up preferred servers, then use those by default
272  
273 $self->default_MOBY_server( $ENV{MOBY_SERVER} ) if $ENV{MOBY_SERVER};
274 $self->default_MOBY_uri( $ENV{MOBY_URI} ) if $ENV{MOBY_URI};
275 $self->default_MOBY_type( $ENV{MOBY_TYPE} ) if $ENV{MOBY_TYPE};
276 $self->default_MOBY_proxy( $ENV{MOBY_PROXY} ) if $ENV{MOBY_PROXY};
277 if ( $self->Registries ) {
278 my $regno = 0;
279 my %reg = %{ $self->Registries };
280 while ( my ( $name, $acc ) = each %reg ) {
281 $self->default_MOBY_servername($name); # set the current as the default... if there is only one, then it becomes default, which is nice! If ther eis more than one, then the person shold be explicitly calling one or the other anyway
282
283 $regno++; # count how many registries we have in total
284 my $url = $acc->{URL} ? $acc->{URL} : $self->default_MOBY_server;
285 my $uri = $acc->{URI} ? $acc->{URI} : $self->default_MOBY_uri;
286 my $type = $acc->{TYPE} ? $acc->{TYPE} : $self->default_MOBY_type;
287 my $proxy = $acc->{PROXY} ? $acc->{PROXY} : $self->default_MOBY_proxy;
288 $type ||= 'soap';
289 if ( lc($type) eq "get" ) {
290 push @{ $self->Connections }, [ $name, $type, $url ];
291 }
292 else {
293 my @soapargs;
294 if ($proxy) {
295 @soapargs = ( $url, proxy => [ 'http' => $proxy ], user_agent => $self->user_agent, );
296 }
297 else {
298 @soapargs = ($url);
299 }
300 push @{ $self->Connections },
301 [
302 $name, $type,
303 SOAP::Lite->proxy(@soapargs, agent=>$self->user_agent )->uri($uri)->on_fault(
304 sub {
305 my ( $soap, $res ) = @_;
306 die ref $res
307 ? ("\nConnection to MOBY Central at '$uri' died because:\n\t" . $res->faultstring)
308 : ("Failed with status:" . $soap->transport->status),
309 "\n ERROR ERROR ERROR\n";
310 }
311 )
312 ];
313 }
314 } # Done iterating over multiple registries
315 $self->multiple_registries( $regno - 1 )
316 ; # one is not "multiple", it is just a change in default -> set to "false" if only one
317 }
318 else { # no registries specified
319 $self->multiple_registries(0);
320 if ( lc( $self->default_MOBY_type ) eq "get" ) {
321 push @{ $self->Connections },
322 [
323 $self->default_MOBY_servername, $self->default_MOBY_type,
324 $self->default_MOBY_server
325 ];
326 }
327 else {
328 $self->Registries(
329 {
330 $self->default_MOBY_servername => {
331 URL => $self->default_MOBY_server,
332 URI => $self->default_MOBY_uri
333 }
334 }
335 );
336 my @soapargs;
337 if ( $self->default_MOBY_proxy ) {
338 @soapargs = (
339 $self->default_MOBY_server,
340 proxy => [ 'http' => $self->default_MOBY_proxy ]
341 );
342 }
343 else {
344 @soapargs = ( $self->default_MOBY_server );
345 }
346 push @{ $self->Connections },
347 [
348 $self->default_MOBY_servername,
349 $self->default_MOBY_type,
350 SOAP::Lite->proxy(@soapargs, agent=>$self->user_agent )->uri( $self->default_MOBY_uri )
351 ->on_fault(
352 sub {
353 my ( $soap, $res ) = @_;
354 die ref $res
355 ? ("\nConnection to default MOBY Central died because:\n\t" . $res->faultstring)
356 : ("Failed with status:" . $soap->transport->status),
357 "\n ERROR ERROR ERROR\n";
358 }
359 )
360 ];
361 }
362 }
363 return undef unless $self->Connection(); # gotta have at least one...
364 return $self;
365 }
366  
367  
368 sub _getDefaultCentral {
369  
370 use LWP::UserAgent;
371 use HTTP::Request::Common qw(HEAD);
372
373 my $ua = LWP::UserAgent->new;
374 my $req = HEAD 'http://biomoby.org/mobycentral';
375 my $res = $ua->simple_request($req);
376 my $mobycentral = $res->header('location');
377
378 $req = HEAD 'http://biomoby.org/ontologyserver';
379 $res = $ua->simple_request($req);
380 my $ontologyserver = $res->header('location');
381 return ($mobycentral, $ontologyserver);
382 }
383  
384 =head2 registerObject a.k.a registerObjectClass
385  
386 Usage : $REG = $MOBY->registerObject(%args)
387 Usage : $REG = $MOBY->registerObjectClass(%args)
388 Function : register a new type of MOBY Object
389 Returns : MOBY::Registration object
390 Args : objectType => "the name of the Object"
391 description => "a human-readable description of the object"
392 contactEmail => "your@email.address"
393 authURI => "URI of the registrar of this object"
394 Relationships => {
395 relationshipType1 => [
396 {object => Object1,
397 articleName => ArticleName1},
398 {object => Object2,
399 articleName => ArticleName2}
400 ],
401 relationshipType2 => [
402 {object => Object3,
403 articleName => ArticleName3}
404 ]
405 }
406  
407 =cut
408  
409 sub registerObjectClass {
410 my ( $self, %a ) = @_;
411 return $self->registerObject(%a);
412 }
413  
414 sub registerObject {
415 my ( $self, %a ) = @_;
416 return $self->errorRegXML(
417 "Function not allowed when querying multiple registries")
418 if $self->multiple_registries;
419 return $self->errorRegXML(
420 "Contact email address (contactEmail parameter) is required for object registration"
421 )
422 if ( !$a{contactEmail} );
423 my $term = $a{'objectType'} || "";
424 my $desc = $a{'description'} || "";
425 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
426 $desc = $1;
427 }
428 my $contactEmail = $a{'contactEmail'} || "";
429 my $authURI = $a{'authURI'} || "";
430 my %Relationships = %{ $a{'Relationships'} };
431 my $clobber = $a{'Clobber'} ? $a{'Clobber'} : 0;
432 my $message = "<registerObjectClass>
433 <objectType>$term</objectType>
434 <Description><![CDATA[$desc]]></Description>
435 <authURI>$authURI</authURI>
436 <contactEmail>$contactEmail</contactEmail>
437 <Clobber>$clobber</Clobber>\n";
438  
439 while ( my ( $type, $objlistref ) = each %Relationships ) {
440 $message .= "<Relationship relationshipType='$type'>\n";
441 foreach my $objnamepair ( @{$objlistref} ) {
442 my $object = $objnamepair->{object};
443 my $article = $objnamepair->{articleName};
444 return $self->errorRegXML(
445 "Object name missing from one of your $type relationships")
446 unless ($object);
447 $article ||= "";
448 $message .=
449 "<objectType articleName='$article'>$object</objectType>\n";
450 }
451 $message .= "</Relationship>\n";
452 }
453 $message .= "</registerObjectClass>";
454  
455 # my $return = $self->SOAP_connection->call(registerObjectClass => ($message))->paramsall;
456 my ($return) = $self->_call( 'default', 'registerObjectClass', $message );
457 return ( $self->parseRegXML($return) );
458 }
459  
460 =head2 deregisterObject a.k.a. deregisterObjectClass
461  
462 Usage : $REG = $MOBY->deregisterObject(%args)
463 Usage : $REG = $MOBY->deregisterObjectClass(%args)
464 Function : deregister a MOBY Object
465 Returns : MOBY::Registration object
466 Args : objectType => $objectName (from Object ontology)
467  
468  
469 =cut
470  
471 sub deregisterObjectClass {
472 my ( $self, %a ) = @_;
473 return $self->deregisterObject(%a);
474 }
475  
476 sub deregisterObject {
477 my ( $self, %a ) = @_;
478 return $self->errorRegXML(
479 "Function not allowed when querying multiple registries")
480 if $self->multiple_registries;
481 my $id = $a{'objectType'} || "";
482 my $message = "
483 <deregisterObjectClass>
484 <objectType>$id</objectType>
485 </deregisterObjectClass>";
486  
487 # my $return = $self->SOAP_connection->call(deregisterObjectClass => ($message))->paramsall;
488 my ($return) = $self->_call( 'default', 'deregisterObjectClass', $message );
489 return ( $self->parseRegXML($return) );
490 }
491  
492  
493  
494 =head2 registerServiceType
495  
496 Usage : $REG = $MOBY->registerServiceType(%args)
497 Function : register a new MOBY Service type
498 Returns : MOBY::Registration object
499 Args : serviceType => $serviceType
500 description => "human readable description"
501 Relationships => {$relationshipType1 => \@services,
502 $relationshipType2 => \@services}
503 contactEmail => "your@email.address.here"
504 authURI => "your.authority.info"
505  
506 =cut
507  
508 sub registerServiceType {
509 my ( $self, %a ) = @_;
510 return $self->errorRegXML(
511 "Function not allowed when querying multiple registries")
512 if $self->multiple_registries;
513 my $type = $a{'serviceType'} || "";
514 my $desc = $a{'description'};
515 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
516 $desc = $1;
517 }
518 $desc ||= "";
519 my $email = $a{'contactEmail'} || "";
520 my $auth = $a{'authURI'} || "";
521 my %Relationships = %{ $a{'Relationships'} };
522 my $message = "
523 <registerServiceType>
524 <serviceType>$type</serviceType>
525 <Description><![CDATA[$desc]]></Description>
526 <contactEmail>$email</contactEmail>
527 <authURI>$auth</authURI>\n";
528  
529 while ( my ( $type, $servlistref ) = each %Relationships ) {
530 $message .= "<Relationship relationshipType='$type'>\n";
531 foreach my $servicetype ( @{$servlistref} ) {
532 $message .= "<serviceType>$servicetype</serviceType>\n";
533 }
534 $message .= "</Relationship>\n";
535 }
536 $message .= "</registerServiceType>";
537  
538 # my $return = $self->SOAP_connection->call(registerServiceType => ($message))->paramsall;
539 my ($return) = $self->_call( 'default', 'registerServiceType', $message );
540 return ( $self->parseRegXML($return) );
541 }
542  
543 =head2 deregisterServiceType
544  
545 Usage : $REG = $MOBY->deregisterServiceType(%args)
546 Function : deregister a deprecated MOBY Service Type
547 Returns : MOBY::Registration object
548 Args : serviceType => $serviceType (from ontology)
549  
550  
551 =cut
552  
553 sub deregisterServiceType {
554 my ( $self, %a ) = @_;
555 return $self->errorRegXML(
556 "Function not allowed when querying multiple registries")
557 if $self->multiple_registries;
558 my $id = $a{'serviceType'} || "";
559 my $message = "
560 <deregisterServiceType>
561 <serviceType>$id</serviceType>
562 </deregisterServiceType>";
563  
564 # my $return = $self->SOAP_connection->call(deregisterServiceType => ($message))->paramsall;
565 my ($return) = $self->_call( 'default', 'deregisterServiceType', $message );
566 return ( $self->parseRegXML($return) );
567 }
568  
569 =head2 registerNamespace
570  
571 Usage : $REG = $MOBY->registerNamespace(%args)
572 Function : register a new Namespace
573 Returns : MOBY::Registration object
574 Args : namespaceType => $namespaceType (required)
575 authURI => your.authority.URI (required)
576 description => "human readable description of namespace" (required)
577 contactEmail => "your@address.here" (required)
578  
579  
580 =cut
581  
582 sub registerNamespace {
583 my ( $self, %a ) = @_;
584 return $self->errorRegXML(
585 "Function not allowed when querying multiple registries")
586 if $self->multiple_registries;
587 my $type = $a{'namespaceType'} || "";
588 my $authURI = $a{'authURI'} || "";
589 my $desc = $a{'description'};
590 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
591 $desc = $1;
592 }
593 $desc ||= "";
594 my $contact = $a{'contactEmail'} || "";
595 my $message = "
596 <registerNamespace>
597 <namespaceType>$type</namespaceType>
598 <Description><![CDATA[$desc]]></Description>
599 <authURI>$authURI</authURI>
600 <contactEmail>$contact</contactEmail>
601 </registerNamespace>";
602  
603 # my $return = $self->SOAP_connection->call(registerNamespace => ($message))->paramsall;
604 my ($return) = $self->_call( 'default', 'registerNamespace', $message );
605 return ( $self->parseRegXML($return) );
606 }
607  
608 =head2 deregisterNamespace
609  
610 Usage : $REG = $MOBY->deregisterNamespace(%args)
611 Function : deregister a deprecated MOBY Namespace
612 Returns : MOBY::Registration object
613 Args : namespaceType => $mynamespaceType (from ontology)
614  
615  
616 =cut
617  
618 sub deregisterNamespace {
619 my ( $self, %a ) = @_;
620 return $self->errorRegXML(
621 "Function not allowed when querying multiple registries")
622 if $self->multiple_registries;
623 my $id = $a{'namespaceType'} || "";
624 my $message = "
625 <deregisterNamespace>
626 <namespaceType>$id</namespaceType>
627 </deregisterNamespace>";
628  
629 # my $return = $self->SOAP_connection->call(deregisterNamespace => ($message))->paramsall;
630 my ($return) = $self->_call( 'default', 'deregisterNamespace', $message );
631 return ( $self->parseRegXML($return) );
632 }
633  
634 =head2 registerService
635  
636 Usage : $REG = $MOBY->registerService(%args)
637 Function : register a new MOBY Service instance
638 Returns : MOBY::Registration object
639 Common Required Args :
640  
641 serviceName => $serviceName,
642 serviceType => $serviceType,
643 authURI => $authURI,
644 contactEmail => "your@mail.address",
645 description => $human_readable_description,
646 category => "moby" | "cgi-async" | "cgi" | "moby-async" | "doc-literal" | "doc-literal-async"
647 URL => $URL_TO_SERVICE (or URL to WSDL document for wsdl-type services)
648  
649 input: listref; (articleName may be undef)
650 input =>[
651 [articleName1,[objType1 => \@namespaces]], # Simple
652 [articleName2, [[objType2 => \@namespaces]]], # collection of one object type
653 [articleName3,[[objType3 => \@namespaces],
654 [objType4 => \@namespaces]]] # collection of multiple object types
655 ]
656  
657  
658 output: listref; (articleName may be undef)
659 output =>[
660 [articleName1,[objType1 => \@namespaces]], # Simple
661 [articleName2,[[objType2 => \@namespaces]]], # collection of one object type
662 [articleName3,[[objType3 => \@namespaces],
663 [objType4 => \@namespaces]]] # collection of multiple object types
664 ]
665  
666 secondary: hashref
667 secondary => {parametername1 => {
668 datatype => TYPE,
669 description => "cutoff value",
670 default => DEFAULT,
671 max => MAX,
672 min => MIN,
673 enum => [one, two]},
674 parametername2 => {
675 datatype => TYPE,
676 description => "e-value",
677 default => DEFAULT,
678 max => MAX,
679 min => MIN,
680 enum => [one, two]}
681 }
682  
683  
684  
685 =cut
686  
687 sub registerService {
688 my ( $self, %a ) = @_;
689 return $self->errorRegXML(
690 "Function not allowed when querying multiple registries")
691 if $self->multiple_registries;
692 my $name = $a{serviceName} || "";
693 my $type = $a{serviceType} || "";
694 my $authURI = $a{authURI} || "";
695 my $email = $a{contactEmail} || "";
696 my $URL = $a{URL} || "";
697 my $desc = $a{description} || "";
698  
699 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
700 $desc = $1;
701 }
702 #TODO ensure that sigURL and URL are valid urls
703 # ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))? <- matches any uri
704 # ^((([^:/?#]+):)?(//)?[\w]+\.[\w](\.[w])*((\/|\.)?[\w]+)*)$ <- my version
705 my $signatureURL = $a{signatureURL} || "";
706 my $Category = lc( $a{category} );
707 chomp $Category;
708 $Category ||= "";
709  
710 #____________call RDFagent__________________________________________________
711 if ( $signatureURL ne "" ) {
712 my $ch = 0;
713 my $sign_req;
714 foreach $sign_req ( $name, $type, $authURI, $email, $URL, $desc,
715 $Category )
716 {
717 if ( $sign_req ne "" ) {
718 $ch = 1;
719  
720 }
721 }
722 if ( $ch == 0 ) {
723 # print "call Agent\n";
724 my $message = "
725 <registerService>
726 <Category></Category>
727 <serviceName></serviceName>
728 <serviceType></serviceType>
729 <Description></Description>
730 <signatureURL>$signatureURL</signatureURL>
731 <URL></URL>
732 <authURI></authURI>
733 <contactEmail></contactEmail>
734 </registerService>";
735 my ($return) =
736 $self->_call( 'default', 'registerService', $message );
737 return ( $self->parseRegXML($return) );
738  
739 }
740 }
741  
742 #____________________________________________________________________________________________
743 return $self->errorRegXML(
744 "Only 'moby', 'cgi', 'cgi-async', 'moby-async', 'doc-literal', 'doc-literal-async' Service Categories are currently allowed - you gave me $Category"
745 )
746 unless ( ( $Category eq 'moby' )
747 || ( $Category eq 'moby-async' )
748 || ( $Category eq 'cgi-async' )
749 || ( $Category eq 'doc-literal' )
750 || ( $Category eq 'doc-literal-async' )
751 || ( $Category eq 'cgi' ));
752 return $self->errorRegXML(
753 "All Fields Required: serviceName, serviceType, authURI, contactEmail, URL, description, Category, input, output, secondary"
754 )
755 unless ( $name
756 && $type
757 && $authURI
758 && $email
759 && $URL
760 && $desc
761 && $Category );
762 my $message = "
763 <registerService>
764 <Category>$Category</Category>
765 <serviceName>$name</serviceName>
766 <serviceType>$type</serviceType>
767 <Description><![CDATA[$desc]]></Description>
768 <signatureURL>$signatureURL</signatureURL>
769 <URL>$URL</URL>
770 <authURI>$authURI</authURI>
771 <contactEmail>$email</contactEmail>";
772  
773  
774 my %SEC;
775 if ( $a{'secondary'} && ( ref( $a{'secondary'} ) eq 'HASH' ) ) {
776 %SEC = %{ $a{secondary} };
777 }
778 elsif ( $a{'secondary'} && ( ref( $a{'secondary'} ) ne 'HASH' ) ) {
779 return $self->errorRegXML(
780 "invalid structure of secondary parameters. Expected hashref."
781 );
782 }
783 my %funkyhash = ( Input => $a{input}, Output => $a{output} );
784 while ( my ( $inout, $param ) = each %funkyhash ) {
785 my $inout_lc = lc($inout);
786 my @ALLARTICLES = @{$param};
787 $message .= "<${inout_lc}Objects><${inout}>\n";
788  
789 # input =>[
790 # [articleName1,[objType1 => \@namespaces]], # Simple
791 # [articleName2, [[objType2 => \@namespaces]]], # collection of one object type
792 # [articleName3,[[objType3 => \@namespaces],
793 # [objType4 => \@namespaces]]] # collection of multiple object types (THIS IS NOW ILLEGAL!)
794 # ]
795 foreach my $article (@ALLARTICLES) {
796 my ( $articleName, $def ) = @{$article};
797 $articleName ||= "";
798 my @Objects; #
799 unless ( ref($def) eq 'ARRAY') { # $def = [objType => \@ns] or $def=[[objType => \@ns]]
800 return $self->errorRegXML("invalid structure of $inout objects, expected SINGLE arrayref for article $articleName as required by the 0.86 API");
801 }
802 my @objectdefs;
803 if ( ( ref $def->[0] ) eq 'ARRAY' ) { # collection $def->[0] = [objType => \@ns]
804 # def= [[objType2 => [ns3, ns4...]], ...]
805 $message .= "<Collection articleName='$articleName'>\n";
806 if (scalar(@{$def->[0]} > 2)){
807 return $self->errorRegXML("invalid structure of $inout objects. Collections may not have more than one Simple content type as per API version 0.86");
808 }
809 @objectdefs = @{$def};
810 if (scalar(@objectdefs) > 1){
811 return $self->errorRegXML("invalid structure of $inout objects. Collections may not have more than one Simple content type as per API version 0.86");
812 }
813 } else { # Simple $def->[0] = objType
814 # def = [objType1 => [ns1, ns2...]],
815 @objectdefs = ($def);
816 }
817 foreach my $objectdef (@objectdefs) {
818 if ( ref( $def->[0] ) eq 'ARRAY' ) {
819 $message .= "<Simple>\n";
820 }
821 else {
822 $message .= "<Simple articleName='$articleName'>\n";
823 }
824 my ( $type, $Namespaces ) = @{$objectdef};
825 $type ||= "";
826 $message .= "<objectType>$type</objectType>\n";
827 unless ( ref($Namespaces) eq 'ARRAY' ) {
828 return $self->errorRegXML(
829 "invalid structure of $inout namespaces for object $type in article $articleName; expected arrayref"
830 );
831 }
832 foreach my $ns ( @{$Namespaces} ) {
833 $message .= "<Namespace>$ns</Namespace>\n";
834 }
835 $message .= "</Simple>\n";
836 }
837 if ( ref( $def->[0] ) eq 'ARRAY' ) {
838 $message .= "</Collection>\n";
839 }
840 }
841 $message .= "</${inout}></${inout_lc}Objects>\n";
842 }
843  
844 # secondary => {parametername1 => {datatype => TYPE,
845 # default => DEFAULT,
846 # max => MAX,
847 # min => MIN,
848 # enum => [one, two]},
849 # parametername2 => {datatype => TYPE,
850 # default => DEFAULT,
851 # max => MAX,
852 # min => MIN,
853 # enum => [one, two]}
854 # }
855 #
856 $message .= "<secondaryArticles>\n";
857 while ( my ( $param, $desc ) = each %SEC ) {
858 unless ( ref($desc) eq 'HASH' ) {
859 return $self->errorRegXML( "invalid structure of secondary article $param; expected hashref of limitations"
860 );
861 }
862 my %data = %{$desc};
863 my $default = defined($data{default})?$data{default}:"";
864 my $max = defined($data{max})?$data{max}:"";
865 my $min = defined($data{min})?$data{min}:"";
866 my $descr = defined($data{description})?$data{description}:"";
867 my $datatype = $data{datatype} || "";
868 my $enums = $data{enum} || [];
869 unless ($datatype) {
870 return $self->errorRegXML("a secondaryArticle must contain at least a datatype value in secondary article $param"
871 );
872 }
873 unless ( $datatype =~ /Integer|Float|String|DateTime|Boolean/ )
874 {
875 return $self->errorRegXML("a secondaryArticle must have a datatype of Integer, Float, String, Boolean or DateTime"
876 );
877 }
878 unless ( ref($enums) eq 'ARRAY' ) {
879 return $self->errorRegXML("invalid structure of enum limits in secondary article $param; expected arrayref"
880 );
881 }
882 my @enums = @{$enums};
883 $message .= "<Parameter articleName='$param'>\n";
884 $message .= "<default>$default</default>\n";
885 $message .= "<description>$descr</description>\n";
886 $message .= "<datatype>$datatype</datatype>\n";
887 $message .= "<max>$max</max>\n";
888 $message .= "<min>$min</min>\n";
889 foreach (@enums) {
890 $message .= "<enum>$_</enum>\n";
891 }
892 $message .= "</Parameter>\n";
893 }
894 $message .= "</secondaryArticles>\n";
895 $message .= "</registerService>";
896  
897  
898 $debug && &_LOG(" message\n\n$message\n\n");
899  
900 my ($return) = $self->_call( 'default', 'registerService', $message );
901  
902 #_______call a new version RDFbuilder (by Eddie Kawas) _________________________________________
903 my $reg = $self->parseRegXML($return);
904
905 return $reg;
906  
907 #_______________________________________________________________________________________________
908  
909 }
910  
911 =head2 registerServiceWSDL
912  
913 Usage : Needs documentation
914  
915 =cut
916  
917 sub registerServiceWSDL {
918 my ( $self, %a ) = @_;
919 return $self->errorRegXML(
920 "Function not allowed when querying multiple registries")
921 if $self->multiple_registries;
922 my $message = "";
923  
924 # my $return = $self->SOAP_connection->call(registerServiceWSDL => ($message))->paramsall;
925 my ($return) = $self->_call( 'default', 'registerServiceWSDL', $message );
926  
927 return ( $self->parseRegXML($return) );
928 }
929  
930 =head2 deregisterService
931  
932 Usage : $REG = $MOBY->deregisterService(%args)
933 Function : deregister a registered MOBY Service
934 Returns : MOBY::Registration object
935 Args : serviceName => $serviceID, authURI => $authority
936  
937  
938 =cut
939  
940 sub deregisterService {
941 my ( $self, %a ) = @_;
942 return $self->errorRegXML(
943 "Function not allowed when querying multiple registries")
944 if $self->multiple_registries;
945 my $name = $a{'serviceName'};
946 my $auth = $a{'authURI'};
947 ( defined($name) && defined($auth) ) || return (
948 &parseRegXML( "
949 <MOBYRegistration>
950 <id></id>
951 <success>0</success>
952 <message><![CDATA[you did not pass a valid service Identifier]]></message>
953 </MOBYRegistration>" )
954 );
955 my $message = "
956 <deregisterService>
957 <serviceName>$name</serviceName>
958 <authURI>$auth</authURI>
959 </deregisterService>";
960  
961 # my $return = $self->SOAP_connection->call(deregisterService => ($message))->paramsall;
962 my ($return) = $self->_call( 'default', 'deregisterService', $message );
963 return ( $self->parseRegXML($return) );
964 }
965  
966 =head2 findService
967  
968 Usage : ($ServiceInstances, $RegObject) = $MOBY->findService(%args)
969 Function : Find services that match certain search criterion
970 Returns : ON SUCCESS: arrayref of MOBY::Client::ServiceInstance objects, and undef
971 ON FAILURE: undef, and a MOBY::Registration object indicating the reason for failure
972 Args :
973 Registry => which registry do you want to search (optional)
974 serviceName => $serviceName, (optional)
975 serviceType => $serviceType, (optional)
976 authURI => $authURI, (optional)
977 authoritative => 1, (optional)
978 category => "moby" | "cgi" | "moby-async" (optional)
979 expandObjects => 1, (optional)
980 expandServices => 1, (optional)
981 URL => $URL_TO_SERVICE (optional)
982 keywords => [kw1, kw2, kw3] (optional)
983 input =>[ (optional)
984 [objType1 => [ns1, ns2...]], # Simple
985 [[objType2 => [ns3, ns4...]]], # collection of one object type
986 [[objType3 => [ns3, ns4...]],
987 [objType4 => [ns5, ns6...]]], # collection of multiple object types
988 ]
989 output =>[ (optional)
990 [objType1 => [ns1, ns2...]], # Simple
991 [[objType2 => [ns3, ns4...]]], # collection of one object type
992 [[objType3 => [ns3, ns4...]],
993 [objType4 => [ns5, ns6...]]], # collection of multiple object types
994 ]
995  
996  
997 =cut
998  
999 sub findService {
1000 my ( $self, %a ) = @_;
1001 my $reg = ( $a{Registry} ) ? $a{Registry} : $self->default_MOBY_servername;
1002 my $id = $a{'serviceID'};
1003 my $servicename = $a{'serviceName'} || "";
1004 my $authoritative = $a{'authoritative'} || "";
1005 my $serviceType = $a{'serviceType'} || "";
1006 my $authURI = $a{'authURI'} || "";
1007 my $category = $a{'category'} || "";
1008 my $exObj = $a{'expandObjects'} || 0;
1009 my $exServ = $a{'expandServices'} || 0;
1010 my $kw = $a{'keywords'} || [];
1011 ref($kw) eq 'ARRAY' || return (
1012 undef,
1013 $self->errorRegXML(
1014 "invalid structure of keywords. Expected arrayref"
1015 )
1016 );
1017 my @kw = @{$kw};
1018 my $message = "<findService>\n";
1019 defined($authoritative)
1020 && ( $message .= "<authoritative>$authoritative</authoritative>\n" );
1021 $category && ( $message .= "<Category>$category</Category>\n" );
1022 $serviceType && ( $message .= "<serviceType>$serviceType</serviceType>\n" );
1023 $servicename && ( $message .= "<serviceName>$servicename</serviceName>\n" );
1024 $authURI && ( $message .= "<authURI>$authURI</authURI>\n" );
1025 defined($exObj)
1026 && ( $message .= "<expandObjects>$exObj</expandObjects> \n" );
1027 defined($exServ)
1028 && ( $message .= "<expandServices>$exServ</expandServices>\n" );
1029  
1030 if ( scalar(@kw) ) {
1031 $message .= " <keywords>\n";
1032 foreach my $kwd (@kw) {
1033 $message .= "<keyword>$kwd</keyword>\n";
1034 }
1035 $message .= "</keywords>\n";
1036 }
1037  
1038 #$a{input} = [[]] unless (defined $a{input});
1039 #$a{output} = [[]] unless (defined $a{output});
1040 if ( defined $a{input} && ( ref( $a{input} ) ne 'ARRAY' ) ) {
1041 return (
1042 undef,
1043 $self->errorRegXML(
1044 "invalid structure of input objects, expected arrayref for input"
1045 )
1046 );
1047 }
1048 if ( defined $a{output} && ( ref( $a{output} ) ne 'ARRAY' ) ) {
1049 return (
1050 undef,
1051 $self->errorRegXML(
1052 "invalid structure of output objects, expected arrayref for output"
1053 )
1054 );
1055 }
1056 my %funkyhash;
1057 $funkyhash{Input} = $a{input} if ( defined $a{input} );
1058 $funkyhash{Output} = $a{output} if ( defined $a{output} );
1059  
1060 #input =>[
1061 # [objType1 => [ns1, ns2...]], # Simple
1062 # [[objType2 => [ns3, ns4...]]], # collection of one object type
1063 # [[objType3 => [ns3, ns4...]],
1064 # [objType4 => [ns5, ns6...]]], # collection of multiple object types
1065 # ]
1066 while ( my ( $inout, $param ) = each %funkyhash ) {
1067 die "no inout parameter from teh funkyhash" unless defined $inout;
1068 die "no param parameter from teh funkyhash" unless defined $param;
1069 die "param parameter should be a listref"
1070 unless ( ref($param) eq 'ARRAY' );
1071 my $inout_lc = lc($inout);
1072 my @PARAM = @{$param};
1073 $message .= "<${inout_lc}Objects><${inout}>\n";
1074 foreach my $param (@PARAM) {
1075 unless ( ref($param) eq 'ARRAY' ) {
1076 return (
1077 undef,
1078 $self->errorRegXML(
1079 "invalid structure of $inout objects, expected arrayref of class and \@namespaces"
1080 )
1081 );
1082 }
1083 my ( $class, $namespaces ) = @{$param};
1084 die "no class part of param " unless defined $class;
1085  
1086 #warn "no namespace part of the param" unless defined $namespaces;
1087 my @objectdefs;
1088 if ( ref $class eq 'ARRAY' ) { # collection
1089 $message .= "<Collection>\n";
1090 @objectdefs = $class;
1091 }
1092 else { # Nipple
1093 @objectdefs = ($param);
1094 }
1095 foreach my $objectdef (@objectdefs) {
1096 $message .= "<Simple>\n";
1097 my ( $type, $Namespaces ) = @{$objectdef};
1098 die "type is missing from objectdef " unless $type;
1099 $message .= "<objectType>$type</objectType>\n";
1100 if ( defined($Namespaces)
1101 && ( ref($Namespaces) ne 'ARRAY' ) )
1102 {
1103 return (
1104 undef,
1105 $self->errorRegXML(
1106 "invalid structure of $inout namespaces for object $type; expected arrayref"
1107 )
1108 );
1109 }
1110 foreach my $ns ( @{$Namespaces} ) {
1111 next unless $ns;
1112 $message .= "<Namespace>$ns</Namespace>\n";
1113 }
1114 $message .= "</Simple>\n";
1115 }
1116 if ( ref($class) eq 'ARRAY' ) {
1117 $message .= "</Collection>\n";
1118 }
1119 }
1120 $message .= "</${inout}></${inout_lc}Objects>\n";
1121 }
1122 $message .= "</findService>\n";
1123  
1124 # my $return = $self->SOAP_connection($reg)->call('findService' => ($message))->paramsall;
1125 my ($return) = $self->_call( $reg, 'findService', $message );
1126 return ( $self->_parseServices( $reg, $return ), undef );
1127 }
1128  
1129 =head2 retrieveService
1130
1131 Usage : $WSDL = $MOBY->retrieveService($ServiceInstance)
1132 Function : get the WSDL definition of the service with this name/authority URI
1133 Returns : a WSDL string
1134 Args : The ServiceInstance object for that service (from findService call)
1135  
1136 =cut
1137  
1138 sub retrieveService {
1139 my ( $self, $SI ) = @_;
1140 return undef unless $SI && $SI->isa('MOBY::Client::ServiceInstance');
1141 my $auth = $SI->authority;
1142 my $name = $SI->name;
1143 my $reg = $SI->registry;
1144 return undef unless ( $auth && $name && $self->Connection($reg) );
1145 my $message = "
1146 <retrieveService>
1147 " . ( $SI->XML ) . "
1148 </retrieveService>";
1149  
1150 my ($return) = $self->_call( $reg, 'retrieveService', $message );
1151 my $parser = XML::LibXML->new();
1152 my $doc = $parser->parse_string($return);
1153 my $de = $doc->getDocumentElement;
1154 my @child = $de->childNodes;
1155 my $content;
1156 foreach (@child) {
1157 $debug && &_LOG( getNodeTypeName($_), "\t", $_->toString, "\n" );
1158 if ( $_->nodeType == TEXT_NODE ) {
1159 $content .= $_->nodeValue; #else try $_->textContent
1160 }
1161 else {
1162 $content .= $_->toString;
1163 }
1164 }
1165 $content =~ s/^\n//gs;
1166 $content =~ s/<!\[CDATA\[((?>[^\]]+))\]\]>/$1/gs;
1167  
1168 return $content;
1169 }
1170  
1171  
1172 =head2 retrieveResourceURLs
1173  
1174 Usage : $names = $MOBY->retrieveResourceURLs()
1175 Function : get a hash of the URL's for each of the MOBY ontologies
1176 Returns : hashref to the following hash
1177 $names{Ontology} = [URL1, URL2,...]
1178 Args : none
1179  
1180 =cut
1181  
1182 sub retrieveResourceURLs {
1183 my ($self, %args) = shift;
1184 my $reg = $args{registry};
1185 $reg = $reg ? $reg : $self->default_MOBY_servername;
1186 return undef unless ( $self->Connection($reg) );
1187 my ($return) = $self->_call( $reg, 'retrieveResourceURLs', "" );
1188 my $parser = XML::LibXML->new();
1189 my $doc = $parser->parse_string($return);
1190 my $root = $doc->getDocumentElement;
1191 my $urls_list = $root->childNodes;
1192 my %urls;
1193 for ( my $x = 1 ; $x <= $urls_list->size() ; $x++ ) {
1194 next unless $urls_list->get_node($x)->nodeType == ELEMENT_NODE;
1195 my $ontology = $urls_list->get_node($x)->getAttributeNode('name')->getValue;
1196 my $url = $urls_list->get_node($x)->getAttributeNode('url')->getValue;
1197 push @{ $urls{$ontology} }, $url
1198 }
1199 return \%urls;
1200 }
1201  
1202  
1203 =head2 retrieveServiceNames
1204  
1205 Usage : $names = $MOBY->retrieveServiceNames(%args)
1206 Function : get a (redundant) list of all registered service names
1207 (N.B. NOT service types!)
1208 Returns : hashref to the following hash
1209 $names{$AuthURI} = [serviceName_1, serviceName_2, serviceName3...]
1210 Args : registry => $reg_name: name of registry you wish to retrieve from (optional)
1211 as_lsid => $boolean: return service names as their corresponding LSID's (default off)
1212  
1213 =cut
1214  
1215 sub retrieveServiceNames {
1216 my ($self, %args) = @_;
1217 my $reg = $args{registry};
1218 my $aslsid = $args{as_lsid};
1219
1220 $reg = $reg ? $reg : $self->default_MOBY_servername;
1221 return undef unless ( $self->Connection($reg) );
1222  
1223 # my $return = $self->SOAP_connection($reg)->call('retrieveServiceNames' => (@_))->paramsall;
1224 my ($return) = $self->_call( $reg, 'retrieveServiceNames', "" );
1225 my $parser = XML::LibXML->new();
1226 my $doc = $parser->parse_string($return);
1227 my $root = $doc->getDocumentElement;
1228 my $names_list = $root->childNodes;
1229 my %servicenames;
1230 for ( my $x = 1 ; $x <= $names_list->size() ; $x++ ) {
1231 next unless $names_list->get_node($x)->nodeType == ELEMENT_NODE;
1232 my $name =
1233 $names_list->get_node($x)->getAttributeNode('name')->getValue;
1234 my $auth =
1235 $names_list->get_node($x)->getAttributeNode('authURI')->getValue;
1236 my $lsid = $names_list->get_node($x)->getAttributeNode('lsid');
1237 if ($lsid){
1238 $lsid = $lsid->getValue;
1239 } else {
1240 $lsid = $name;
1241 }
1242 $lsid ||=$name;
1243 push @{ $servicenames{$auth} }, $aslsid?$lsid:$name;
1244 }
1245 return \%servicenames;
1246 }
1247  
1248 =head2 retrieveServiceProviders
1249  
1250 Usage : @URIs = $MOBY->retrieveServiceProviders([$reg_name])
1251 Function : get the list of all provider's AuthURI's
1252 Returns : list of service provider URI strings
1253 Args : $reg_name: name of registry you wish to retrieve from (optional)
1254  
1255 =cut
1256  
1257 sub retrieveServiceProviders {
1258 my ($self) = shift;
1259 my $reg = shift;
1260 $reg = $reg ? $reg : $self->default_MOBY_servername;
1261 return undef unless ( $self->Connection($reg) );
1262  
1263 # my $return = $self->SOAP_connection($reg)->call('retrieveServiceProviders' => (@_))->paramsall;
1264 my ($return) = $self->_call( $reg, 'retrieveServiceProviders', "" );
1265 my $parser = XML::LibXML->new();
1266 my $doc = $parser->parse_string($return);
1267 my $root = $doc->getDocumentElement;
1268 my $providers = $root->childNodes;
1269 my @serviceproviders;
1270 for ( my $x = 1 ; $x <= $providers->size() ; $x++ ) {
1271 next unless $providers->get_node($x)->nodeType == ELEMENT_NODE;
1272 push @serviceproviders,
1273 $providers->get_node($x)->getAttributeNode('name')->getValue;
1274 }
1275 return @serviceproviders;
1276 }
1277  
1278 =head2 retrieveServiceTypes
1279  
1280 Usage : $types = $MOBY->retrieveServiceTypes(%args)
1281 Function : get the list of all registered service types
1282 Returns : hashref of $types{$type} = $definition
1283 Args : registry => $reg_name: name of registry you wish to retrieve from (optional)
1284 as_lsid => $boolean: return the $type as its corresponding LSID (defualt off)
1285  
1286 =cut
1287  
1288 sub retrieveServiceTypes {
1289 my ($self, %args) = shift;
1290 my $reg = $args{registry};
1291 my $as_lsid = $args{as_lsid};
1292
1293 $reg = $reg ? $reg : $self->default_MOBY_servername;
1294 return undef unless ( $self->Connection($reg) );
1295  
1296 # my $return = $self->SOAP_connection($reg)->call('retrieveServiceTypes' => (@_))->paramsall;
1297 my ($return) = $self->_call( $reg, 'retrieveServiceTypes', "" );
1298 my $parser = XML::LibXML->new();
1299 my $doc = $parser->parse_string($return);
1300 my $root = $doc->getDocumentElement;
1301 my $types = $root->childNodes;
1302 my %servicetypes;
1303 for ( my $x = 1 ; $x <= $types->size() ; $x++ ) {
1304 next unless $types->get_node($x)->nodeType == ELEMENT_NODE;
1305 my $type = $types->get_node($x)->getAttributeNode('name')->getValue;
1306 my $lsid = $types->get_node($x)->getAttributeNode('lsid');
1307 if ($lsid){
1308 $lsid = $lsid->getValue;
1309 } else {
1310 $lsid = $type;
1311 }
1312 my $desc;
1313 for
1314 my $elem ( $types->get_node($x)->getElementsByTagName('Description') )
1315 {
1316 $desc = $elem->firstChild->toString;
1317 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1318 $desc = $1;
1319 }
1320 }
1321 $desc =~ s/<!\[CDATA\[((?>[^\]]+))\]\]>/$1/gs;
1322 $servicetypes{$as_lsid?$lsid:$type} = $desc;
1323 }
1324 return \%servicetypes;
1325 }
1326  
1327  
1328 =head2 retrieveServiceTypesFull
1329  
1330 Usage : $types = $MOBY->retrieveServiceTypesFull(%args)
1331 Function : get all details of all service types
1332 Returns : hashref of $types{$type} = {Description => "definition",
1333 authURI => "authority.uri.here",
1334 contactEmail => "email@addy.here",
1335 ISA => "parentType", # possibly empty string ""
1336 ISA_LSID => "urn:lsid...parentLSID"} # possibly empty string ""
1337 Args : registry => $reg_name: name of registry you wish to retrieve from (optional)
1338 as_lsid => $boolean: return the $type as its corresponding LSID (defualt off)
1339  
1340 =cut
1341  
1342  
1343 sub retrieveServiceTypesFull {
1344 my ($self, %args) = shift;
1345 my $reg = $args{registry};
1346 my $as_lsid = $args{as_lsid};
1347
1348 $reg = $reg ? $reg : $self->default_MOBY_servername;
1349 return undef unless ( $self->Connection($reg) );
1350  
1351 # my $return = $self->SOAP_connection($reg)->call('retrieveServiceTypes' => (@_))->paramsall;
1352 my ($return) = $self->_call( $reg, 'retrieveServiceTypes', "" );
1353 my $parser = XML::LibXML->new();
1354 my $doc = $parser->parse_string($return);
1355 my $root = $doc->getDocumentElement;
1356 my $types = $root->childNodes;
1357 my %servicetypes;
1358 for ( my $x = 1 ; $x <= $types->size() ; $x++ ) {
1359 next unless $types->get_node($x)->nodeType == ELEMENT_NODE;
1360 my $type = $types->get_node($x)->getAttributeNode('name')->getValue;
1361 my $lsid = $types->get_node($x)->getAttributeNode('lsid');
1362 if ($lsid){
1363 $lsid = $lsid->getValue;
1364 } else {
1365 $lsid = $type;
1366 }
1367 my ($desc, $auth, $email, $ISA, $ISA_LSID) = ("","","","","");
1368 for
1369 my $elem ( $types->get_node($x)->getElementsByTagName('Description') )
1370 {
1371 $desc = $elem->firstChild->toString;
1372 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1373 $desc = $1;
1374 }
1375 }
1376 for
1377 my $elem ( $types->get_node($x)->getElementsByTagName('authURI') )
1378 {
1379 $auth = $elem->firstChild->toString;
1380 if ( $auth =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1381 $auth = $1;
1382 }
1383 }
1384 for
1385 my $elem ( $types->get_node($x)->getElementsByTagName('contactEmail') )
1386 {
1387 $email = $elem->firstChild->toString;
1388 if ( $email =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1389 $email = $1;
1390 }
1391 }
1392 for
1393 my $elem ( $types->get_node($x)->getElementsByTagName('ISA') )
1394 {
1395 $ISA = $elem->firstChild;
1396 $ISA = $ISA?$ISA->toString:"";
1397 if ( $email =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1398 $email = $1;
1399 }
1400 $ISA_LSID = $elem->getAttributeNode('lsid')->getValue;
1401 }
1402  
1403 $desc =~ s/<!\[CDATA\[((?>[^\]]+))\]\]>/$1/gs; # somehow these CDATA elements are nested sometimes???
1404 $servicetypes{$as_lsid?$lsid:$type} = {Description => $desc, authURI => $auth, contactEmail => $email, ISA => $ISA, ISA_LSID => $ISA_LSID};
1405 }
1406 return \%servicetypes;
1407 }
1408  
1409  
1410 =head2 retrieveObjectNames
1411  
1412 Usage : $names = $MOBY->retrieveObjectNames(%args)
1413 Function : get the list of all registered Object types
1414 Returns : hashref of hash:
1415 $names{$name} = $definition
1416 Args : registry => $reg_name: name of registry you wish to retrieve from (optional)
1417 as_lsid => $boolean: return $name as its correspnding LSID (optional default off)
1418  
1419 =cut
1420  
1421 sub retrieveObjectNames {
1422 my ($self, %args) = @_;
1423 my $reg = $args{registry};
1424 my $as_lsid = $args{as_lsid};
1425 $reg = $reg ? $reg : $self->default_MOBY_servername;
1426 return undef unless ( $self->Connection($reg) );
1427 my ($return) = $self->_call( $reg, 'retrieveObjectNames', "" );
1428 my $parser = XML::LibXML->new();
1429 my $doc = $parser->parse_string($return);
1430 my $root = $doc->getDocumentElement;
1431 my $obnames = $root->childNodes;
1432 my %objectnames;
1433 for ( my $x = 1 ; $x <= $obnames->size() ; $x++ ) {
1434 next unless $obnames->get_node($x)->nodeType == ELEMENT_NODE;
1435 my $name = $obnames->get_node($x)->getAttributeNode('name')->getValue;
1436 my $lsid = $obnames->get_node($x)->getAttributeNode('lsid');
1437 if ($lsid){
1438 $lsid = $lsid->getValue;
1439 } else {
1440 $lsid = $name;
1441 }
1442 my $desc;
1443 for my $elem (
1444 $obnames->get_node($x)->getElementsByTagName('Description') )
1445 {
1446 $desc = $elem->firstChild->toString;
1447 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1448 $desc = $1;
1449 }
1450 }
1451 $desc =~ s/<!\[CDATA\[((?>[^\]]+))\]\]>/$1/gs;
1452 $objectnames{$as_lsid?$lsid:$name} = $desc;
1453 }
1454 return \%objectnames;
1455 }
1456  
1457  
1458 =head2 retrieveObjectDefinition
1459  
1460 Usage : $DEF = $MOBY->retrieveObjectDefinition(objectType => $objectType)
1461 Function : retrieve the $XML that was used to register an object and its relationships
1462 Returns : hashref, identical to the hash sent during Object registration, plus
1463 an additional XML hash key that contains the actual XML containing
1464 the object definition as sent by MOBY Central (used for a visual
1465 overview, rather than parsing all of the hash keys)
1466 objectType => "the name of the Object"
1467 objectLSID => "urn:lsid:..."
1468 description => "a human-readable description of the object"
1469 contactEmail => "your@email.address"
1470 authURI => "URI of the registrar of this object"
1471 Relationships => {
1472 relationshipType1 => [
1473 {object => Object1,
1474 articleName => ArticleName1,
1475 lsid => lsid1},
1476 {object => Object2,
1477 articleName => ArticleName2,
1478 lsid => lsid2}
1479 ],
1480 relationshipType2 => [
1481 {object => Object3,
1482 articleName => ArticleName3,
1483 lsid => lsid3}
1484 ]
1485 }
1486 XML => <....XML of object registration.../>
1487  
1488 Args : objectType => the name or LSID URI for an object
1489  
1490 =cut
1491  
1492 sub retrieveObjectDefinition {
1493 my ( $self, %a ) = @_;
1494 my $id = $a{objectType};
1495 return $self->errorRegXML(
1496 "Function not allowed when querying multiple registries")
1497 if $self->multiple_registries;
1498 my %def;
1499 return \%def unless $id;
1500 my $message = "
1501 <retrieveObjectDefinition>
1502 <objectType>$id</objectType>
1503 </retrieveObjectDefinition>";
1504 my ($return) =
1505 $self->_call( 'default', 'retrieveObjectDefinition', $message );
1506 return \%def unless $return;
1507 my ( $term, $lsid, $desc, $relationships, $email, $authURI ) =
1508 &_ObjectDefinitionPayload($return);
1509 $def{objectType} = $term;
1510 $def{objectLSID} = $lsid;
1511 $def{description} = $desc;
1512 $def{contactEmail} = $email;
1513 $def{authURI} = $authURI;
1514 $def{Relationships} = $relationships;
1515 $def{XML} = $return;
1516 return ( \%def );
1517 }
1518  
1519 sub _ObjectDefinitionPayload {
1520 my ($payload) = @_;
1521 my $Parser = XML::LibXML->new();
1522 my $doc = $Parser->parse_string($payload);
1523 my $Object = $doc->getDocumentElement();
1524 my $obj = $Object->nodeName;
1525 return undef unless ( $obj eq 'retrieveObjectDefinition' );
1526 my $term = &_nodeTextContent( $Object, "objectType" );
1527 my $lsid = &_nodeAttributeValue( $Object, "objectType", "lsid");
1528 my $desc = &_nodeCDATAContent( $Object, "Description" );
1529 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1530 $desc = $1;
1531 }
1532 my $authURI = &_nodeTextContent( $Object, "authURI" );
1533 my $email = &_nodeTextContent( $Object, "contactEmail" );
1534 my %att_value;
1535 my %relationships;
1536 my $x = $doc->getElementsByTagName("Relationship");
1537 my $no_relationships = $x->size();
1538 for ( my $n = 1 ; $n <= $no_relationships ; ++$n ) { #get_node starts at one
1539 my $relationshipType =
1540 $x->get_node($n)->getAttributeNode('relationshipType')
1541 ; # may or may not have a name
1542 if ($relationshipType) {
1543 $relationshipType = $relationshipType->getValue();
1544 }
1545 else {
1546 return
1547 "FAILED! must include a relationshipType in every relationship\n";
1548 }
1549 my @child = $x->get_node($n)->childNodes;
1550 foreach (@child) {
1551 next unless $_->nodeType == ELEMENT_NODE;
1552 my $article =
1553 $_->getAttributeNode('articleName'); # may or may not have a name
1554 my $rlsid =
1555 $_->getAttributeNode('lsid'); # may or may not have a name
1556 if ($article) { $article = $article->getValue() }
1557 if ($rlsid) { $rlsid = $rlsid->getValue() }
1558
1559 my @child2 = $_->childNodes;
1560 foreach (@child2) {
1561  
1562 #print getNodeTypeName($_), "\t", $_->toString,"\n";
1563 next unless $_->nodeType == TEXT_NODE;
1564 push @{ $relationships{$relationshipType} },
1565 { object => $_->toString,
1566 articleName => $article,
1567 lsid => $rlsid };
1568 }
1569 }
1570 }
1571 return ( $term, $lsid, $desc, \%relationships, $email, $authURI );
1572 }
1573  
1574  
1575  
1576 =head2 retrieveNamespaces
1577  
1578 Usage : $ns = $MOBY->retrieveNamespaces(%args)
1579 Function : get the list of all registered Namespace types
1580 Returns : hashref of hash:
1581 $ns{$namespace} = $definition
1582 Args : registry => $reg_name: name of registry you wish to retrieve from (optional)
1583 as_lsid => $boolean: retrieve $namespace as its corresponding LSID (default off)
1584  
1585 =cut
1586  
1587 sub retrieveNamespaces {
1588 my ($self, %args) = shift;
1589 my $reg = $args{registry};
1590 $reg = $reg ? $reg : $self->default_MOBY_servername;
1591 return undef unless ( $self->Connection($reg) );
1592 my $as_lsid = $args{as_lsid};
1593
1594 my ($return) = $self->_call( $reg, 'retrieveNamespaces', "" );
1595 my $parser = XML::LibXML->new();
1596 my $doc = $parser->parse_string($return);
1597 my $root = $doc->getDocumentElement;
1598 my $namesp = $root->childNodes;
1599 my %namespaces;
1600 for ( my $x = 1 ; $x <= $namesp->size() ; $x++ ) {
1601 next unless $namesp->get_node($x)->nodeType == ELEMENT_NODE;
1602 my $ns = $namesp->get_node($x)->getAttributeNode('name')->getValue;
1603 my $lsid = $namesp->get_node($x)->getAttributeNode('lsid');
1604 if ($lsid){
1605 $lsid = $lsid->getValue;
1606 } else {
1607 $lsid = $ns;
1608 }
1609 my $desc;
1610 for my $elem (
1611 $namesp->get_node($x)->getElementsByTagName('Description') )
1612 {
1613 $desc = $elem->firstChild;
1614 $desc = $desc ? $desc->toString : "";
1615 $desc ||="";
1616 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1617 $desc = $1;
1618 }
1619 }
1620 # $desc =~ s/<!\[CDATA\[((?>[^\]]+))\]\]>/$1/gs;
1621 $namespaces{$as_lsid?$lsid:$ns} = $desc;
1622 }
1623 return \%namespaces;
1624 }
1625  
1626 =head2 retrieveNamespacesFull
1627  
1628 Usage : $ns = $MOBY->retrieveNamespaces(%args)
1629 Function : get all details about all namespaces
1630 Returns : hashref of hash:
1631 $ns{$namespace} = {Definition => $definition,
1632 authURI => $authority,
1633 contactEmail => $email}
1634 Args : registry => $reg_name: name of registry you wish to retrieve from (optional)
1635 as_lsid => $boolean: retrieve $namespace as its corresponding LSID (default off)
1636  
1637 =cut
1638  
1639 sub retrieveNamespacesFull {
1640 my ($self, %args) = shift;
1641 my $reg = $args{registry};
1642 $reg = $reg ? $reg : $self->default_MOBY_servername;
1643 return undef unless ( $self->Connection($reg) );
1644 my $as_lsid = $args{as_lsid};
1645
1646 my ($return) = $self->_call( $reg, 'retrieveNamespaces', "" );
1647 my $parser = XML::LibXML->new();
1648 my $doc = $parser->parse_string($return);
1649 my $root = $doc->getDocumentElement;
1650 my $namesp = $root->childNodes;
1651 my %namespaces;
1652 for ( my $x = 1 ; $x <= $namesp->size() ; $x++ ) {
1653 next unless $namesp->get_node($x)->nodeType == ELEMENT_NODE;
1654 my $ns = $namesp->get_node($x)->getAttributeNode('name')->getValue;
1655 my $lsid = $namesp->get_node($x)->getAttributeNode('lsid');
1656 if ($lsid){
1657 $lsid = $lsid->getValue;
1658 } else {
1659 $lsid = $ns;
1660 }
1661 my ($desc, $auth, $email);
1662 for my $elem (
1663 $namesp->get_node($x)->getElementsByTagName('Description') )
1664 {
1665 $desc = $elem->firstChild;
1666 $desc = $desc ? $desc->toString : "";
1667 $desc ||="";
1668 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1669 $desc = $1;
1670 }
1671 }
1672 for my $elem (
1673 $namesp->get_node($x)->getElementsByTagName('authURI') )
1674 {
1675 $auth = $elem->firstChild;
1676 $auth = $auth ? $auth->toString : "";
1677 $auth ||="";
1678 if ( $auth =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1679 $auth = $1;
1680 }
1681 }
1682 for my $elem (
1683 $namesp->get_node($x)->getElementsByTagName('contactEmail') )
1684 {
1685 $email = $elem->firstChild;
1686 $email = $email ? $email->toString : "";
1687 $email ||="";
1688 if ( $email =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1689 $email = $1;
1690 }
1691 }
1692 $namespaces{$as_lsid?$lsid:$ns} = {Description => $desc, authURI => $auth, contactEmail => $email};
1693 }
1694 return \%namespaces;
1695 }
1696  
1697  
1698 =head2 retrieveObject
1699  
1700 Usage : $objects = $MOBY->retrieveObjectNames(%args)
1701 Function : get the object xsd
1702 Returns : hashref of hash:
1703 $objects{$name} = $W3C_XML_Schema_string
1704 Args : registry => $reg - name of MOBY Central you want to use (must pass undef otherwise)
1705 objectType => $name - object name (from ontology) or undef to get all objects
1706 as_lsid => $boolean - return $name as its corresponding LSID (default off)
1707  
1708 =cut
1709  
1710 sub retrieveObject {
1711 my ($self, %args) = shift;
1712 my ($reg) = $args{registry};
1713 my $type = $args{objectType};
1714 my $as_lsid = $args{as_lsid};
1715 my $message = "
1716 <retrieveObject>
1717 <objectType>$type</objectType>
1718 </retrieveObject>";
1719 $reg = $reg ? $reg : $self->default_MOBY_servername;
1720 return undef unless ( $self->Connection($reg) );
1721  
1722 my ($return) = $self->_call( $reg, 'retrieveObject', $message );
1723 my $parser = XML::LibXML->new();
1724 my $doc = $parser->parse_string($return);
1725 my $root = $doc->getDocumentElement;
1726 my $objects = $root->childNodes;
1727 my %objects;
1728 for ( my $x = 1 ; $x <= $objects->size() ; $x++ ) {
1729 next unless $objects->get_node($x)->nodeType == ELEMENT_NODE;
1730 my $name = $objects->get_node($x)->getAttributeNode('name')->getValue;
1731 my $lsid = $objects->get_node($x)->getAttributeNode('lsid');
1732 if ($lsid){
1733 $lsid = $lsid->getValue;
1734 } else {
1735 $lsid = $name;
1736 }
1737 my $desc;
1738 for my $elem ( $objects->get_node($x)->getElementsByTagName('Schema') )
1739 {
1740 $desc = $elem->firstChild->nodeValue;
1741 if ( $desc =~ /<!\[CDATA\[((?>[^\]]+))\]\]>/ ) {
1742 $desc = $1;
1743 }
1744 }
1745 $desc =~ s/<!\[CDATA\[((?>[^\]]+))\]\]>/$1/gs;
1746 $objects{$name} = $desc;
1747 }
1748 return \%objects;
1749 }
1750  
1751 =head2 Relationships
1752  
1753 Usage : $def = $MOBY->Relationships(%args)
1754 Function : traverse and return the relationships in the ontology
1755 Returns : hashref of
1756 FOR SERVICES:
1757 $hash{'isa'}=[{lsid => $lsid, term => 'termy'},...]
1758 FOR OBJECTS:
1759 $hash{relationship_type}=[{lsid => $lsid, articleName => 'thingy', term => 'termy'},...]
1760 Args : EITHER serviceType => $term_or_lsid
1761 OR objectType => $term_or_lsid
1762 Relationships => \@relationship_types (optional, 'all' if parameter is missing)
1763 Registry => $registry_name (optional)
1764 expandRelationships => [1/0] (optional)
1765 direction => ['root'/'leaves'] (optional)
1766  
1767 =cut
1768  
1769 sub Relationships {
1770 my ( $self, %args ) = @_;
1771 my $object = $args{'objectType'};
1772 my $service = $args{'serviceType'};
1773 my $expand = $args{'expandRelationships'};
1774 $expand = $args{'expandRelationship'}
1775 unless defined($expand); # be forgiving of typos
1776 my $direction = $args{'direction'} ?
1777 $args{'direction'} :
1778 'root'; # make 'root' default to stay compatible
1779 my @relationships;
1780 @relationships = @{ $args{'Relationships'} }
1781 if ( $args{'Relationships'}
1782 && ( ref( $args{'Relationships'} ) eq 'ARRAY' ) );
1783 push @relationships, 'isa' unless $relationships[0]; # need to have at least one relationship
1784 my $reg = $args{'Registry'};
1785 my $m;
1786 my $payload;
1787 return {} unless ( $object || $service );
1788  
1789 if ($object) {
1790 $m = "
1791 <Relationships>
1792 <objectType>$object</objectType>\n";
1793 foreach (@relationships) {
1794 $m .= "<relationshipType>$_</relationshipType>\n";
1795 }
1796 $m .= "<expandRelationship>1</expandRelationship>\n" if $expand;
1797 $m .= "<direction>$direction</direction>\n";
1798 $m .= "</Relationships>";
1799 $reg = $reg ? $reg : $self->default_MOBY_servername;
1800 return undef unless ( $self->Connection($reg) );
1801  
1802 #$payload = $self->SOAP_connection($reg)->call('Relationships' => ($m))->paramsall;
1803 ($payload) = $self->_call( $reg, 'Relationships', $m );
1804 }
1805 elsif ($service) {
1806 $m = "
1807 <Relationships>
1808 <serviceType>$service</serviceType>\n";
1809 foreach (@relationships) {
1810 $m .= "<relationshipType>$_</relationshipType>\n";
1811 }
1812 $m .= "<expandRelationship>1</expandRelationship>\n" if $expand;
1813 $m .= "<direction>$direction</direction>\n";
1814 $m .= "</Relationships>";
1815 $reg = $reg ? $reg : $self->default_MOBY_servername;
1816 return undef unless ( $self->Connection($reg) );
1817  
1818 # $payload = $self->SOAP_connection($reg)->call('Relationships' => ($m))->paramsall;
1819 ($payload) = $self->_call( $reg, 'Relationships', $m );
1820 }
1821 return &_relationshipsPayload($payload);
1822 }
1823  
1824 sub _relationshipsPayload {
1825 my ($payload) = @_;
1826 return undef unless $payload;
1827 my %att_value;
1828 my %relationships;
1829 my $Parser = XML::LibXML->new();
1830 my $doc = $Parser->parse_string($payload);
1831 my $x = $doc->getElementsByTagName("Relationship");
1832 my $no_relationships = $x->size();
1833 for ( my $n = 1 ; $n <= $no_relationships ; ++$n ) {
1834 my $relationshipType = $x->get_node($n)->getAttributeNode('relationshipType'); # may or may not have a name
1835 if ($relationshipType) {
1836 $relationshipType = $relationshipType->getValue();
1837 } else {
1838 return "FAILED! must include a relationshipType in every relationship\n";
1839 }
1840 my @child = $x->get_node($n)->childNodes;
1841 foreach my $child(@child) {
1842 my ($lsid, $article, $term) = ("", "", "");
1843 next unless $child->nodeType == ELEMENT_NODE;
1844 my $lsidattr = $child->getAttributeNode('lsid'); # may or may not have a name
1845 if ($lsidattr) {
1846 $lsid = $lsidattr->getValue();
1847 }
1848 my $ARTattr = $child->getAttributeNode('articleName'); # may or may not have a name
1849 if ($ARTattr) {
1850 $article = $ARTattr->getValue();
1851 }
1852 my %info;
1853 $info{lsid} = $lsid;
1854 ($info{articleName} = $article) if $article;
1855 my @child2 = $child->childNodes;
1856 foreach my $child2(@child2) {
1857 next unless $child2->nodeType == TEXT_NODE;
1858 $info{term} = $child2->toString;
1859 push @{ $relationships{$relationshipType} }, \%info;
1860 }
1861 }
1862 }
1863 return \%relationships;
1864 }
1865  
1866 =head2 ISA
1867  
1868 Usage : $def = $MOBY->ISA($class1, $class2)
1869 Function : a pre-canned use of the Relationships function
1870 to quickly get an answer to whether class1 ISA class2
1871 Returns : Boolean
1872 Args : $class1 - an Object ontology term or LSID
1873 $class2 - an Object ontology term or LSID
1874  
1875 =cut
1876  
1877 sub ISA {
1878 my ( $self, $class1, $class2 ) = @_;
1879 return 1
1880 if ( ( $class1 eq $class2 )
1881 || ( "moby:$class1" eq $class2 )
1882 || ( $class1 eq "moby:$class2" ) );
1883 my $lsid1 = $self->ObjLSID($class1);
1884 my $lsid2 = $self->ObjLSID($class2);
1885 return 0 unless $lsid1 && $lsid2;
1886 my @lsids;
1887 unless ( @lsids = $self->ISA_CACHE($lsid1) ) {
1888 my $resp = $self->Relationships(
1889 objectType => $lsid1,
1890 expandRelationship => 1,
1891 Relationships => ['isa']
1892 );
1893 my $lsids = $resp->{'isa'};
1894 map {push @lsids, $self->ObjLSID($_->{lsid})} @$lsids; # convert to LSID
1895 $self->ISA_CACHE( $lsid1, [@lsids] );
1896 $self->ISA_CACHE( $class1, [@lsids] );
1897 my @hold = @lsids;
1898 while ( shift @hold ) {
1899 $self->ISA_CACHE( $_, [@hold] );
1900 if ( $_ =~ /^urn:lsid:biomoby.org.\w+\.(\S+)/ ) {
1901 $self->ISA_CACHE( $1, [@lsids] );
1902 }
1903 }
1904 }
1905 foreach (@lsids) {
1906 return 1 if $_ eq $lsid2;
1907 }
1908 return 0;
1909 }
1910  
1911 =head2 DUMP
1912  
1913 Usage : ($mobycentral, $mobyobject, $mobyservice, $mobynamespace, $mobyrelationship) = $MOBY->DUMP(['registry'])
1914 Function : DUMP the mysql for the current MOBY Central database
1915 Returns : text
1916 Args : $reg - name of MOBY Central you want to use if not default
1917  
1918  
1919 =cut
1920  
1921 sub DUMP {
1922 my ($self) = shift;
1923 my ($reg) = shift;
1924 my $type = shift;
1925 $reg = $reg ? $reg : $self->default_MOBY_servername;
1926 return undef unless ( $self->Connection($reg) );
1927  
1928 # return $self->SOAP_connection($reg)->call('DUMP')->paramsall;
1929 my ($SQLs) = $self->_call( $reg, 'DUMP_MySQL', "" );
1930 my (
1931 $mobycentral, $mobyobject, $mobyservice,
1932 $mobynamespace, $mobyrelationship
1933 ) = @{$SQLs} unless ref($SQLs) eq 'HASH';
1934  
1935 # cases where soap message is serialized as a HASH
1936 (
1937 $mobycentral, $mobyobject, $mobyservice,
1938 $mobynamespace, $mobyrelationship
1939 ) = @{$SQLs->{item}} if ref($SQLs) eq 'HASH';
1940
1941 return (
1942 $mobycentral, $mobyobject, $mobyservice,
1943 $mobynamespace, $mobyrelationship
1944 );
1945 }
1946 *DUMP_MySQL = \&DUMP;
1947 *DUMP_MySQL = \&DUMP;
1948  
1949 sub _parseServices {
1950 my ( $self, $Registry, $XML ) = @_;
1951 my $Parser = XML::LibXML->new();
1952 # fix empty string problem
1953 return [] unless $XML;
1954 my $doc = $Parser->parse_string($XML);
1955 my $Object = $doc->getDocumentElement();
1956 my $Services = $Object->getElementsByTagName("Service");
1957 my $num = $Services->size();
1958 my @Services;
1959 for ( my $x = 1 ; $x <= $num ; $x++ ) {
1960 my $Service = $Services->get_node($x);
1961 my $AuthURI = $Service->getAttributeNode('authURI')->getValue;
1962 my $servicename = $Service->getAttributeNode('serviceName')->getValue;
1963 my $lsid = $Service->getAttributeNode('lsid');
1964 if ($lsid){
1965 $lsid = $lsid->getValue;
1966 } else {
1967 $lsid = "";
1968 }
1969 my $Type = &_nodeTextContent( $Service, 'serviceType' );
1970 my $signatureURL = &_nodeTextContent( $Service, 'signatureURL' );
1971 my $authoritative = &_nodeTextContent( $Service, 'authoritative' );
1972 my $contactEmail = &_nodeTextContent( $Service, 'contactEmail' );
1973 my $URL = &_nodeTextContent( $Service, 'URL' );
1974  
1975 #my $Output = &_nodeTextContent($Service, 'outputObject');
1976 my $Description = &_nodeCDATAContent( $Service, 'Description' );
1977 $Description =~ s/<!\[CDATA\[((?>[^\]]+))\]\]>/$1/gs;
1978 my $cat = &_nodeTextContent( $Service, 'Category' );
1979 my @INPUTS;
1980 my @OUTPUTS;
1981 foreach my $inout ( "Input", "Output" ) {
1982 my $xPuts =
1983 $Service->getElementsByTagName($inout)
1984 ; # there should only be one, but... who knows what
1985 for my $in ( 1 .. $xPuts->size() ) {
1986 my $current = $xPuts->get_node($in);
1987 foreach my $child ( $current->childNodes )
1988 { # child nodes will be either "Simple" or "Collection" tagnames
1989 next unless $child->nodeType == ELEMENT_NODE;
1990 my $THIS;
1991 if ( $child->nodeName eq "Simple" ) {
1992 $THIS =
1993 MOBY::Client::SimpleArticle->new( XML_DOM => $child );
1994 }
1995 elsif ( $child->nodeName eq "Collection" ) {
1996 $THIS =
1997 MOBY::Client::CollectionArticle->new(
1998 XML_DOM => $child );
1999 }
2000 else {
2001 next;
2002 }
2003 if ( $inout eq "Input" ) {
2004 push @INPUTS, $THIS;
2005 }
2006 else {
2007 push @OUTPUTS, $THIS;
2008 }
2009 }
2010 }
2011 }
2012 my @SECONDARIES;
2013 my $secs =
2014 $Service->getElementsByTagName("secondaryArticles")
2015 ; # there should only be one, but... who knows what
2016 for my $in ( 1 .. $secs->size() ) {
2017 my $current = $secs->get_node($in);
2018 foreach my $param ( $current->childNodes )
2019 { # child nodes will be "Parameter" tag names
2020 next
2021 unless $param->nodeType == ELEMENT_NODE
2022 && $param->nodeName eq "Parameter";
2023 my $THIS;
2024 $THIS =
2025 MOBY::Client::SecondaryArticle->new( XML_DOM => $param );
2026 push @SECONDARIES, $THIS;
2027 }
2028 }
2029 my $Instance = MOBY::Client::ServiceInstance->new(
2030 authority => $AuthURI,
2031 authoritative => $authoritative,
2032 URL => $URL,
2033 LSID => $lsid,
2034 contactEmail => $contactEmail,
2035 name => $servicename,
2036 type => $Type,
2037 category => $cat,
2038 input => \@INPUTS,
2039 output => \@OUTPUTS,
2040 secondary => \@SECONDARIES,
2041 description => $Description,
2042 registry => $Registry,
2043 signatureURL => $signatureURL,
2044 XML => $Service->toString,
2045 );
2046 push @Services, $Instance;
2047 }
2048 return \@Services;
2049 }
2050  
2051 # my ($e, $m, $lsid) = $OS->objectExists(term => $_);
2052  
2053 =head2 ObjLSID
2054  
2055 =cut
2056  
2057 sub ObjLSID {
2058 my ( $self, $term ) = @_;
2059 return undef unless $term;
2060 my $lsid;
2061 if ( $lsid = $self->LSID_CACHE($term) ) {
2062 return $lsid;
2063 }
2064 else {
2065 my $os = MOBY::Client::OntologyServer->new;
2066 my ( $s, $m, $tlsid ) = $os->objectExists( term => $term );
2067 if ($tlsid) {
2068 $self->LSID_CACHE( $term, $tlsid ); # link both the term
2069 $self->LSID_CACHE( $tlsid, $tlsid ); # and the lsid to itself
2070 return $tlsid;
2071 }
2072 else {
2073 return undef;
2074 }
2075 }
2076 }
2077  
2078 =head2 LSID_CACHE
2079  
2080 Usage : $lsid = $MOBY->LSID_CACHE($term, $lsid)
2081 Function : get/set LSID from the cache
2082 Returns : lsid as a scalar
2083 Args : the term for which you have/want an lsid,
2084 and optionally the lsid to set.
2085  
2086 =cut
2087  
2088 sub LSID_CACHE {
2089 my ( $self, $term, $lsid ) = @_;
2090 if ( $term && $lsid ) {
2091 $self->{LSID_CACHE}->{$term} = $lsid;
2092 return $self->{LSID_CACHE}->{$term};
2093 }
2094 elsif ($term) {
2095 return $self->{LSID_CACHE}->{$term};
2096 }
2097 else {
2098 return undef;
2099 }
2100 }
2101  
2102 =head2 ISA_CACHE
2103  
2104 Usage : @lsids = $MOBY->ISA_CACHE($lsid, \@isas)
2105 Function : get/set the ISA relationships in the cache
2106 Returns : list of ISA relationships. The ISA list
2107 is IN ORDER from, excluding the term itself, to
2108 root Object. Base Object returns an empty list.
2109 Args : The LSID for which you have/want the ISA parentage,
2110 and optionally the parentage listref to set.
2111 Note : WHAT COMES BACK ARE LSIDs!!!
2112  
2113 =cut
2114  
2115 sub ISA_CACHE {
2116 my ( $self, $desiredterm, $isas ) = @_;
2117 my $term = $desiredterm;
2118 return (undef) if $isas && ( ref($isas) ne 'ARRAY');
2119 if ( $term && $isas ) {
2120 my @isalsids;
2121 foreach (@$isas){
2122 my $lsid = $self->ObjLSID($_);
2123 next unless ($lsid =~ /^urn\:lsid/);
2124 push @isalsids, $lsid;
2125 }
2126 $self->{ISA_CACHE}->{$desiredterm} = [(@isalsids)]; # can't assign a listreference or it will empty itself!
2127 while ( my $term = shift(@isalsids) ) { # traverse down and flatten the list
2128 $self->{ISA_CACHE}->{$term} = [(@isalsids)];
2129 }
2130 return @{ $self->{ISA_CACHE}->{$desiredterm} };
2131 }
2132 elsif ( $term && $self->{ISA_CACHE}->{$desiredterm} ) {
2133 return @{ $self->{ISA_CACHE}->{$desiredterm} };
2134 }
2135 else {
2136 return ();
2137 }
2138 }
2139  
2140 sub parseRegXML {
2141  
2142 #<MOBYRegistration>
2143 # <id>$id</id>
2144 # <success>$success</success>
2145 # <message><![CDATA[$message]]></message>
2146 #</MOBYRegistration>
2147 my ( $self, $xml ) = @_;
2148 my $Parser = XML::LibXML->new();
2149  
2150 #print STDERR $xml;
2151 my $doc = $Parser->parse_string($xml);
2152 my $Object = $doc->getDocumentElement();
2153 my $obj = $Object->nodeName;
2154 return undef unless ( $obj eq 'MOBYRegistration' );
2155 my $id = &_nodeTextContent( $Object, 'id' );
2156 my $success = &_nodeTextContent( $Object, 'success' );
2157 my $message = &_nodeCDATAContent( $Object, 'message' );
2158  
2159 #print STDERR "******$message******\n";
2160 my $RDF = &_nodeRawContent( $Object, 'RDF' );
2161 my $reg = MOBY::Client::Registration->new(
2162 success => $success,
2163 message => $message,
2164 registration_id => $id,
2165 RDF => $RDF,
2166 id => $id
2167 );
2168 return $reg;
2169 }
2170  
2171 sub errorRegXML {
2172 my ( $self, $message ) = @_;
2173 my $reg = MOBY::Client::Registration->new(
2174 success => 0,
2175 message => $message,
2176 registration_id => -1,
2177 );
2178 return $reg;
2179 }
2180  
2181 sub _nodeCDATAContent {
2182  
2183 # will get text of **all** child $node from the given $DOM
2184 # regardless of their depth!!
2185 my ( $DOM, $node ) = @_;
2186 my $x = $DOM->getElementsByTagName($node);
2187 unless ( $x->get_node(1) ) { return }
2188 my @child = $x->get_node(1)->childNodes;
2189 my $content;
2190 foreach (@child) {
2191  
2192 #print getNodeTypeName($_), "\t", $_->toString,"\n";
2193 next
2194 unless ( ( $_->nodeType == TEXT_NODE )
2195 || ( $_->nodeType == CDATA_SECTION_NODE ) );
2196 $content = $_->textContent;
2197 }
2198 $content ||= "";
2199 $content =~ s/<!\[CDATA\[((?>[^\]]+))\]\]>/$1/gs;
2200 return $content;
2201 }
2202  
2203 sub _nodeTextContent {
2204  
2205 # will get text of **all** child $node from the given $DOM
2206 # regardless of their depth!!
2207 my ( $DOM, $node ) = @_;
2208 my $x = $DOM->getElementsByTagName($node);
2209 unless ( $x->get_node(1) ) { return }
2210 my @child = $x->get_node(1)->childNodes;
2211 my $content;
2212 foreach (@child) {
2213  
2214 #print getNodeTypeName($_), "\t", $_->toString,"\n";
2215 next
2216 unless ( ( $_->nodeType == TEXT_NODE )
2217 || ( $_->nodeType == CDATA_SECTION_NODE ) );
2218 $content = $_->textContent;
2219 }
2220 return $content;
2221 }
2222  
2223 sub _nodeAttributeValue {
2224  
2225 my ( $DOM, $node, $attr ) = @_;
2226 return "" unless $attr;
2227 my $x = $DOM->getElementsByTagName($node);
2228 unless ( $x->get_node(1) ) { return "" }
2229 my $n = $x->get_node(1);
2230 my $nodemap = $n->attributes($attr); # XML::LibXML::NamedNodeMap - the worst documented (i.e. undocumented) piece of code ever written! You have to read the source to figure out the interface...
2231 my $attrnode = $nodemap->getNamedItem($attr);
2232 my $attrval = $attrnode?($attrnode->value):"";
2233 return $attrval;
2234 }
2235  
2236 sub _nodeRawContent {
2237  
2238 # will get XML of **all** child $node from the given $DOM
2239 # regardless of their depth!!
2240 my ( $DOM, $node ) = @_;
2241 my $x = $DOM->getElementsByTagName($node);
2242 unless ( $x->get_node(1) ) { return }
2243 my @child = $x->get_node(1)->childNodes;
2244 my $content;
2245 foreach (@child) {
2246  
2247 #print getNodeTypeName($_), "\t", $_->toString,"\n";
2248 # next unless $_->nodeType == TEXT_NODE;
2249 $content .= $_->toString;
2250 }
2251 return $content;
2252 }
2253  
2254 sub _nodeArrayContent {
2255  
2256 # will get array content of all child $node from given $DOM
2257 # regardless of depth!
2258 my ( $DOM, $node ) = @_;
2259 $debug && &_LOG( "_nodeArrayContext received DOM: ",
2260 $DOM->toString, "\nsearching for node $node\n" );
2261 my @result;
2262 my $x = $DOM->getElementsByTagName($node);
2263 my @child = $x->get_node(1)->childNodes;
2264 foreach (@child) {
2265 next unless $_->nodeType == ELEMENT_NODE;
2266 my @child2 = $_->childNodes;
2267 foreach (@child2) {
2268  
2269 #print getNodeTypeName($_), "\t", $_->toString,"\n";
2270 next
2271 unless ( ( $_->nodeType == TEXT_NODE )
2272 || ( $_->nodeType == CDATA_SECTION_NODE ) );
2273 push @result, $_->textContent;
2274 }
2275 }
2276 return @result;
2277 }
2278  
2279 sub AUTOLOAD {
2280 no strict "refs";
2281 my ( $self, $newval ) = @_;
2282 $AUTOLOAD =~ /.*::(\w+)/;
2283 my $attr = $1;
2284 if ( $self->_accessible( $attr, 'write' ) ) {
2285 *{$AUTOLOAD} = sub {
2286 if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
2287 return $_[0]->{$attr};
2288 }; ### end of created subroutine
2289 ### this is called first time only
2290 if ( defined $newval ) {
2291 $self->{$attr} = $newval;
2292 }
2293 return $self->{$attr};
2294 }
2295 elsif ( $self->_accessible( $attr, 'read' ) ) {
2296 *{$AUTOLOAD} = sub {
2297 return $_[0]->{$attr};
2298 }; ### end of created subroutine
2299 return $self->{$attr};
2300 }
2301  
2302 # Must have been a mistake then...
2303 croak "No such method: $AUTOLOAD";
2304 }
2305 sub DESTROY { }
2306  
2307 sub _LOG {
2308 return unless $debug;
2309 open LOG, ">>/tmp/CentralLogOut.txt" or die "can't open logfile $!\n";
2310 print LOG join "\n", @_;
2311 print LOG "\n---\n";
2312 close LOG;
2313 }
2314 1;
« blib/lib/MOBY/Adaptor/moby/DataAccessI.pm ↑ Summary blib/lib/auto/share/dist/MOBY/scripts/CloneCentralDatabases.pl »