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};
67 $like = 1 if ($search_type =~ /like$/o);
69 for my $term (@terms) {
70 $log->debug("Searching $cdbi for $col using type $search_type, value '$term'",DEBUG);
71 $client->respond( [ $cdbi->fast_fieldmapper($term,$col,$like) ] );
82 my $cdbi = $self->{cdbi};
86 my $rec = $cdbi->create($node);
87 $success = $rec->id if ($rec);
100 my $cdbi = $self->{cdbi};
102 return $cdbi->update($node);
110 my $cdbi = $self->{cdbi};
114 $success = $cdbi->delete($node);
126 my $cdbi = $self->{cdbi};
127 my $api_name = $self->api_name;
128 (my $single_call_api_name = $api_name) =~ s/batch\.//o;
130 $log->debug("Default $api_name looking up $single_call_api_name...",INTERNAL);
131 my $method = $self->method_lookup($single_call_api_name);
134 while ( my $node = shift(@nodes) ) {
135 my ($res) = $method->run( $node );
136 push(@success, 1) if ($res >= 0);
139 my $insert_total = 0;
140 $insert_total += $_ for (@success);
142 return $insert_total;
145 for my $fmclass ( Fieldmapper->classes ) {
146 (my $cdbi = $fmclass) =~ s/^Fieldmapper:://o;
147 (my $class = $cdbi) =~ s/::.*//o;
148 (my $api_class = $cdbi) =~ s/::/./go;
149 my $registration_class = __PACKAGE__ . "::$class";
150 my $api_prefix = 'open-ils.storage.'.$api_class;
152 # Create the search method
153 unless ( __PACKAGE__->is_registered( $api_prefix.'.search' ) ) {
154 __PACKAGE__->register_method(
155 api_name => $api_prefix.'.search',
163 # Create the retrieve method
164 unless ( __PACKAGE__->is_registered( $api_prefix.'.retrieve' ) ) {
165 __PACKAGE__->register_method(
166 api_name => $api_prefix.'.retrieve',
167 method => 'retrieve_node',
173 # Create the batch retrieve method
174 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.retrieve' ) ) {
175 __PACKAGE__->register_method(
176 api_name => $api_prefix.'.batch.retrieve',
177 method => 'retrieve_node',
184 for my $field ($fmclass->real_fields) {
185 unless ( __PACKAGE__->is_registered( $api_prefix.'.search.'.$field ) ) {
186 __PACKAGE__->register_method(
187 api_name => $api_prefix.'.search.'.$field,
188 method => 'search_one_field',
193 unless ( __PACKAGE__->is_registered( $api_prefix.'.search_like.'.$field ) ) {
194 __PACKAGE__->register_method(
195 api_name => $api_prefix.'.search_like.'.$field,
196 method => 'search_one_field',
204 # Create the create method
205 unless ( __PACKAGE__->is_registered( $api_prefix.'.create' ) ) {
206 __PACKAGE__->register_method(
207 api_name => $api_prefix.'.create',
208 method => 'create_node',
214 # Create the batch create method
215 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.create' ) ) {
216 __PACKAGE__->register_method(
217 api_name => $api_prefix.'.batch.create',
218 method => 'batch_call',
224 # Create the update method
225 unless ( __PACKAGE__->is_registered( $api_prefix.'.update' ) ) {
226 __PACKAGE__->register_method(
227 api_name => $api_prefix.'.update',
228 method => 'update_node',
234 # Create the batch update method
235 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.update' ) ) {
236 __PACKAGE__->register_method(
237 api_name => $api_prefix.'.batch.update',
238 method => 'batch_call',
244 # Create the delete method
245 unless ( __PACKAGE__->is_registered( $api_prefix.'.delete' ) ) {
246 __PACKAGE__->register_method(
247 api_name => $api_prefix.'.delete',
248 method => 'delete_node',
254 # Create the batch delete method
255 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.delete' ) ) {
256 __PACKAGE__->register_method(
257 api_name => $api_prefix.'.batch.delete',
258 method => 'batch_call',