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 $search_type = $self->api_name) =~ s/.*\.(search[^.]*).*/$1/o;
48 (my $col = $self->api_name) =~ s/.*\.$search_type\.([^.]+).*/$1/;
49 my $cdbi = $self->{cdbi};
50 $log->debug("Searching $cdbi for $col using type $search_type, value '$term'",DEBUG);
53 $like = 1 if ($search_type =~ /like$/o);
55 return [ $cdbi->fast_fieldmapper($term,$col,$like) ];
64 my $cdbi = $self->{cdbi};
68 my $rec = $cdbi->create($node);
69 $success = $rec->id if ($rec);
82 my $cdbi = $self->{cdbi};
84 return $cdbi->update($node);
92 my $cdbi = $self->{cdbi};
96 $success = $cdbi->delete($node);
108 my $cdbi = $self->{cdbi};
109 my $api_name = $self->api_name;
110 (my $single_call_api_name = $api_name) =~ s/batch\.//o;
112 $log->debug("Default $api_name looking up $single_call_api_name...",INTERNAL);
113 my $method = $self->method_lookup($single_call_api_name);
116 while ( my $node = shift(@nodes) ) {
117 my ($res) = $method->run( $node );
118 push(@success, 1) if ($res >= 0);
121 my $insert_total = 0;
122 $insert_total += $_ for (@success);
124 return $insert_total;
127 for my $fmclass ( Fieldmapper->classes ) {
128 (my $cdbi = $fmclass) =~ s/^Fieldmapper:://o;
129 (my $class = $cdbi) =~ s/::.*//o;
130 (my $api_class = $cdbi) =~ s/::/./go;
131 my $registration_class = __PACKAGE__ . "::$class";
132 my $api_prefix = 'open-ils.storage.'.$api_class;
134 # Create the retrieve method
135 unless ( __PACKAGE__->is_registered( $api_prefix.'.retrieve' ) ) {
136 __PACKAGE__->register_method(
137 api_name => $api_prefix.'.retrieve',
138 method => 'retrieve_node',
144 # Create the batch retrieve method
145 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.retrieve' ) ) {
146 __PACKAGE__->register_method(
147 api_name => $api_prefix.'.batch.retrieve',
148 method => 'retrieve_node',
155 for my $field ($fmclass->real_fields) {
156 unless ( __PACKAGE__->is_registered( $api_prefix.'.search.'.$field ) ) {
157 __PACKAGE__->register_method(
158 api_name => $api_prefix.'.search.'.$field,
164 unless ( __PACKAGE__->is_registered( $api_prefix.'.search_like.'.$field ) ) {
165 __PACKAGE__->register_method(
166 api_name => $api_prefix.'.search_like.'.$field,
175 # Create the create method
176 unless ( __PACKAGE__->is_registered( $api_prefix.'.create' ) ) {
177 __PACKAGE__->register_method(
178 api_name => $api_prefix.'.create',
179 method => 'create_node',
185 # Create the batch create method
186 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.create' ) ) {
187 __PACKAGE__->register_method(
188 api_name => $api_prefix.'.batch.create',
189 method => 'batch_call',
195 # Create the update method
196 unless ( __PACKAGE__->is_registered( $api_prefix.'.update' ) ) {
197 __PACKAGE__->register_method(
198 api_name => $api_prefix.'.update',
199 method => 'update_node',
205 # Create the batch update method
206 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.update' ) ) {
207 __PACKAGE__->register_method(
208 api_name => $api_prefix.'.batch.update',
209 method => 'batch_call',
215 # Create the delete method
216 unless ( __PACKAGE__->is_registered( $api_prefix.'.delete' ) ) {
217 __PACKAGE__->register_method(
218 api_name => $api_prefix.'.delete',
219 method => 'delete_node',
225 # Create the batch delete method
226 unless ( __PACKAGE__->is_registered( $api_prefix.'.batch.delete' ) ) {
227 __PACKAGE__->register_method(
228 api_name => $api_prefix.'.batch.delete',
229 method => 'batch_call',