blib/lib/MOBY/Admin.pm untested

filter: Statementstmt 0.0% 0 / 94 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 140 CC 8 SCAR 30.9
CC
8
Cov
0%
_deregisterService
72.0
deregisterService
2.0
BEGIN
2.0
CRAP 22.0
1  
2 =head1 NAME
3  
4 MOBY::Admin.pm - API for adminning the MOBY Central registry
5  
6 =cut
7  
8 package MOBY::Admin;
9 use strict;
10 use Carp;
11 use vars qw($AUTOLOAD $WSDL_TEMPLATE);
12 use XML::LibXML;
13 use MOBY::OntologyServer;
14 use MOBY::service_type;
15 use MOBY::authority;
16 use MOBY::service_instance;
17 use MOBY::simple_input;
18 use MOBY::simple_output;
19 use MOBY::collection_input;
20 use MOBY::collection_output;
21 use MOBY::secondary_input;
22 use MOBY::central_db_connection;
23 use MOBY::Config;
24 use MOBY::CommonSubs;
25 use MOBY::MobyXMLConstants;
26  
27 use vars qw /$VERSION/;
28 $VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /: (\d+)\.(\d+)/;
29  
30 sub deregisterService {
31 my ( $self, $xml ) = @_;
32  
33 # parse the xml that is passed into this method
34 # pass the hash to the _deregisterService sub routine.
35 use XML::LibXML;
36 my ( $name, $authority, $phrase );
37 my $Parser = XML::LibXML->new();
38 my $doc = $Parser->parse_string($xml);
39  
40 # extract the element 'name'
41 my $element = $doc->getElementsByTagName("name")->get_node(1);
42 $name = $element->textContent || "";
43  
44 # extract the element 'authority'
45 $element = $doc->getElementsByTagName("authority")->get_node(1);
46 $authority = $element->textContent || "";
47  
48 # extract the element 'phrase'
49 $element = $doc->getElementsByTagName("phrase")->get_node(1);
50 $phrase = $element->textContent || "";
51 my $returnValue = $self->_deregisterService(
52 servicename => $name,
53 authority => $authority,
54 phrase => $phrase
55 );
56 return $returnValue;
57 }
58  
59 ###ERROR CODES RETURNED ###################
60 # 101 = no authority URI
61 # 102 = no service name
62 # 103 = no keyphrase
63 # 501 = key phrase dont match
64 # 200 = service successfully deleted
65 # 404 = service not found
66 # 500 = other unknown error
67 ############################################
68 sub _deregisterService {
69 my ( $self, %args ) = @_;
70 my $uri = $args{authority};
71 my $val = '500';
72 if ( not $uri ) {
73 return '101';
74 }
75  
76 my $name = $args{servicename};
77 if ( not $name ) {
78 return '102';
79 }
80  
81 my $phrase = $args{phrase};
82 if ( not $phrase ) {
83 return '103';
84  
85 }
86 eval {
87  
88 # get the passphrase
89 my $CONF = MOBY::Config->new;
90  
91 if ( $CONF->{mobycentral}{keyphrase} ne $phrase ) {
92 $val = '501';
93 }
94  
95 my $service = MOBY::service_instance->new(
96 servicename => $name,
97 authority_uri => $uri,
98 test => 1
99 );
100  
101 if ($service) {
102 $service = MOBY::service_instance->new( servicename => $name,
103 authority_uri => $uri, );
104  
105 $val = '200' if $service->DELETE_THYSELF;
106 }
107 else {
108  
109 $val = '404';
110 }
111 };
112 if ($@) {
113 print STDERR "Error in deregisterService: : " . $@;
114 return 500;
115 }
116 return $val;
117 }
118  
119 1;