line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::File::FedoraCommons; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.4'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
272174
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
561701
|
|
|
3
|
|
|
|
|
25
|
|
6
|
3
|
|
|
3
|
|
850
|
use Moo; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
18
|
|
7
|
3
|
|
|
3
|
|
1002
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
202
|
|
8
|
3
|
|
|
3
|
|
1203
|
use Catmandu; |
|
3
|
|
|
|
|
342888
|
|
|
3
|
|
|
|
|
19
|
|
9
|
3
|
|
|
3
|
|
694
|
use Catmandu::Util; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
143
|
|
10
|
3
|
|
|
3
|
|
1503
|
use Catmandu::FedoraCommons; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Catmandu::Store::File::FedoraCommons::Index; |
12
|
|
|
|
|
|
|
use Catmandu::Store::File::FedoraCommons::Bag; |
13
|
|
|
|
|
|
|
use Data::UUID; |
14
|
|
|
|
|
|
|
use namespace::clean; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
with 'Catmandu::FileStore', 'Catmandu::Droppable'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has baseurl => (is => 'ro', default => sub {'http://localhost:8080/fedora'}); |
19
|
|
|
|
|
|
|
has user => (is => 'ro', default => sub {'fedoraAdmin'}); |
20
|
|
|
|
|
|
|
has password => (is => 'ro', default => sub {'fedoraAdmin'}); |
21
|
|
|
|
|
|
|
has namespace => (is => 'ro', default => sub {'demo'}); |
22
|
|
|
|
|
|
|
has dsnamespace => (is => 'ro', default => sub {'DS'}); |
23
|
|
|
|
|
|
|
has md5enabled => (is => 'ro', default => sub {'1'}); |
24
|
|
|
|
|
|
|
has versionable => (is => 'ro', default => sub {'0'}); |
25
|
|
|
|
|
|
|
has purge => (is => 'ro', default => sub {'0'}); |
26
|
|
|
|
|
|
|
has model => (is => 'ro', predicate => 1 ); |
27
|
|
|
|
|
|
|
has fedora => (is => 'lazy'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _build_fedora { |
31
|
|
|
|
|
|
|
my ($self) = @_; |
32
|
|
|
|
|
|
|
my $fedora = Catmandu::FedoraCommons->new($self->baseurl, $self->user, |
33
|
|
|
|
|
|
|
$self->password); |
34
|
|
|
|
|
|
|
$fedora->{namespace} = $self->namespace; |
35
|
|
|
|
|
|
|
$fedora->{dsnamespace} = $self->dsnamespace; |
36
|
|
|
|
|
|
|
$fedora->{md5enabled} = $self->md5enabled; |
37
|
|
|
|
|
|
|
$fedora->{versionable} = $self->versionable; |
38
|
|
|
|
|
|
|
$fedora->{purge} = $self->purge; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $model = $self->model; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if ($model && !(Catmandu::Util::is_invocant($model) || Catmandu::Util::is_code_ref($model))) { |
43
|
|
|
|
|
|
|
my $class = $model =~ /^\+(.+)/ ? $1 |
44
|
|
|
|
|
|
|
: "Catmandu::Store::FedoraCommons::$model"; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
eval { |
47
|
|
|
|
|
|
|
$self->{model} = Catmandu::Util::require_package($class)->new(fedora => $fedora); |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
if ($@) { |
50
|
|
|
|
|
|
|
croak $@; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$fedora; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub drop { |
58
|
|
|
|
|
|
|
my ($self) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$self->index->delete_all; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Catmandu::Store::File::FedoraCommons - A Catmandu::FileStore to store files on disk into a Fedora3 server |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# From the command line |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Create a configuration file |
78
|
|
|
|
|
|
|
$ cat catmandu.yml |
79
|
|
|
|
|
|
|
--- |
80
|
|
|
|
|
|
|
store: |
81
|
|
|
|
|
|
|
files: |
82
|
|
|
|
|
|
|
package: File::FedoraCommons |
83
|
|
|
|
|
|
|
options: |
84
|
|
|
|
|
|
|
baseurl: http://localhost:8080/fedora |
85
|
|
|
|
|
|
|
username: fedoraAdmin |
86
|
|
|
|
|
|
|
password: fedoraAdmin |
87
|
|
|
|
|
|
|
namespace: demo |
88
|
|
|
|
|
|
|
model: DC |
89
|
|
|
|
|
|
|
purge: 1 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Export a list of all file containers |
92
|
|
|
|
|
|
|
$ catmandu export files to YAML |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Export a list of all files in container 'demo:1234' |
95
|
|
|
|
|
|
|
$ catmandu export files --bag 1234 to YAML |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Add a file to the container 'demo:1234' |
98
|
|
|
|
|
|
|
$ catmandu stream /tmp/myfile.txt to files --bag 1234 --id myfile.txt |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Download the file 'myfile.txt' from the container 'demo:1234' |
101
|
|
|
|
|
|
|
$ catmandu stream files --bag 1234 --id myfile.txt to /tmp/output.txt |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Delete the file 'myfile.txt' from the container 'demo:1234' |
104
|
|
|
|
|
|
|
$ catmandu delete files --root t/data --bag 1234 --id myfile.txt |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# From Perl |
107
|
|
|
|
|
|
|
use Catmandu; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $store = Catmandu->store('File::FedoraCommons' |
110
|
|
|
|
|
|
|
, baseurl => 'http://localhost:8080/fedora' |
111
|
|
|
|
|
|
|
, username => 'fedoraAdmin' |
112
|
|
|
|
|
|
|
, password => 'fedoraAdmin' |
113
|
|
|
|
|
|
|
, namespace => 'demo' |
114
|
|
|
|
|
|
|
, purge => 1); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $index = $store->index; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# List all folder |
119
|
|
|
|
|
|
|
$index->bag->each(sub { |
120
|
|
|
|
|
|
|
my $container = shift; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
print "%s\n" , $container->{_id}; |
123
|
|
|
|
|
|
|
}); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Add a new folder |
126
|
|
|
|
|
|
|
$index->add({ _id => '1234' }); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Get the folder |
129
|
|
|
|
|
|
|
my $files = $index->files('1234'); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Add a file to the folder |
132
|
|
|
|
|
|
|
$files->upload(IO::File->new('<foobar.txt'), 'foobar.txt'); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Retrieve a file |
135
|
|
|
|
|
|
|
my $file = $files->get('foobar.txt'); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Stream the contents of a file |
138
|
|
|
|
|
|
|
$files->stream(IO::File->new('>foobar.txt'), $file); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Delete a file |
141
|
|
|
|
|
|
|
$files->delete('foobar.txt'); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Delete a folder |
144
|
|
|
|
|
|
|
$index->delete('1234'); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 DESCRIPTION |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L<Catmandu::Store::File::FedoraCommons> is a L<Catmandu::FileStore> implementation to |
149
|
|
|
|
|
|
|
store files in a Fedora Commons 3 server. Each L<Catmandu::FileBag>. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 METHODS |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 new(%connection_parameters) |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Create a new Catmandu::Store::FedoraCommons. The following connection paramaters |
156
|
|
|
|
|
|
|
can be provided: |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item baseurl |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The location of the Fedora Commons endpoint. Default: http://localhost:8080/fedora |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item user |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The username to connect to Fedora Commons |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item password |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
The password to connect to Fedora Commons |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item namespace |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
The namespace in which all bag identifiers live. Default: demo |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item dsnamespace |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The namespace used to create new data streams. Default: DS |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item md5enabled |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Calculate and add a MD5 checksum when uploading content. Default: 1 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item versionable |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Make data streams in Fedora versionable. Default: 0 |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item purge |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
When purge is active, deletion of datastreams and records will purge the |
191
|
|
|
|
|
|
|
content in FedoraCommons. Otherwise it will set the status to 'D' (deleted). |
192
|
|
|
|
|
|
|
Default: 0 |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item model |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
When a model is set, then descriptive metadata can be added to the File::Store |
197
|
|
|
|
|
|
|
folders. Only one type of model is currenty available 'DC'. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Examples: |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
$ cat record.yml |
202
|
|
|
|
|
|
|
--- |
203
|
|
|
|
|
|
|
_id: 1234 |
204
|
|
|
|
|
|
|
title: |
205
|
|
|
|
|
|
|
- My title |
206
|
|
|
|
|
|
|
creator: |
207
|
|
|
|
|
|
|
- John Brown |
208
|
|
|
|
|
|
|
- Max Musterman |
209
|
|
|
|
|
|
|
description: |
210
|
|
|
|
|
|
|
- Files and more things |
211
|
|
|
|
|
|
|
... |
212
|
|
|
|
|
|
|
$ catmandu import YAML to files < record.yml |
213
|
|
|
|
|
|
|
$ catmandu export files to YAML --id 1234 |
214
|
|
|
|
|
|
|
--- |
215
|
|
|
|
|
|
|
_id: 1234 |
216
|
|
|
|
|
|
|
title: |
217
|
|
|
|
|
|
|
- My title |
218
|
|
|
|
|
|
|
creator: |
219
|
|
|
|
|
|
|
- John Brown |
220
|
|
|
|
|
|
|
- Max Musterman |
221
|
|
|
|
|
|
|
description: |
222
|
|
|
|
|
|
|
- Files and more things |
223
|
|
|
|
|
|
|
... |
224
|
|
|
|
|
|
|
$ catmandu stream foobar.pdf to files --bag 1234 --id foobar.pdf |
225
|
|
|
|
|
|
|
$ catmandu export files --bag 1234 |
226
|
|
|
|
|
|
|
--- |
227
|
|
|
|
|
|
|
_id: foobar.pdf |
228
|
|
|
|
|
|
|
_stream: !!perl/code '{ "DUMMY" }' |
229
|
|
|
|
|
|
|
content_type: application/pdf |
230
|
|
|
|
|
|
|
control_group: M |
231
|
|
|
|
|
|
|
created: '1504170797' |
232
|
|
|
|
|
|
|
format_uri: '' |
233
|
|
|
|
|
|
|
info_type: '' |
234
|
|
|
|
|
|
|
location: demo:1234+DS.0+DS.0.0 |
235
|
|
|
|
|
|
|
locationType: INTERNAL_ID |
236
|
|
|
|
|
|
|
md5: 6112b4f1b1a439917b8bbacc93b7d3fa |
237
|
|
|
|
|
|
|
modified: '1504170797' |
238
|
|
|
|
|
|
|
size: '534' |
239
|
|
|
|
|
|
|
state: A |
240
|
|
|
|
|
|
|
version_id: DS.0.0 |
241
|
|
|
|
|
|
|
versionable: 'false' |
242
|
|
|
|
|
|
|
... |
243
|
|
|
|
|
|
|
$ catmandu stream files --bag 1234 --id foobar.pdf > foobar.pdf |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=back |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
This Catmandu::FileStore implements: |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=over 3 |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=item L<Catmandu::FileStore> |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=back |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
The index Catmandu::Bag in this Catmandu::Store implements: |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=over 3 |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item L<Catmandu::FileBag::Index> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=back |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
The file Catmandu::Bag in this Catmandu::Store implements: |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=over 3 |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=item L<Catmandu::FileBag> |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=item L<Catmandu::Droppable> |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=back |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 SEE ALSO |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
L<Catmandu::Store::File::FedoraCommons::Index>, |
286
|
|
|
|
|
|
|
L<Catmandu::Store::File::FedoraCommons::Bag>, |
287
|
|
|
|
|
|
|
L<Catmandu::FileStore> |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=cut |