| 1 | # ===================================================================== | ||
| 2 | # Copyright (c) 2002,2003 IBM Corporation | ||
| 3 | # All rights reserved. This program and the accompanying materials | ||
| 4 | # are made available under the terms of the Common Public License v1.0 | ||
| 5 | # which accompanies this distribution, and is available at | ||
| 6 | # http://www.opensource.org/licenses/cpl.php | ||
| 7 | # | ||
| 8 | # ===================================================================== | ||
| 9 | |||
| 10 | package LS::Assigning::Client; | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use warnings; | ||
| 14 | |||
| 15 | use LS; | ||
| 16 | use LS::ID; | ||
| 17 | use LS::Client; | ||
| 18 | |||
| 19 | use LS::Service::Response; | ||
| 20 | |||
| 21 | use LS::Assigning::Serializer; | ||
| 22 | |||
| 23 | use SOAP::Lite; | ||
| 24 | |||
| 25 | use base 'LS::Client'; | ||
| 26 | |||
| 27 | |||
| 28 | # | ||
| 29 | # new( %options ) - | ||
| 30 | # | ||
| 31 | sub new { | ||
| 32 | |||
| 33 | my ($self, %options) = @_; | ||
| 34 | |||
| 35 | unless($options{'url'}) { | ||
| 36 | |||
| 37 | LS::Base->recordError('Missing url parameter in sub new'); | ||
| 38 | LS::Base->addStackTrace(); | ||
| 39 | |||
| 40 | return undef; | ||
| 41 | } | ||
| 42 | |||
| 43 | unless(ref $self) { | ||
| 44 | |||
| 45 | $self = bless { | ||
| 46 | |||
| 47 | %options, | ||
| 48 | |||
| 49 | _err=> undef, | ||
| 50 | }, $self; | ||
| 51 | } | ||
| 52 | |||
| 53 | my $soap = SOAP::Lite->on_fault(sub {}) | ||
| 54 | ->on_action(sub { return ''; }) | ||
| 55 | ->uri('http://www.omg.org/LSID/2003/Assigning/StandardSOAPBinding') | ||
| 56 | ->proxy( $options{'url'} ); | ||
| 57 | |||
| 58 | unless($soap) { | ||
| 59 | |||
| 60 | $self->recordError("Unable to initialize SOAP proxy object for url: $options{url}"); | ||
| 61 | $self->addStackTrace(); | ||
| 62 | |||
| 63 | return undef; | ||
| 64 | } | ||
| 65 | |||
| 66 | $self->{'_soap'} = $soap; | ||
| 67 | |||
| 68 | return $self; | ||
| 69 | } | ||
| 70 | |||
| 71 | # | ||
| 72 | # _soap_call( %options ) - | ||
| 73 | # | ||
| 74 | sub _soap_call { | ||
| 75 | |||
| 76 | my ($self, %options) = @_; | ||
| 77 | |||
| 78 | unless($options{'method'}) { | ||
| 79 | |||
| 80 | $self->recordError('Missing method parameter in sub getContent'); | ||
| 81 | $self->addStackTrace(); | ||
| 82 | |||
| 83 | return undef; | ||
| 84 | } | ||
| 85 | |||
| 86 | my $method = $options{'method'}; | ||
| 87 | delete $options{'method'}; | ||
| 88 | |||
| 89 | my $service = $self->{'_soap'}; | ||
| 90 | my @params = @{ $options{'params'} } if($options{'params'}); | ||
| 91 | |||
| 92 | if($self->credentials) { | ||
| 93 | |||
| 94 | my $username = $self->credentials->username; | ||
| 95 | my $password = $self->credentials->password; | ||
| 96 | |||
| 97 | eval("sub SOAP::Transport::HTTP::Client::get_basic_credentials { return $username=> $password; }"); | ||
| 98 | } | ||
| 99 | |||
| 100 | my $som = $service->call("$method"=> @params); | ||
| 101 | |||
| 102 | unless($som) { | ||
| 103 | |||
| 104 | $self->recordError("Method: $method - returned an invalid response in sub getContent"); | ||
| 105 | $self->addStackTrace(); | ||
| 106 | |||
| 107 | return undef; | ||
| 108 | } | ||
| 109 | |||
| 110 | if ($som->fault) { | ||
| 111 | |||
| 112 | $self->{'_err'} = $som->faultstring . "\n" . | ||
| 113 | ( ref $som->faultdetail ? $som->faultdetail->{'errorcode'} . ' - ' . $som->faultdetail->{'description'} : 'No details provided' ); | ||
| 114 | return undef; | ||
| 115 | } | ||
| 116 | |||
| 117 | return $som; | ||
| 118 | } | ||
| 119 | |||
| 120 | # | ||
| 121 | # assignLSID( %options ) - | ||
| 122 | # | ||
| 123 | sub assignLSID { | ||
| 124 | |||
| 125 | my ($self, %options) = @_; | ||
| 126 | |||
| 127 | unless($options{'authority'} && | ||
| 128 | $options{'namespace'} && | ||
| 129 | $options{'propertyList'}) { | ||
| 130 | |||
| 131 | $self->recordError('Missing method parameter in sub assignLSID'); | ||
| 132 | $self->addStackTrace(); | ||
| 133 | |||
| 134 | return undef; | ||
| 135 | } | ||
| 136 | |||
| 137 | my $authority = SOAP::Data->prefix('') | ||
| 138 | ->name(authority=> $options{'authority'}); | ||
| 139 | |||
| 140 | my $namespace = SOAP::Data->prefix('') | ||
| 141 | ->name(namespace=> $options{'namespace'}); | ||
| 142 | |||
| 143 | my $properties = SOAP::Data->prefix('') | ||
| 144 | ->name('propertyList') | ||
| 145 | ->type(propertyList=> $options{'propertyList'} ); | ||
| 146 | |||
| 147 | my $som = $self->_soap_call(method=> 'assignLSID', | ||
| 148 | params=> [ $authority, $namespace, $properties ]); | ||
| 149 | |||
| 150 | return undef unless($som); | ||
| 151 | |||
| 152 | return LS::Service::Response->new(response=> $som->result); | ||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | # | ||
| 157 | # assignLSIDFromList( %options ) - | ||
| 158 | # | ||
| 159 | sub assignLSIDFromList { | ||
| 160 | |||
| 161 | my ($self, %options) = @_; | ||
| 162 | |||
| 163 | unless($options{'LSIDList'} && | ||
| 164 | $options{'propertyList'}) { | ||
| 165 | |||
| 166 | $self->recordError('Missing method parameter in sub assignLSIDFromList'); | ||
| 167 | $self->addStackTrace(); | ||
| 168 | |||
| 169 | return undef; | ||
| 170 | } | ||
| 171 | |||
| 172 | my $properties = SOAP::Data->prefix('') | ||
| 173 | ->name('propertyList') | ||
| 174 | ->type(propertyList=> $options{'propertyList'}); | ||
| 175 | |||
| 176 | my $lsids = SOAP::Data->prefix('') | ||
| 177 | ->name('suggestedLSIDs') | ||
| 178 | ->type(LSIDList=> $options{'LSIDList'} ); | ||
| 179 | |||
| 180 | my $som = $self->_soap_call(method=> 'assignLSIDFromList', | ||
| 181 | params=> [ $properties, $lsids ]); | ||
| 182 | |||
| 183 | return undef unless($som); | ||
| 184 | |||
| 185 | return LS::Service::Response->new(response=> $som->result); | ||
| 186 | } | ||
| 187 | |||
| 188 | |||
| 189 | # | ||
| 190 | # getLSIDPattern( %options ) - | ||
| 191 | # | ||
| 192 | sub getLSIDPattern { | ||
| 193 | |||
| 194 | my ($self, %options) = @_; | ||
| 195 | |||
| 196 | unless($options{'authority'} && | ||
| 197 | $options{'namespace'} && | ||
| 198 | $options{'propertyList'}) { | ||
| 199 | |||
| 200 | $self->recordError('Missing method parameter in sub getLSIDPattern'); | ||
| 201 | $self->addStackTrace(); | ||
| 202 | |||
| 203 | return undef; | ||
| 204 | } | ||
| 205 | |||
| 206 | my $authority = SOAP::Data->prefix('') | ||
| 207 | ->name(authority=> $options{'authority'}); | ||
| 208 | |||
| 209 | my $namespace = SOAP::Data->prefix('') | ||
| 210 | ->name(namespace=> $options{'namespace'}); | ||
| 211 | |||
| 212 | my $properties = SOAP::Data->prefix('') | ||
| 213 | ->name('propertyList') | ||
| 214 | ->type(propertyList=> $options{'propertyList'} ); | ||
| 215 | |||
| 216 | my $som = $self->_soap_call(method=> 'getLSIDPattern', | ||
| 217 | params=> [ $authority, $namespace, $properties ]); | ||
| 218 | |||
| 219 | return undef unless($som); | ||
| 220 | |||
| 221 | return LS::Service::Response->new(response=> $som->result); | ||
| 222 | } | ||
| 223 | |||
| 224 | |||
| 225 | # | ||
| 226 | # getLSIDPatternFromList( %options ) - | ||
| 227 | # | ||
| 228 | sub getLSIDPatternFromList { | ||
| 229 | |||
| 230 | my ($self, %options) = @_; | ||
| 231 | |||
| 232 | unless($options{'propertyList'} && | ||
| 233 | $options{'LSIDPatternList'}) { | ||
| 234 | |||
| 235 | $self->recordError('Missing method parameter in sub getLSIDPatternFromList'); | ||
| 236 | $self->addStackTrace(); | ||
| 237 | |||
| 238 | return undef; | ||
| 239 | } | ||
| 240 | |||
| 241 | my $properties = SOAP::Data->prefix('') | ||
| 242 | ->name('propertyList') | ||
| 243 | ->type(propertyList=> $options{'propertyList'} ); | ||
| 244 | |||
| 245 | my $patterns = SOAP::Data->prefix('') | ||
| 246 | ->name('suggestedLSIDPatterns') | ||
| 247 | ->type(LSIDPatternList=> $options{'LSIDPatternList'} ); | ||
| 248 | |||
| 249 | my $som = $self->_soap_call(method=> 'getLSIDPatternFromList', | ||
| 250 | params=> [ $properties, $patterns ]); | ||
| 251 | |||
| 252 | return undef unless($som); | ||
| 253 | |||
| 254 | return LS::Service::Response->new(response=> $som->result); | ||
| 255 | } | ||
| 256 | |||
| 257 | |||
| 258 | # | ||
| 259 | # assignLSIDForNewRevision( %options ) - | ||
| 260 | # | ||
| 261 | sub assignLSIDForNewRevision { | ||
| 262 | |||
| 263 | my ($self, %options) = @_; | ||
| 264 | |||
| 265 | unless($options{'lsid'}) { | ||
| 266 | |||
| 267 | $self->recordError('Missing method parameter in sub assignLSIDForNewRevision'); | ||
| 268 | $self->addStackTrace(); | ||
| 269 | |||
| 270 | return undef; | ||
| 271 | } | ||
| 272 | |||
| 273 | my $lsid = $options{'lsid'}; | ||
| 274 | $lsid = LS::ID->new( $options{'lsid'} )->as_string if(! UNIVERSAL::isa($options{'lsid'}, 'LS::ID')); | ||
| 275 | |||
| 276 | unless($lsid) { | ||
| 277 | |||
| 278 | $self->recordError('Parameter is not of correct type: LS::ID in sub assignLSIDForNewRevision'); | ||
| 279 | $self->addStackTrace(); | ||
| 280 | |||
| 281 | return undef; | ||
| 282 | } | ||
| 283 | |||
| 284 | $lsid = $lsid->as_string; | ||
| 285 | |||
| 286 | my $SOAPlsid = SOAP::Data->prefix('') | ||
| 287 | ->name('previousLSID'=> $lsid); | ||
| 288 | |||
| 289 | my $som = $self->_soap_call(method=> 'assignLSIDForNewRevision', | ||
| 290 | params=> [ $SOAPlsid ]); | ||
| 291 | |||
| 292 | return undef unless($som); | ||
| 293 | |||
| 294 | return LS::Service::Response->new(response=> $som->result); | ||
| 295 | } | ||
| 296 | |||
| 297 | |||
| 298 | # | ||
| 299 | # getAllowedPropertyNames( %options ) - | ||
| 300 | # | ||
| 301 | sub getAllowedPropertyNames { | ||
| 302 | |||
| 303 | my $self = shift; | ||
| 304 | |||
| 305 | my $som = $self->_soap_call(method=> 'getAllowedPropertyNames', | ||
| 306 | params=> [ ]); | ||
| 307 | |||
| 308 | return undef unless($som); | ||
| 309 | |||
| 310 | my $p_ref = $self->getMethodResponse($som); | ||
| 311 | |||
| 312 | my $r = []; | ||
| 313 | |||
| 314 | foreach my $prop (@{ $p_ref->[0]->[2] }) { | ||
| 315 | |||
| 316 | push @{ $r }, $prop->[2]; | ||
| 317 | } | ||
| 318 | |||
| 319 | return LS::Service::Response->new(response=> $r); | ||
| 320 | } | ||
| 321 | |||
| 322 | |||
| 323 | # | ||
| 324 | # getAuthoritiesAndNamespaces( %options ) - | ||
| 325 | # | ||
| 326 | sub getAuthoritiesAndNamespaces { | ||
| 327 | |||
| 328 | my $self = shift; | ||
| 329 | |||
| 330 | my $som = $self->_soap_call(method=> 'getAuthoritiesAndNamespaces', | ||
| 331 | params=> [ ]); | ||
| 332 | |||
| 333 | return undef unless($som); | ||
| 334 | |||
| 335 | my $p_ref = $self->getMethodResponse($som); | ||
| 336 | |||
| 337 | my $r = []; | ||
| 338 | |||
| 339 | foreach my $an (@{ $p_ref->[0]->[2] }) { | ||
| 340 | |||
| 341 | |||
| 342 | my $a = $an->[2]->[0]->[2]; | ||
| 343 | my $n = $an->[2]->[1]->[2]; | ||
| 344 | |||
| 345 | push @{ $r }, { $a=> $n }; | ||
| 346 | } | ||
| 347 | |||
| 348 | return LS::Service::Response->new(response=> $r); | ||
| 349 | } | ||
| 350 | |||
| 351 | # | ||
| 352 | # SOAP::Lite bug | ||
| 353 | # | ||
| 354 | sub getMethodResponse { | ||
| 355 | |||
| 356 | my $self = shift; | ||
| 357 | my $som = shift; | ||
| 358 | my $method = shift; | ||
| 359 | |||
| 360 | return $som->{'_content'}->[2]->[0]->[2]->[0]->[2]; | ||
| 361 | } | ||
| 362 | |||
| 363 | 1; | ||
| 364 | |||
| 365 | __END__ |