]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/CNBrowse.pm
making OpenILS::Application the base app so that authoritative works
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search / CNBrowse.pm
1 package OpenILS::Application::Search::CNBrowse;
2 use base qw/OpenILS::Application/;
3 use strict; use warnings;
4
5 use OpenSRF::EX qw(:try);
6 use OpenILS::Application::AppUtils;
7 use Data::Dumper;
8 use OpenSRF::Utils::Logger qw/:logger/;
9 use OpenSRF::AppSession;
10 my $U = "OpenILS::Application::AppUtils";
11
12
13 __PACKAGE__->register_method(
14         method  => "cn_browse_start",
15         api_name        => "open-ils.search.callnumber.browse.target",
16         notes           => "Starts a callnumber browse"
17         );
18
19 __PACKAGE__->register_method(
20         method  => "cn_browse_up",
21         api_name        => "open-ils.search.callnumber.browse.page_up",
22         notes           => "Returns the previous page of callnumbers", 
23         );
24
25 __PACKAGE__->register_method(
26         method  => "cn_browse_down",
27         api_name        => "open-ils.search.callnumber.browse.page_down",
28         notes           => "Returns the next page of callnumbers", 
29         );
30
31 # XXX Deprecate me
32
33 sub cn_browse_start {
34         my( $self, $client, @params ) = @_;
35         my $method;
36         $method = 'open-ils.storage.asset.call_number.browse.target.atomic' 
37                 if( $self->api_name =~ /target/ );
38         $method = 'open-ils.storage.asset.call_number.browse.page_up'
39                 if( $self->api_name =~ /page_up/ );
40         $method = 'open-ils.storage.asset.call_number.browse.page_down'
41                 if( $self->api_name =~ /page_down/ );
42
43         return $U->simplereq( 'open-ils.storage', $method, @params );
44 }
45
46
47
48
49 __PACKAGE__->register_method(
50         method  => "cn_browse",
51         api_name        => "open-ils.search.callnumber.browse",
52         notes           => "Starts a callnumber browse"
53 );
54
55 sub cn_browse {
56         my( $self, $conn, $cn, $orgid, $size, $offset ) = @_;
57         my $ses = OpenSRF::AppSession->create('open-ils.supercat');
58
59         my $tree = $U->get_slim_org_tree;
60         my $name = _find_shortname($orgid, $tree);
61
62         $logger->debug("cn browse found or name $name");
63
64         my $data = $ses->request(
65                 'open-ils.supercat.call_number.browse', 
66                 $cn, $name, $size, $offset )->gather(1);
67
68         return [] unless $data;
69
70         my @res;
71         for my $d (@$data) {
72                 my $mods = $U->record_to_mvr($d->record);
73                 $d->owning_lib( $d->owning_lib->id );
74                 $d->record($mods->doc_id);
75                 push( @res, { cn        => $d, mods     => $mods });
76         }
77
78         return \@res;
79 }
80
81
82 sub _find_shortname {
83         my $id = shift;
84         my $node = shift;
85         return undef unless $node;
86         return $node->shortname if $node->id == $id;
87         if( $node->children ) {
88                 for my $c (@{$node->children()}) {
89                         my $d = _find_shortname($id, $c);
90                         return $d if $d;
91                 }
92         }
93         return undef;
94 }
95
96 1;
97