| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Store::File::FedoraCommons; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.3'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
165172
|
use Catmandu::Sane; |
|
|
3
|
|
|
|
|
368703
|
|
|
|
3
|
|
|
|
|
18
|
|
|
6
|
3
|
|
|
3
|
|
690
|
use Moo; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
14
|
|
|
7
|
3
|
|
|
3
|
|
909
|
use Carp; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
146
|
|
|
8
|
3
|
|
|
3
|
|
945
|
use Catmandu; |
|
|
3
|
|
|
|
|
253778
|
|
|
|
3
|
|
|
|
|
19
|
|
|
9
|
3
|
|
|
3
|
|
804
|
use Catmandu::Util; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
137
|
|
|
10
|
3
|
|
|
3
|
|
1337
|
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 CONFIGURATION |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=over |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item baseurl |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The location of the Fedora Commons endpoint. Default: http://localhost:8080/fedora |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item user |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
The username to connect to Fedora Commons |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item password |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
The password to connect to Fedora Commons |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item namespace |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The namespace in which all bag identifiers live. Default: demo |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item dsnamespace |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
The namespace used to create new data streams. Default: DS |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item md5enabled |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Calculate and add a MD5 checksum when uploading content. Default: 1 |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item versionable |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Make data streams in Fedora versionable. Default: 0 |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item purge |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
When purge is active, deletion of datastreams and records will purge the |
|
186
|
|
|
|
|
|
|
content in FedoraCommons. Otherwise it will set the status to 'D' (deleted). |
|
187
|
|
|
|
|
|
|
Default: 0 |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item model |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
When a model is set, then descriptive metadata can be added to the File::Store |
|
192
|
|
|
|
|
|
|
folders. Only one type of model is currenty available 'DC'. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Examples: |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
$ cat record.yml |
|
197
|
|
|
|
|
|
|
--- |
|
198
|
|
|
|
|
|
|
_id: 1234 |
|
199
|
|
|
|
|
|
|
title: |
|
200
|
|
|
|
|
|
|
- My title |
|
201
|
|
|
|
|
|
|
creator: |
|
202
|
|
|
|
|
|
|
- John Brown |
|
203
|
|
|
|
|
|
|
- Max Musterman |
|
204
|
|
|
|
|
|
|
description: |
|
205
|
|
|
|
|
|
|
- Files and more things |
|
206
|
|
|
|
|
|
|
... |
|
207
|
|
|
|
|
|
|
$ catmandu import YAML to files < record.yml |
|
208
|
|
|
|
|
|
|
$ catmandu export files to YAML --id 1234 |
|
209
|
|
|
|
|
|
|
--- |
|
210
|
|
|
|
|
|
|
_id: 1234 |
|
211
|
|
|
|
|
|
|
title: |
|
212
|
|
|
|
|
|
|
- My title |
|
213
|
|
|
|
|
|
|
creator: |
|
214
|
|
|
|
|
|
|
- John Brown |
|
215
|
|
|
|
|
|
|
- Max Musterman |
|
216
|
|
|
|
|
|
|
description: |
|
217
|
|
|
|
|
|
|
- Files and more things |
|
218
|
|
|
|
|
|
|
... |
|
219
|
|
|
|
|
|
|
$ catmandu stream foobar.pdf to files --bag 1234 --id foobar.pdf |
|
220
|
|
|
|
|
|
|
$ catmandu export files --bag 1234 |
|
221
|
|
|
|
|
|
|
--- |
|
222
|
|
|
|
|
|
|
_id: foobar.pdf |
|
223
|
|
|
|
|
|
|
_stream: !!perl/code '{ "DUMMY" }' |
|
224
|
|
|
|
|
|
|
content_type: application/pdf |
|
225
|
|
|
|
|
|
|
control_group: M |
|
226
|
|
|
|
|
|
|
created: '1504170797' |
|
227
|
|
|
|
|
|
|
format_uri: '' |
|
228
|
|
|
|
|
|
|
info_type: '' |
|
229
|
|
|
|
|
|
|
location: demo:1234+DS.0+DS.0.0 |
|
230
|
|
|
|
|
|
|
locationType: INTERNAL_ID |
|
231
|
|
|
|
|
|
|
md5: 6112b4f1b1a439917b8bbacc93b7d3fa |
|
232
|
|
|
|
|
|
|
modified: '1504170797' |
|
233
|
|
|
|
|
|
|
size: '534' |
|
234
|
|
|
|
|
|
|
state: A |
|
235
|
|
|
|
|
|
|
version_id: DS.0.0 |
|
236
|
|
|
|
|
|
|
versionable: 'false' |
|
237
|
|
|
|
|
|
|
... |
|
238
|
|
|
|
|
|
|
$ catmandu stream files --bag 1234 --id foobar.pdf > foobar.pdf |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=back |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
L<Catmandu::Store::File::FedoraCommons::Index>, |
|
245
|
|
|
|
|
|
|
L<Catmandu::Store::File::FedoraCommons::Bag>, |
|
246
|
|
|
|
|
|
|
L<Catmandu::FileStore> |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |