Skip to content

Commit

Permalink
Merge pull request #28 from eprintsug/master
Browse files Browse the repository at this point in the history
import improvements
  • Loading branch information
wfyson committed Feb 19, 2020
2 parents f411917 + 30177a8 commit 3f51182
Show file tree
Hide file tree
Showing 5 changed files with 2,116 additions and 1,957 deletions.
1 change: 1 addition & 0 deletions lib/lang/en/phrases/z_orcid_support_advance.xml
Expand Up @@ -9,6 +9,7 @@
<epp:phrase id="user_fieldname_orcid_token_expires">ORCID Token Expiry</epp:phrase>

<epp:phrase id="eprint_fieldname_creators_putcode">ORCID Put Code</epp:phrase>
<epp:phrase id="eprint_fieldname_editors_putcode">ORCID Put Code</epp:phrase>

<!-- Authenticate ORCID -->
<epp:phrase id="Plugin/Screen/AuthenticateOrcid:title"><img class="orcid-icon" src="/images/orcid_16x16.png"/>Create or Connect your ORCID iD</epp:phrase>
Expand Down
5 changes: 3 additions & 2 deletions lib/plugins/EPrints/Plugin/Screen/ExportToOrcid.pm
Expand Up @@ -55,8 +55,9 @@ sub can_be_viewed{
return 1;
}

if( $screenid eq "Workflow::View") #user profile screen
{
my $dataset = $self->{repository}->param( "dataset" );
if( $screenid eq "Workflow::View" && $dataset eq 'user') #user profile screen
{
my $userid = $self->{repository}->param( "dataobj" );
if( defined $userid )
{
Expand Down
93 changes: 48 additions & 45 deletions lib/plugins/EPrints/Plugin/Screen/ImportFromOrcid.pm
Expand Up @@ -54,8 +54,9 @@ sub can_be_viewed
return 1;
}

if( $screenid eq "Workflow::View") #user profile screen
{
my $dataset = $self->{repository}->param( "dataset" );
if( $screenid eq "Workflow::View" && $dataset eq 'user') #user profile screen
{
my $userid = $self->{repository}->param( "dataobj" );
if( defined $userid )
{
Expand Down Expand Up @@ -454,7 +455,7 @@ sub render_orcid_records
$import_count++;
}
if( $import_count == 0 ) {
$ul->appendChild( $xml->create_text_node( $self->html_phrase( "no_items" ) ) );
$ul->appendChild( $self->html_phrase( "no_items" ) );
}
return $ul;
}
Expand Down Expand Up @@ -704,7 +705,6 @@ sub import_via_orcid
}
}
}

$epdata->{eprint_status} = $repo->config( "orcid_support_advance", "import_destination") || "inbox";
$epdata->{userid} = $user->get_value( "userid" );

Expand Down Expand Up @@ -778,8 +778,8 @@ sub import_via_orcid
$eprint->set_value( "id_number", "doi".$identifier->{"external-id-value"} );
}
}
elsif ( $identifier->{"external-id-type"} eq "urn" )
{
elsif ( $identifier->{"external-id-type"} eq "urn" )
{
if( $repo->dataset( 'eprint' )->has_field( "urn" ) )
{
$eprint->set_value( "urn", $identifier->{"external-id-value"} );
Expand All @@ -788,15 +788,15 @@ sub import_via_orcid
{
$eprint->set_value( "id_number", $identifier->{"external-id-value"} );
}
}
elsif ( $identifier->{"external-id-type"} eq "issn" )
{
}
elsif ( $identifier->{"external-id-type"} eq "issn" )
{
$eprint->set_value( "issn", $identifier->{"external-id-value"} );
}
elsif ( $identifier->{"external-id-type"} eq "isbn" )
{
}
elsif ( $identifier->{"external-id-type"} eq "isbn" )
{
$eprint->set_value( "isbn", $identifier->{"external-id-value"} );
}
}
}
}

Expand All @@ -806,25 +806,25 @@ sub import_via_orcid
{
foreach my $contributor (@{$work->{"contributors"}->{"contributor"}} )
{
my ($username,$putcode,$orcid) = undef;

my $users_orcid = $user->value( "orcid" );
my ($username,$putcode,$orcid) = undef;

my $users_orcid = $user->value( "orcid" );
my $c_user; # a user object derived from creator object, additional to the logged in one
if( defined( $contributor->{"contributor-orcid"} ) )
{
#search for user with orcid and add username to eprint contributor if found
$orcid = $contributor->{"contributor-orcid"}->{"path"};
$user = EPrints::ORCID::Utils::user_with_orcid( $repo, $orcid );

# Save putcode if this contributor is the importing user
if( $users_orcid eq $orcid )
{
my @work_putcodes = ( $work->{"put-code"} );
foreach my $work_putcode (@work_putcodes)
{
$putcode = $work_putcode;
}
}
$c_user = EPrints::ORCID::Utils::user_with_orcid( $repo, $orcid );

# Save putcode if this contributor is the importing user
if( $users_orcid eq $orcid )
{
my @work_putcodes = ( $work->{"put-code"} );
foreach my $work_putcode (@work_putcodes)
{
$putcode = $work_putcode;
}
}

}

Expand All @@ -847,12 +847,12 @@ sub import_via_orcid
family => $family,
},
};
#putcode only or
#putcode only or
$contributor->{"putcode"} = $putcode if defined $putcode;
#Add orcid if we have one
$contributor->{orcid} = $orcid if defined $orcid;
#Add user email if we have linked a user
$contributor->{"id"} = $user->get_value( "email" ) if defined $user;
$contributor->{"id"} = $c_user->get_value( "email" ) if defined $c_user;

#add user to appropriate field
if( $contrib_role eq "creators" )
Expand All @@ -862,33 +862,36 @@ sub import_via_orcid
}
}


# If there have been no contributor AND no creators were parsed from citation...
# assume the user is a creator
if( !$creators && !$eprint->is_set("creators") )
{
my $users_name = $user->get_value("name");
my $putcode = undef;
my @work_putcodes = ( $work->{"put-code"} );
foreach my $work_putcode (@work_putcodes)
{
$putcode = $work_putcode;
}
# If there have been no contributor AND no creators were parsed from citation...
# assume the user is a creator
if( !$creators && !$eprint->is_set("creators") )
{
my $users_name = $user->get_value("name");
my $putcode = undef;
my @work_putcodes = ( $work->{"put-code"} );
foreach my $work_putcode (@work_putcodes)
{
$putcode = $work_putcode;
}
my $contributor = {
name => {
given => $users_name->{given},
family => $users_name->{family},
},
id => $user->get_value( "email" ),
id => $user->get_value( "email" ),
orcid => $user->value( "orcid" ),
putcode => $putcode,
};
push @{$creators}, $contributor;
}
#If creators set then this takes precednce over what's been gleaned from citation
push @{$creators}, $contributor;
}
# use Data::Dumper;
# print STDERR "creators from orcid.contributirs: ".Dumper($creators)."\n";

#If creators set then this takes precednce over what's been gleaned from citation
$eprint->set_value( "creators", $creators ) if EPrints::Utils::is_set($creators);

#save the record
$eprint->commit;
# print STDERR "creators in eprint: ".Dumper($eprint->value( "creators"))."\n";
return $eprint;
}

0 comments on commit 3f51182

Please sign in to comment.