Skip to content

Instantly share code, notes, and snippets.

@alenkovich
Last active February 27, 2017 21:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alenkovich/9596992 to your computer and use it in GitHub Desktop.
Save alenkovich/9596992 to your computer and use it in GitHub Desktop.
EPrints - OpenAIRE Guidelines compliance example (New set, filters and output formating)
3 files shown
FILE: <EPrints>/archives/ARCHIVE_ID/cfg/cfg.d/z_oai.pl
----------------------------------------------------------------------------------------
# don't use Export::OAI_DC for oai_dc metadataPrefix...
$c->{plugins}->{"Export::OAI_DC"}->{params}->{metadataPrefix} = undef;
# ...use Export::OAI_DC_Ext instead
$c->{plugins}->{"Export::OAI_DC_Ext"}->{params}->{metadataPrefix} = "oai_dc";
if(defined $c->{oai}->{custom_sets})
{
@{ $c->{oai}->{custom_sets} } = (@{ $c->{oai}->{custom_sets} }, (
{
spec => "ec_fundedresources",
name => "EC_fundedresources",
filters => [
{ meta_fields => ["comprojects_type" ], value => "FP 7", },
#{ meta_fields => ["comprojects_type" ], value => qw(FP 7,FP7), match=>"ANY" },
]
},
{
spec => "openaire",
name => "OpenAIRE",
filters => [
{ meta_fields => ["comprojects_type" ], value => "FP 7", },
#{ meta_fields => ["comprojects_type" ], value => qw(FP 7,FP7), match=>"ANY" },
]
},
));
}
else
{
my $custom_sets = {};
$custom_sets = [
{
spec => "rbi_test",
name => "Test Set no existing CS",
filters => [
{ meta_fields => ["full_text_status" ], value => "public", },
]
},
];
$c->{oai}->{custom_sets} = $custom_sets;
}
----------------------------------------------------------------------------------------
END FILE: <EPrints>/archives/ARCHIVE_ID/cfg/cfg.d/z_oai.pl
FILE: <EPrints>/archives/ARCHIVE_ID/cfg/plugins/EPrints/Plugin/Export/OAI_DC_Ext.pm
----------------------------------------------------------------------------------------
package EPrints::Plugin::Export::OAI_DC_Ext;
use base qw/ EPrints::Plugin::Export::OAI_DC /;
use strict;
sub xml_dataobj
{
my( $plugin, $dataobj ) = @_;
my $main_dc_plugin = $plugin->{session}->plugin( "Export::DC_Ext" );
my $data = $main_dc_plugin->convert_dataobj( $dataobj );
my $dc = $plugin->{session}->make_element(
"oai_dc:dc",
"xmlns:oai_dc" => "http://www.openarchives.org/OAI/2.0/oai_dc/",
"xmlns:dc" => "http://purl.org/dc/elements/1.1/",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation" =>
"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd" );
# turn the list of pairs into XML blocks (indented by 8) and add them
# them to the DC element.
foreach( @{$data} )
{
$dc->appendChild( $plugin->{session}->render_data_element( 8, "dc:".$_->[0], $_->[1] ) );
# produces <key>value</key>
}
return $dc;
}
1;
----------------------------------------------------------------------------------------
END FILE: <EPrints>/archives/ARCHIVE_ID/cfg/plugins/EPrints/Plugin/Export/OAI_DC_Ext.pm
FILE: <EPrints>/archives/ARCHIVE_ID/cfg/plugins/EPrints/Plugin/Export/DC_Ext.pm
----------------------------------------------------------------------------------------
package EPrints::Plugin::Export::DC_Ext;
use base qw/ EPrints::Plugin::Export::DC /;
use strict;
sub convert_dataobj
{
my( $self, $eprint ) = @_;
my @dcdata = ();
# Get standard DC metadata from superclass
my $data_ref = $self->SUPER::convert_dataobj($eprint);
push @dcdata, @$data_ref;
# Show extended metadata for FP7 projects
if( $eprint->exists_and_set( "comprojects" ) && ( $eprint->value( "comprojects" )->[0]->{type} eq "FP 7" || $eprint->value( "comprojects" )->[0]->{type} eq "FP7") )
{
push @dcdata, [ "type", $eprint->get_value( "fp7_type" ) ] if($eprint->exists_and_set( "fp7_type" ));
push @dcdata, [ "relation", 'info:eu-repo/grantAgreement/EC/FP7/' . $eprint->value( "comprojects" )->[0]->{code} ] if($eprint->exists_and_set( "comprojects" ));
my $embargoed = 0;
my $open = 0;
my $restricted = 0;
my @documents = $eprint->get_all_documents();
foreach ( @documents )
{
if( !$_->is_public)
{
my $embargo = $_->get_value("date_embargo");
if($embargo != "")
{
$embargoed = 1;
# EPrints embargo date may be just be a year or year/month.
# Need to normalise and format as per guidelines
$embargo = $embargo . "-01-01" if (length $embargo == 4);
$embargo = $embargo . "-01" if (length $embargo == 7);
push @dcdata, [ "date", "info:eu-repo/date/embargoEnd/" . $embargo ] ;
}
else
{
$restricted = 1;
}
}
else
{
$open = 1;
}
}
if($embargoed)
{
# Override anything set in the metadata if we have an embargo in force
push @dcdata, [ "rights", "info:eu-repo/semantics/embargoedAccess" ];
}
elsif ($restricted)
{
push @dcdata, [ "rights", "info:eu-repo/semantics/restrictedAccess" ];
#push @dcdata, [ "rights", $eprint->get_value( "access_rights" ) ] if($eprint->exists_and_set( "access_rights" ));
}
else
{
push @dcdata, [ "rights", "info:eu-repo/semantics/openAccess" ];
}
}
return \@dcdata;
}
----------------------------------------------------------------------------------------
END FILE: <EPrints>/archives/ARCHIVE_ID/cfg/plugins/EPrints/Plugin/Export/DC_Ext.pm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment