package EPrints::Plugin::Export::REF2014; @ISA = qw( EPrints::Plugin::Export ); use strict; sub new { my( $class, %params ) = @_; my $self = $class->SUPER::new( %params ); $self->{name} = "REF2014 Data"; $self->{advertise} = 0; $self->{accept} = [qw( list/ref_selection dataobj/ref_selection )]; $self->{eprint_type_map} = {qw( book A book_section C article D conference_item E exhibition M performance I patent F composition J )}; $self->{eprint_optional_map} = {map { $_ => 1 } qw( R_publisher P_publisher N_publisher Q_publisher R_isbn E_issn A_doi B_doi C_doi R_doi E_doi N_doi S_doi T_doi A_url B_url C_url R_url D_url E_url L_url P_url M_url I_url F_url N_url K_url J_url Q_url S_url G_url T_url )}; return $self; } sub output_dataobj { my( $self, $selection, %opts ) = @_; my $problems = $opts{problems} ||= []; my $refdata = $self->dataobj_to_refdata( $selection, %opts ); my $output = ""; $output .= join '', map { $_->toString . "\n" } @$problems; $output .= Data::Dumper::Dumper( $refdata ); } sub dataobj_to_refdata { my( $self, $selection, %opts ) = @_; my $repo = $self->{session}; my %ref; my $problems = $opts{problems} || []; my $eprint = $opts{eprint}; if( !defined $eprint ) { $eprint = $repo->eprint( $selection->value( "eprint_id" ) ); } if( !defined $eprint ) { push @$problems, $self->html_phrase( "bad_eprint" ); return {}; } my $type = $selection->is_set( "type" ) ? $selection->value( "type" ) : $self->param( "eprint_type_map" )->{$eprint->value( "type" )}; if( !defined $type ) { $type = 'T'; # we need type for other choices push @$problems, $self->html_phrase( "bad_type", eprint_type => $repo->make_text( $eprint->value( "type" ) ) ); return \%ref; } $ref{output_type} = $type; # Output Title if( $type =~ /[AB]/ ) { $ref{output_title} = $eprint->value( "book_title" ); } else { $ref{output_title} = $eprint->value( "title" ); } # Place if( $type =~ /[LPMIST]/ ) { $ref{place} = $eprint->value( "place_of_pub" ); } elsif( $type =~ /[MI]/ ) { $ref{place} = $eprint->value( "event_location" ); } elsif( $type =~ /[NO]/ ) { # TODO Commissioning body } # Publisher if( $type =~ /[ABCRNQG]/ ) { $ref{publisher} = $eprint->value( "publisher" ); } # TODO P - Manufacturer # Volume title if( $type =~ /[CR]/ ) { $ref{volume_title} = $eprint->value( "book_title" ); } elsif( $type =~ /[D]/ ) { $ref{volume_title} = $eprint->value( "publication" ); } elsif( $type =~ /[E]/ ) { $ref{volume_title} = $eprint->value( "event_title" ); } # Article number if( $type =~ /[D]/ ) { # TODO $ref{article_number} = $eprint->value( "" ); } # Volume if( $type =~ /[DE]/ ) { $ref{volume} = $eprint->value( "volume" ); } # Issue if( $type =~ /[DE]/ ) { $ref{issue} = $eprint->value( "number" ); } # First page if( $type =~ /[DE]/ ) { no warnings; # undef ($ref{first_page}) = split '-', $eprint->value( "pagerange" ); } # ISBN if( $type =~ /[ABCR]/ ) { $ref{isbn} = $eprint->value( "isbn" ); } # ISSN if( $type =~ /[DE]/ ) { $ref{issn} = $eprint->value( "issn" ); } # DOI if( $type =~ /[ABCRDENST]/ ) { $ref{doi} = $eprint->value( "id_number" ); undef $ref{doi} if defined $ref{doi} && $ref{doi} !~ /^(doi:)?10\.\d\d\d\d\//; } # Patent Number if( $type =~ /[F]/ ) { $ref{patent_number} = $eprint->value( "id_number" ); } # Year { no warnings; $ref{year} = substr($eprint->value( "date" ),0,4); } # URL { $ref{url} = $eprint->value( "official_url" ); } # Media of Output if( $type =~ /[LPMIKJQSHGT]/ ) { $ref{media_of_output} = $eprint->value( "output_media" ); } foreach my $key (sort keys %ref) { next if defined $ref{$key}; next if $self->param( "eprint_optional_map" )->{"${type}_${key}"}; my $desc = ( $repo->dataset( 'eprint' )->has_field( $key ) ) ? $repo->html_phrase( "eprint_fieldname_$key" ) : $repo->make_text( $key ); push @$problems, $repo->html_phrase( "ref:validate:missing_field", fieldname => $desc ); } return \%ref; } 1;