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

(-)a/C4/Context.pm (+64 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
  my $triplestore = C4::Context->triplestore($model_name);
781
782
Returns a handle to an initialised RDF::Trine::Model object
783
784
=cut
785
786
sub triplestore {
787
    my ($self,$name) = @_;
788
    die "Must provide a model name as an argument for the triplestore() method" unless $name;
789
    my $triplestore = ( $context->{triplestore} && $context->{triplestore}->{$name} ) ? $context->{triplestore}->{$name} : undef;
790
    if ( ! $triplestore ){
791
        my $config_file = $context->config('triplestore_config');
792
        if ( -f $config_file ){
793
            my $config = YAML::LoadFile($config_file);
794
            if ($config && $name){
795
                my $new_triplestore = $self->_new_triplestore($config,$name);
796
                if ( $new_triplestore && $new_triplestore->isa("RDF::Trine::Model") ){
797
                    $triplestore = $new_triplestore;
798
                    $context->{triplestore}->{$name} = $new_triplestore;
799
                }
800
            }
801
        }
802
    }
803
    return $triplestore;
804
}
805
806
=head2 _new_triplestore
807
808
=cut
809
810
sub _new_triplestore {
811
    my ($self, $config,$name) = @_;
812
    if ($config && $name){
813
        my $models = $config->{models};
814
        if ($models){
815
            my $model = $models->{$name};
816
            if ($model){
817
                my $module = $model->{module};
818
                if ($module && $module eq 'RDF::Trine::Store::SPARQL'){
819
                    if ($module && can_load( 'modules' => { $module => undef } ) ){
820
                        my $url = URI->new($model->{url});
821
                        if ($url){
822
                            my $ua = RDF::Trine->default_useragent;
823
                            if ($ua){
824
                                my $realm = $model->{realm};
825
                                my $username = $model->{username};
826
                                my $password = $model->{password};
827
                                $ua->credentials($url->host.":".$url->port, $realm, $username, $password);
828
                            }
829
                            my $store = RDF::Trine::Store::SPARQL->new($url);
830
                            my $model = RDF::Trine::Model->new($store);
831
                            return $model;
832
                        }
833
                    }
834
                }
835
            }
836
        }
837
    }
838
    return;
839
}
840
777
=head2 queryparser
841
=head2 queryparser
778
842
779
  $queryparser = C4::Context->queryparser
843
  $queryparser = C4::Context->queryparser
(-)a/C4/Installer/PerlDependencies.pm (+5 lines)
Lines 862-867 our $PERL_DEPS = { Link Here
862
        'required' => '0',
862
        'required' => '0',
863
        'min_ver'  => '0.07',
863
        'min_ver'  => '0.07',
864
    },
864
    },
865
    'RDF::Trine' => {
866
        'usage' => 'Managing RDF and triplestores',
867
        'required' => '1',
868
        'min_ver' => '1.017',
869
    },
865
};
870
};
866
871
867
1;
872
1;
(-)a/debian/scripts/koha-create (+4 lines)
Lines 711-716 eof Link Here
711
    generate_config_file zebra.passwd.in \
711
    generate_config_file zebra.passwd.in \
712
        "/etc/koha/sites/$name/zebra.passwd"
712
        "/etc/koha/sites/$name/zebra.passwd"
713
713
714
    # Generate and install triplestore config file
715
    generate_config_file triplestore.yaml.in \
716
        "/etc/koha/sites/$name/triplestore.yaml"
717
714
718
715
    # Create a GPG-encrypted file for requesting a DB to be set up.
719
    # Create a GPG-encrypted file for requesting a DB to be set up.
716
    if [ "$op" = request ]
720
    if [ "$op" = request ]
(-)a/debian/templates/koha-conf-site.xml.in (+3 lines)
Lines 327-331 __END_SRU_PUBLICSERVER__ Link Here
327
     <index_name>koha___KOHASITE__</index_name>
327
     <index_name>koha___KOHASITE__</index_name>
328
 </elasticsearch>
328
 </elasticsearch>
329
329
330
 <!-- Configuration for RDF triplestore -->
331
 <triplestore_config>/etc/koha/sites/__KOHASITE__/triplestore.yaml</triplestore_config>
332
330
</config>
333
</config>
331
</yazgfs>
334
</yazgfs>
(-)a/debian/templates/triplestore.yaml.in (+30 lines)
Line 0 Link Here
1
---
2
models:
3
    query:
4
        #module must be a valid RDF::Trine::Store::* module
5
        module: RDF::Trine::Store::SPARQL
6
7
        #When using RDF::Trine::Store::SPARQL:
8
        url:
9
        realm:
10
        username:
11
        password:
12
    update:
13
        #module must be a valid RDF::Trine::Store::* module
14
        module: RDF::Trine::Store::SPARQL
15
16
        #When using RDF::Trine::Store::SPARQL:
17
        url:
18
        realm:
19
        username:
20
        password:
21
    #NOTE: Only the above models are likely to be used in Koha
22
    read/write:
23
        #module must be a valid RDF::Trine::Store::* module
24
        module: RDF::Trine::Store::SPARQL
25
26
        #When using RDF::Trine::Store::SPARQL:
27
        url:
28
        realm:
29
        username:
30
        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 (+30 lines)
Line 0 Link Here
1
---
2
models:
3
    query:
4
        #module must be a valid RDF::Trine::Store::* module
5
        module: RDF::Trine::Store::SPARQL
6
7
        #When using RDF::Trine::Store::SPARQL:
8
        url:
9
        realm:
10
        username:
11
        password:
12
    update:
13
        #module must be a valid RDF::Trine::Store::* module
14
        module: RDF::Trine::Store::SPARQL
15
16
        #When using RDF::Trine::Store::SPARQL:
17
        url:
18
        realm:
19
        username:
20
        password:
21
    #NOTE: Only the above models are likely to be used in Koha
22
    read/write:
23
        #module must be a valid RDF::Trine::Store::* module
24
        module: RDF::Trine::Store::SPARQL
25
26
        #When using RDF::Trine::Store::SPARQL:
27
        url:
28
        realm:
29
        username:
30
        password:
(-)a/t/db_dependent/triplestore.t (-1 / +67 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 4;
5
use Test::Exception;
6
use YAML;
7
use File::Temp qw/ tempfile /;
8
9
use C4::Context;
10
11
#Make a temporary configuration file for the triplestore
12
my ($fh, $filename) = tempfile(undef, UNLINK => 1);
13
my $temp_config = {
14
    models => {
15
        test => {
16
            module => 'RDF::Trine::Store::SPARQL',
17
            url => 'http://localhost/example/rdf',
18
            realm => undef,
19
            username => undef,
20
            password => undef,
21
        }
22
    }
23
};
24
25
#Tell C4::Context to use the temporary configuration file as the triplestore_config
26
my $context = $C4::Context::context;
27
$context->{config}->{triplestore_config} = $filename;
28
29
subtest 'success' => sub {
30
    YAML::DumpFile($filename, $temp_config);
31
32
    my $context_object = C4::Context->new();
33
    my $triplestore = $context_object->triplestore("test");
34
    is(ref $triplestore, 'RDF::Trine::Model', 'C4::Context->new()->triplestore returns RDF::Trine::Model if module equals RDF::Trine::Store::SPARQL');
35
};
36
37
subtest 'missing url' => sub {
38
    #Reset triplestore context
39
    delete $context->{triplestore}->{test};
40
41
    my $url = delete $temp_config->{models}->{test}->{url};
42
    YAML::DumpFile($filename, $temp_config);
43
44
    my $context_object = C4::Context->new();
45
    my $triplestore = $context_object->triplestore("test");
46
    is($triplestore, undef, 'C4::Context->new()->triplestore returns undef if missing url for SPARQL store');
47
48
    #Restore url for other tests
49
    $temp_config->{url} = $url;
50
};
51
52
subtest 'bad module' => sub {
53
    #Reset triplestore context
54
    delete $context->{triplestore}->{test};
55
56
    $temp_config->{module} = 'Local::RDF::Bad::Module';
57
    YAML::DumpFile($filename, $temp_config);
58
59
    my $context_object = C4::Context->new();
60
    my $triplestore = $context_object->triplestore("test");
61
    is($triplestore, undef, 'C4::Context->new()->triplestore returns undef if module equals Local::RDF::Bad::Module');
62
};
63
64
subtest 'missing model name' => sub {
65
    my $context_object = C4::Context->new();
66
    dies_ok { $context_object->triplestore } 'C4::Context::triplestore() method dies if no model name provided';
67
};

Return to bug 18585