Skip to content

Commit

Permalink
and an example exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Francois committed Jul 30, 2014
1 parent 26c304f commit 6ad2d4c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 30 deletions.
37 changes: 36 additions & 1 deletion cfg/cfg.d/z_example_reports.pl.off
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,40 @@ $c->{plugins}{"Screen::Report::Example"}{params}{disable} = 0;
$c->{plugins}{"Screen::Report::Example::Articles"}{params}{disable} = 0;
$c->{plugins}{"Screen::Report::Example::ConferenceItems"}{params}{disable} = 0;

#$c->{plugins}{"Export::Report::CSV::ROS"}{params}{disable} = 0;
$c->{plugins}{"Export::Report::CSV::Example"}{params}{disable} = 0;

my @example_fields = (
{
target => "EPrint ID",
source => "eprint.eprintid",
validate => "required",
},
{
target => "Title",
# just to demonstrate getting data via a sub {}
source => sub {
my( $plugin, $objects ) = @_;

my $eprint = $objects->{eprint};
return $eprint->value( 'title' );
},
validate => sub {
my( $plugin, $objects, $problems ) = @_;

my $eprint = $objects->{eprint};

if( $eprint->value( 'title' ) =~ /the/i )
{
push @$problems, "Problems detected!!";
}
}
},
);

$c->{reports}->{"example-articles"}->{fields} = [ map { $_->{target} } @example_fields ];
$c->{reports}->{"example-articles"}->{mappings} = { map { $_->{target} => $_->{source} } @example_fields };
$c->{reports}->{"example-articles"}->{validate} = { map { $_->{target} => $_->{validate} } @example_fields };

$c->{reports}->{"example-conf-items"}->{fields} = [ map { $_->{target} } @example_fields ];
$c->{reports}->{"example-conf-items"}->{mappings} = { map { $_->{target} => $_->{source} } @example_fields };
$c->{reports}->{"example-conf-items"}->{validate} = { map { $_->{target} => $_->{validate} } @example_fields };
4 changes: 4 additions & 0 deletions lib/lang/en/phrases/reports.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
<epp:phrase id="Plugin/Screen/Report:title">Reports</epp:phrase>
<epp:phrase id="Plugin/Screen/Report:no_reports">No available reports</epp:phrase>

<!-- the Example reports -->
<epp:phrase id="Plugin/Screen/Report/Example:title">Example</epp:phrase>
<epp:phrase id="Plugin/Screen/Report/Example/Articles:title">Articles</epp:phrase>
<epp:phrase id="Plugin/Screen/Report/Example/ConferenceItems:title">Conference Items</epp:phrase>

</epp:phrases>
21 changes: 21 additions & 0 deletions lib/plugins/EPrints/Plugin/Export/Report/CSV/Example.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package EPrints::Plugin::Export::Report::CSV::Example;

use EPrints::Plugin::Export::Report::CSV;
our @ISA = ( "EPrints::Plugin::Export::Report::CSV" );

use strict;

sub new
{
my( $class, %params ) = @_;

my $self = $class->SUPER::new( %params );

$self->{name} = "Example CSV";
$self->{accept} = [ 'report/example-articles', 'report/example-conf-items' ];
$self->{advertise} = 1;
return $self;
}


1;
29 changes: 0 additions & 29 deletions lib/plugins/EPrints/Plugin/Screen/Report/Example.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,4 @@ sub get_related_objects
return $objects;
}

# All outputs entered on the Books, Journals or Conferences worksheets must have at least one of the following unique identifiers: ISBN, ISSN, DOI, UKPMC
sub validate_dataobj
{
my( $plugin, $dataobj ) = @_;

my @problems;

# random decision to decide if a data-obj is valid or not

# of course on a "real" report, you would need to set-up proper validation rules, perhaps defined by some national agencies such as HEFCE, RCUK, ...

if( int( rand( 100 ) ) % 2 == 0 )
{
push @problems, "Problems detected!!";
}

push @problems, $plugin->SUPER::validate_dataobj( $dataobj );

return @problems;
}

sub report_fields_order
{
my( $plugin, $dataobj ) = @_;

return $plugin->SUPER::report_fields_order( $dataobj );
}


1;

0 comments on commit 6ad2d4c

Please sign in to comment.