-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
340 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package AmuseWikiFarm::Archive::OAI::ORE; | ||
|
||
use utf8; | ||
use strict; | ||
use warnings; | ||
|
||
use Moo; | ||
use Types::Standard qw/Object Str InstanceOf CodeRef/; | ||
use AmuseWikiFarm::Log::Contextual; | ||
use XML::Writer; | ||
use Data::Dumper::Concise; | ||
use DateTime; | ||
|
||
has text => (is => 'ro', isa => Object, required => 1); | ||
has uri_maker => (is => 'ro', isa => CodeRef, default => sub { sub { return shift } }); | ||
|
||
sub as_rdf_xml { | ||
my $self = shift; | ||
my $text = $self->text; | ||
my $site = $text->site; | ||
my $created = $text->pubdate->iso8601 . 'Z'; | ||
my $updated = $text->f_timestamp->iso8601 . 'Z'; | ||
my $full_uri = $text->full_uri; | ||
my @canonical_dc; | ||
my @aggregated_dcs; | ||
my @aggregated_urls; | ||
foreach my $pmh ($text->oai_pmh_records->not_deleted->all) { | ||
if (my @dc = @{ $pmh->dublin_core_record || [] }) { | ||
my $datestamp = $pmh->zulu_datestamp; | ||
push @dc, [ | ||
'dcterms:created', | ||
[ 'rdf:datatype' => "http://www.w3.org/2001/XMLSchema#dateTime" ], | ||
$datestamp, | ||
]; | ||
push @dc, [ | ||
'dcterms:modified', | ||
[ 'rdf:datatype' => "http://www.w3.org/2001/XMLSchema#dateTime" ], | ||
$datestamp, | ||
]; | ||
if ($pmh->identifier eq $full_uri) { | ||
@canonical_dc = @dc; | ||
} | ||
push @aggregated_dcs, | ||
[ 'rdf:Description' => [ 'rdf:about', $self->uri_maker->($pmh->identifier) ], \@dc ]; | ||
push @aggregated_urls, | ||
[ 'ore:aggregates' => [ 'rdf:resource', $self->uri_maker->($pmh->identifier) ], undef ]; | ||
} | ||
} | ||
push @canonical_dc, @aggregated_urls; | ||
my $data = [ | ||
'rdf:RDF' => [ | ||
'xmlns:rdf' => "http://www.w3.org/1999/02/22-rdf-syntax-ns#" , | ||
'xmlns:ore' => "http://www.openarchives.org/ore/terms/", | ||
'xmlns:dc' => "http://purl.org/dc/elements/1.1/", | ||
'xmlns:dcterms' => "http://purl.org/dc/terms/", | ||
'xmlns:foaf' => "http://xmlns.com/foaf/0.1/", | ||
'xmlns:rdfs' => "http://www.w3.org/2000/01/rdf-schema#", | ||
], | ||
[ | ||
[ 'rdf:Description' => [ 'rdf:about', $self->uri_maker->($text->full_ore_rdf_uri) ], | ||
[ | ||
[ 'ore:describes' => [ 'rdf:resource' => $self->uri_maker->($text->full_ore_aggregation_uri) ], undef], | ||
[ 'dcterms:creator' => [ 'rdf:parseType' => "Resource" ], | ||
[ | ||
[ 'foaf:name' => $site->sitename || $site->canonical ], | ||
[ 'foaf:page' => [ 'rdf:resource' => $site->canonical_url ], undef ], | ||
], | ||
], | ||
[ 'dcterms:created' => [ 'rdf:datatype' => "http://www.w3.org/2001/XMLSchema#dateTime" ], $created ], | ||
[ 'dcterms:modified' => [ 'rdf:datatype' => "http://www.w3.org/2001/XMLSchema#dateTime" ], $updated ], | ||
], | ||
], | ||
|
||
[ 'rdf:Description' => [ 'rdf:about', $self->uri_maker->($text->full_ore_aggregation_uri) ], | ||
\@canonical_dc, | ||
], | ||
@aggregated_dcs, | ||
] | ||
]; | ||
my $w = XML::Writer->new(OUTPUT => "self", | ||
DATA_INDENT => 2, | ||
ENCODING => "UTF-8", | ||
DATA_MODE => 1); | ||
$w->xmlDecl; | ||
AmuseWikiFarm::Utils::XML::generate_xml($w, @$data); | ||
$w->end; | ||
return "$w"; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package AmuseWikiFarm::Model::OaiOre; | ||
|
||
use strict; | ||
use warnings; | ||
use base 'Catalyst::Model::Factory::PerRequest'; | ||
|
||
use AmuseWikiFarm::Log::Contextual; | ||
|
||
__PACKAGE__->config(class => 'AmuseWikiFarm::Archive::OAI::ORE'); | ||
|
||
sub prepare_arguments { | ||
my ($self, $c) = @_; | ||
my %args = ( | ||
text => $c->stash->{text}, | ||
uri_maker => sub { $c->uri_for(@_) }, | ||
); | ||
return \%args; | ||
} | ||
|
||
|
||
=head1 NAME | ||
AmuseWikiFarm::Model::OaiOre - AOI ORE model | ||
=head1 DESCRIPTION | ||
Wrap L<AmuseWikiFarm::Archive::OAI::ORE> into the catalyst app | ||
=cut | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package AmuseWikiFarm::Utils::XML; | ||
|
||
use utf8; | ||
use strict; | ||
use warnings; | ||
use Data::Dumper::Concise; | ||
|
||
=head1 SYNOPSIS | ||
my $w = XML::Writer->new(OUTPUT => "self", | ||
DATA_INDENT => 2, | ||
ENCODING => "UTF-8", | ||
DATA_MODE => 1); | ||
$w->xmlDecl; | ||
generate_xml($w, @data); | ||
$w->end; | ||
=cut | ||
|
||
sub generate_xml { | ||
my ($w, $name, @args) = @_; | ||
my ($attrs, $value); | ||
if (@args == 0) { | ||
# all undef | ||
} | ||
elsif (@args == 1) { | ||
$attrs = []; | ||
$value = $args[0]; | ||
} | ||
elsif (@args == 2) { | ||
($attrs, $value) = @args; | ||
} | ||
else { | ||
die "Bad usage" . Dumper(\@_); | ||
} | ||
if (defined $value) { | ||
$w->startTag($name, @$attrs); | ||
if (ref($value) eq 'ARRAY') { | ||
foreach my $v (@$value) { | ||
# recursive call | ||
generate_xml($w, @$v) | ||
} | ||
} | ||
elsif (ref($value)) { | ||
die "Not an array ref! " . Dumper($value); | ||
} | ||
else { | ||
$w->characters($value); | ||
} | ||
$w->endTag; | ||
} | ||
else { | ||
$w->emptyTag($name, @$attrs); | ||
} | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.