1 package OpenILS::Application::Search::CNBrowse;
2 use base qw/OpenILS::Application/;
3 use strict; use warnings;
5 use OpenSRF::EX qw(:try);
6 use OpenILS::Application::AppUtils;
8 use OpenSRF::Utils::Logger qw/:logger/;
9 use OpenSRF::AppSession;
10 my $U = "OpenILS::Application::AppUtils";
13 __PACKAGE__->register_method(
14 method => "cn_browse_start",
15 api_name => "open-ils.search.callnumber.browse.target",
16 notes => "Starts a callnumber browse"
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",
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",
34 my( $self, $client, @params ) = @_;
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/ );
43 return $U->simplereq( 'open-ils.storage', $method, @params );
47 __PACKAGE__->register_method(
48 method => "cn_browse",
49 api_name => "open-ils.search.callnumber.browse",
51 desc => q/Paged call number browse/,
54 desc => 'The target call number lable',
57 desc => 'The org unit shortname (or "-" or undef for global) to browse',
59 { name => 'page_size',
60 desc => 'Count of call numbers to retrieve, default is 9',
63 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
66 desc => 'Array of statuses to filter copies by, optional and can be undef.',
68 { name => 'locations',
69 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
74 desc => q/List of callnumber (acn) and record (mvr) objects/
80 my( $self, $conn, $cn, $orgid, $size, $offset, $copy_statuses, $copy_locations ) = @_;
81 my $ses = OpenSRF::AppSession->create('open-ils.supercat');
83 my $tree = $U->get_org_tree;
84 my $name = _find_shortname($orgid, $tree);
86 $logger->debug("cn browse found or name $name");
88 my $data = $ses->request(
89 'open-ils.supercat.call_number.browse',
90 $cn, $name, $size, $offset, $copy_statuses, $copy_locations )->gather(1);
92 return [] unless $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 });
106 sub _find_shortname {
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);