]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/Application/Search/CNBrowse.pm
Make Evergreen Perl modules installable via Module::Build to match OpenSRF
[Evergreen.git] / Open-ILS / src / perlmods / lib / 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 __PACKAGE__->register_method(
48         method => "cn_browse",
49         api_name => "open-ils.search.callnumber.browse",
50     signature => {
51         desc => q/Paged call number browse/,
52         params => [
53             { name => 'label',
54               desc => 'The target call number lable',
55               type => 'string' },
56             { name => 'org_unit',
57               desc => 'The org unit shortname (or "-" or undef for global) to browse',
58               type => 'string' },
59             { name => 'page_size',
60               desc => 'Count of call numbers to retrieve, default is 9',
61               type => 'number' },
62             { name => 'offset',
63               desc => 'The page of call numbers to retrieve, calculated based on page_size.  Can be positive, negative or 0.',
64               type => 'number' },
65             { name => 'statuses',
66               desc => 'Array of statuses to filter copies by, optional and can be undef.',
67               type => 'array' },
68             { name => 'locations',
69               desc => 'Array of copy locations to filter copies by, optional and can be undef.',
70               type => 'array' },
71         ],
72         return => {
73             type => 'array',
74             desc => q/List of callnumber (acn) and record (mvr) objects/
75         }
76     }
77 );
78
79 sub cn_browse {
80         my( $self, $conn, $cn, $orgid, $size, $offset, $copy_statuses, $copy_locations ) = @_;
81         my $ses = OpenSRF::AppSession->create('open-ils.supercat');
82
83         my $tree = $U->get_slim_org_tree;
84         my $name = _find_shortname($orgid, $tree);
85
86         $logger->debug("cn browse found or name $name");
87
88         my $data = $ses->request(
89                 'open-ils.supercat.call_number.browse', 
90                 $cn, $name, $size, $offset, $copy_statuses, $copy_locations )->gather(1);
91
92         return [] unless $data;
93
94         my @res;
95         for my $d (@$data) {
96                 my $mods = $U->record_to_mvr($d->record);
97                 $d->owning_lib( $d->owning_lib->id );
98                 $d->record($mods->doc_id);
99                 push( @res, { cn        => $d, mods     => $mods });
100         }
101
102         return \@res;
103 }
104
105
106 sub _find_shortname {
107         my $id = shift;
108         my $node = shift;
109         return undef unless $node;
110         return $node->shortname if $node->id == $id;
111         if( $node->children ) {
112                 for my $c (@{$node->children()}) {
113                         my $d = _find_shortname($id, $c);
114                         return $d if $d;
115                 }
116         }
117         return undef;
118 }
119
120 1;
121