1 package OpenILS::Application::Storage::Publisher;
2 use base qw/OpenILS::Application::Storage/;
5 use OpenSRF::EX qw/:try/;;
6 use OpenSRF::Utils::Logger;
7 my $log = 'OpenSRF::Utils::Logger';
9 use OpenILS::Utils::Fieldmapper;
10 use OpenILS::Application::Storage::CDBI;
12 #use OpenILS::Application::Storage::CDBI::actor;
13 #use OpenILS::Application::Storage::CDBI::asset;
14 #use OpenILS::Application::Storage::CDBI::biblio;
15 #use OpenILS::Application::Storage::CDBI::config;
16 #use OpenILS::Application::Storage::CDBI::metabib;
18 use OpenILS::Application::Storage::Publisher::actor;
19 #use OpenILS::Application::Storage::Publisher::asset;
20 use OpenILS::Application::Storage::Publisher::biblio;
21 use OpenILS::Application::Storage::Publisher::config;
22 use OpenILS::Application::Storage::Publisher::metabib;
29 my $cdbi = $self->{cdbi};
34 my ($rec) = $cdbi->fast_fieldmapper($id);
35 $client->respond( $rec ) if ($rec);
37 last if ($self->api_name !~ /batch/o);
47 my $cdbi = $self->{cdbi};
49 $log->debug("Searching $cdbi for { ".join(',', map { "$_ => $$searches{$_}" } keys %$searches).' }',DEBUG);
51 for my $obj ($cdbi->search($searches)) {
52 $client->respond( $obj->to_fieldmapper );
57 sub search_one_field {
62 (my $search_type = $self->api_name) =~ s/.*\.(search[^.]*).*/$1/o;
63 (my $col = $self->api_name) =~ s/.*\.$search_type\.([^.]+).*/$1/;
64 my $cdbi = $self->{cdbi};
65 $log->debug("Searching $cdbi for $col using type $search_type, value '$term'",DEBUG);
68 $like = 1 if ($search_type =~ /like$/o);
70 return [ $cdbi->fast_fieldmapper($term,$col,$like) ];
79 my $cdbi = $self->{cdbi};
83 my $rec = $cdbi->create($node);
84 $success = $rec->id if ($rec);
97 my $cdbi = $self->{cdbi};
99 return $cdbi->update($node);
107 my $cdbi = $self->{cdbi};
111 $success = $cdbi->delete($node);
123 my $cdbi = $self->{cdbi};
124 my $api_name = $self->api_name;
125 (my $single_call_api_name = $api_name) =~ s/batch\.//o;
127 $log->debug("Default $api_name looking up $single_call_api_name...",INTERNAL);
128 my $method = $self->method_lookup($single_call_api_name);
131 while ( my $node = shift(@nodes) ) {
132 my ($res) = $method->run( $node );
133 push(@success, 1) if ($res >= 0);
136 my $insert_total = 0;
137 $insert_total += $_ for (@success);
139 return $insert_total;
142 for my $fmclass ( Fieldmapper->classes ) {
143 (my $cdbi = $fmclass) =~ s/^Fieldmapper:://o;
144 (my $class = $cdbi) =~ s/::.*//o;
145 (my $api_class = $cdbi) =~ s/::/./go;
146 my $registration_class = __PACKAGE__ . "::$class";
147 my $api_prefix = 'open-ils.storage.'.$api_class;
149 # Create the search method
150 unless ( __PACKAGE__->is_registered( $api_prefix.'.search' ) ) {
151 __PACKAGE__->register_method(
152 api_name => $api_prefix.'.search',
160 # Create the retrieve method
161 unless ( __PACKAGE__->is_registered( $api_prefix.'.retrieve' ) ) {
162 __PACKAGE__->register_method(
163 api_name => $api_prefix.'.retrieve',
164 method => 'retrieve_node',
170 # Create the batch retrieve method
171 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.retrieve' ) ) {
172 __PACKAGE__->register_method(
173 api_name => $api_prefix.'.batch.retrieve',
174 method => 'retrieve_node',
181 for my $field ($fmclass->real_fields) {
182 unless ( __PACKAGE__->is_registered( $api_prefix.'.search.'.$field ) ) {
183 __PACKAGE__->register_method(
184 api_name => $api_prefix.'.search.'.$field,
185 method => 'search_one_field',
190 unless ( __PACKAGE__->is_registered( $api_prefix.'.search_like.'.$field ) ) {
191 __PACKAGE__->register_method(
192 api_name => $api_prefix.'.search_like.'.$field,
193 method => 'search_one_field',
201 # Create the create method
202 unless ( __PACKAGE__->is_registered( $api_prefix.'.create' ) ) {
203 __PACKAGE__->register_method(
204 api_name => $api_prefix.'.create',
205 method => 'create_node',
211 # Create the batch create method
212 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.create' ) ) {
213 __PACKAGE__->register_method(
214 api_name => $api_prefix.'.batch.create',
215 method => 'batch_call',
221 # Create the update method
222 unless ( __PACKAGE__->is_registered( $api_prefix.'.update' ) ) {
223 __PACKAGE__->register_method(
224 api_name => $api_prefix.'.update',
225 method => 'update_node',
231 # Create the batch update method
232 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.update' ) ) {
233 __PACKAGE__->register_method(
234 api_name => $api_prefix.'.batch.update',
235 method => 'batch_call',
241 # Create the delete method
242 unless ( __PACKAGE__->is_registered( $api_prefix.'.delete' ) ) {
243 __PACKAGE__->register_method(
244 api_name => $api_prefix.'.delete',
245 method => 'delete_node',
251 # Create the batch delete method
252 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.delete' ) ) {
253 __PACKAGE__->register_method(
254 api_name => $api_prefix.'.batch.delete',
255 method => 'batch_call',