]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/Application.pm
LP#1635737 Use new OpenSRF interval_to_seconds() context
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / Application.pm
1 package OpenILS::Application;
2 use OpenSRF::Application;
3 use UNIVERSAL::require;
4 use base qw/OpenSRF::Application/;
5 use OpenILS::Utils::Fieldmapper;
6
7 sub ils_version {
8     # version format is "x-y-z", for example "2-0-0" for Evergreen 2.0.0
9     # For branches, format is "x-y"
10     return "HEAD";
11 }
12
13 __PACKAGE__->register_method(
14     api_name    => 'opensrf.open-ils.system.ils_version',
15     api_level   => 1,
16     method      => 'ils_version',
17 );
18
19 __PACKAGE__->register_method(
20     api_name => 'opensrf.open-ils.fetch_idl.file',
21     api_level => 1,
22     method => 'get_idl_file',
23 );
24 sub get_idl_file {
25     use OpenSRF::Utils::SettingsClient;
26     return OpenSRF::Utils::SettingsClient->new->config_value('IDL');
27 }
28
29 sub publish_fieldmapper {
30     my ($self,$client,$class) = @_;
31
32     return $Fieldmapper::fieldmap unless (defined $class);
33     return undef unless (exists($$Fieldmapper::fieldmap{$class}));
34     return {$class => $$Fieldmapper::fieldmap{$class}};
35 }
36 __PACKAGE__->register_method(
37     api_name    => 'opensrf.open-ils.system.fieldmapper',
38     api_level   => 1,
39     method      => 'publish_fieldmapper',
40 );
41
42 sub register_method {
43     my $class = shift;
44     my %args = @_;
45     my %dup_args = %args;
46
47     $class = ref($class) || $class;
48
49     $args{package} ||= $class;
50     __PACKAGE__->SUPER::register_method( %args );
51
52     if (exists($dup_args{authoritative}) and $dup_args{authoritative}) {
53         (my $name = $dup_args{api_name}) =~ s/$/.authoritative/o;
54         if ($name ne $dup_args{api_name}) {
55             $dup_args{real_api_name} = $dup_args{api_name};
56             $dup_args{method} = 'authoritative_wrapper';
57             $dup_args{api_name} = $name;
58             $dup_args{package} = __PACKAGE__;
59             __PACKAGE__->SUPER::register_method( %dup_args );
60         }
61     }
62 }
63
64 sub authoritative_wrapper {
65
66     if (!$OpenILS::Utils::CStoreEditor::_loaded) {
67         die "Couldn't load OpenILS::Utils::CStoreEditor!" unless 'OpenILS::Utils::CStoreEditor'->use;
68     }
69
70     my $self = shift;
71     my $client = shift;
72     my @args = @_;
73
74     my $method = $self->method_lookup($self->{real_api_name});
75     die unless $method;
76
77     local $OpenILS::Utils::CStoreEditor::always_xact = 1;
78
79     $client->respond( $_ ) for ( $method->run(@args) );
80
81     OpenILS::Utils::CStoreEditor->flush_forced_xacts();
82
83     return undef;
84 }
85
86 1;
87