Skip to content
Snippets Groups Projects
Commit a15cff50 authored by Gerhard Gonter's avatar Gerhard Gonter :speech_balloon:
Browse files

added test mode and OJS namespace

parent fc2d5444
Branches
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ my $config_file= '/etc/irma/DataCite.json'; ...@@ -41,6 +41,7 @@ my $config_file= '/etc/irma/DataCite.json';
# identifiers table # identifiers table
my $na_path= 'na/na-dcd-10-25365'; my $na_path= 'na/na-dcd-10-25365';
my $identifiers_file= join ('/', $na_path, 'identifiers.tsv'); my $identifiers_file= join ('/', $na_path, 'identifiers.tsv');
my $ifx= '10.25365/phaidra'; my $ifx= '10.25365/phaidra';
my $na_id= 1; my $na_id= 1;
my $context_id= 1; my $context_id= 1;
...@@ -63,6 +64,11 @@ while (defined ($arg= shift (@ARGV))) ...@@ -63,6 +64,11 @@ while (defined ($arg= shift (@ARGV)))
if ($opt eq 'help') { usage(); } if ($opt eq 'help') { usage(); }
elsif ($opt eq 'ticket') { $ticket= $val || shift (@ARGV); } elsif ($opt eq 'ticket') { $ticket= $val || shift (@ARGV); }
elsif ($opt eq 'doit') { $register_live= 1; } elsif ($opt eq 'doit') { $register_live= 1; }
elsif ($opt eq 'test')
{
$na_path= 'na/na-dcd-10-5072';
$identifiers_file= join ('/', $na_path, 'identifiers.tsv');
}
else { usage(); } else { usage(); }
} }
elsif ($arg =~ /^-(.+)/) elsif ($arg =~ /^-(.+)/)
...@@ -130,6 +136,7 @@ sub register_url ...@@ -130,6 +136,7 @@ sub register_url
print __LINE__, " repo_url=[$repo_url]\n"; print __LINE__, " repo_url=[$repo_url]\n";
if ($repo_url =~ m#^https?://(phaidra(-(sandbox|temp))?\.univie\.ac\.at)/(detail_object|view/)?(o:\d+)$# if ($repo_url =~ m#^https?://(phaidra(-(sandbox|temp))?\.univie\.ac\.at)/(detail_object|view/)?(o:\d+)$#
# || $repo_url =~ m# ... uscholar ... #) # || $repo_url =~ m# ... uscholar ... #)
|| $repo_url =~ m#https://(ojs3test\.(univie)\.(ac)\.at)/(index\.php)/wks/article/view/(\d+)$#
) )
{ {
my ($repo, $s1, $s2, $s3, $pid)= ($1, $2, $3, $4, $5); my ($repo, $s1, $s2, $s3, $pid)= ($1, $2, $3, $4, $5);
...@@ -154,28 +161,31 @@ sub register_url ...@@ -154,28 +161,31 @@ sub register_url
} }
my ($pfx, $ns, $nr)= split_doi_string ($prod_doi_string); my ($pfx, $ns, $nr)= split_doi_string ($prod_doi_string);
# print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr]\n";
my $fo_xml= join ('/', $na_path, 'metadata', $ns, join ('.', $ns, $nr, 'xml')); my $dc_xml= join ('/', $na_path, 'metadata', $ns, join ($repo_cnf->{id_separator}, $ns, $nr) .'.xml');
print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr] fo_xml=[$fo_xml]\n"; print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr] dc_xml=[$dc_xml]\n";
my $prod_xml_new; # DataCite Metadata in XML format my $prod_xml_new; # DataCite Metadata in XML format
if (-f $fo_xml) if (-f $dc_xml)
{ {
my @st= stat(_); my @st= stat(_);
my $size= $st[7]; my $size= $st[7];
print "ATTN: XML file [$fo_xml] already exists, reading it!\n"; print "ATTN: XML file [$dc_xml] already exists, reading it!\n";
unless (open (FO_XML, '<:utf8', $fo_xml)) unless (open (DC_XML, '<:utf8', $dc_xml))
{ {
print "ATTN: can not read XML from [$fo_xml]\n"; print "ATTN: can not read XML from [$dc_xml]\n";
return; return;
} }
sysread (FO_XML, $prod_xml_new, $size); sysread (DC_XML, $prod_xml_new, $size);
close (FO_XML); close (DC_XML);
} }
else else
{ # no XML found, so fetch metadata, convert it to XML and test it on the mds.test.datacite.org { # no XML found, so fetch metadata, convert it to XML and test it on the mds.test.datacite.org
if ($repo_cnf->{repo_type} eq 'phaidra')
{
my $repo_obj= new Phaidra::DataCite (config => $repo_cnf); my $repo_obj= new Phaidra::DataCite (config => $repo_cnf);
# print __LINE__, " repo_obj: ", main::Dumper ($repo_obj); # print __LINE__, " repo_obj: ", main::Dumper ($repo_obj);
...@@ -230,13 +240,13 @@ print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr ...@@ -230,13 +240,13 @@ print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr
$prod_xml_new= $repo_obj->json_2_xml ($md); $prod_xml_new= $repo_obj->json_2_xml ($md);
unless (open (FO_XML, '>:utf8', $fo_xml)) unless (open (DC_XML, '>:utf8', $dc_xml))
{ {
print "ATTN: can not write XML to [$fo_xml]\n"; print "ATTN: can not write XML to [$dc_xml]\n";
return; return;
} }
syswrite (FO_XML, $prod_xml_new); syswrite (DC_XML, $prod_xml_new);
close (FO_XML); close (DC_XML);
print "metatada fetched: ", get_ts(), "\n"; print "metatada fetched: ", get_ts(), "\n";
if ($dc_res->{status} ne 'OK') if ($dc_res->{status} ne 'OK')
...@@ -251,6 +261,12 @@ print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr ...@@ -251,6 +261,12 @@ print __LINE__, " prod_doi_string=[$prod_doi_string] pfx=[$pfx] ns=[$ns] nr=[$nr
return undef; return undef;
} }
} }
else
{
print "ERROR: can't fetch metadata for this type of repository! [", $repo_cnf->{repo_type}, "]\n";
return undef;
}
}
print __LINE__, " prod_xml_new=[$prod_xml_new]\n"; print __LINE__, " prod_xml_new=[$prod_xml_new]\n";
...@@ -309,7 +325,7 @@ sub split_doi_string ...@@ -309,7 +325,7 @@ sub split_doi_string
my $doi= shift; # e.g. 10.25365/phaidra.1 my $doi= shift; # e.g. 10.25365/phaidra.1
my ($pfx, $sfx)= split ('/', $doi, 2); my ($pfx, $sfx)= split ('/', $doi, 2);
my ($ns, $nr)= split (/\./, $sfx, 2); my ($ns, $nr)= split (/[\.\-]/, $sfx, 2);
($pfx, $ns, $nr); ($pfx, $ns, $nr);
} }
......
...@@ -61,7 +61,7 @@ url=$repo_url ...@@ -61,7 +61,7 @@ url=$repo_url
EOX EOX
my ($code2, $res2)= $self->datacite_request ('POST', 'doi', $doi_reg, 'application/xml;charset=UTF-8'); my ($code2, $res2)= $self->datacite_request ('POST', 'doi', $doi_reg, 'application/xml;charset=UTF-8');
print __LINE__, " code2=[$code2] res2=[$res2]\n"; print __LINE__, " doi_reg=[$doi_reg] code2=[$code2] res2=[$res2]\n";
unless ($code2 =~ m#^20[01]#) unless ($code2 =~ m#^20[01]#)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment