-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataCite.pm
301 lines (217 loc) · 8.59 KB
/
DataCite.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
=head1 NAME
EPrints::Plugin::Export::DataCite
=head1 DESCRIPTION
=cut
# Author: Volker Schallehn, Universitätsbibliothek der LMU München, Germany
# Exports Metadata via OAI-PMH using the DataCite Metadata Schema 4.1
# Version: 1.0 / 7. May 2018
# Version: 1.1 / 18. October 2018
# - relatedIdentifier added
package EPrints::Plugin::Export::DataCite;
use EPrints v3.3.0;
use EPrints::Plugin::Export::XMLFile;
@ISA = ( "EPrints::Plugin::Export::XMLFile" );
use strict;
sub new
{
my( $class, %opts ) = @_;
my $self = $class->SUPER::new( %opts );
$self->{name} = "DataCite";
$self->{accept} = [ 'dataobj/eprint' ];
$self->{visible} = "all";
$self->{metadataPrefix} = "datacite";
$self->{xmlns} = "http://www.w3.org/2001/XMLSchema-instance",
$self->{schemaLocation} = "http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4.1/metadata.xsd";
return $self;
}
sub xml_dataobj
{
my( $plugin, $dataobj, $prefix ) = @_;
my $session = $plugin->{ session };
my $dataset = $dataobj->get_dataset;
my $resource = $session->make_element(
"resource",
"xmlns" => "http://datacite.org/schema/kernel-4",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation" => "http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4.1/metadata.xsd",
);
# DOI
$resource->appendChild( _make_doi( $session, $dataset, $dataobj ));
# Full-Publication-URLs
$resource->appendChild( _make_full_data_url( $session, $dataset, $dataobj ));
# title
$resource->appendChild( _make_title( $session, $dataset, $dataobj ));
# creators
$resource->appendChild( _make_creators( $session, $dataset, $dataobj ));
# abstract
$resource->appendChild( _make_abstract( $session, $dataset, $dataobj ));
# subjects
$resource->appendChild( _make_subjects( $session, $dataset, $dataobj ));
# date_issue
$resource->appendChild( _make_issue_date( $session, $dataset, $dataobj ));
# publisher
$resource->appendChild( _make_publisher( $session, $dataset, $dataobj ));
return $resource;
}
sub output_dataobj
{
my( $plugin, $dataobj ) = @_;
my $xml = $plugin->xml_dataobj( $dataobj );
return EPrints::XML::to_string( $xml );
}
sub _make_creators
{
my( $session, $dataset, $dataobj ) = @_;
# creators is obligatory, even if it is empty
my $creators = undef;
my $creators_tag = $session->make_element( "creators" );
if ( $dataobj->exists_and_set( "creators_name" ) )
{
$creators = $dataobj->get_value( "creators_name" );
foreach my $creator ( @{$creators} )
{
next if !defined $creator;
$creators_tag->appendChild( my $creator_tag = $session->make_element( "creator" ));
$creator_tag->appendChild(my $name = $session->make_element( "creatorName", "nameType" => "Personal" ));
$creator_tag->appendChild(my $given = $session->make_element( "givenName" ));
$creator_tag->appendChild(my $family = $session->make_element( "familyName" ));
my $forename = $creator->{'given'};
my $surname = $creator->{'family'};
$name->appendChild( $session->make_text( EPrints::Utils::make_name_string( $creator )));
$given->appendChild( $session->make_text( $forename ));
$family->appendChild( $session->make_text( $surname ));
}
}
# in case there is no creator
else {
my $creator_tag = $session->make_element( "creator" );
$creators_tag->appendChild( my $creator_tag = $session->make_element( "creator" ));
$creator_tag->appendChild(my $name = $session->make_element( "creatorName", "nameType" => "Personal" ));
$name->appendChild( $session->make_text( "none supplied" ));
}
return $creators_tag;
}
sub _make_title
{
my( $session, $dataset, $dataobj ) = @_;
return $session->make_doc_fragment unless $dataset->has_field( "title" );
my $val = $dataobj->get_value( "title" );
return $session->make_doc_fragment unless defined $val;
my $titleInfo = $session->make_element( "titles" );
$titleInfo->appendChild( my $title = $session->make_element( "title" ));
$title->appendChild( $session->make_text( $val ));
return $titleInfo;
}
# For "Open Data LMU", the abstract field is a compound field with the subfields "name" and "lang".
# For repositories with a simple abstract field the following commented out "sub _make_abstract" should do it.
# sub _make_abstract
# {
# my( $session, $dataset, $dataobj ) = @_;
# return $session->make_doc_fragment unless $dataset->has_field( "abstract" );
# my $val = $dataobj->get_value( "abstract" );
# return $session->make_doc_fragment unless defined $val;
# my $descriptions = $session->make_element( "descriptions" );
# $descriptions->appendChild( my $description = $session->make_element( "description", "descriptionType" => "Abstract" ));
# $description->appendChild( $session->make_text( $val ));
# return $descriptions;
# }
sub _make_abstract
{
my( $session, $dataset, $dataobj ) = @_;
my $descriptions = $session->make_element( "descriptions" );
return $session->make_doc_fragment unless $dataset->has_field( "abstract" );
my $abstracts = $dataobj->get_value( "abstract_name" );
return $session->make_doc_fragment unless defined $abstracts;
foreach my $abstract ( @{$abstracts} )
{
next if !defined $abstract;
$descriptions->appendChild( my $description = $session->make_element( "description", "descriptionType" => "Abstract" ));
$description->appendChild( $session->make_text( $abstract ));
}
return $descriptions;
}
sub _make_doi
{
my( $session, $dataset, $dataobj ) = @_;
return $session->make_doc_fragment unless $dataset->has_field( "doi" );
my $val = $dataobj->get_value( "doi" );
$val =~ s/^doi:(.*)$/$1/;
return $session->make_doc_fragment unless defined $val;
my $identifier = $session->make_element( "identifier", "identifierType" => "DOI" );
$identifier->appendChild( $session->make_text( $val ));
return $identifier;
}
sub _make_full_data_url
{
my( $session, $dataset, $dataobj ) = @_;
my $frag = $session->make_element( "relatedIdentifiers" );
my @documents = $dataobj->get_all_documents();
foreach my $doc ( @documents )
{
my %files = $doc->files;
if( defined $files{$doc->get_main} )
{
my $fileurl = $doc->get_url;
my $relatedIdentifier = $session->make_element( "relatedIdentifier", 'relatedIdentifierType'=>"URL", 'relationType'=>"IsIdenticalTo" );
$relatedIdentifier->appendChild( $session->make_text( $fileurl ));
$frag->appendChild( $relatedIdentifier );
}
}
return $frag;
}
# In case of "Open Data LMU" the DDC (Dewey) as part of the subjects is exported
sub _make_subjects
{
my( $session, $dataset, $dataobj ) = @_;
my $frag = $session->make_element( "subjects" );
my $subjects = $dataset->has_field("ddc") ?
$dataobj->get_value("ddc") :
undef;
return $frag unless EPrints::Utils::is_set( $subjects );
foreach my $val (@$subjects)
{
my $subject = EPrints::DataObj::Subject->new( $session, $val );
next unless defined $subject;
$frag->appendChild( my $classification = $session->make_element( "subject", "schemeURI" => "http://dewey.info/", "subjectScheme" => "dewey"));
$classification->appendChild( $session->make_text( EPrints::XML::to_string($subject->render_description)));
}
return $frag;
}
sub _make_issue_date
{
my( $session, $dataset, $dataobj ) = @_;
return $session->make_doc_fragment unless $dataset->has_field( "date" );
my $val = $dataobj->get_value( "date" );
return $session->make_doc_fragment unless defined $val;
$val =~ s/(-0+)+$//;
# Deletes month and year
$val =~ s/^(\d{4}).*$/$1/;
my $publicationYear = $session->make_element( "publicationYear" );
$publicationYear->appendChild( $session->make_text( $val ));
return $publicationYear;
}
sub _make_publisher
{
my( $session, $dataset, $dataobj ) = @_;
my $publisher = $session->make_element( "publisher" );
$publisher->appendChild( $session->make_text( "Universitätsbibliothek der Ludwig-Maximilians-Universität München" ));
return $publisher;
}
1;
=head1 COPYRIGHT
=for COPYRIGHT BEGIN
Copyright 2000-2011 University of Southampton.
=for COPYRIGHT END
=for LICENSE BEGIN
This file is part of EPrints L<http://www.eprints.org/>.
EPrints is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
EPrints is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with EPrints. If not, see L<http://www.gnu.org/licenses/>.
=for LICENSE END