Skip to content

Commit

Permalink
Merge branch 'oai-ore-440'
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Sep 16, 2023
2 parents 5f3919f + 37c4da6 commit 78973d3
Show file tree
Hide file tree
Showing 13 changed files with 340 additions and 42 deletions.
5 changes: 5 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ lib/AmuseWikiFarm/Archive/CgitEmulated.pm
lib/AmuseWikiFarm/Archive/Lexicon.pm
lib/AmuseWikiFarm/Archive/Lexicon/Handles.pm
lib/AmuseWikiFarm/Archive/Lexicon/Site.pm
lib/AmuseWikiFarm/Archive/OAI/ORE.pm
lib/AmuseWikiFarm/Archive/OAI/PMH.pm
lib/AmuseWikiFarm/Archive/StaticIndexes.pm
lib/AmuseWikiFarm/Archive/Xapian.pm
Expand All @@ -894,6 +895,7 @@ lib/AmuseWikiFarm/Controller/Listing.pm
lib/AmuseWikiFarm/Controller/Mirror.pm
lib/AmuseWikiFarm/Controller/Monthly.pm
lib/AmuseWikiFarm/Controller/Nodes.pm
lib/AmuseWikiFarm/Controller/OAI.pm
lib/AmuseWikiFarm/Controller/OaiPmh.pm
lib/AmuseWikiFarm/Controller/OPDS.pm
lib/AmuseWikiFarm/Controller/Publish.pm
Expand Down Expand Up @@ -950,6 +952,7 @@ lib/AmuseWikiFarm/Model/BookBuilder.pm
lib/AmuseWikiFarm/Model/Cgit.pm
lib/AmuseWikiFarm/Model/DB.pm
lib/AmuseWikiFarm/Model/Lexicon.pm
lib/AmuseWikiFarm/Model/OaiOre.pm
lib/AmuseWikiFarm/Model/OaiPmh.pm
lib/AmuseWikiFarm/Model/OPDS.pm
lib/AmuseWikiFarm/Model/Webserver.pm
Expand Down Expand Up @@ -1042,6 +1045,7 @@ lib/AmuseWikiFarm/Utils/Paginator.pm
lib/AmuseWikiFarm/Utils/Paginator/Object.pm
lib/AmuseWikiFarm/Utils/Paths.pm
lib/AmuseWikiFarm/Utils/Webserver.pm
lib/AmuseWikiFarm/Utils/XML.pm
lib/AmuseWikiFarm/View/Atom.pm
lib/AmuseWikiFarm/View/HTML.pm
lib/AmuseWikiFarm/View/JSON.pm
Expand Down Expand Up @@ -1920,6 +1924,7 @@ t/not-found.t
t/not/parsable/ciao.muse
t/notify-deferred.t
t/numeric-collation-cats.t
t/oai-ore.t
t/oai-pmh.t
t/open-graph.t
t/other-sites.t
Expand Down
90 changes: 90 additions & 0 deletions lib/AmuseWikiFarm/Archive/OAI/ORE.pm
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;
40 changes: 2 additions & 38 deletions lib/AmuseWikiFarm/Archive/OAI/PMH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Types::Standard qw/Object Str CodeRef HashRef ArrayRef InstanceOf/;
use AmuseWikiFarm::Log::Contextual;
use DateTime;
use AmuseWikiFarm::Utils::Paths;
use AmuseWikiFarm::Utils::XML;
use Path::Tiny;
use XML::Writer;
use Data::Dumper::Concise;
Expand Down Expand Up @@ -269,48 +270,11 @@ sub process_request {
@response,
]
];
_generate_xml($w, @$data);
AmuseWikiFarm::Utils::XML::generate_xml($w, @$data);
$w->end;
return "$w";
}

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);
}
}

sub list_records {
my ($self, $params) = @_;
$self->_list_records(ListRecords => $params);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package AmuseWikiFarm::Controller::OaiPmh;
package AmuseWikiFarm::Controller::OAI;
use Moose;

use namespace::autoclean;
Expand Down Expand Up @@ -26,7 +26,7 @@ There is a single entry point.
=cut

sub root :Chained('/site') :PathPart('oai-pmh') :Args(0) {
sub pmh :Chained('/site') :PathPart('oai-pmh') :Args(0) {
my ($self, $c) = @_;
my $params = $c->request->params;
my $xml = $c->model('OaiPmh')->process_request($params);
Expand Down
31 changes: 31 additions & 0 deletions lib/AmuseWikiFarm/Model/OaiOre.pm
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;
2 changes: 1 addition & 1 deletion lib/AmuseWikiFarm/Model/OaiPmh.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sub prepare_arguments {
my ($self, $c) = @_;
my %args = (
site => $c->stash->{site},
oai_pmh_url => $c->uri_for_action('/oaipmh/root'),
oai_pmh_url => $c->uri_for_action('/oai/pmh'),
);
return \%args;
}
Expand Down
12 changes: 12 additions & 0 deletions lib/AmuseWikiFarm/Role/Controller/Text.pm
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ sub match :Chained('base') PathPart('') :CaptureArgs(1) {
$c->stash(page_title => HTML::Entities::decode_entities($text->title),
text_json_api => $c->uri_for($text->full_header_api),
show_preview_only => $show_preview_only);
if ($c->stash->{f_class} eq 'text') {
$c->stash(ore_rdf_link => $c->uri_for($text->full_ore_rdf_uri));
}

}
elsif (my $attach = $site->attachments->by_uri($canonical . $append_ext)) {
log_debug { "Found attachment $canonical$append_ext" };
Expand Down Expand Up @@ -264,6 +268,14 @@ sub json :Chained('match') PathPart('json') :Args(0) {
$c->detach($c->view('JSON'));
}

sub ore_rdf :Chained('match') PathPart('ore.rdf') :Args(0) {
my ($self, $c) = @_;
# depends on stash.text being present
my $ore = $c->model('OaiOre');
$c->response->content_type('application/rdf+xml');
$c->response->body($ore->as_rdf_xml);
}

sub mirror_manifest :Chained('match') PathPart('manifest.json') :Args(0) {
my ($self, $c) = @_;
$c->stash(json => $c->stash->{text}->mirror_manifest);
Expand Down
10 changes: 10 additions & 0 deletions lib/AmuseWikiFarm/Schema/Result/Title.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,16 @@ sub full_header_api {
return $self->full_uri . '/json';
}

sub full_ore_rdf_uri {
my $self = shift;
return $self->full_uri . '/ore.rdf';
}

sub full_ore_aggregation_uri {
my $self = shift;
return $self->full_uri . '/ore.rdf#aggregation';
}

sub full_rebuild_uri {
my $self = shift;
return $self->full_uri . '/rebuild';
Expand Down
6 changes: 6 additions & 0 deletions lib/AmuseWikiFarm/Schema/ResultSet/OaiPmhRecord.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ sub oldest_record {
})->first;
}

sub not_deleted {
my $self = shift;
my $me = $self->current_source_alias;
$self->search({ "$me.deleted" => 0 });
}

sub set_deleted_flag_on_obsolete_records {
my ($self, $ids) = @_;
die "Missing ids" unless $ids && ref($ids) eq 'ARRAY';
Expand Down
57 changes: 57 additions & 0 deletions lib/AmuseWikiFarm/Utils/XML.pm
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;
4 changes: 4 additions & 0 deletions root/src/layout.tt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
[% END %]
[% END %]

[% IF ore_rdf_link %]
<link rel="resourcemap" type="application/rdf+xml" href="[% ore_rdf_link %]"/>
[% END %]

[%- IF open_graph %]
<!-- open graph stanza -->
[%- FOREACH open_graph_meta IN open_graph %]
Expand Down
Loading

0 comments on commit 78973d3

Please sign in to comment.