diff --git a/dcd.pl b/dcd.pl index 7a86edbdb603e5e923b32579b743eac75199d726..9ede85e97c2700a8d499d39c1c472045e4ee2edf 100755 --- a/dcd.pl +++ b/dcd.pl @@ -227,17 +227,17 @@ print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr return undef; } - my $dc_res= $api_res->{datacite}; - # print __LINE__, " dc_res: ", Dumper ($dc_res); + my $datacite_res= $api_res->{datacite}; + print __LINE__, " datacite_res: ", Dumper ($datacite_res); # 2018-11-19 Phaidra's DataCite output is quite ... broken ... - fixup_datacite_data ($dc_res); + fixup_datacite_data ($datacite_res); # TODO: # * mint new DOI # * insert DOI in metadata - # NOTE: if ($dc_res->{status} ne 'OK') request a dummy doi_string + # NOTE: if ($datacite_res->{status} ne 'OK') request a dummy doi_string my $t_reg_obj= new DataCite::API (config => $t_reg_cnf, 'xmode' => 'test'); my $doi_string= $t_reg_obj->mint_doi(); @@ -256,7 +256,7 @@ print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr }; print __LINE__, " doi_element: ", main::Dumper($doi_element); - my $md= $dc_res->{datacite_elements}; + my $md= $datacite_res->{datacite_elements}; unshift (@$md, $doi_element); print __LINE__, " md: ", main::Dumper ($md); @@ -281,9 +281,9 @@ print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr close (DC_XML); print "metatada fetched: ", get_ts(), "\n"; - if ($dc_res->{status} ne 'OK') + if ($datacite_res->{status} ne 'OK') { - print "Metadata not ok; status=[$dc_res->{status}] errors: ", Dumper ($dc_res->{errors}); + print "Metadata not ok; status=[$datacite_res->{status}] errors: ", Dumper ($datacite_res->{errors}); return undef; } @@ -440,8 +440,11 @@ sub fixup_datacite_data { my $dc= shift; + my $data= $dc->{data}; + foreach my $dce (@{$dc->{datacite_elements}}) { + print __LINE__, ' dce: ', Dumper($dce); if ($dce->{xmlname} eq 'creators') { my @filtered_creators= (); @@ -459,7 +462,13 @@ sub fixup_datacite_data } elsif ($dce->{xmlname} eq 'publicationYear') { - if ($dce->{value} =~ m#^(\d{4})(-\d{2})?(-\d{2})?$#) + print __LINE__, " publicationYear: dce=", Dumper($dce); + if (!defined($dce->{value})) + { + my $year= $data->{publicationYear}->[0]->{value}; + $dce->{value}= $year if (defined($year)); + } + elsif ($dce->{value} =~ m#^(\d{4})(-\d{2})?(-\d{2})?$#) { my $new_year= $1; print __LINE__, " publicationYear fixed from [", $dce->{value}, "] to [$new_year]\n"; @@ -524,7 +533,7 @@ number from the idenetifiers table and register them. Until then, this also should work - tsv identifiers.tsv --select ticket=##### --col canoical_url -O- | xargs ./dcd.pl register --doit + tsv identifiers.tsv --select ticket=##### --col canonical_url -O- | xargs ./dcd.pl register --doit =head1 NOTES