Last active
August 14, 2017 22:20
-
-
Save jesusbagpuss/134f0f1bd908e98878c3567cf7fbbd91 to your computer and use it in GitHub Desktop.
Include ORCIDs (stored in an creator->orcid field) in OAI output format - with info:eu-repo/dai/mx/orcid/ prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=head1 NAME | |
EPrints::Plugin::Export::OAI_DC_ORCID | |
=cut | |
package EPrints::Plugin::Export::OAI_DC_ORCID; | |
use EPrints::Plugin::Export::OAI_DC; | |
@ISA = ( "EPrints::Plugin::Export::OAI_DC", "EPrints::Plugin::Export::DC" ); | |
use strict; | |
sub new | |
{ | |
my( $class, %opts ) = @_; | |
my $self = $class->SUPER::new( %opts ); | |
$self->{name} = "Dublin Core - OAI + ORCID Schema"; | |
$self->{accept} = [ 'dataobj/eprint' ]; | |
$self->{visible} = ""; | |
$self->{suffix} = ".xml"; | |
$self->{mimetype} = "text/xml"; | |
$self->{metadataPrefix} = "oai_dc_orcid"; | |
$self->{xmlns} = "http://www.openarchives.org/OAI/2.0/oai_dc/"; | |
$self->{schemaLocation} = "http://www.openarchives.org/OAI/2.0/oai_dc.xsd"; | |
return $self; | |
} | |
sub xml_dataobj | |
{ | |
my( $plugin, $dataobj ) = @_; | |
my $data = $plugin->convert_dataobj( $dataobj ); | |
my $dc = $plugin->{session}->make_element( | |
"oai_dc:dc", | |
"xmlns:oai_dc" => "http://www.openarchives.org/OAI/2.0/oai_dc/", | |
"xmlns:dc" => "http://purl.org/dc/elements/1.1/", | |
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", | |
"xsi:schemaLocation" => | |
"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd" ); | |
# turn the list of pairs into XML blocks (indented by 8) and add them | |
# them to the DC element. | |
foreach( @{$data} ) | |
{ | |
$dc->appendChild( $plugin->{session}->render_data_element( 8, "dc:".$_->[0], $_->[1], %{$_->[2]} ) ); | |
} | |
return $dc; | |
} | |
sub convert_dataobj | |
{ | |
my( $plugin, $eprint ) = @_; | |
my $dataset = $eprint->{dataset}; | |
my @dcdata = (); | |
push @dcdata, $plugin->simple_value( $eprint, title => "title" ); | |
if( $eprint->exists_and_set( "creators" ) ) | |
{ | |
my $creators = $eprint->get_value( "creators" ); | |
foreach my $creator ( @$creators ) | |
{ | |
next if !defined $creator; | |
if( defined $creator->{orcid} ){ | |
push @dcdata, [ "creator", EPrints::Utils::make_name_string( $creator->{name} ), { 'id' => 'info:eu-repo/dai/mx/orcid/'.$creator->{orcid} } ]; | |
} else { | |
push @dcdata, [ "creator", EPrints::Utils::make_name_string( $creator->{name} ) ]; | |
} | |
} | |
} | |
if( $eprint->exists_and_set( "subjects" ) ) | |
{ | |
my $subjectid; | |
foreach $subjectid ( @{$eprint->get_value( "subjects" )} ) | |
{ | |
my $subject = EPrints::DataObj::Subject->new( $plugin->{session}, $subjectid ); | |
# avoid problems with bad subjects | |
next unless( defined $subject ); | |
push @dcdata, [ "subject", EPrints::Utils::tree_to_utf8( $subject->render_description() ) ]; | |
} | |
} | |
push @dcdata, $plugin->simple_value( $eprint, abstract => "description" ); | |
push @dcdata, $plugin->simple_value( $eprint, publisher => "publisher" ); | |
if( $eprint->exists_and_set( "editors_name" ) ) | |
{ | |
my $editors = $eprint->get_value( "editors_name" ); | |
if( defined $editors ) | |
{ | |
foreach my $editor ( @{$editors} ) | |
{ | |
push @dcdata, [ "contributor", EPrints::Utils::make_name_string( $editor ) ]; | |
} | |
} | |
} | |
## Date for discovery. For a month/day we don't have, assume 01. | |
if( $eprint->exists_and_set( "date" ) ) | |
{ | |
my $date = $eprint->get_value( "date" ); | |
if( defined $date ) | |
{ | |
$date =~ s/(-0+)+$//; | |
push @dcdata, [ "date", $date ]; | |
} | |
} | |
if( $eprint->exists_and_set( "type" ) ) | |
{ | |
push @dcdata, [ "type", EPrints::Utils::tree_to_utf8( $eprint->render_value( "type" ) ) ]; | |
} | |
my $ref = "NonPeerReviewed"; | |
if( $eprint->exists_and_set( "refereed" ) && $eprint->get_value( "refereed" ) eq "TRUE" ) | |
{ | |
$ref = "PeerReviewed"; | |
} | |
push @dcdata, [ "type", $ref ]; | |
my @documents = $eprint->get_all_documents(); | |
my $mimetypes = $plugin->{session}->get_repository->get_conf( "oai", "mime_types" ); | |
foreach( @documents ) | |
{ | |
my $format = $mimetypes->{$_->get_value("format")}; | |
$format = $_->get_value("format") unless defined $format; | |
#$format = "application/octet-stream" unless defined $format; | |
push @dcdata, [ "format", $format ]; | |
push @dcdata, [ "identifier", $_->get_url() ]; | |
} | |
# Most commonly a DOI or journal link | |
push @dcdata, $plugin->simple_value( $eprint, official_url => "relation" ); | |
# The citation for this eprint | |
push @dcdata, [ "identifier", | |
EPrints::Utils::tree_to_utf8( $eprint->render_citation() ) ]; | |
# The URL of the abstract page | |
if( $eprint->is_set( "eprintid" ) ) | |
{ | |
push @dcdata, [ "relation", $eprint->get_url() ]; | |
} | |
# dc.language not handled yet. | |
# dc.source not handled yet. | |
# dc.coverage not handled yet. | |
# dc.rights not handled yet. | |
return \@dcdata; | |
} | |
1; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment