line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Exporter::MediaHaven; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
61654
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
129579
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.0603'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
306
|
use Moo; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
9
|
|
8
|
1
|
|
|
1
|
|
311
|
use Cpanel::JSON::XS; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
53
|
|
9
|
1
|
|
|
1
|
|
327
|
use Catmandu::MediaHaven; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
10
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
11
|
1
|
|
|
1
|
|
5
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Catmandu::Exporter'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'url' => (is => 'ro' , required => 1); |
16
|
|
|
|
|
|
|
has 'username' => (is => 'ro' , required => 1); |
17
|
|
|
|
|
|
|
has 'password' => (is => 'ro' , required => 1); |
18
|
|
|
|
|
|
|
has 'json_key' => (is => 'ro' , required => 1); |
19
|
|
|
|
|
|
|
has 'record_query' => (is => 'ro' , default => sub { "q=%%2B(MediaObjectFragmentId:%s)"; }); |
20
|
|
|
|
|
|
|
has 'mediahaven' => (is => 'lazy'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _build_mediahaven { |
23
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
24
|
0
|
|
|
|
|
|
Catmandu::MediaHaven->new( |
25
|
|
|
|
|
|
|
url => $self->url, |
26
|
|
|
|
|
|
|
username => $self->username, |
27
|
|
|
|
|
|
|
password => $self->password, |
28
|
|
|
|
|
|
|
record_query => $self->record_query, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add { |
33
|
|
|
|
|
|
|
my ($self,$data) = @_; |
34
|
|
|
|
|
|
|
my $id = $data->{_id}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
croak "add needs id" unless $id; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $key = $self->json_key; |
39
|
|
|
|
|
|
|
my $json = encode_json($data); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $result = $self->mediahaven->edit($id,$key,$json); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
if (defined($result) && $result->{ok}) { |
44
|
|
|
|
|
|
|
return 1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->log->error("failed to update $id"); |
49
|
|
|
|
|
|
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub commit { 1 } |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=pod |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Catmandu::Exporter::MediaHaven - a exporter that updates Zeticon MediaHaven records |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SYNOPSIS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# From the commandline |
68
|
|
|
|
|
|
|
$ cat catmandu.yml |
69
|
|
|
|
|
|
|
--- |
70
|
|
|
|
|
|
|
exporter: |
71
|
|
|
|
|
|
|
mh: |
72
|
|
|
|
|
|
|
package: MediaHaven |
73
|
|
|
|
|
|
|
options: |
74
|
|
|
|
|
|
|
url: https://archief.viaa.be/mediahaven-rest-api/resources/media |
75
|
|
|
|
|
|
|
username: ... |
76
|
|
|
|
|
|
|
password: ... |
77
|
|
|
|
|
|
|
json_key: description |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$ catmandu convert YAML to mh < records.yml |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 DESCRIPTION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This Exporter will convert metadata records into a JSON encoded field in the |
84
|
|
|
|
|
|
|
MediaHaven database. A `json_key` is required. This is the field were the JSON |
85
|
|
|
|
|
|
|
encoded data is stored. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Attn: take some seconds/minutes to have the metadata updates available and |
88
|
|
|
|
|
|
|
indexed in the backend database. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 METHODS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 new(%connection_parameters) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Create a new Catmandu::Store::File::MediaHaven with the following connection |
95
|
|
|
|
|
|
|
parameters: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=over |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item url |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Required. The URL to the MediaHaven REST endpoint. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item username |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Required. Username used to connect to MediaHaven. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item password |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Required. Password used to connect to MediaHaven. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item json_key |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Required. The metdata field where the record data as a JSON blob is stored |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item record_query |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Optional. MediaHaven query to extract a record '_id' from the database. |
118
|
|
|
|
|
|
|
Default: "q=%%2B(MediaObjectFragmentId:%s)" |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This Catmandu::Exporter::MediaHaven implements |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=over 3 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item L<Catmandu::Exporter> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item L<Catmandu::Logger> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item L<Catmandu::Addable> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item L<Catmandu::Fixable> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item L<Catmandu::Counter> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=back |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SEE ALSO |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L<Catmandu::Importer::MediaHaven> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |