Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
reworked Export plugin so that *any* EPrint field can be mapped if a …
Browse files Browse the repository at this point in the history
…corresponding sub is found in zzz_datacite_mapping
  • Loading branch information
Rory McNicholl committed Aug 21, 2017
1 parent be7a6c2 commit 336a27c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 60 deletions.
83 changes: 83 additions & 0 deletions lib/cfg.d/zzz_datacite_mapping.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
####################################################
# New architecture for print => datacite mapping
####################################################

#These first two both map to resourceType (and resourceTypeGeneral) the first is for pubs repos the second for data (but either can be used for ether f the eprint field is there)
$c->{datacite_mapping_type} = sub {

my ( $xml, $dataobj, $repo, $value ) = @_;

my $pub_resourceType = $repo->get_conf( "datacitedoi", "typemap", $value );
if(defined $pub_resourceType){
return $xml->create_data_element( "resourceType", $pub_resourceType->{'v'}, resourceTypeGeneral=>$pub_resourceType->{'a'});
}

return undef;
};

$c->{datacite_mapping_data_type} = sub {

my ( $xml, $dataobj, $repo, $value ) = @_;

return $xml->create_data_element( "resourceType", $value, resourceTypeGeneral=>$value);
};

$c->{datacite_mapping_creators} = sub {

my ( $xml, $dataobj, $repo, $value ) = @_;

my $creators = $xml->create_element( "creators" );

foreach my $name ( @$value ){
my $author = $xml->create_element( "creator" );

my $name_str = EPrints::Utils::make_name_string( $name->{name});

my $family = $name->{name}->{family};
my $given = $name->{name}->{given};
my $orcid = $name->{orcid};

if ($family eq '' && $given eq ''){
$creators->appendChild( $author );
} else {
$author->appendChild( $xml->create_data_element("creatorName", $name_str ) );
}
if ($given eq ''){
$creators->appendChild( $author );
} else {
$author->appendChild( $xml->create_data_element("givenName",$given ) );
}
if ($family eq ''){
$creators->appendChild( $author );
} else {
$author->appendChild( $xml->create_data_element("familyName", $family ) );
}
if ($dataobj->exists_and_set( "creators_orcid" )) {

if ($orcid eq '') {
$creators->appendChild( $author );
} else {
$author->appendChild( $xml->create_data_element("nameIdentifier", $orcid, schemeURI=>"http://orcid.org/", nameIdentifierScheme=>"ORCID" ) );
}
}

$creators->appendChild( $author );
}
return $creators
};

=comment
$c->{datacite_mapping_somefield} = sub {
my ( $xml, $dataobj, $repo, $value ) = @_;
#Do the mapping/validation here....
return $xml #of somedescription
}
=cut
71 changes: 11 additions & 60 deletions lib/plugins/EPrints/Plugin/Export/DataCiteXML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,75 +58,26 @@ sub output_dataobj
my $prefix = $repo->get_conf( "datacitedoi", "prefix");
return $thisdoi if($thisdoi !~ /^$prefix/);
}

$entry->appendChild( $xml->create_data_element( "identifier", $thisdoi , identifierType=>"DOI" ) );

# AH 04/11/2016: adding <resourceType> element as it is required for the
# DataCite 4.0 XML Metadata Schema. For publications repositories, it uses the
# eprint_type value. For data repositories, it uses the eprint_data_type value.
my $resourceType_element;
my $pub_resourceType = $repo->get_conf( "datacitedoi", "typemap", $dataobj->get_value("type") );
if(defined $pub_resourceType){
$resourceType_element = $xml->create_data_element( "resourceType", $pub_resourceType->{'v'}, resourceTypeGeneral=>$pub_resourceType->{'a'});
}
if( $dataobj->exists_and_set( "data_type" ) ) {
my $data_type = $dataobj->get_value( "data_type" );
$resourceType_element = $xml->create_data_element( "resourceType", $data_type, resourceTypeGeneral=>$data_type);
}
$entry->appendChild( $resourceType_element );

#RM otherwise we'll leave this alone for now
foreach my $field ( $dataobj->{dataset}->get_fields )
{
my $mapping_fn = "datacite_mapping_".$field->get_name;
if($repo->can_call($mapping_fn) && $dataobj->exists_and_set($field->get_name)){
my $mapped_element = $repo->call( $mapping_fn, $xml, $dataobj, $repo, $dataobj->value($field->get_name) );
$entry->appendChild( $mapped_element ) if(defined $mapped_element);
}
}

#RM extract licens from documents by some means:
my $license = undef;


if( $repo->can_call( "datacite_license" ) ){
$license = $repo->call( "datacite_license", $xml, $entry, $dataobj, $repo );
}

if( $dataobj->exists_and_set( "creators" ) ){
my $creators = $xml->create_element( "creators" );
my $names = $dataobj->get_value( "creators" );

foreach my $name ( @$names ){
my $author = $xml->create_element( "creator" );

my $name_str = EPrints::Utils::make_name_string( $name->{name});



my $family = $name->{name}->{family};
my $given = $name->{name}->{given};
my $orcid = $name->{orcid};

if ($family eq '' && $given eq ''){
$creators->appendChild( $author );
} else {
$author->appendChild( $xml->create_data_element("creatorName", $name_str ) );
}
if ($given eq ''){
$creators->appendChild( $author );
} else {
$author->appendChild( $xml->create_data_element("givenName",$given ) );
}
if ($family eq ''){
$creators->appendChild( $author );
} else {
$author->appendChild( $xml->create_data_element("familyName", $family ) );
}
if ($dataobj->exists_and_set( "creators_orcid" )) {

if ($orcid eq '') {
$creators->appendChild( $author );
} else {
$author->appendChild( $xml->create_data_element("nameIdentifier", $orcid, schemeURI=>"http://orcid.org/", nameIdentifierScheme=>"ORCID" ) );
}
}

$creators->appendChild( $author );
}
$entry->appendChild( $creators );
}
##########################################################################################################################################################################
################################# From here on in you can redefine datacite_ampping_[fieldname] sub routines in lib/cfg.d/zzz_datacite_mapping.pl #######################


if ($dataobj->exists_and_set( "title" )) {
Expand Down

0 comments on commit 336a27c

Please sign in to comment.