| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PICA::SOAPClient; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$PICA::SOAPClient::VERSION = '0.585'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
#ABSTRACT: PICA::Store via SOAP access (aka 'webcat') |
|
6
|
4
|
|
|
4
|
|
30
|
use strict; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
183
|
|
|
7
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
200
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
693
|
use PICA::Record; |
|
|
4
|
|
|
|
|
12
|
|
|
|
4
|
|
|
|
|
282
|
|
|
10
|
4
|
|
|
4
|
|
28
|
use PICA::Store; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
100
|
|
|
11
|
4
|
|
|
4
|
|
7144
|
use SOAP::Lite; # +trace => 'debug'; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use SOAP::Lite; |
|
13
|
|
|
|
|
|
|
use Carp qw(croak); |
|
14
|
|
|
|
|
|
|
use Cwd qw(cwd); |
|
15
|
|
|
|
|
|
|
use Encode qw(encode_utf8); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @ISA=qw(PICA::Store); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
|
21
|
|
|
|
|
|
|
my ($class) = shift; |
|
22
|
|
|
|
|
|
|
my ($soap, %params) = (@_ % 2) ? (@_) : (undef, @_); |
|
23
|
|
|
|
|
|
|
$params{SOAP} = $soap if defined $soap; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
PICA::Store::readconfigfile( \%params, $ENV{PICASTORE} ) |
|
26
|
|
|
|
|
|
|
if exists $params{config} or exists $params{conf} ; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
croak "Missing SOAP base url (webcat)" unless defined $params{webcat}; |
|
29
|
|
|
|
|
|
|
$params{dbsid} = "" unless defined $params{dbsid}; |
|
30
|
|
|
|
|
|
|
$params{userkey} = "" unless defined $params{userkey}; |
|
31
|
|
|
|
|
|
|
$params{language} = "en" unless defined $params{language}; |
|
32
|
|
|
|
|
|
|
$params{password} = "" unless defined $params{password}; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$soap = SOAP::Lite->uri('http://www.gbv.de/schema/webcat-1.0') |
|
35
|
|
|
|
|
|
|
->proxy($params{webcat}); |
|
36
|
|
|
|
|
|
|
# ->encoding('utf-8') |
|
37
|
|
|
|
|
|
|
# ->on_fault(sub{}) |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $self = bless { |
|
40
|
|
|
|
|
|
|
'soap' => $soap, |
|
41
|
|
|
|
|
|
|
'format' => SOAP::Data->name( "format" )->type( string => "pp" ), |
|
42
|
|
|
|
|
|
|
'rectype_title' => SOAP::Data->name( "rectype" )->type( string => "title" ), |
|
43
|
|
|
|
|
|
|
'rectype_entry' => SOAP::Data->name( "rectype" )->type( string => "entry" ), |
|
44
|
|
|
|
|
|
|
'baseurl' => $params{webcat}, |
|
45
|
|
|
|
|
|
|
}, $class; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
return $self->access( %params ); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get { |
|
52
|
|
|
|
|
|
|
my ($self, $id) = @_; |
|
53
|
|
|
|
|
|
|
my %result = $self->_soap_query( "get", |
|
54
|
|
|
|
|
|
|
SOAP::Data->name( "ppn" )->type( string => $id ) |
|
55
|
|
|
|
|
|
|
); |
|
56
|
|
|
|
|
|
|
$result{record} = PICA::Record->new($result{record}) if $result{record}; |
|
57
|
|
|
|
|
|
|
return %result; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub create { |
|
62
|
|
|
|
|
|
|
my ($self, $record) = @_; |
|
63
|
|
|
|
|
|
|
croak('create needs a PICA::Record object') |
|
64
|
|
|
|
|
|
|
unless UNIVERSAL::isa($record,'PICA::Record'); |
|
65
|
|
|
|
|
|
|
my $rectype = $self->{"rectype_title"}; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $sf = $record->subfield('002@$0'); |
|
68
|
|
|
|
|
|
|
$rectype = $self->{"rectype_entry"} if ($sf && $sf =~ /^T/); # authority record |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $recorddata = encode_utf8( $record->string ); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return $self->_soap_query( "create", |
|
73
|
|
|
|
|
|
|
SOAP::Data->name( "record" )->type( string => $recorddata ), |
|
74
|
|
|
|
|
|
|
$rectype |
|
75
|
|
|
|
|
|
|
); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub update { |
|
80
|
|
|
|
|
|
|
my ($self, $id, $record, $version) = @_; |
|
81
|
|
|
|
|
|
|
my $recorddata; |
|
82
|
|
|
|
|
|
|
if ( UNIVERSAL::isa( $id, 'PICA::Record' ) ) { # TODO: Test this |
|
83
|
|
|
|
|
|
|
$version = $record; |
|
84
|
|
|
|
|
|
|
$record = $id; |
|
85
|
|
|
|
|
|
|
$id = $id->ppn; |
|
86
|
|
|
|
|
|
|
$record->ppn( undef ); |
|
87
|
|
|
|
|
|
|
$recorddata = encode_utf8( $record->string ); |
|
88
|
|
|
|
|
|
|
$record->ppn($id); |
|
89
|
|
|
|
|
|
|
} else { |
|
90
|
|
|
|
|
|
|
croak('update needs an ID and a PICA::Record object') |
|
91
|
|
|
|
|
|
|
unless UNIVERSAL::isa ($record,'PICA::Record'); |
|
92
|
|
|
|
|
|
|
$recorddata = encode_utf8( $record->string ); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
if (not defined $version) { |
|
96
|
|
|
|
|
|
|
my %current = $self->get( $id ); |
|
97
|
|
|
|
|
|
|
return %current unless $current{version}; |
|
98
|
|
|
|
|
|
|
$version = $current{version}; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return $self->_soap_query( "update", |
|
102
|
|
|
|
|
|
|
SOAP::Data->name("ppn")->type( string => $id ), |
|
103
|
|
|
|
|
|
|
SOAP::Data->name("record")->type( string => $recorddata ), |
|
104
|
|
|
|
|
|
|
SOAP::Data->name("version")->type( string => $version ) |
|
105
|
|
|
|
|
|
|
); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub delete { |
|
110
|
|
|
|
|
|
|
my ($self, $id) = @_; |
|
111
|
|
|
|
|
|
|
return $self->_soap_query( "delete", |
|
112
|
|
|
|
|
|
|
SOAP::Data->name( "ppn" )->type( string => $id ) |
|
113
|
|
|
|
|
|
|
); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub access { |
|
118
|
|
|
|
|
|
|
my ($self, %params) = @_; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
for my $key (qw(userkey password dbsid language)) { |
|
121
|
|
|
|
|
|
|
$self->{$key} = |
|
122
|
|
|
|
|
|
|
SOAP::Data->name( $key => $params{$key} )->type('string') |
|
123
|
|
|
|
|
|
|
if defined $params{$key}; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
return $self; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub about { |
|
131
|
|
|
|
|
|
|
my $self = shift; |
|
132
|
|
|
|
|
|
|
return "CWS Webcat: " . $self->{baseurl}; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _soap_query { |
|
138
|
|
|
|
|
|
|
my ($self, $operation, @params) = @_; |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
push @params, $self->{"format"} unless $operation eq "delete"; |
|
141
|
|
|
|
|
|
|
push @params, ($self->{dbsid}, $self->{userkey}, $self->{language}); |
|
142
|
|
|
|
|
|
|
push @params, $self->{password} if defined $self->{password}; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $response = $self->{soap}->$operation( @params ); |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my %result; |
|
147
|
|
|
|
|
|
|
if (!$response) { |
|
148
|
|
|
|
|
|
|
$result{errorcode} = "1"; |
|
149
|
|
|
|
|
|
|
$result{errormessage} = "No response to SOAP operation '$operation'."; |
|
150
|
|
|
|
|
|
|
} elsif ($response->fault) { |
|
151
|
|
|
|
|
|
|
$result{errorcode} = $response->faultcode; |
|
152
|
|
|
|
|
|
|
$result{errormessage} = $response->faultstring; |
|
153
|
|
|
|
|
|
|
chomp $result{errormessage}; |
|
154
|
|
|
|
|
|
|
} else { |
|
155
|
|
|
|
|
|
|
$result{id} = $response->valueof("//ppn") if defined $response->valueof("//ppn"); |
|
156
|
|
|
|
|
|
|
$result{record} = PICA::Record->new( $response->valueof("//record") ) |
|
157
|
|
|
|
|
|
|
if defined $response->valueof("//record"); |
|
158
|
|
|
|
|
|
|
$result{version} = $response->valueof("//version") |
|
159
|
|
|
|
|
|
|
if defined $response->valueof("//version"); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
return %result; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__END__ |