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

Commit

Permalink
updating the datacite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Borys Feldman committed Sep 19, 2017
1 parent 336a27c commit 2b68f3d
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 354 deletions.
75 changes: 16 additions & 59 deletions cfg/cfg.d/z_datacitedoi.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use Data::Dumper;

#Enable the plugin
$c->{plugins}{"Export::DataCiteXML"}{params}{disable} = 0;
$c->{plugins}{"Event::DataCiteEvent"}{params}{disable} = 0;
Expand All @@ -13,24 +15,27 @@

#set these (you will get the from data site)
# doi = {prefix}/{repoid}/{eprintid}
$c->{datacitedoi}{prefix} = "10.5072";
$c->{datacitedoi}{repoid} = $c->{host};
$c->{datacitedoi}{apiurl} = "https://test.datacite.org/mds/";
$c->{datacitedoi}{user} = "USER";
$c->{datacitedoi}{pass} = "PASS";
#$c->{datacitedoi}{prefix} = "10.5072";
$c->{datacitedoi}{prefix} = "10.17864";
$c->{datacitedoi}{repoid} = "1947";
$c->{datacitedoi}{apiurl} = "https://mds.datacite.org/";
#$c->{datacitedoi}{apiurl} = "https://mds.test.datacite.org/";
$c->{datacitedoi}{user} = "BL.READING";
$c->{datacitedoi}{pass} = "rdawk201";

# datacite requires a Publisher
# The name of the entity that holds, archives, publishes,
# prints, distributes, releases, issues, or produces the
# resource. This property will be used to formulate the
# citation, so consider the prominence of the role.
# eg World Data Center for Climate (WDCC);
$c->{datacitedoi}{publisher} = "Eprints Repo";
$c->{datacitedoi}{publisher} = "University of Reading";

# Namespace and location for datacite XML schema
# feel free to update, though no guarantees it'll be accepted if you do
$c->{datacitedoi}{xmlns} = "http://datacite.org/schema/kernel-4.0";
$c->{datacitedoi}{schemaLocation} = $c->{datacitedoi}{xmlns}." http://schema.datacite.org/meta/kernel-4.0/metadata.xsd";
#$c->{datacitedoi}{xmlns} = "http://datacite.org/schema/kernel-2.2";
$c->{datacitedoi}{xmlns} = "http://datacite.org/schema/kernel-4";
$c->{datacitedoi}{schemaLocation} = $c->{datacitedoi}{xmlns}." http://schema.datacite.org/meta/kernel-4/metadata.xsd";

# need to map eprint type (article, dataset etc) to ResourceType
# Controled list http://schema.datacite.org/meta/kernel-2.2/doc/DataCite-MetadataKernel_v2.2.pdf
Expand Down Expand Up @@ -66,7 +71,7 @@
$c->{datacitedoi}{allow_custom_doi} = 0;

#Datacite recommend digits of length 8-10 set this param to pad the id to required length
$c->{datacitedoi}{zero_padding} = 8;
$c->{datacitedoi}{zero_padding} = 0;

##########################################
### Override which URL gets registered ###
Expand Down Expand Up @@ -99,7 +104,7 @@

return undef if (!defined $repository);

if (defined $params{dataobj}) {
if (defined %params->{dataobj}) {
my $dataobj = $params{dataobj};
my $eprint_id = $dataobj->id;
$repository->dataset( "event_queue" )->create_dataobj({
Expand All @@ -119,52 +124,4 @@
}





#BF sub method for can call for funder
$c->{datacite_custom_funder} = sub
{

my ( $xml, $entry, $dataobj ) = @_;

if ($dataobj->exists_and_set( "funders" )) {
my $funders = $dataobj->get_value( "funders" );
my $thefunders = $xml->create_element( "funders" );
foreach my $funder ( @$funders )
{
my $fund = $funder->{funders};
my $grant = $funder->{grant};
my $others = $dataobj->get_value( "funders_other_funder" );
if($fund eq "other"){
foreach my $other ( @$others )
{

$thefunders->appendChild( $xml->create_data_element( "funderName", $other) );
}} else {
$thefunders->appendChild( $xml->create_data_element( "funderName", $fund) );
}

$thefunders->appendChild( $xml->create_data_element( "awardNumber", $grant) );


}
$entry->appendChild( $thefunders );
}
};


#BF sub method for can call for language
$c->{datacite_custom_language} = sub
{
my ( $xml, $entry, $dataobj ) = @_;

my $lan = $dataobj->get_value( "language" );
if ($dataobj->exists_and_set( "language" )) {
foreach my $la ( @$lan )
{
my $thelanguage = $la->{l};
$entry->appendChild( $xml->create_data_element( "language", $thelanguage) );
}
}
}
#With this we effectively turn off the repo_link => relatedIdentifier mapping for this repository
267 changes: 267 additions & 0 deletions lib/cfg.d/z_datacite_mapping.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
#####################################################
# 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
};


$c->{datacite_mapping_title} = sub {
my($xml, $dataobj, $repo, $value) = @_;



my $titles = $xml->create_element("titles");
$titles->appendChild($xml->create_data_element("title", $dataobj->render_value("title"), "xml:lang"=>"en-us"));






return $titles# of somedescription
};






$c->{datacite_mapping_abstract} = sub {
my($xml, $dataobj, $repo, $value) = @_;

my $abstract = $dataobj->get_value("abstract");
my $description = $xml->create_element("descriptions");

$description->appendChild($xml->create_data_element("description", $abstract, "xml:lang"=>"en-us", descriptionType=>"Abstract"));

if ($dataobj->exists_and_set("collection_method")) {
my $collection = $dataobj->get_value("collection_method");
$description->appendChild($xml->create_data_element("description", $collection, descriptionType =>"Methods"));
}

if ($dataobj->exists_and_set("provenance")) {
my $processing = $dataobj->get_value("provenance");
$description->appendChild($xml->create_data_element("description", $processing, descriptionType =>"Methods"));
}




return $description# of somedescription
};






$c->{datacite_mapping_date} = sub {
my ( $xml, $dataobj, $repo, $value ) = @_;
$dataobj->get_value( "date" ) =~ /^([0-9]{4})/;
return $xml->create_data_element( "publicationYear", $1 ) if $1;

};


$c->{datacite_mapping_keywords} = sub {
my($xml, $dataobj, $repo, $value) = @_;

if ($dataobj->exists_and_set("keywords")) {
my $subjects = $xml->create_element("subjects");
my $keywords = $dataobj->get_value("keywords");
if (ref($keywords) eq "ARRAY") {
foreach my $keyword(@$keywords) {
$subjects->appendChild($xml->create_data_element("subject", $keyword, "xml:lang"=>"en-us"));
}
return $subjects

} else {
$subjects->appendChild($xml->create_data_element("subject", $keywords, "xml:lang"=>"en-us"));
return $subjects
}
}
};

$c->{datacite_mapping_geographic_cover} = sub {
my($xml, $dataobj, $repo, $value) = @_;

my $geo_locations = $xml->create_element("geoLocations");
my $geo_location = $xml->create_element("geoLocation");
if ($dataobj->exists_and_set("geographic_cover")) {

#
#Create XML elements

# Get value of geographic_cover field and append to $geo_location XML element
my $geographic_cover = $dataobj->get_value("geographic_cover");
$geo_location->appendChild($xml->create_data_element("geoLocationPlace", $geographic_cover));

#
# Get values of bounding box
my $west = $dataobj->get_value("bounding_box_west_edge");
my $east = $dataobj->get_value("bounding_box_east_edge");
my $south = $dataobj->get_value("bounding_box_south_edge");
my $north = $dataobj->get_value("bounding_box_north_edge");

#
# Check to see
# if $north, $south, $east, or $west values are defined
if (defined $north && defined $south && defined $east && defined $west) {#
#Created $geo_location_box XML element
my $geo_location_box = $xml->create_element("geoLocationBox");#
#If $long / lat is defined, created XML element with the appropriate value
$geo_location_box->appendChild($xml->create_data_element("westBoundLongitude", $west));
$geo_location_box->appendChild($xml->create_data_element("eastBoundLongitude", $east));
$geo_location_box->appendChild($xml->create_data_element("southBoundLatitude", $south));
$geo_location_box->appendChild($xml->create_data_element("northBoundLatitude", $north));#
#Append child $geo_location_box XML element to parent $geo_location XML element
$geo_location->appendChild($geo_location_box);
}
#Append child $geo_location XML element to parent $geo_locations XML element
$geo_locations->appendChild($geo_location);
#Append $geo_locations XML element to XML document# $entry - > appendChild($geo_locations);
}

return $geo_locations;
};

$c->{datacite_mapping_funders} = sub {
my($xml, $dataobj, $repo, $value) = @_;


#
# if ($repo - >can_call("datacite_custom_funder")) {#
# return $repo - > call("datacite_custom_funder", $xml, $dataobj);#
# }

my $funders = $dataobj->get_value("funders");
my $grant = $dataobj->get_value("grant");
my $projects = $dataobj->get_value("projects");
if ($dataobj->exists_and_set("funders")) {
my $thefunders = $xml->create_element("funders");
foreach my $funder(@$funders) {
foreach my $project(@$projects) {
$thefunders->appendChild($xml->create_data_element("funderName", $funder));
$thefunders->appendChild($xml->create_data_element("awardNumber", $grant));
}
}
return $thefunders;
}
};



$c->{datacite_mapping_rights} = sub {
my($xml, $dataobj, $repo, $value) = @_;
my $author = $xml->create_element("rightsList");

foreach my $doc($dataobj->get_all_documents()) {

my $license = $doc->get_value("license");

if (defined $license && $license ne '') {

if ($license eq "attached") {

$author ->appendChild($xml->create_data_element("rights", $repo->phrase("licenses_typename_attached"), rightsURI =>$doc->get_url));
} else {

my $licenseuri = $repo->phrase("licenses_uri_$license");
$author->appendChild($xml->create_data_element("rights", $license, rightsURI =>$licenseuri));
}
}


}
return $author;
};






$c->{datacite_mapping_repo_link} = sub {

my($xml, $entry, $dataobj) = @_;

my $relatedIdentifiers = undef;
#default codein plugin (for reference)
# my $theurls = $dataobj->get_value( "repo_link" );
# my $relatedIdentifiers = $xml->create_element( "relatedIdentifiers" );
# foreach my $theurl ( @$theurls ) {
# my $linkk = $theurl->{link};
# if (!$linkk eq ''){
# $relatedIdentifiers->appendChild( $xml->create_data_element( "relatedIdentifier", $linkk, relatedIdentifierType=>"URL", relationType=>"IsReferencedBy" ) );
# }
# }


return $relatedIdentifiers;

};
Loading

0 comments on commit 2b68f3d

Please sign in to comment.