View | Details | Raw Unified | Return to bug 18585
Collapse All | Expand All

(-)a/C4/Context.pm (+55 lines)
Lines 96-101 use POSIX (); Link Here
96
use DateTime::TimeZone;
96
use DateTime::TimeZone;
97
use Module::Load::Conditional qw(can_load);
97
use Module::Load::Conditional qw(can_load);
98
use Carp;
98
use Carp;
99
use YAML;
99
100
100
use C4::Boolean;
101
use C4::Boolean;
101
use C4::Debug;
102
use C4::Debug;
Lines 774-779 sub restore_dbh Link Here
774
    # return something, then this function should, too.
775
    # return something, then this function should, too.
775
}
776
}
776
777
778
=head2 triplestore
779
780
  $triplestore = C4::Context->triplestore
781
782
Returns a handle to an initialised RDF::Trine::Model object
783
784
=cut
785
786
sub triplestore {
787
    my $self = shift;
788
    unless (defined $context->{"triplestore"}) {
789
        my $config_file = $context->config('triplestore_config');
790
        if ( -f $config_file ){
791
            my $config = YAML::LoadFile($config_file);
792
            if ($config){
793
                $context->{"triplestore"} = &_new_triplestore($config);
794
            }
795
        }
796
    }
797
    return
798
      defined( $context->{"triplestore"} )
799
      ? $context->{"triplestore"}
800
      : undef;
801
}
802
803
=head _new_triplestore
804
805
=cut
806
807
sub _new_triplestore {
808
    my ($config) = @_;
809
    if ($config){
810
        my $module = $config->{module};
811
        if ($module eq 'RDF::Trine::Store::SPARQL'){
812
            if ($module && can_load( 'modules' => { $module => undef } ) ){
813
                my $url = URI->new($config->{url});
814
                if ($url){
815
                    my $ua = RDF::Trine->default_useragent;
816
                    if ($ua){
817
                        my $realm = $config->{realm};
818
                        my $username = $config->{username};
819
                        my $password = $config->{password};
820
                        $ua->credentials($url->host.":".$url->port, $realm, $username, $password);
821
                    }
822
                    my $store = RDF::Trine::Store::SPARQL->new($url);
823
                    my $model = RDF::Trine::Model->new($store);
824
                    return $model;
825
                }
826
            }
827
        }
828
    }
829
    return;
830
}
831
777
=head2 queryparser
832
=head2 queryparser
778
833
779
  $queryparser = C4::Context->queryparser
834
  $queryparser = C4::Context->queryparser
(-)a/debian/scripts/koha-create (+4 lines)
Lines 709-714 eof Link Here
709
    generate_config_file zebra.passwd.in \
709
    generate_config_file zebra.passwd.in \
710
        "/etc/koha/sites/$name/zebra.passwd"
710
        "/etc/koha/sites/$name/zebra.passwd"
711
711
712
    # Generate and install triplestore config file
713
    generate_config_file triplestore.yaml.in \
714
        "/etc/koha/sites/$name/triplestore.yaml"
715
712
716
713
    # Create a GPG-encrypted file for requesting a DB to be set up.
717
    # Create a GPG-encrypted file for requesting a DB to be set up.
714
    if [ "$op" = request ]
718
    if [ "$op" = request ]
(-)a/debian/templates/koha-conf-site.xml.in (+3 lines)
Lines 322-326 __END_SRU_PUBLICSERVER__ Link Here
322
 <plack_max_requests>50</plack_max_requests>
322
 <plack_max_requests>50</plack_max_requests>
323
 <plack_workers>2</plack_workers>
323
 <plack_workers>2</plack_workers>
324
324
325
 <!-- Configuration for RDF triplestore -->
326
 <triplestore_config>/etc/koha/sites/__KOHASITE__/triplestore.yaml</triplestore_config>
327
325
</config>
328
</config>
326
</yazgfs>
329
</yazgfs>
(-)a/debian/templates/triplestore.yaml.in (+9 lines)
Line 0 Link Here
1
---
2
#module must be a valid RDF::Trine::Store::* module
3
module: RDF::Trine::Store::SPARQL
4
5
#When using RDF::Trine::Store::SPARQL:
6
url:
7
realm:
8
username:
9
password:
(-)a/etc/koha-conf.xml (+3 lines)
Lines 153-157 __PAZPAR2_TOGGLE_XML_POST__ Link Here
153
 <plack_max_requests>50</plack_max_requests>
153
 <plack_max_requests>50</plack_max_requests>
154
 <plack_workers>2</plack_workers>
154
 <plack_workers>2</plack_workers>
155
155
156
 <!-- Configuration for RDF triplestore -->
157
 <triplestore_config>__KOHA_CONF_DIR__/triplestore.yaml</triplestore_config>
158
156
</config>
159
</config>
157
</yazgfs>
160
</yazgfs>
(-)a/etc/triplestore.yaml (+9 lines)
Line 0 Link Here
1
---
2
#module must be a valid RDF::Trine::Store::* module
3
module: RDF::Trine::Store::SPARQL
4
5
#When using RDF::Trine::Store::SPARQL:
6
url:
7
realm:
8
username:
9
password:
(-)a/t/db_dependent/triplestore.t (-1 / +57 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 3;
5
use YAML;
6
use File::Temp qw/ tempfile /;
7
8
use C4::Context;
9
10
#Make a temporary configuration file for the triplestore
11
my ($fh, $filename) = tempfile(undef, UNLINK => 1);
12
my $temp_config = {
13
    module => 'RDF::Trine::Store::SPARQL',
14
    url => 'http://localhost/example/rdf',
15
    realm => undef,
16
    username => undef,
17
    password => undef,
18
};
19
20
#Tell C4::Context to use the temporary configuration file as the triplestore_config
21
my $context = $C4::Context::context;
22
$context->{config}->{triplestore_config} = $filename;
23
24
SUCCESS: {
25
    YAML::DumpFile($filename, $temp_config);
26
27
    my $context_object = C4::Context->new();
28
    my $triplestore = $context_object->triplestore;
29
    is(ref $triplestore, 'RDF::Trine::Model', 'C4::Context->new()->triplestore returns RDF::Trine::Model if module equals RDF::Trine::Store::SPARQL');
30
}
31
32
MISSING_URL: {
33
    #Reset triplestore context
34
    delete $context->{triplestore};
35
36
    my $url = delete $temp_config->{url};
37
    YAML::DumpFile($filename, $temp_config);
38
39
    my $context_object = C4::Context->new();
40
    my $triplestore = $context_object->triplestore;
41
    is($triplestore, undef, 'C4::Context->new()->triplestore returns undef if missing url for SPARQL store');
42
43
    #Restore url for other tests
44
    $temp_config->{url} = $url;
45
}
46
47
BAD_MODULE: {
48
    #Reset triplestore context
49
    delete $context->{triplestore};
50
51
    $temp_config->{module} = 'Local::RDF::Bad::Module';
52
    YAML::DumpFile($filename, $temp_config);
53
54
    my $context_object = C4::Context->new();
55
    my $triplestore = $context_object->triplestore;
56
    is($triplestore, undef, 'C4::Context->new()->triplestore returns undef if module equals Local::RDF::Bad::Module');
57
}

Return to bug 18585