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

(-)a/C4/Context.pm (+64 lines)
Lines 97-102 use POSIX (); Link Here
97
use DateTime::TimeZone;
97
use DateTime::TimeZone;
98
use Module::Load::Conditional qw(can_load);
98
use Module::Load::Conditional qw(can_load);
99
use Carp;
99
use Carp;
100
use YAML;
100
101
101
use C4::Boolean;
102
use C4::Boolean;
102
use C4::Debug;
103
use C4::Debug;
Lines 775-780 sub restore_dbh Link Here
775
    # return something, then this function should, too.
776
    # return something, then this function should, too.
776
}
777
}
777
778
779
=head2 triplestore
780
781
  my $triplestore = C4::Context->triplestore($model_name);
782
783
Returns a handle to an initialised RDF::Trine::Model object
784
785
=cut
786
787
sub triplestore {
788
    my ($self,$name) = @_;
789
    die "Must provide a model name as an argument for the triplestore() method" unless $name;
790
    my $triplestore = ( $context->{triplestore} && $context->{triplestore}->{$name} ) ? $context->{triplestore}->{$name} : undef;
791
    if ( ! $triplestore ){
792
        my $config_file = $context->config('triplestore_config');
793
        if ( -f $config_file ){
794
            my $config = YAML::LoadFile($config_file);
795
            if ($config && $name){
796
                my $new_triplestore = $self->_new_triplestore($config,$name);
797
                if ( $new_triplestore && $new_triplestore->isa("RDF::Trine::Model") ){
798
                    $triplestore = $new_triplestore;
799
                    $context->{triplestore}->{$name} = $new_triplestore;
800
                }
801
            }
802
        }
803
    }
804
    return $triplestore;
805
}
806
807
=head2 _new_triplestore
808
809
=cut
810
811
sub _new_triplestore {
812
    my ($self, $config,$name) = @_;
813
    if ($config && $name){
814
        my $models = $config->{models};
815
        if ($models){
816
            my $model = $models->{$name};
817
            if ($model){
818
                my $module = $model->{module};
819
                if ($module && $module eq 'RDF::Trine::Store::SPARQL'){
820
                    if ($module && can_load( 'modules' => { $module => undef } ) ){
821
                        my $url = URI->new($model->{url});
822
                        if ($url){
823
                            my $ua = RDF::Trine->default_useragent;
824
                            if ($ua){
825
                                my $realm = $model->{realm};
826
                                my $username = $model->{username};
827
                                my $password = $model->{password};
828
                                $ua->credentials($url->host.":".$url->port, $realm, $username, $password);
829
                            }
830
                            my $store = RDF::Trine::Store::SPARQL->new($url);
831
                            my $model = RDF::Trine::Model->new($store);
832
                            return $model;
833
                        }
834
                    }
835
                }
836
            }
837
        }
838
    }
839
    return;
840
}
841
778
=head2 queryparser
842
=head2 queryparser
779
843
780
  $queryparser = C4::Context->queryparser
844
  $queryparser = C4::Context->queryparser
(-)a/C4/Installer/PerlDependencies.pm (+5 lines)
Lines 867-872 our $PERL_DEPS = { Link Here
867
        'required' => '0',
867
        'required' => '0',
868
        'min_ver'  => '0.07',
868
        'min_ver'  => '0.07',
869
    },
869
    },
870
    'RDF::Trine' => {
871
        'usage' => 'Managing RDF and triplestores',
872
        'required' => '1',
873
        'min_ver' => '1.017',
874
    },
870
};
875
};
871
876
872
1;
877
1;
(-)a/debian/scripts/koha-create (+4 lines)
Lines 728-733 eof Link Here
728
    generate_config_file zebra.passwd.in \
728
    generate_config_file zebra.passwd.in \
729
        "/etc/koha/sites/$name/zebra.passwd"
729
        "/etc/koha/sites/$name/zebra.passwd"
730
730
731
    # Generate and install triplestore config file
732
    generate_config_file triplestore.yaml.in \
733
        "/etc/koha/sites/$name/triplestore.yaml"
734
731
735
732
    # Create a GPG-encrypted file for requesting a DB to be set up.
736
    # Create a GPG-encrypted file for requesting a DB to be set up.
733
    if [ "$op" = request ]
737
    if [ "$op" = request ]
(-)a/debian/templates/koha-conf-site.xml.in (+3 lines)
Lines 348-352 __END_SRU_PUBLICSERVER__ Link Here
348
     <partner_code>ILLLIBS</partner_code>
348
     <partner_code>ILLLIBS</partner_code>
349
 </interlibrary_loans>
349
 </interlibrary_loans>
350
350
351
 <!-- Configuration for RDF triplestore -->
352
 <triplestore_config>/etc/koha/sites/__KOHASITE__/triplestore.yaml</triplestore_config>
353
351
</config>
354
</config>
352
</yazgfs>
355
</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 174-178 __PAZPAR2_TOGGLE_XML_POST__ Link Here
174
     <partner_code>ILLLIBS</partner_code>
174
     <partner_code>ILLLIBS</partner_code>
175
 </interlibrary_loans>
175
 </interlibrary_loans>
176
176
177
 <!-- Configuration for RDF triplestore -->
178
 <triplestore_config>__KOHA_CONF_DIR__/triplestore.yaml</triplestore_config>
179
177
</config>
180
</config>
178
</yazgfs>
181
</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