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::action;
20 use OpenILS::Application::Storage::Publisher::asset;
21 use OpenILS::Application::Storage::Publisher::biblio;
22 use OpenILS::Application::Storage::Publisher::config;
23 use OpenILS::Application::Storage::Publisher::metabib;
30 my $cdbi = $self->{cdbi};
35 my ($rec) = $cdbi->fast_fieldmapper($id);
36 $client->respond( $rec ) if ($rec);
38 last if ($self->api_name !~ /batch/o);
48 my $cdbi = $self->{cdbi};
50 $log->debug("Searching $cdbi for { ".join(',', map { "$_ => $$searches{$_}" } keys %$searches).' }',DEBUG);
52 for my $obj ($cdbi->search($searches)) {
53 $client->respond( $obj->to_fieldmapper );
58 sub search_one_field {
63 (my $search_type = $self->api_name) =~ s/.*\.(search[^.]*).*/$1/o;
64 (my $col = $self->api_name) =~ s/.*\.$search_type\.([^.]+).*/$1/;
65 my $cdbi = $self->{cdbi};
68 $like = 1 if ($search_type =~ /like$/o);
70 for my $term (@terms) {
71 $log->debug("Searching $cdbi for $col using type $search_type, value '$term'",DEBUG);
72 $client->respond( [ $cdbi->fast_fieldmapper($term,$col,$like) ] );
83 my $cdbi = $self->{cdbi};
87 my $rec = $cdbi->create($node);
88 $success = $rec->id if ($rec);
101 my $cdbi = $self->{cdbi};
103 return $cdbi->update($node);
111 my $where = 'WHERE ';
113 my $cdbi = $self->{cdbi};
114 my $table = $cdbi->table;
116 my @keys = sort keys %$search;
120 for my $col ( @keys ) {
121 if (ref($$search{$col}) and ref($$search{$col}) =~ /ARRAY/o) {
122 push @wheres, "$col IN (" . join(',', map { '?' } @{ $$search{$col} }) . ')';
123 push @binds, map { "$_" } @{ $$search{$col} };
125 push @wheres, "$col = ?";
126 push @binds, $$search{$col};
129 $where .= join ' AND ', @wheres;
131 my $delete = "DELETE FROM $table $where";
133 $log->debug("Performing MASS deletion : $delete",DEBUG);
135 my $dbh = $cdbi->db_Main;
138 my $sth = $dbh->prepare($delete);
139 $sth->execute( @binds );
141 $log->debug("MASS Delete succeeded",DEBUG);
143 $log->debug("MASS Delete FAILED : ".shift(),DEBUG);
154 my $cdbi = $self->{cdbi};
158 $success = $cdbi->delete($node);
170 my $cdbi = $self->{cdbi};
171 my $api_name = $self->api_name;
172 (my $single_call_api_name = $api_name) =~ s/batch\.//o;
174 $log->debug("Default $api_name looking up $single_call_api_name...",INTERNAL);
175 my $method = $self->method_lookup($single_call_api_name);
178 while ( my $node = shift(@nodes) ) {
179 my ($res) = $method->run( $node );
180 push(@success, 1) if ($res >= 0);
183 my $insert_total = 0;
184 $insert_total += $_ for (@success);
186 return $insert_total;
189 for my $fmclass ( Fieldmapper->classes ) {
190 (my $cdbi = $fmclass) =~ s/^Fieldmapper:://o;
191 (my $class = $cdbi) =~ s/::.*//o;
192 (my $api_class = $cdbi) =~ s/::/./go;
193 my $registration_class = __PACKAGE__ . "::$class";
194 my $api_prefix = 'open-ils.storage.direct.'.$api_class;
196 # Create the search method
197 unless ( __PACKAGE__->is_registered( $api_prefix.'.search' ) ) {
198 __PACKAGE__->register_method(
199 api_name => $api_prefix.'.search',
207 # Create the retrieve method
208 unless ( __PACKAGE__->is_registered( $api_prefix.'.retrieve' ) ) {
209 __PACKAGE__->register_method(
210 api_name => $api_prefix.'.retrieve',
211 method => 'retrieve_node',
217 # Create the batch retrieve method
218 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.retrieve' ) ) {
219 __PACKAGE__->register_method(
220 api_name => $api_prefix.'.batch.retrieve',
221 method => 'retrieve_node',
228 for my $field ($fmclass->real_fields) {
229 unless ( __PACKAGE__->is_registered( $api_prefix.'.search.'.$field ) ) {
230 __PACKAGE__->register_method(
231 api_name => $api_prefix.'.search.'.$field,
232 method => 'search_one_field',
237 unless ( __PACKAGE__->is_registered( $api_prefix.'.search_like.'.$field ) ) {
238 __PACKAGE__->register_method(
239 api_name => $api_prefix.'.search_like.'.$field,
240 method => 'search_one_field',
248 # Create the create method
249 unless ( __PACKAGE__->is_registered( $api_prefix.'.create' ) ) {
250 __PACKAGE__->register_method(
251 api_name => $api_prefix.'.create',
252 method => 'create_node',
258 # Create the batch create method
259 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.create' ) ) {
260 __PACKAGE__->register_method(
261 api_name => $api_prefix.'.batch.create',
262 method => 'batch_call',
268 # Create the update method
269 unless ( __PACKAGE__->is_registered( $api_prefix.'.update' ) ) {
270 __PACKAGE__->register_method(
271 api_name => $api_prefix.'.update',
272 method => 'update_node',
278 # Create the batch update method
279 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.update' ) ) {
280 __PACKAGE__->register_method(
281 api_name => $api_prefix.'.batch.update',
282 method => 'batch_call',
288 # Create the delete method
289 unless ( __PACKAGE__->is_registered( $api_prefix.'.delete' ) ) {
290 __PACKAGE__->register_method(
291 api_name => $api_prefix.'.delete',
292 method => 'delete_node',
298 # Create the batch delete method
299 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.delete' ) ) {
300 __PACKAGE__->register_method(
301 api_name => $api_prefix.'.batch.delete',
302 method => 'batch_call',
308 # Create the search-based mass delete method
309 unless ( __PACKAGE__->is_registered( $api_prefix.'.mass_delete' ) ) {
310 __PACKAGE__->register_method(
311 api_name => $api_prefix.'.mass_delete',
312 method => 'mass_delete',