<event code='1633' textcode='MONEY_DESK_PAYMENT_NOT_FOUND'>
<desc xml:lang='en-US'>The requested money_collections_tracker was not found</desc>
</event>
+ <event code='1634' textcode='REPORTER_TEMPLATE_NOT_FOUND'>
+ <desc xml:lang='en-US'>The requested reporter_template was not found</desc>
+ </event>
+ <event code='1635' textcode='REPORTER_REPORT_NOT_FOUND'>
+ <desc xml:lang='en-US'>The requested reporter_report was not found</desc>
+ </event>
+ <event code='1636' textcode='REPORTER_OUTPUT_FOLDER_NOT_FOUND'>
+ <desc xml:lang='en-US'>The requested reporter_output_folder was not found</desc>
+ </event>
+ <event code='1637' textcode='REPORTER_REPORT_FOLDER_NOT_FOUND'>
+ <desc xml:lang='en-US'>The requested reporter_report_folder was not found</desc>
+ </event>
+ <event code='1638' textcode='REPORTER_TEMPLATE_FOLDER_NOT_FOUND'>
+ <desc xml:lang='en-US'>The requested reporter_template_folder was not found</desc>
+ </event>
+
package OpenILS::Application::Reporter;
use base qw/OpenSRF::Application/;
use strict; use warnings;
+use OpenSRF::Utils::Logger qw/$logger/;
use OpenILS::Utils::CStoreEditor qw/:funcs/;
use OpenILS::Utils::Fieldmapper;
use OpenILS::Application::AppUtils;
}
+__PACKAGE__->register_method(
+ api_name => 'open-ils.reporter.template.update',
+ method => 'update_template');
+sub update_template {
+ my( $self, $conn, $auth, $tmpl ) = @_;
+ my $e = new_rstore_editor(authtoken=>$auth, xact=>1);
+ return $e->event unless $e->checkauth;
+ return $e->event unless $e->allowed('RUN_REPORTS');
+ my $t = $e->retrieve_reporter_template($tmpl->id)
+ or return $e->die_event;
+ return 0 if $t->owner ne $e->requestor->id;
+ $e->update_reporter_template($tmpl)
+ or return $e->die_event;
+ $e->commit;
+ return 1;
+}
+
+
+
+__PACKAGE__->register_method(
+ method => 'magic_fetch_all',
+ api_name => 'open-ils.reporter.magic_fetch');
+sub magic_fetch_all {
+ my( $self, $conn, $auth, $args ) = @_;
+ my $e = new_editor(authtoken => $auth);
+ return $e->event unless $e->checkauth;
+ return $e->event unless $e->allowed('RUN_REPORTS');
+
+ my $hint = $$args{hint};
+
+ # Find the class the iplements the given hint
+ my ($class) = grep {
+ $Fieldmapper::fieldmap->{$_}{hint} eq $hint } Fieldmapper->classes;
+
+ return undef unless $class->Selector;
+
+ $class =~ s/Fieldmapper:://og;
+ $class =~ s/::/_/og;
+ my $method = "retrieve_all_$class";
+
+ $logger->info("reporter.magic_fetch => $method");
+
+ return $e->$method();
+}
+
+
1;
use vars qw(@EXPORT_OK %EXPORT_TAGS);
use Exporter;
use base qw/Exporter/;
-push @EXPORT_OK, 'new_editor';
-%EXPORT_TAGS = ( funcs => [ qw/ new_editor / ] );
+push @EXPORT_OK, ( 'new_editor', 'new_rstore_editor' );
+%EXPORT_TAGS = ( funcs => [ qw/ new_editor new_rstore_editor / ] );
sub new_editor { return OpenILS::Utils::CStoreEditor->new(@_); }
+sub new_rstore_editor {
+ my $e = OpenILS::Utils::CStoreEditor->new(@_);
+ $e->app('open-ils.reporter-store');
+ return $e;
+}
+
# -----------------------------------------------------------------------------
# Log levels
return $self;
}
+
+sub app {
+ my( $self, $app ) = @_;
+ $self->{app} = $app if $app;
+ $self->{app} = 'open-ils.cstore' unless $self->{app};
+ return $self->{app};
+}
+
+
# -----------------------------------------------------------------------------
# Log the editor metadata along with the log string
# -----------------------------------------------------------------------------
}
# -----------------------------------------------------------------------------
+# Destroys the transaction and disconnects where necessary,
+# then returns the last event that occurred
+# -----------------------------------------------------------------------------
+sub die_event {
+ my $self = shift;
+ $self->rollback;
+ return $self->event;
+}
+
+
+# -----------------------------------------------------------------------------
# Clears the last caught event
# -----------------------------------------------------------------------------
sub clear_event {
$self->{session} = $session if $session;
if(!$self->{session}) {
- $self->{session} = OpenSRF::AppSession->create('open-ils.cstore');
+ $self->{session} = OpenSRF::AppSession->create($self->app);
if( ! $self->{session} ) {
my $str = "Error creating cstore session with OpenSRF::AppSession->create()!";
sub xact_start {
my $self = shift;
$self->log(D, "starting new db session");
- my $stat = $self->request('open-ils.cstore.transaction.begin');
+ my $stat = $self->request($self->app . '.transaction.begin');
$self->log(E, "error starting database transaction") unless $stat;
return $stat;
}
sub xact_commit {
my $self = shift;
$self->log(D, "comitting db session");
- my $stat = $self->request('open-ils.cstore.transaction.commit');
+ my $stat = $self->request($self->app.'.transaction.commit');
$self->log(E, "error comitting database transaction") unless $stat;
return $stat;
}
sub xact_rollback {
my $self = shift;
$self->log(I, "rolling back db session");
- return $self->request("open-ils.cstore.transaction.rollback");
+ return $self->request($self->app.".transaction.rollback");
}
}
my @arg = ( ref($arg) eq 'ARRAY' ) ? @$arg : ($arg);
- my $method = "open-ils.cstore.direct.$type.$action";
+ my $method = $self->app.".direct.$type.$action";
if( $action eq 'search' ) {
$method = "$method.atomic";