lib/MOSES/MOBY/Cache/Central.pm

filter: Statementstmt 15.6% 82 / 523 Branchbran 3.8% 8 / 210 Conditioncond 4.2% 5 / 119 MC/DCmcdc 0.0% 0 / 67 Subroutinesub 51.0% 24 / 47 Podpod 92.8% 13 / 14 totaltotal 13.4% 132 / 980 CC 169 SCAR 71.9
CC
169
Cov
11%
_createServiceFromXML
3782.0
_createDataTypeFromXML
1332.0
update_service_cache
182.0
CRAP 1321.9
↑ Summary lib/MOSES/MOBY/Parser.pm »
1 #-----------------------------------------------------------------
2 # MOSES::MOBY::Cache::Central
3 # Author: Edward Kawas <edward.kawas@gmail.com>,
4 # Martin Senger <martin.senger@gmail.com>
5 # For copyright and disclaimer see below.
6 #
7 # $Id: Central.pm,v 1.9 2009/10/09 17:29:28 kawas Exp $
8 #-----------------------------------------------------------------
9  
10 package MOSES::MOBY::Cache::Central;
11  
12 1 ▶use MOSES::MOBY::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use base qw( MOSES::MOBY::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use MOSES::MOBY::Cache::Registries;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use MOSES::MOBY::Def::DataType;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use MOSES::MOBY::Def::Service;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use MOSES::MOBY::Def::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use MOSES::MOBY::Def::Namespace;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use MOSES::MOBY::Def::Relationship;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use vars qw ($DEFAULT_REGISTRY_URL $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # names of cache directories/files
27 1 ▶use constant LIST_FILE => '__L__I__S__T__';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use constant DATATYPES_CACHE => 'dataTypes';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use constant SERVICES_CACHE => 'services';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use constant NAMESPACES_CACHE => 'namespaces';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use constant SERVICETYPES_CACHE => 'serviceTypes';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 # the version of this file:
34 1 $VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /: (\d+)\.(\d+)/;
35  
36 =head1 NAME
37  
38 MOSES::MOBY::Cache::Central - access to locally cached Moby entities
39  
40 =cut
41  
42 =head1 SYNOPSIS
43  
44 use MOSES::MOBY::Cache::Central;
45  
46 # create an aceess to a Moby registry cache
47 # (use 'registry' only for non-default registries)
48 my $cache = new MOSES::MOBY::Cache::Central
49 ( cachedir =>'/usr/local/cache/',
50 );
51  
52 my $cache = new MOSES::MOBY::Cache::Central
53 ( cachedir =>'/usr/local/cache/',
54 registry => 'IRRI'
55 );
56  
57 # get the location of the cache and the URL of a registry (whose
58 # cache we are accessing)
59 print $cache->cachedir;
60 print $cache->registry();
61  
62 # create a cache for datatypes and fill it up
63 $cache->create_datatype_cache;
64
65 #update the datatype cache
66 $cache->update_datatype_cache;
67
68 # create a cache for services and fill it up
69 $cache->create_service_cache;
70
71 #update the services cache
72 $cache->update_service_cache;
73
74 # get a data type called DNASequence
75 my $dna = $cache->get_datatype ('DNASequence');
76
77 # get all datatypes from cache
78 my @dts = $cache->get_datatypes;
79  
80 # get all services provided by the given authority
81 my @services = $cache->get_service ('bioinfo.inibap.org');
82  
83 # get some services provided by the given authority
84 my @services = $cache->get_service
85 ('bioinfo.inibap.org',
86 qw( Get_TropGENE_Distance_Matrix Get_TropGENE_Nj_Tree ));
87  
88 # get all authorities and service names
89 require Data::Dumper;
90 my %all = $cache->get_service_names;
91 print Data::Dumper->Dump ( [ \%all ], ['By_authorities']);
92  
93 =cut
94  
95 =head1 DESCRIPTION
96  
97 Access to a cached Moby entities, such as data types and service
98 definitions. It does not create a cache, just reads it.
99  
100 =head1 AUTHORS
101  
102 Edward Kawas (edward.kawas [at] gmail [dot] com)
103 Martin Senger (martin.senger [at] gmail [dot] com)
104  
105 =cut
106  
107 #-----------------------------------------------------------------
108 # A list of allowed attribute names. See MOSES::MOBY::Base for details.
109 #-----------------------------------------------------------------
110  
111 =head1 ACCESSIBLE ATTRIBUTES
112  
113 Details are in L<MOSES::MOBY::Base>. Here just a list of them:
114  
115 =over
116  
117 =item B<cachedir>
118  
119 A mandatory parameter containing a name of a local directory where is
120 a Moby cache. The Moby cache directory can contain more caches (from
121 more Moby registries). The location points to the top-level directory
122 name. For example, if we have the following directory structure
123 (containing caches from four different Moby registries):
124  
125 /work/moby-live/Java/myCache/
126 http58.47.47bioinfo46icapture46ubc46ca47cgi45bin47mobycentral47MOBY45Central46pl/
127 dataTypes/
128 namespaces/
129 services/
130 serviceTypes/
131 http58.47.47cropwiki46irri46org47cgi45bin47MOBY45Central46pl/
132 ...
133 http58.47.47mips46gsf46de47cgi45bin47proj47planet47moby47MOBY45Central46pl/
134 ...
135 http58.47.47mobycentral46icapture46ubc46ca47cgi45bin47MOBY0547mobycentral46pl/
136 ...
137  
138 Then, the location should be C</work/moby-live/Java/myCache>.
139  
140 =item B<registry>
141  
142 A URL of a moby registry whose cache you are going to access. Or an
143 abbreviation (a synonym) of a BioMoby registry. See more about
144 synonyms in L<MOSES::MOBY::Cache::Registries>.
145  
146 For a default registry, use string 'default' (but there is no need to
147 do so: default is default by default).
148  
149 =item B<registries>
150  
151 An object of type MOSES::MOBY::Cache::Registries that you can manipulate to add
152 more registries. See more about this object in L<MOSES::MOBY::Cache::Registries>.
153  
154 =back
155  
156 =cut
157  
158 {
159 1 my %_allowed =
160 (
161 cachedir => undef,
162 registries=> new MOSES::MOBY::Cache::Registries,
163 registry => { type => MOSES::MOBY::Base->STRING,
164 post => \&_check_registry },
165 # undocumented, for internal use only (so far)
166 datatypes => {type => 'MOSES::MOBY::Def::DataType', is_array => 1},
167 # services => {type => 'MOSES::MOBY::Def::Service', is_array => 1},
168 );
169  
170 4 ▶ sub _accessible {
Subroutine _accessible: called CC=2 SCAR=7.2
171 4 my ($self, $attr) = @_;
172 4 ▶ exists $_allowed{$attr} or $self->SUPER::_accessible ($attr);
Branch: 1 branch
BranchTrueFalseTotal
exists $_allowed{$attr} or $self->SUPER::_accessible($attr) 4 0 4
173 }
174 16 ▶ sub _attr_prop {
Subroutine _attr_prop: called CC=3 SCAR=11.0
175 16 my ($self, $attr_name, $prop_name) = @_;
176 16 my $attr = $_allowed {$attr_name};
177 16 ▶ return ref ($attr) ? $attr->{$prop_name} : $attr if $attr;
Branch: 2 branches
BranchTrueFalseTotal
if $attr 12 4 16
ref $attr ? : 12 0 12
178 4 return $self->SUPER::_attr_prop ($attr_name, $prop_name);
179 }
180 }
181  
182 1 ▶sub _check_registry {
Subroutine _check_registry: called CC=3 SCAR=12.5
183 3 my $self = shift;
184 3 ▶ $self->{registry} = $self->{registry} || $MOBYCFG::REGISTRY || 'default';
Condition40%2/5
$self->{'registry'} || $MOBYCFG::REGISTRY || 'default'
l!l
30
$self->{"registry"} or $MOBYCFG::REGISTRY
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->{'registry'} || $MOBYCFG::REGISTRY || 'default'
$self->{"registry"} $MOBYCFG::REGISTRY
Truth table33%1/3
A or B
A= $self->{"registry"}B= $MOBYCFG::REGISTRY
ABresult
1X1
011
000
185 }
186  
187  
188 #-----------------------------------------------------------------
189  
190 =head1 SUBROUTINES
191  
192 =cut
193  
194 #-----------------------------------------------------------------
195 # _endpoint
196 # Return an endpoint of the $self->registry, or of a given
197 # registry.
198 #-----------------------------------------------------------------
199 2 ▶sub _endpoint {
Subroutine _endpoint: called CC=4 SCAR=15.9
200 2 my ($self, $registry) = @_;
201 2 ▶ $registry ||= $self->registry;
Condition33%1/3
$registry ||= $self->registry
l!l&&r!l&&!r
020
MC/DC0%0/2
$registry ||= $self->registry
$registry $self->registry
Truth table33%1/3
A ||= B
A= $registryB= $self->registry
ABresult
1X1
011
000
202 2 ▶ return $registry if $registry =~ m"^http://";
Branch: 1 branch
BranchTrueFalseTotal
if $registry =~ m[^http://] 0 2 2
203 2 my $reg = $self->registries->get ($registry);
204 2 ▶ return $reg->{endpoint} if $reg;
Branch: 1 branch
BranchTrueFalseTotal
if $reg 2 0 2
205 0 return $self->registries->get ('default')->{endpoint};
206 }
207  
208 #-----------------------------------------------------------------
209 # _namespace
210 # Return a namespace of the $self->registry, or of a given
211 # registry.
212 #-----------------------------------------------------------------
213 2 ▶sub _namespace {
Subroutine _namespace: called CC=4 SCAR=15.9
214 2 my ($self, $registry) = @_;
215 2 ▶ $registry ||= $self->registry;
Condition33%1/3
$registry ||= $self->registry
l!l&&r!l&&!r
020
MC/DC0%0/2
$registry ||= $self->registry
$registry $self->registry
Truth table33%1/3
A ||= B
A= $registryB= $self->registry
ABresult
1X1
011
000
216 2 ▶ return "http://localhost/MOBY/Central" if $registry =~ m"^http://";
Branch: 1 branch
BranchTrueFalseTotal
if $registry =~ m[^http://] 0 2 2
217 2 my $reg = $self->registries->get ($registry);
218 2 ▶ return $reg->{namespace} if $reg;
Branch: 1 branch
BranchTrueFalseTotal
if $reg 2 0 2
219 0 return $self->registries->get ('default')->{namespace};
220 }
221  
222  
223 #-----------------------------------------------------------------
224 # init
225 #-----------------------------------------------------------------
226 2 ▶sub init {
Subroutine init: called CC=2 SCAR=7.0
Pod documented
227 2 my ($self) = shift;
228 2 $self->SUPER::init();
229 2 ▶ $self->registry ($MOBYCFG::REGISTRY || 'default');
Condition50%1/2
$MOBYCFG::REGISTRY || 'default'
l!l
02
MC/DC0%0/1
$MOBYCFG::REGISTRY || 'default'
$MOBYCFG::REGISTRY
Truth table50%1/2
A
A= $MOBYCFG::REGISTRY
Aresult
11
00
230 2 $self->cachedir ($MOBYCFG::CACHEDIR);
231 2 $self->registries( new MOSES::MOBY::Cache::Registries);
232 2 $self->datatypes ([]);
233 # $self->services ([]);
234 }
235  
236 #-----------------------------------------------------------------
237 # get_datatypes
238 #-----------------------------------------------------------------
239  
240 =head2 get_datatypes
241  
242 Return a reference to an array of C<MOSES::MOBY::Def::DataType> objects. They
243 were generated from the local Moby cache. All data types found in the
244 cache are returned.
245  
246 No arguments (at least, so far).
247  
248 =cut
249  
250 0 ▶sub get_datatypes {
Subroutine get_datatypes: not called CC=3 SCAR=24.8
Pod documented
251 0 my $self = shift;
252  
253 # get all available names
254 0 my @names = $self->get_datatype_names;
255 0 foreach my $name (@names) {
256 # $self->add_datatypes ($self->get_datatype ($name);
257 0 push @{ $self->{datatypes} }, $self->get_datatype ($name);
258 }
259 0 ▶ return $self->datatypes ? $self->datatypes : [];
Branch: 1 branch
BranchTrueFalseTotal
$self->datatypes ? : 0 0 0
260 }
261  
262 #-----------------------------------------------------------------
263 # get_datatype
264 #-----------------------------------------------------------------
265  
266 =head2 get_datatype
267  
268 Return a Moby data type definition (type MOSES::MOBY::Def::DataType), as
269 obtained from a local cache. The argument is a name of a data type
270 that will be returned.
271  
272 Throw an exception if such named data type does not exist in the local
273 cache.
274  
275 =cut
276  
277 0 ▶sub get_datatype {
Subroutine get_datatype: not called CC=3 SCAR=24.8
Pod documented
278 0 my ($self, $datatype_name) = @_;
279 0 ▶ $self->throw ("No data type given.")
Branch: 1 branch
BranchTrueFalseTotal
unless $datatype_name 0 0 0
280 unless $datatype_name;
281 0 my $file = File::Spec->catfile ($self->cachedir,
282 $self->_clean ($self->_endpoint),
283 DATATYPES_CACHE,
284 $datatype_name);
285 0 my $xml = '';
286 0 local $/ = undef;
287 0 ▶ open (FILE, "<$file")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<$file" or $self->throw("Can't open file $file for reading: $!") 0 0 0
288 or $self->throw ("Can't open file $file for reading: $!");
289 0 $xml = <FILE>;
290 0 close FILE;
291
292 0 return $self->_createDataTypeFromXML ($xml);
293 }
294  
295 #-----------------------------------------------------------------
296 # create_datatype_cache
297 #-----------------------------------------------------------------
298  
299 =head2 create_datatype_cache
300  
301 Create the datatype cache. This will over write any pre-existing
302 cache that it finds.
303  
304 Throw an exception if any of the following occur:
305 * There is a SOAP error calling the registry
306 * There were write errors on the cache directory or its contents
307  
308 =cut
309  
310 0 ▶sub create_datatype_cache {
Subroutine create_datatype_cache: not called CC=4 SCAR=30.0
Pod documented
311 0 my ($self) = @_;
312
313 # 2 steps:
314 # -> create a LIST file
315 my $soap =
316 SOAP::Lite->uri($self->_namespace)
317 ->proxy( $self->_endpoint )->on_fault(
318 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
319 0 my $soap = shift;
320 0 my $res = shift;
321 0 $self->throw ("There was a problem calling the registry: " . $self->_endpoint . "\@ " . $self->_namespace . ".\n" . $res);
322 }
323 0 );
324  
325 0 my $xml =
326 $soap->retrieveObjectNames( )->result;
327 # create cache dirs as needed
328 0 $self->create_cache_dirs;
329 0 my $file = File::Spec->catfile ($self->cachedir,
330 $self->_clean ($self->_endpoint),
331 DATATYPES_CACHE,
332 LIST_FILE);
333 0 ▶ open (FILE, ">$file")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or $self->throw("Can't open file '${file}' for writing: $!") 0 0 0
334 or $self->throw ("Can't open file '$file' for writing: $!");
335 0 print FILE $xml;
336 0 close FILE;
337
338 0 $LOG->debug("Saving the '". LIST_FILE . "' file.");
339
340 # 2-> foreach datatype store 'retrieveObjectDefinition'
341 0 my $parser = XML::LibXML->new();
342 0 my $doc = $parser->parse_string($xml);
343
344 0 my $nodes = $doc->documentElement()->getChildrenByTagName('Object');
345 0 for (1 .. $nodes->size()) {
346 0 my $name = $nodes->get_node($_ )->getAttribute('name');
347 0 my $input =<<END;
348 <retrieveObjectDefinition>
349 <objectType>$name</objectType>
350 </retrieveObjectDefinition>
351 END
352 0 $LOG->debug("Processing the datatype, '$name'.");
353 0 $xml =
354 $soap->retrieveObjectDefinition ( SOAP::Data->type('string' => "$input") )->result;
355 0 $file = File::Spec->catfile ($self->cachedir,
356 $self->_clean ($self->_endpoint),
357 DATATYPES_CACHE,
358 $name);
359 0 ▶ open (FILE, ">$file") or $self->throw ("Can't open file '$file' for writing: $!");
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or $self->throw("Can't open file '${file}' for writing: $!") 0 0 0
360 0 print FILE $xml;
361 0 close FILE;
362 }
363
364 }
365  
366 #-----------------------------------------------------------------
367 # update_datatype_cache
368 #-----------------------------------------------------------------
369  
370 =head2 update_datatype_cache
371  
372 Update the datatype cache. This will update any items that are 'old',
373 by relying on the LSID for the datatype.
374  
375 Throw an exception if any of the following occur:
376 * A cache to update doesn't exist
377 * There is a SOAP error calling the registry
378 * There were read/write errors on the cache directory or its contents
379  
380 =cut
381  
382 0 ▶sub update_datatype_cache {
Subroutine update_datatype_cache: not called CC=12 SCAR=50.5
Pod documented
383 0 my ($self) = @_;
384
385 0 my %old_datatypes = ();
386 0 my %new_datatypes = ();
387 0 my @changed_datatypes = ();
388
389 0 ▶ if (!(-e File::Spec->catfile (
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "File::Spec"->catfile($self->cachedir, $self->_clean($self->_endpoint), "dataTypes")) 0 0 0
390 $self->cachedir,
391 $self->_clean ($self->_endpoint),
392 DATATYPES_CACHE))) {
393 0 $self->throw("Datatype cache doesn't exist, so I can't update it. Please create a datatype cache first!");
394 }
395 0 ▶ if (!(-e File::Spec->catfile (
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "File::Spec"->catfile($self->cachedir, $self->_clean($self->_endpoint), "dataTypes", "__L__I__S__T__")) 0 0 0
396 $self->cachedir,
397 $self->_clean ($self->_endpoint),
398 DATATYPES_CACHE,
399 LIST_FILE))) {
400 0 $self->throw("Datatypes LIST_FILE doesn't exist, so I can't update the cache. Please create a datatype cache first!");
401 }
402 # steps:
403 # read in the LIST file and extract lsids for all datatypes
404 0 $LOG->debug("Reading the cached '" . LIST_FILE ."'.");
405 0 my $file = File::Spec->catfile ($self->cachedir,
406 $self->_clean ($self->_endpoint),
407 DATATYPES_CACHE,
408 LIST_FILE);
409 0 my $parser = XML::LibXML->new();
410 0 my $doc = $parser->parse_file($file);
411 0 my $nodes = $doc->documentElement()->getChildrenByTagName('Object');
412 0 for (1 .. $nodes->size()) {
413 0 my $name = $nodes->get_node($_ )->getAttribute('name');
414 0 my $lsid = $nodes->get_node($_ )->getAttribute('lsid');
415 0 $old_datatypes{$name} = $lsid;
416 }
417 0 $LOG->debug("Retrieving an up to date '". LIST_FILE ."'.");
418 # get the new LIST file and extract lsids for all datatypes
419 my $soap =
420 SOAP::Lite->uri($self->_namespace)
421 ->proxy( $self->_endpoint )->on_fault(
422 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
423 0 my $soap = shift;
424 0 my $res = shift;
425 0 $self->throw ("There was a problem calling the registry: " . $self->_endpoint . "\@ " . $self->_namespace . ".\n" . $res);
426 }
427 0 );
428  
429 0 my $xml = $soap->retrieveObjectNames( )->result;
430 0 $parser = XML::LibXML->new();
431 0 $doc = $parser->parse_string($xml);
432 0 $nodes = $doc->documentElement()->getChildrenByTagName('Object');
433 0 for (1 .. $nodes->size()) {
434 0 my $name = $nodes->get_node($_ )->getAttribute('name');
435 0 my $lsid = $nodes->get_node($_ )->getAttribute('lsid');
436 0 $new_datatypes{$name} = $lsid;
437 }
438 # go through the keys of the new one and if the keys doesnt exist or has been modified, add to 'download' queue
439 0 foreach my $dt (keys %new_datatypes) {
440 0 ▶ next unless !$old_datatypes{$dt} or $old_datatypes{$dt} ne $new_datatypes{$dt};
Branch: 1 branch
BranchTrueFalseTotal
unless not $old_datatypes{$dt} or $old_datatypes{$dt} ne $new_datatypes{$dt} 0 0 0
Condition0%0/3
not $old_datatypes{$dt} or $old_datatypes{$dt} ne $new_datatypes{$dt}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $old_datatypes{$dt} or $old_datatypes{$dt} ne $new_datatypes{$dt}
not $old_datatypes{$dt} $old_datatypes{$dt} ne $new_datatypes{$dt}
Truth table0%0/3
not(A) or B
A= not $old_datatypes{$dt}B= $old_datatypes{$dt} ne $new_datatypes{$dt}
ABresult
1X1
011
000
441 0 push @changed_datatypes, $dt;
442 0 $LOG->debug("The datatype, '$dt', seems to have been modified.");
443 }
444
445 # if their where changes, save new LIST file over the old one and get changes
446 0 ▶ if (scalar @changed_datatypes) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @changed_datatypes) 0 0 0
447 # save new LIST file
448 0 ▶ open (FILE, ">$file")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or $self->throw("Can't open file '${file}' for writing: $!") 0 0 0
449 or $self->throw ("Can't open file '$file' for writing: $!");
450 0 print FILE $xml;
451 0 close FILE;
452 # clear used values
453 0 $xml = undef;
454 0 $file = undef;
455 0 $parser = undef;
456 0 $doc = undef;
457 0 $nodes = undef;
458 0 foreach my $name (@changed_datatypes) {
459 0 print "Found modified datatype, '$name', updating ...\n";
460 0 my $input =<<END;
461 <retrieveObjectDefinition>
462 <objectType>$name</objectType>
463 </retrieveObjectDefinition>
464 END
465  
466 0 $LOG->debug("Updating the datatype, '$name'.");
467 0 $xml =
468 $soap->retrieveObjectDefinition ( SOAP::Data->type('string' => "$input") )->result;
469 0 $file = File::Spec->catfile ($self->cachedir,
470 $self->_clean ($self->_endpoint),
471 DATATYPES_CACHE,
472 $name);
473 0 ▶ open (FILE, ">$file") or $self->throw ("Can't open file '$file' for writing: $!");
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or $self->throw("Can't open file '${file}' for writing: $!") 0 0 0
474 0 print FILE $xml;
475 0 close FILE;
476 }
477 }
478 }
479  
480 #-----------------------------------------------------------------
481 # create_service_cache
482 #-----------------------------------------------------------------
483  
484 =head2 create_service_cache
485  
486 Create the service cache. This will over write any pre-existing
487 cache that it finds.
488  
489 Throw an exception if any of the following occurs:
490 * A SOAP error as a result of calling the registry
491 * Problems writing to the cache directory
492  
493 =cut
494  
495 0 ▶sub create_service_cache {
Subroutine create_service_cache: not called CC=5 SCAR=34.0
Pod documented
496 0 my ($self) = @_;
497
498 # 2 steps:
499 # -> create a LIST file
500 my $soap =
501 SOAP::Lite->uri($self->_namespace)
502 ->proxy( $self->_endpoint )->on_fault(
503 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
504 0 my $soap = shift;
505 0 my $res = shift;
506 0 $self->throw ("There was a problem calling the registry: " . $self->_endpoint . "\@ " . $self->_namespace . ".\n" . $res);
507 }
508 0 );
509  
510 0 my $xml =
511 $soap->retrieveServiceNames( )->result;
512 # create cache dirs as needed
513 0 $self->create_cache_dirs;
514 0 my $file = File::Spec->catfile ($self->cachedir,
515 $self->_clean ($self->_endpoint),
516 SERVICES_CACHE,
517 LIST_FILE);
518 0 ▶ open (FILE, ">$file")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or $self->throw("Can't open file '${file}' for writing: $!") 0 0 0
519 or $self->throw ("Can't open file '$file' for writing: $!");
520 0 print FILE $xml;
521 0 close FILE;
522
523 # 2-> foreach datatype store 'findService' on the authority
524 0 my $parser = XML::LibXML->new();
525 0 my $doc = $parser->parse_string($xml);
526 0 my %authorities_completed = ();
527 0 my $nodes = $doc->documentElement()->getChildrenByTagName('serviceName');
528 0 for (1 .. $nodes->size()) {
529 0 my $name = $nodes->get_node($_ )->getAttribute('authURI');
530 0 ▶ next if $authorities_completed{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $authorities_completed{$name} 0 0 0
531 0 $authorities_completed{$name} = 1;
532 0 my $input =<<END;
533 <findService>
534 <authURI>$name</authURI>
535 </findService>
536 END
537 0 $xml =
538 $soap->findService ( SOAP::Data->type('string' => "$input") )->result;
539 0 $file = File::Spec->catfile ($self->cachedir,
540 $self->_clean ($self->_endpoint),
541 SERVICES_CACHE,
542 $name);
543 0 ▶ open (FILE, ">$file") or $self->throw ("Can't open file '$file' for writing: $!");
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or $self->throw("Can't open file '${file}' for writing: $!") 0 0 0
544 0 print FILE $xml;
545 0 close FILE;
546 }
547
548 }
549  
550 #-----------------------------------------------------------------
551 # update_service_cache
552 #-----------------------------------------------------------------
553  
554 =head2 update_service_cache
555  
556 Update the services cache. This will update any items that are 'old',
557 by relying on the LSID for the datatype.
558  
559 Throw an exception if any of the following occur:
560 * A cache to update doesn't exist
561 * There is a SOAP error calling the registry
562 * There were read/write errors on the cache directory or its contents
563  
564 =cut
565  
566 0 ▶sub update_service_cache {
Subroutine update_service_cache: not called CC=13 SCAR=52.0
Pod documented
567 0 my ($self) = @_;
568
569 0 my %old_services = ();
570 0 my %new_services = ();
571 0 my %changed_services = ();
572
573 0 ▶ if (!(-e File::Spec->catfile (
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "File::Spec"->catfile($self->cachedir, $self->_clean($self->_endpoint), "services")) 0 0 0
574 $self->cachedir,
575 $self->_clean ($self->_endpoint),
576 SERVICES_CACHE))) {
577 0 $self->throw("Services cache doesn't exist, so I can't update it. Please create a services cache first!");
578 }
579
580 0 ▶ if (!(-e File::Spec->catfile (
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "File::Spec"->catfile($self->cachedir, $self->_clean($self->_endpoint), "services", "__L__I__S__T__")) 0 0 0
581 $self->cachedir,
582 $self->_clean ($self->_endpoint),
583 SERVICES_CACHE,
584 LIST_FILE))) {
585 0 $self->throw("Services LIST_FILE doesn't exist, so I can't update the cache. Please create a services cache first!");
586 }
587
588 # steps:
589 # read in the LIST file and extract lsids for all datatypes
590 0 my $file = File::Spec->catfile ($self->cachedir,
591 $self->_clean ($self->_endpoint),
592 SERVICES_CACHE,
593 LIST_FILE);
594 0 my $parser = XML::LibXML->new();
595 0 my $doc = $parser->parse_file($file);
596 0 my $nodes = $doc->documentElement()->getChildrenByTagName('serviceName');
597 0 for (1 .. $nodes->size()) {
598 0 my $name = $nodes->get_node($_ )->getAttribute('authURI');
599 0 my $lsid = $nodes->get_node($_ )->getAttribute('lsid');
600 0 $old_services{$name}{$lsid} = 1;
601 }
602 # get the new LIST file and extract lsids for all datatypes
603 my $soap =
604 SOAP::Lite->uri($self->_namespace)
605 ->proxy( $self->_endpoint )->on_fault(
606 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
607 0 my $soap = shift;
608 0 my $res = shift;
609 0 $self->throw ("There was a problem calling the registry: " . $self->_endpoint . "\@ " . $self->_namespace . ".\n" . $res);
610 }
611 0 );
612  
613 0 my $xml = $soap->retrieveServiceNames( )->result;
614 0 $parser = XML::LibXML->new();
615 0 $doc = $parser->parse_string($xml);
616 0 $nodes = $doc->documentElement()->getChildrenByTagName('serviceName');
617 0 for (1 .. $nodes->size()) {
618 0 my $name = $nodes->get_node($_ )->getAttribute('authURI');
619 0 my $lsid = $nodes->get_node($_ )->getAttribute('lsid');
620 0 $new_services{$name}{$lsid} = 1;
621 }
622 # go through the keys of the new one and if the keys doesnt exist or has been modified, add to 'download' queue
623 0 foreach my $auth (keys %new_services) {
624 0 ▶ next if $changed_services{$auth};
Branch: 1 branch
BranchTrueFalseTotal
if $changed_services{$auth} 0 0 0
625 0 foreach my $lsid (keys %{$new_services{$auth}}) {
626 0 ▶ next unless !$old_services{$auth}{$lsid};
Branch: 1 branch
BranchTrueFalseTotal
if $old_services{$auth}{$lsid} 0 0 0
627 0 $changed_services{$auth} = 1;
628 }
629
630 }
631  
632 # if their where changes, save new LIST file over the old one and get changes
633 0 ▶ if (keys %changed_services) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %changed_services) 0 0 0
634 # save new LIST file
635 0 ▶ open (FILE, ">$file")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or $self->throw("Can't open file '${file}' for writing: $!") 0 0 0
636 or $self->throw ("Can't open file '$file' for writing: $!");
637 0 print FILE $xml;
638 0 close FILE;
639 # clear used values
640 0 $xml = undef;
641 0 $file = undef;
642 0 $parser = undef;
643 0 $doc = undef;
644 0 $nodes = undef;
645 0 foreach my $authURI (keys %changed_services) {
646 0 my $input =<<END;
647 <findService>
648 <authURI>$authURI</authURI>
649 </findService>
650 END
651 0 $xml =
652 $soap->findService ( SOAP::Data->type('string' => "$input") )->result;
653 0 $file = File::Spec->catfile ($self->cachedir,
654 $self->_clean ($self->_endpoint),
655 SERVICES_CACHE,
656 $authURI);
657 0 ▶ open (FILE, ">$file") or $self->throw ("Can't open file '$file' for writing: $!");
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or $self->throw("Can't open file '${file}' for writing: $!") 0 0 0
658 0 print FILE $xml;
659 0 close FILE;
660 }
661 }
662 }
663  
664 #-----------------------------------------------------------------
665 # _createDataTypeFromXML
666 # given xmlString, build a MOSES::MOBY::Def::DataType
667 #-----------------------------------------------------------------
668 0 ▶sub _createDataTypeFromXML {
Subroutine _createDataTypeFromXML: not called CC=36 SCAR=71.9
669 0 my ($self, $xml) = @_;
670 0 my $parser = XML::LibXML->new();
671 0 my $doc = $parser->parse_string($xml);
672
673 #print $doc->toString(1) ."\n";
674 0 my $datatype = MOSES::MOBY::Def::DataType->new();
675
676 0 my $nodes = $doc->documentElement()->getChildrenByTagName('objectType');
677
678 # nodes should contain 1 element
679 0 ▶ my $lsid = $nodes->get_node(1)->getAttribute('lsid')
Branch: 1 branch
BranchTrueFalseTotal
if $nodes and $nodes->get_node(1) and $nodes->get_node(1)->getAttribute("lsid") 0 0 0
Condition0%0/6
$nodes and $nodes->get_node(1) and $nodes->get_node(1)->getAttribute("lsid")
!ll&&!rl&&r
000
$nodes and $nodes->get_node(1)
!ll&&!rl&&r
000
MC/DC0%0/3
$nodes and $nodes->get_node(1) and $nodes->get_node(1)->getAttribute("lsid")
$nodes $nodes->get_node(1) $nodes->get_node(1)->getAttribute("lsid")
Truth table0%0/4
A and B and C
A= $nodesB= $nodes->get_node(1)C= $nodes->get_node(1)->getAttribute("lsid")
ABCresult
0XX0
10X0
1100
1111
680 if ( $nodes
681 and $nodes->get_node(1)
682 and $nodes->get_node(1)->getAttribute('lsid') );
683 0 $datatype->lsid($lsid);
684 0 ▶ my $datatypeName = $nodes->get_node(1)->textContent
Branch: 1 branch
BranchTrueFalseTotal
if $nodes and $nodes->get_node(1) and $nodes->get_node(1) 0 0 0
Condition0%0/6
$nodes and $nodes->get_node(1) and $nodes->get_node(1)
!ll&&!rl&&r
000
$nodes and $nodes->get_node(1)
!ll&&!rl&&r
000
MC/DC0%0/3
$nodes and $nodes->get_node(1) and $nodes->get_node(1)
$nodes $nodes->get_node(1) $nodes->get_node(1)
Truth table0%0/4
A and B and C
A= $nodesB= $nodes->get_node(1)C= $nodes->get_node(1)
ABCresult
0XX0
10X0
1100
1111
685 if ( $nodes
686 and $nodes->get_node(1)
687 and $nodes->get_node(1) );
688 0 $datatype->name($datatypeName);
689
690 0 $nodes = $doc->documentElement()->getChildrenByTagName('Description');
691 0 ▶ my $desc = $nodes->get_node(1)->textContent
Branch: 1 branch
BranchTrueFalseTotal
if $nodes and $nodes->get_node(1) 0 0 0
Condition0%0/3
$nodes and $nodes->get_node(1)
!ll&&!rl&&r
000
MC/DC0%0/2
$nodes and $nodes->get_node(1)
$nodes $nodes->get_node(1)
Truth table0%0/3
A and B
A= $nodesB= $nodes->get_node(1)
ABresult
0X0
100
111
692 if ( $nodes and $nodes->get_node(1) );
693 0 $datatype->description($desc);
694
695 0 $nodes = $doc->documentElement()->getChildrenByTagName('authURI');
696 0 ▶ my $auth = $nodes->get_node(1)->textContent
Branch: 1 branch
BranchTrueFalseTotal
if $nodes and $nodes->get_node(1) 0 0 0
Condition0%0/3
$nodes and $nodes->get_node(1)
!ll&&!rl&&r
000
MC/DC0%0/2
$nodes and $nodes->get_node(1)
$nodes $nodes->get_node(1)
Truth table0%0/3
A and B
A= $nodesB= $nodes->get_node(1)
ABresult
0X0
100
111
697 if ( $nodes and $nodes->get_node(1) );
698 0 $datatype->authority($auth);
699
700 0 $nodes = $doc->documentElement()->getChildrenByTagName('contactEmail');
701 0 ▶ my $email = $nodes->get_node(1)->textContent
Branch: 1 branch
BranchTrueFalseTotal
if $nodes and $nodes->get_node(1) 0 0 0
Condition0%0/3
$nodes and $nodes->get_node(1)
!ll&&!rl&&r
000
MC/DC0%0/2
$nodes and $nodes->get_node(1)
$nodes $nodes->get_node(1)
Truth table0%0/3
A and B
A= $nodesB= $nodes->get_node(1)
ABresult
0X0
100
111
702 if ( $nodes and $nodes->get_node(1) );
703 0 $datatype->email($email);
704
705 # extract relationships :-> an array of up to 3 nodes
706 0 $nodes = $doc->documentElement()->getChildrenByTagName('Relationship');
707 0 my $count = $nodes->size();
708 0 ▶ while ( $count > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) 0 0 0
709 0 my $node = $nodes->get_node( $count-- );
710 0 my $relationship = $node->getAttribute('relationshipType');
711 0 ▶ if ( $relationship =~ /^.*isa$/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($relationship =~ /^.*isa$/i) { } 0 0 0
elsif ($relationship =~ /^.*hasa$/i) { } 0 0 0
elsif ($relationship =~ /^.*has$/i) { } 0 0 0
712 0 my $parent = $node->getChildrenByTagName('objectType');
713 0 ▶ my $isa = $parent->get_node(1)->textContent
Branch: 1 branch
BranchTrueFalseTotal
if $parent and $parent->get_node(1) and $parent->get_node(1) 0 0 0
Condition0%0/6
$parent and $parent->get_node(1) and $parent->get_node(1)
!ll&&!rl&&r
000
$parent and $parent->get_node(1)
!ll&&!rl&&r
000
MC/DC0%0/3
$parent and $parent->get_node(1) and $parent->get_node(1)
$parent $parent->get_node(1) $parent->get_node(1)
Truth table0%0/4
A and B and C
A= $parentB= $parent->get_node(1)C= $parent->get_node(1)
ABCresult
0XX0
10X0
1100
1111
714 if ( $parent and $parent->get_node(1) and $parent->get_node(1) );
715 0 $datatype->parent($isa);
716 }
717 elsif ( $relationship =~ /^.*hasa$/i ) {
718 0 my $pNode = $node->getChildrenByTagName('objectType');
719 0 ▶ for ( my $i = 1 ; $i <= $pNode->size() ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $pNode->size) 0 0 0
720 0 ▶ my $article = $pNode->get_node($i)->getAttribute('articleName')
Branch: 1 branch
BranchTrueFalseTotal
if $pNode and $pNode->get_node(1) and $pNode->get_node($i)->getAttribute("articleName") 0 0 0
Condition0%0/6
$pNode and $pNode->get_node(1) and $pNode->get_node($i)->getAttribute("articleName")
!ll&&!rl&&r
000
$pNode and $pNode->get_node(1)
!ll&&!rl&&r
000
MC/DC0%0/3
$pNode and $pNode->get_node(1) and $pNode->get_node($i)->getAttribute("articleName")
$pNode $pNode->get_node(1) $pNode->get_node($i)->getAttribute("articleName")
Truth table0%0/4
A and B and C
A= $pNodeB= $pNode->get_node(1)C= $pNode->get_node($i)->getAttribute("articleName")
ABCresult
0XX0
10X0
1100
1111
721 if ( $pNode
722 and $pNode->get_node(1)
723 and $pNode->get_node($i)->getAttribute('articleName') );
724 0 ▶ my $dt = $pNode->get_node($i)->textContent
Branch: 1 branch
BranchTrueFalseTotal
if $pNode and $pNode->get_node($i) and $pNode->get_node($i) 0 0 0
Condition0%0/6
$pNode and $pNode->get_node($i) and $pNode->get_node($i)
!ll&&!rl&&r
000
$pNode and $pNode->get_node($i)
!ll&&!rl&&r
000
MC/DC0%0/3
$pNode and $pNode->get_node($i) and $pNode->get_node($i)
$pNode $pNode->get_node($i) $pNode->get_node($i)
Truth table0%0/4
A and B and C
A= $pNodeB= $pNode->get_node($i)C= $pNode->get_node($i)
ABCresult
0XX0
10X0
1100
1111
725 if ( $pNode
726 and $pNode->get_node($i)
727 and $pNode->get_node($i) );
728 push(
729 0 ▶ @{ $datatype->children },
Condition0%0/2
$article || 'MISSING_MEMBER_NAME'
l!l
00
MC/DC0%0/1
$article || 'MISSING_MEMBER_NAME'
$article
Truth table0%0/2
A
A= $article
Aresult
11
00
730 new MOSES::MOBY::Def::Relationship(
731 memberName => $article || 'MISSING_MEMBER_NAME',
732 datatype => $dt,
733 relationship => HASA
734 )
735 );
736 }
737 }
738 elsif ( $relationship =~ /^.*has$/i ) {
739 0 my $pNode = $node->getChildrenByTagName('objectType');
740 0 ▶ for ( my $i = 1 ; $i <= $pNode->size() ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $pNode->size) 0 0 0
741 0 ▶ my $article = $pNode->get_node($i)->getAttribute('articleName')
Branch: 1 branch
BranchTrueFalseTotal
if $pNode and $pNode->get_node($i) and $pNode->get_node($i)->getAttribute("articleName") 0 0 0
Condition0%0/6
$pNode and $pNode->get_node($i) and $pNode->get_node($i)->getAttribute("articleName")
!ll&&!rl&&r
000
$pNode and $pNode->get_node($i)
!ll&&!rl&&r
000
MC/DC0%0/3
$pNode and $pNode->get_node($i) and $pNode->get_node($i)->getAttribute("articleName")
$pNode $pNode->get_node($i) $pNode->get_node($i)->getAttribute("articleName")
Truth table0%0/4
A and B and C
A= $pNodeB= $pNode->get_node($i)C= $pNode->get_node($i)->getAttribute("articleName")
ABCresult
0XX0
10X0
1100
1111
742 if ( $pNode
743 and $pNode->get_node($i)
744 and $pNode->get_node($i)->getAttribute('articleName') );
745 0 ▶ my $dt = $pNode->get_node($i)->textContent
Branch: 1 branch
BranchTrueFalseTotal
if $pNode and $pNode->get_node(1) and $pNode->get_node(1) 0 0 0
Condition0%0/6
$pNode and $pNode->get_node(1) and $pNode->get_node(1)
!ll&&!rl&&r
000
$pNode and $pNode->get_node(1)
!ll&&!rl&&r
000
MC/DC0%0/3
$pNode and $pNode->get_node(1) and $pNode->get_node(1)
$pNode $pNode->get_node(1) $pNode->get_node(1)
Truth table0%0/4
A and B and C
A= $pNodeB= $pNode->get_node(1)C= $pNode->get_node(1)
ABCresult
0XX0
10X0
1100
1111
746 if ( $pNode and $pNode->get_node(1) and $pNode->get_node(1) );
747 push(
748 0 ▶ @{ $datatype->children },
Condition0%0/2
$article || 'MISSING_MEMBER_NAME'
l!l
00
MC/DC0%0/1
$article || 'MISSING_MEMBER_NAME'
$article
Truth table0%0/2
A
A= $article
Aresult
11
00
749 new MOSES::MOBY::Def::Relationship(
750 memberName => $article || 'MISSING_MEMBER_NAME',
751 datatype => $dt,
752 relationship => HAS
753 )
754 );
755 }
756 }
757 }
758
759 0 return $datatype;
760  
761 #print $datatype->toString();
762 }
763  
764 #-----------------------------------------------------------------
765 # get_datatype_names
766 #-----------------------------------------------------------------
767  
768 =head2 get_datatype_names
769  
770 Return an array of data type names obtained from the cache. The cache
771 is defined by the C<cachedir> (and optionally by the C<registry>)
772 parameters given in the constructor of this instance.
773  
774 =cut
775  
776 0 ▶sub get_datatype_names {
Subroutine get_datatype_names: not called CC=3 SCAR=24.8
Pod documented
777 0 my $self = shift;
778  
779 0 my $pathToList = File::Spec->catfile ($self->cachedir,
780 $self->_clean ($self->_endpoint),
781 DATATYPES_CACHE);
782 0 my @names = ();
783 0 my $parser = XML::LibXML->new();
784  
785 0 my $doc = $parser->parse_file ( File::Spec->catfile ($pathToList, LIST_FILE) );
786
787 0 my $nodes = $doc->documentElement()->getChildrenByTagName ('Object');
788 0 ▶ for ( my $i = 1 ; $i <= $nodes->size() ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $nodes->size) 0 0 0
789 0 my $node = $nodes->get_node($i);
790 0 ▶ next unless $node->getAttribute ('name');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->getAttribute("name") 0 0 0
791 0 push (@names, $node->getAttribute ('name'));
792 }
793 0 return @names;
794 }
795  
796 #-----------------------------------------------------------------
797 # _clean
798 # Returns a string that has all of the non-digits and letters
799 # converted to a numerical ASCII representation. Used for creating a
800 # directory name from the registry URL.
801 #-----------------------------------------------------------------
802 0 ▶sub _clean {
Subroutine _clean: not called CC=5 SCAR=34.0
803 0 my $self = shift;
804 0 my $lastOneWasDigitalized = 0;
805
806 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
807 0 my $toBeCleaned = shift;
808 0 my $string = '';
809 0 my @array = split( //, $toBeCleaned );
810 0 foreach my $char (@array) {
811 0 ▶ if ( not $char =~ /[a-zA-z0-9]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $char =~ /[a-zA-z0-9]/) { } 0 0 0
812 0 ▶ $string = $string
Branch: 1 branch
BranchTrueFalseTotal
$lastOneWasDigitalized == 1 ? : 0 0 0
813 . ( ( $lastOneWasDigitalized == 1 ? "." : "" ) . ord($char) );
814 0 $lastOneWasDigitalized = 1;
815 }
816 else {
817 0 $lastOneWasDigitalized = 0;
818 0 $string = $string . "$char";
819 }
820 }
821 0 return $string;
822 }
823 0 return '';
824 }
825  
826 #-----------------------------------------------------------------
827 # get_related_types
828 #-----------------------------------------------------------------
829  
830 =head2 get_related_types
831  
832 Return a reference to an array of C<MOSES::MOBY::Def::DataType> objects (they
833 were generated from the local Moby cache). Include only those data
834 types that are referred to (used by) the given data type.
835  
836 An argument is one or more data types (C<MOSES::MOBY::Def::DataType>) whose
837 related data types are looked for.
838  
839 =cut
840  
841 0 ▶sub get_related_types {
Subroutine get_related_types: not called CC=2 SCAR=17.9
Pod documented
842 0 my ($self, @datatypes) = @_;
843 0 my $sofar_seen = {};
844 0 foreach my $datatype (@datatypes) {
845 0 $self->_get_related_types ($datatype, $sofar_seen);
846 }
847 0 return [ sort { $a->name cmp $b->name } values (%{ $sofar_seen }) ];
848 }
849  
850 0 ▶sub _get_related_types {
Subroutine _get_related_types: not called CC=4 SCAR=30.0
851 0 my ($self, $datatype, $sofar_seen) = @_;
852 0 ▶ return $sofar_seen unless $datatype;
Branch: 1 branch
BranchTrueFalseTotal
unless $datatype 0 0 0
853 0 $$sofar_seen{$datatype->name} = $datatype;
854  
855 # go up (ISA line)
856 0 $self->_add_types ($datatype->parent, $sofar_seen);
857  
858 # go down (HAS[A] line)
859 0 ▶ if ($datatype->children) {
Branch: 1 branch
BranchTrueFalseTotal
if ($datatype->children) 0 0 0
860 0 foreach my $child_name (@{ $datatype->children }) {
861 0 $self->_add_types ($child_name->datatype, $sofar_seen);
862 }
863 }
864 }
865  
866 0 ▶sub _add_types {
Subroutine _add_types: not called CC=3 SCAR=24.8
867 0 my ($self, $datatype_name, $sofar_seen) = @_;
868 0 ▶ if ($datatype_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($datatype_name) 0 0 0
869 0 ▶ unless (exists ($$sofar_seen{$datatype_name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $sofar_seen->{$datatype_name}) 0 0 0
870 0 my $related_obj = $self->get_datatype ($datatype_name);
871 0 $self->_get_related_types ($related_obj, $sofar_seen);
872 }
873 }
874 }
875  
876 #-----------------------------------------------------------------
877 # get_all_children
878 # return an array of MOSES::MOBY::Def::Relationship
879 #-----------------------------------------------------------------
880 0 ▶sub get_all_children {
Subroutine get_all_children: not called CC=2 SCAR=17.9
Pod undocumented
881 0 my ($self, $datatype_name) = @_;
882 0 my @children = ();
883 0 ▶ while ($datatype_name ne 'Object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($datatype_name ne "Object") 0 0 0
884 0 my $datatype = $self->get_datatype ($datatype_name);
885 0 push (@children, @{ $datatype->children });
886 0 $datatype_name = $datatype->parent;
887 }
888 0 return @children;
889 }
890  
891 #-----------------------------------------------------------------
892 # get_services
893 #-----------------------------------------------------------------
894  
895 =head2 get_services
896  
897 Return an array of BioMoby service definitions (type
898 C<MOSES::MOBY::Def::Service>), as obtained from a local cache.
899  
900 Without any arguments it returns all services from all authorities:
901  
902 use MOSES::MOBY::Cache::Central;
903  
904 # create an aceess to a Moby registry cache
905 # (use 'registry' only for non-default registries)
906 my $cache = new MOSES::MOBY::Cache::Central
907 ( cachedir =>'/usr/local/cache/',
908 registry => 'http://my.moby.registry/endpoint/mobycentral.pl'
909 );
910  
911 my @services = $cache->get_services;
912  
913 If there is one argument, it should be a scalar, containing an
914 authority name. All services from this authority are returned. It
915 throws an exception if such named authority does not exist in the
916 local cache:
917  
918 @services = $cache->get_services ($authority);
919  
920 If there are more arguments, the first is always an authority name, as
921 above, and the remaining are the service names (from the same
922 authority) wanted to be returned. If any of these names represents an
923 unknown service, it is ignored (no exception thrown):
924  
925 @services = $cache->get_services ('samples.jmoby.net',
926 qw ( HelloBiomobyWorld Mabuhay ));
927 or
928
929 @services = $cache->get_services ('samples.jmoby.net', 'Mabuhay');
930  
931 =cut
932  
933 0 ▶sub get_services {
Subroutine get_services: not called CC=6 SCAR=37.4
Pod documented
934 0 my ($self, @services) = @_;
935  
936 # print "GS: " . join (", ", @services) . "\n";
937  
938 # no authority given: get all services
939 0 ▶ unless (@services) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@services) 0 0 0
940 0 my %by_authorities = $self->get_service_names;
941 0 foreach my $authority (sort keys (%by_authorities)) {
942 0 push (@services, $self->get_services ($authority));
943 }
944 0 return @services;
945 }
946  
947 # okay, we have an authority; read her XML definitions
948 0 my $authority = shift @services;
949 0 my $file = File::Spec->catfile ($self->cachedir,
950 $self->_clean ($self->_endpoint),
951 SERVICES_CACHE,
952 $authority);
953 0 my $xml = '';
954 0 local $/ = undef;
955 0 ▶ open (FILE, "<$file")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<$file" or $self->throw("Can't open file $file for reading: $!") 0 0 0
956 or $self->throw ("Can't open file $file for reading: $!");
957 0 $xml = <FILE>;
958 0 close FILE;
959  
960 # finally, get services from the authority XML
961 0 ▶ if (@services) {
Branch: 1 branch
BranchTrueFalseTotal
if (@services) 0 0 0
962 # get services by name
963 0 my @result = ();
964 0 foreach my $name (@services) {
965 0 push (@result, $self->_createServiceFromXML ($xml, $name, $authority));
966 }
967 0 return @result;
968 }
969  
970 # get them all (from given authority)
971 0 return $self->_createAllServicesFromXML ($xml);
972 }
973  
974 #-----------------------------------------------------------------
975 # _createServiceFromXML
976 # given xmlString and a service name, build a MOSES::MOBY::Def::Service
977 #-----------------------------------------------------------------
978 0 ▶sub _createServiceFromXML {
Subroutine _createServiceFromXML: not called CC=61 SCAR=82.4
979 0 my ($self, $xml, $service_name, $service_authority) = @_;
980 0 my $parser = XML::LibXML->new();
981 0 my $doc = $parser->parse_string($xml);
982
983 0 my $service = MOSES::MOBY::Def::Service->new();
984 0 my @nodes = $doc->documentElement()->findnodes('*[@serviceName="'.$service_name.'"][@authURI="'.$service_authority.'"]');
985 0 my $service_node = undef;
986 0 $service_node = $nodes[0];
987 0 ▶ $self->throw ("Service, '$service_name', under the authority, '$service_authority', was not found in the cache.") unless $service_node;
Branch: 1 branch
BranchTrueFalseTotal
unless $service_node 0 0 0
988
989 0 ▶ $service->name($service_node->getAttribute('serviceName') || $service_name);
Condition0%0/3
$service_node->getAttribute('serviceName') || $service_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$service_node->getAttribute('serviceName') || $service_name
$service_node->getAttribute('serviceName') $service_name
Truth table0%0/3
A || B
A= $service_node->getAttribute('serviceName')B= $service_name
ABresult
1X1
011
000
990 0 ▶ $service->authority($service_node->getAttribute('authURI') || '');
Condition0%0/2
$service_node->getAttribute('authURI') || ''
l!l
00
MC/DC0%0/1
$service_node->getAttribute('authURI') || ''
$service_node->getAttribute('authURI')
Truth table0%0/2
A
A= $service_node->getAttribute('authURI')
Aresult
11
00
991 0 ▶ $service->lsid($service_node->getAttribute('lsid') || '');
Condition0%0/2
$service_node->getAttribute('lsid') || ''
l!l
00
MC/DC0%0/1
$service_node->getAttribute('lsid') || ''
$service_node->getAttribute('lsid')
Truth table0%0/2
A
A= $service_node->getAttribute('lsid')
Aresult
11
00
992 0 ▶ $service->type($service_node->getChildrenByTagName('serviceType')->get_node(1)->textContent) if $service_node->getChildrenByTagName('serviceType')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("serviceType")->size > 0 0 0 0
993 0 ▶ $service->authoritative($service_node->getChildrenByTagName('authoritative')->get_node(1)->textContent) if $service_node->getChildrenByTagName('authoritative')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("authoritative")->size > 0 0 0 0
994 0 ▶ $service->category($service_node->getChildrenByTagName('Category')->get_node(1)->textContent) if $service_node->getChildrenByTagName('Category')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("Category")->size > 0 0 0 0
995 0 ▶ $service->description($service_node->getChildrenByTagName('Description')->get_node(1)->textContent) if $service_node->getChildrenByTagName('Description')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("Description")->size > 0 0 0 0
996 0 ▶ $service->email($service_node->getChildrenByTagName('contactEmail')->get_node(1)->textContent) if $service_node->getChildrenByTagName('contactEmail')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("contactEmail")->size > 0 0 0 0
997 0 ▶ $service->signatureURL($service_node->getChildrenByTagName('signatureURL')->get_node(1)->textContent) if $service_node->getChildrenByTagName('signatureURL')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("signatureURL")->size > 0 0 0 0
998 0 ▶ $service->url($service_node->getChildrenByTagName('URL')->get_node(1)->textContent) if $service_node->getChildrenByTagName('URL')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("URL")->size > 0 0 0 0
999
1000 0 ▶ my $input = $service_node->getChildrenByTagName('Input')->get_node(1) if $service_node->getChildrenByTagName('Input')->size > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("Input")->size > 0 0 0 0
1001 0 ▶ if ($input) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input) 0 0 0
1002 0 my $simples = $input->getChildrenByTagName('Simple');
1003 0 ▶ for ( my $i = 1 ; $i <= $simples->size() ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $simples->size) 0 0 0
1004 0 my $simple = $simples->get_node($i);
1005 0 ▶ my $article_name = $simple->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_INPUT';
Condition0%0/2
$simple->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_INPUT'
l!l
00
MC/DC0%0/1
$simple->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_INPUT'
$simple->getAttribute('articleName')
Truth table0%0/2
A
A= $simple->getAttribute('articleName')
Aresult
11
00
1006 0 ▶ my $object_type = $simple->getChildrenByTagName('objectType')->get_node(1) if $simple->getChildrenByTagName('objectType')->size > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $simple->getChildrenByTagName("objectType")->size > 0 0 0 0
1007 0 ▶ $self->throw('Simple input missing an object type') unless $object_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $object_type 0 0 0
1008 0 $object_type = $object_type->textContent;
1009
1010 0 my $primary = MOSES::MOBY::Def::PrimaryDataSimple->new;
1011 0 $primary->name($article_name);
1012 0 $primary->datatype(new MOSES::MOBY::Def::DataType(name=>$object_type));
1013
1014 0 my $namespaces = $simple->getChildrenByTagName('Namespace');
1015 0 ▶ for ( my $j = 1 ; $j <= $namespaces->size() ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $namespaces->size) 0 0 0
1016 0 my $namespace = $namespaces->get_node($j)->textContent;
1017 0 $primary->add_namespaces(MOSES::MOBY::Def::Namespace->new(name=>$namespace));
1018 }
1019 0 $service->add_inputs($primary);
1020 }
1021 0 my $collections = $input->getChildrenByTagName('Collection');
1022 0 ▶ for ( my $i = 1 ; $i <= $collections->size() ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $collections->size) 0 0 0
1023 0 my $collection = $collections->get_node($i);
1024 0 ▶ my $article_name = $collection->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_INPUT';
Condition0%0/2
$collection->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_INPUT'
l!l
00
MC/DC0%0/1
$collection->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_INPUT'
$collection->getAttribute('articleName')
Truth table0%0/2
A
A= $collection->getAttribute('articleName')
Aresult
11
00
1025 0 my $primaryCollection = MOSES::MOBY::Def::PrimaryDataSet->new(name=>$article_name);
1026 0 ▶ $simples = $collection->getChildrenByTagName('Simple') || ();
Condition0%0/3
$collection->getChildrenByTagName('Simple') || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$collection->getChildrenByTagName('Simple') || ()
$collection->getChildrenByTagName('Simple') ()
Truth table0%0/3
A || B
A= $collection->getChildrenByTagName('Simple')B= ()
ABresult
1X1
011
000
1027 0 ▶ for ( my $j = 1 ; $j <= $simples->size() ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $simples->size) 0 0 0
1028 0 my $simple = $simples->get_node($j);
1029 0 ▶ my $article_name = $simple->getAttribute('articleName') || '';
Condition0%0/2
$simple->getAttribute('articleName') || ''
l!l
00
MC/DC0%0/1
$simple->getAttribute('articleName') || ''
$simple->getAttribute('articleName')
Truth table0%0/2
A
A= $simple->getAttribute('articleName')
Aresult
11
00
1030 0 ▶ my $object_type = $simple->getChildrenByTagName('objectType')->get_node(1) if $simple->getChildrenByTagName('objectType')->size > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $simple->getChildrenByTagName("objectType")->size > 0 0 0 0
1031 0 ▶ $self->throw('Simple input missing an object type') unless $object_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $object_type 0 0 0
1032 0 $object_type = $object_type->textContent;
1033
1034 0 my $primary = MOSES::MOBY::Def::PrimaryDataSimple->new;
1035 0 $primary->name($article_name);
1036 0 $primary->datatype(new MOSES::MOBY::Def::DataType(name=>$object_type));
1037
1038 0 my $namespaces = $simple->getChildrenByTagName('Namespace');
1039 0 ▶ for ( my $j = 1 ; $j <= $namespaces->size() ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $namespaces->size) 0 0 0
1040 0 my $namespace = $namespaces->get_node($j)->textContent;
1041 0 $primary->add_namespaces(MOSES::MOBY::Def::Namespace->new(name=>$namespace));
1042 }
1043 0 $primaryCollection->add_elements($primary);
1044 }
1045 0 $service->add_inputs($primaryCollection);
1046 }
1047 }
1048
1049 0 ▶ my $secondary = $service_node->getChildrenByTagName('secondaryArticles')->get_node(1) if $service_node->getChildrenByTagName('secondaryArticles')->size > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("secondaryArticles")->size > 0 0 0 0
1050 0 ▶ if ($secondary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($secondary) 0 0 0
1051 0 my $parameters = $secondary->getChildrenByTagName('Parameter');
1052 0 ▶ for (my $i = 1; $i <= $parameters->size(); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $parameters->size) 0 0 0
1053 0 my $parameter = $parameters->get_node($i);
1054 0 ▶ my $article_name = $parameter->getAttribute('articleName') || 'MISSING_PARAMETER_NAME';
Condition0%0/2
$parameter->getAttribute('articleName') || 'MISSING_PARAMETER_NAME'
l!l
00
MC/DC0%0/1
$parameter->getAttribute('articleName') || 'MISSING_PARAMETER_NAME'
$parameter->getAttribute('articleName')
Truth table0%0/2
A
A= $parameter->getAttribute('articleName')
Aresult
11
00
1055 0 ▶ my $description = $parameter->getChildrenByTagName('description')->get_node(1)->textContent if $parameter->getChildrenByTagName('description') and $parameter->getChildrenByTagName('description')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $parameter->getChildrenByTagName("description") and $parameter->getChildrenByTagName("description")->size > 0 0 0 0
Condition0%0/3
$parameter->getChildrenByTagName("description") and $parameter->getChildrenByTagName("description")->size > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$parameter->getChildrenByTagName("description") and $parameter->getChildrenByTagName("description")->size > 0
$parameter->getChildrenByTagName("description") $parameter->getChildrenByTagName("description")->size > 0
Truth table0%0/3
A and B
A= $parameter->getChildrenByTagName("description")B= $parameter->getChildrenByTagName("description")->size > 0
ABresult
0X0
100
111
1056 0 ▶ my $default = $parameter->getChildrenByTagName('default')->get_node(1)->textContent if $parameter->getChildrenByTagName('default') and $parameter->getChildrenByTagName('default')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $parameter->getChildrenByTagName("default") and $parameter->getChildrenByTagName("default")->size > 0 0 0 0
Condition0%0/3
$parameter->getChildrenByTagName("default") and $parameter->getChildrenByTagName("default")->size > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$parameter->getChildrenByTagName("default") and $parameter->getChildrenByTagName("default")->size > 0
$parameter->getChildrenByTagName("default") $parameter->getChildrenByTagName("default")->size > 0
Truth table0%0/3
A and B
A= $parameter->getChildrenByTagName("default")B= $parameter->getChildrenByTagName("default")->size > 0
ABresult
0X0
100
111
1057 0 ▶ my $max = $parameter->getChildrenByTagName('max')->get_node(1)->textContent if $parameter->getChildrenByTagName('max') and $parameter->getChildrenByTagName('max')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $parameter->getChildrenByTagName("max") and $parameter->getChildrenByTagName("max")->size > 0 0 0 0
Condition0%0/3
$parameter->getChildrenByTagName("max") and $parameter->getChildrenByTagName("max")->size > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$parameter->getChildrenByTagName("max") and $parameter->getChildrenByTagName("max")->size > 0
$parameter->getChildrenByTagName("max") $parameter->getChildrenByTagName("max")->size > 0
Truth table0%0/3
A and B
A= $parameter->getChildrenByTagName("max")B= $parameter->getChildrenByTagName("max")->size > 0
ABresult
0X0
100
111
1058 0 ▶ my $min = $parameter->getChildrenByTagName('min')->get_node(1)->textContent if $parameter->getChildrenByTagName('min') and $parameter->getChildrenByTagName('min')->size() > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $parameter->getChildrenByTagName("min") and $parameter->getChildrenByTagName("min")->size > 0 0 0 0
Condition0%0/3
$parameter->getChildrenByTagName("min") and $parameter->getChildrenByTagName("min")->size > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$parameter->getChildrenByTagName("min") and $parameter->getChildrenByTagName("min")->size > 0
$parameter->getChildrenByTagName("min") $parameter->getChildrenByTagName("min")->size > 0
Truth table0%0/3
A and B
A= $parameter->getChildrenByTagName("min")B= $parameter->getChildrenByTagName("min")->size > 0
ABresult
0X0
100
111
1059 0 my $enum = $parameter->getChildrenByTagName('enum');
1060
1061 0 my $secondaryParameter = MOSES::MOBY::Def::SecondaryData->new(
1062 name=>$article_name
1063 );
1064
1065 0 ▶ $secondaryParameter->min($min) if $min and $min ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $min and $min ne "" 0 0 0
Condition0%0/3
$min and $min ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$min and $min ne ""
$min $min ne ""
Truth table0%0/3
A and B
A= $minB= $min ne ""
ABresult
0X0
100
111
1066 0 ▶ $secondaryParameter->max($max) if $max and $max ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $max and $max ne "" 0 0 0
Condition0%0/3
$max and $max ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$max and $max ne ""
$max $max ne ""
Truth table0%0/3
A and B
A= $maxB= $max ne ""
ABresult
0X0
100
111
1067 0 ▶ $secondaryParameter->default($default) if $default;
Branch: 1 branch
BranchTrueFalseTotal
if $default 0 0 0
1068 0 ▶ $secondaryParameter->description($description) if $description;
Branch: 1 branch
BranchTrueFalseTotal
if $description 0 0 0
1069 0 ▶ for (my $j = 1; $j <= $enum->size(); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $enum->size) 0 0 0
1070 0 $secondaryParameter->add_allowables($enum->get_node($j)->textContent);
1071 }
1072 0 $service->add_secondarys($secondaryParameter);
1073  
1074 }
1075 }
1076
1077 0 ▶ my $output = $service_node->getChildrenByTagName('Output')->get_node(1) if $service_node->getChildrenByTagName('Output')->size > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $service_node->getChildrenByTagName("Output")->size > 0 0 0 0
1078 0 ▶ if ($output) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output) 0 0 0
1079 0 my $simples = $output->getChildrenByTagName('Simple');
1080 0 ▶ for ( my $i = 1 ; $i <= $simples->size() ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $simples->size) 0 0 0
1081 0 my $simple = $simples->get_node($i);
1082 0 ▶ my $article_name = $simple->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_OUTPUT';
Condition0%0/2
$simple->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_OUTPUT'
l!l
00
MC/DC0%0/1
$simple->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_OUTPUT'
$simple->getAttribute('articleName')
Truth table0%0/2
A
A= $simple->getAttribute('articleName')
Aresult
11
00
1083 0 ▶ my $object_type = $simple->getChildrenByTagName('objectType')->get_node(1) if $simple->getChildrenByTagName('objectType')->size > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $simple->getChildrenByTagName("objectType")->size > 0 0 0 0
1084 0 ▶ $self->throw('Simple output missing an object type') unless $object_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $object_type 0 0 0
1085 0 $object_type = $object_type->textContent;
1086
1087 0 my $primary = MOSES::MOBY::Def::PrimaryDataSimple->new;
1088 0 $primary->name($article_name);
1089 0 $primary->datatype(new MOSES::MOBY::Def::DataType(name=>$object_type));
1090
1091 0 my $namespaces = $simple->getChildrenByTagName('Namespace');
1092 0 ▶ for ( my $j = 1 ; $j <= $namespaces->size() ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $namespaces->size) 0 0 0
1093 0 my $namespace = $namespaces->get_node($j)->textContent;
1094 0 $primary->add_namespaces(MOSES::MOBY::Def::Namespace->new(name=>$namespace));
1095 }
1096 0 $service->add_outputs($primary);
1097 }
1098 0 my $collections = $output->getChildrenByTagName('Collection');
1099 0 ▶ for ( my $i = 1 ; $i <= $collections->size() ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $collections->size) 0 0 0
1100 0 my $collection = $collections->get_node($i);
1101 0 ▶ my $article_name = $collection->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_OUTPUT';
Condition0%0/2
$collection->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_OUTPUT'
l!l
00
MC/DC0%0/1
$collection->getAttribute('articleName') || 'MISSING_ARTICLE_NAME_IN_OUTPUT'
$collection->getAttribute('articleName')
Truth table0%0/2
A
A= $collection->getAttribute('articleName')
Aresult
11
00
1102 0 my $primaryCollection = MOSES::MOBY::Def::PrimaryDataSet->new(name=>$article_name);
1103 0 ▶ $simples = $collection->getChildrenByTagName('Simple') || ();
Condition0%0/3
$collection->getChildrenByTagName('Simple') || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$collection->getChildrenByTagName('Simple') || ()
$collection->getChildrenByTagName('Simple') ()
Truth table0%0/3
A || B
A= $collection->getChildrenByTagName('Simple')B= ()
ABresult
1X1
011
000
1104 0 ▶ for ( my $j = 1 ; $j <= $simples->size() ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $simples->size) 0 0 0
1105 0 my $simple = $simples->get_node($j);
1106 0 ▶ my $article_name = $simple->getAttribute('articleName') || '';
Condition0%0/2
$simple->getAttribute('articleName') || ''
l!l
00
MC/DC0%0/1
$simple->getAttribute('articleName') || ''
$simple->getAttribute('articleName')
Truth table0%0/2
A
A= $simple->getAttribute('articleName')
Aresult
11
00
1107 0 ▶ my $object_type = $simple->getChildrenByTagName('objectType')->get_node(1) if $simple->getChildrenByTagName('objectType')->size > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $simple->getChildrenByTagName("objectType")->size > 0 0 0 0
1108 0 ▶ $self->throw('Simple input missing an object type') unless $object_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $object_type 0 0 0
1109 0 $object_type = $object_type->textContent;
1110
1111 0 my $primary = MOSES::MOBY::Def::PrimaryDataSimple->new;
1112 0 $primary->name($article_name);
1113 0 $primary->datatype(new MOSES::MOBY::Def::DataType(name=>$object_type));
1114
1115 0 my $namespaces = $simple->getChildrenByTagName('Namespace');
1116 0 ▶ for ( my $j = 1 ; $j <= $namespaces->size() ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $namespaces->size) 0 0 0
1117 0 my $namespace = $namespaces->get_node($j)->textContent;
1118 0 $primary->add_namespaces(MOSES::MOBY::Def::Namespace->new(name=>$namespace));
1119 }
1120 0 $primaryCollection->add_elements($primary);
1121 }
1122 0 $service->add_outputs($primaryCollection);
1123 }
1124 }
1125 0 return $service;
1126 }
1127  
1128 #-----------------------------------------------------------------
1129 # _createAllServicesFromXML
1130 # given xmlString, build an array of MOSES::MOBY::Def::Service
1131 # contained in the xml
1132 #-----------------------------------------------------------------
1133 0 ▶sub _createAllServicesFromXML {
Subroutine _createAllServicesFromXML: not called CC=2 SCAR=17.9
1134 0 my ($self, $xml) = @_;
1135 0 my $parser = XML::LibXML->new();
1136 0 my $doc = $parser->parse_string($xml);
1137
1138 0 my $service_name = "";
1139 0 my $authority = "";
1140 0 my @services = ();
1141
1142 0 my $nodes = $doc->documentElement->getChildrenByTagName('Service');
1143 0 ▶ for (my $i = 1; $i <= $nodes->size; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $nodes->size) 0 0 0
1144 0 $service_name = $nodes->get_node($i)->getAttribute('serviceName');
1145 0 $authority = $nodes->get_node($i)->getAttribute('authURI');
1146 0 my $service = $self->_createServiceFromXML($xml, $service_name, $authority);
1147 0 push @services, $service;
1148 }
1149 0 return @services;
1150 }
1151  
1152 #-----------------------------------------------------------------
1153 # get_service_names
1154 #-----------------------------------------------------------------
1155  
1156 =head2 get_service_names
1157  
1158 Return a hash where keys are authority names and values are array
1159 references with service names belonging to corresponding authorities.
1160  
1161 =cut
1162  
1163 0 ▶sub get_service_names {
Subroutine get_service_names: not called CC=4 SCAR=30.0
Pod documented
1164 0 my $self = shift;
1165 0 my $pathToList = File::Spec->catfile ($self->cachedir,
1166 $self->_clean ($self->_endpoint),
1167 SERVICES_CACHE);
1168 0 my %hash;
1169 0 my $parser = XML::LibXML->new();
1170  
1171 0 my $doc = $parser->parse_file ( File::Spec->catfile ($pathToList, LIST_FILE) );
1172
1173 0 my $nodes = $doc->documentElement()->getChildrenByTagName ('serviceName');
1174
1175 0 ▶ for ( my $i = 1 ; $i <= $nodes->size() ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $nodes->size) 0 0 0
1176 0 my $node = $nodes->get_node($i);
1177 0 ▶ next unless $node->getAttribute ('name');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->getAttribute("name") 0 0 0
1178 0 my $name = $node->getAttribute('name');
1179 0 my $authority = $node->getAttribute('authURI');
1180 0 ▶ if (exists $hash{$authority}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash{$authority}) { } 0 0 0
1181 0 my $array_ref = $hash{$authority};
1182 0 my @array = @{$array_ref};
1183 0 push @{array}, $name;
1184 0 $hash{$authority} = \@array;
1185 }else {
1186 0 my @array = ();
1187 0 push @array, $name;
1188 0 $hash{$authority} = \@array;
1189 }
1190 }
1191 0 return %hash;
1192 }
1193  
1194 #-----------------------------------------------------------------
1195 # cache_exists
1196 #-----------------------------------------------------------------
1197  
1198 =head2 cache_exists
1199  
1200 Return true if a local cache for the given registry exists (or
1201 probably exists). An argument is a synonym, or an endpoint, of a
1202 registry. See more about registry synonyms in
1203 L<MOSES::MOBY::Cache::Registries>.
1204  
1205 Here is how to ask for all existing registries:
1206  
1207  
1208  
1209 =cut
1210  
1211 0 ▶sub cache_exists {
Subroutine cache_exists: not called CC=1 SCAR=6.9
Pod documented
1212 0 my ($self, $registry) = @_;
1213 0 my $pathToList = File::Spec->catfile ($self->cachedir,
1214 $self->_clean ($self->_endpoint ($registry)),
1215 SERVICES_CACHE);
1216 0 return -e $pathToList;
1217 }
1218  
1219  
1220 #-----------------------------------------------------------------
1221 # create_cache_dirs
1222 #-----------------------------------------------------------------
1223  
1224 =head2 create_cache_dirs
1225  
1226 Creates the cache directories needed for generating datatypes and services.
1227  
1228 Throws an exception if there are problems creating the directories.
1229  
1230 =cut
1231  
1232 0 ▶sub create_cache_dirs {
Subroutine create_cache_dirs: not called CC=6 SCAR=37.4
Pod documented
1233 0 my ($self)= @_;
1234 0 my @dirs = (
1235 File::Spec->catfile ($self->cachedir,$self->_clean ($self->_endpoint),DATATYPES_CACHE),
1236 File::Spec->catdir ($self->cachedir,$self->_clean ($self->_endpoint),SERVICES_CACHE),
1237 File::Spec->catdir ($self->cachedir,$self->_clean ($self->_endpoint),NAMESPACES_CACHE),
1238 File::Spec->catdir ($self->cachedir,$self->_clean ($self->_endpoint),SERVICETYPES_CACHE),
1239 );
1240
1241 0 foreach my $file (@dirs) {
1242 0 my ($v, $d, $f) = File::Spec->splitpath( $file );
1243 0 my $dir = File::Spec->catdir($v);
1244 0 foreach my $part ( File::Spec->splitdir( ($d.$f ) ) ) {
1245 0 $dir = File::Spec->catdir($dir, $part);
1246 0 ▶ next if -d $dir or -e $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir or -e $dir 0 0 0
Condition0%0/3
-d $dir or -e $dir
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $dir or -e $dir
-d $dir -e $dir
Truth table0%0/3
A or B
A= -d $dirB= -e $dir
ABresult
1X1
011
000
1247 0 ▶ mkdir( $dir ) || $self->throw("Error creating caching directory '".$dir."':\n$!");
Branch: 1 branch
BranchTrueFalseTotal
mkdir $dir or $self->throw(q[Error creating caching directory '] . $dir . "':\n$!") 0 0 0
1248 0 $LOG->debug("creating the directory, '$dir'.");
1249 }
1250 }
1251 }
1252  
1253 1 1;
1254 __END__
↑ Summary lib/MOSES/MOBY/Parser.pm »