]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm
ranged stat_cat search methods... YAY, I got to write some code!
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Publisher / asset.pm
1 package OpenILS::Application::Storage::Publisher::asset;
2 use base qw/OpenILS::Application::Storage/;
3 #use OpenILS::Application::Storage::CDBI::asset;
4 #use OpenSRF::Utils::Logger qw/:level/;
5 #use OpenILS::Utils::Fieldmapper;
6 #
7 #my $log = 'OpenSRF::Utils::Logger';
8
9 sub asset_copy_location_all {
10         my $self = shift;
11         my $client = shift;
12
13         for my $rec ( asset::copy_location->retrieve_all ) {
14                 $client->respond( $rec->to_fieldmapper );
15         }
16
17         return undef;
18 }
19 __PACKAGE__->register_method(
20         method          => 'asset_copy_location_all',
21         api_name        => 'open-ils.storage.direct.asset.copy_location.retrieve.all',
22         argc            => 0,
23         stream          => 1,
24 );
25
26 sub fleshed_copy {
27         my $self = shift;
28         my $client = shift;
29         my $id = ''.shift;
30
31         my $cp = asset::copy->retrieve($id);
32
33         my $cp_fm = $cp->to_fieldmapper;
34         $cp_fm->circ_lib( $cp->circ_lib->to_fieldmapper );
35         $cp_fm->location( $cp->location->to_fieldmapper );
36         $cp_fm->status( $cp->status->to_fieldmapper );
37         return $cp_fm;
38 }
39 __PACKAGE__->register_method(
40         api_name        => 'open-ils.storage.fleshed.asset.copy.retrieve',
41         method          => 'fleshed_copy',
42         argc            => 1,
43 );
44
45 sub fleshed_copy_by_barcode {
46         my $self = shift;
47         my $client = shift;
48         my $bc = ''.shift;
49
50         my ($cp) = asset::copy->search( { barcode => $bc } );
51
52         my $cp_fm = $cp->to_fieldmapper;
53         $cp_fm->circ_lib( $cp->circ_lib->to_fieldmapper );
54         $cp_fm->location( $cp->location->to_fieldmapper );
55         $cp_fm->status( $cp->status->to_fieldmapper );
56
57         return [ $cp_fm ];
58 }       
59 __PACKAGE__->register_method(
60         api_name        => 'open-ils.storage.fleshed.asset.copy.search.barcode',
61         method          => 'fleshed_copy_by_barcode',
62         argc            => 1,
63         stream          => 1,
64 );
65
66 #XXX Fix stored proc calls
67 sub ranged_asset_stat_cat {
68         my $self = shift;
69         my $client = shift;
70         my $ou = ''.shift();
71
72         return undef unless ($ou);
73         my $s_table = asset::stat_cat->table;
74
75         my $select = <<"        SQL";
76                 SELECT  s.*
77                   FROM  $s_table s
78                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
79                   ORDER BY name
80         SQL
81
82         $fleshed = 0;
83         $fleshed = 1 if ($self->api_name =~ /fleshed/o);
84
85         my $sth = asset::stat_cat->db_Main->prepare_cached($select);
86         $sth->execute($ou);
87
88         for my $sc ( map { asset::stat_cat->construct($_) } $sth->fetchall_hash ) {
89                 my $sc_fm = $sc->to_fieldmapper;
90                 $sc_fm->entries(
91                         [ $self->method_lookup( 'open-ils.storage.ranged.asset.stat_cat_entry.search.stat_cat' )->run($ou,$sc->id) ]
92                 ) if ($fleshed);
93                 $client->respond( $sc_fm );
94         }
95
96         return undef;
97 }
98 __PACKAGE__->register_method(
99         api_name        => 'open-ils.storage.ranged.fleshed.asset.stat_cat.all',
100         api_level       => 1,
101         stream          => 1,
102         method          => 'ranged_asset_stat_cat',
103 );
104
105 __PACKAGE__->register_method(
106         api_name        => 'open-ils.storage.ranged.asset.stat_cat.all',
107         api_level       => 1,
108         stream          => 1,
109         method          => 'ranged_asset_stat_cat',
110 );
111
112 #XXX Fix stored proc calls
113 sub ranged_asset_stat_cat_entry {
114         my $self = shift;
115         my $client = shift;
116         my $ou = ''.shift();
117         my $sc = ''.shift();
118
119         return undef unless ($ou);
120         my $s_table = asset::stat_cat_entry->table;
121
122         my $select = <<"        SQL";
123                 SELECT  s.*
124                   FROM  $s_table s
125                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
126                   WHERE stat_cat = ?
127                   ORDER BY name
128         SQL
129
130         my $sth = asset::stat_cat->db_Main->prepare_cached($select);
131         $sth->execute($ou,$sc);
132
133         for my $sce ( map { asset::stat_cat_entry->construct($_) } $sth->fetchall_hash ) {
134                 $client->respond( $sce->to_fieldmapper );
135         }
136
137         return undef;
138 }
139 __PACKAGE__->register_method(
140         api_name        => 'open-ils.storage.ranged.asset.stat_cat_entry.search.stat_cat',
141         api_level       => 1,
142         stream          => 1,
143         method          => 'ranged_asset_stat_cat_entry',
144 );
145
146
147
148 1;