From 29ad5288298749ee0718d3e3da0745f805e122b2 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 28 Sep 2006 04:57:51 +0000 Subject: [PATCH] added some report object events, added reporter-store modification to cstoreeditor, added magic fetch-all method for report data git-svn-id: svn://svn.open-ils.org/ILS/trunk@6241 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/ils_events.xml | 16 ++++++++ .../src/perlmods/OpenILS/Application/Reporter.pm | 47 ++++++++++++++++++++++ .../src/perlmods/OpenILS/Utils/CStoreEditor.pm | 40 ++++++++++++++---- 3 files changed, 96 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index b3f5d20eca..f64ddccda0 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -511,6 +511,22 @@ The requested money_collections_tracker was not found + + The requested reporter_template was not found + + + The requested reporter_report was not found + + + The requested reporter_output_folder was not found + + + The requested reporter_report_folder was not found + + + The requested reporter_template_folder was not found + + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Reporter.pm b/Open-ILS/src/perlmods/OpenILS/Application/Reporter.pm index 3cf9d3b471..36ff88b6f1 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Reporter.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Reporter.pm @@ -1,6 +1,7 @@ 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; @@ -124,4 +125,50 @@ sub retrieve_report { } +__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; diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm b/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm index be38c61f5f..dcb85c9f98 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm @@ -18,11 +18,17 @@ my %PERMS; 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 @@ -48,6 +54,15 @@ sub new { 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 # ----------------------------------------------------------------------------- @@ -84,6 +99,17 @@ sub event { } # ----------------------------------------------------------------------------- +# 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 { @@ -106,7 +132,7 @@ sub session { $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()!"; @@ -127,7 +153,7 @@ sub session { 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; } @@ -138,7 +164,7 @@ sub xact_start { 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; } @@ -149,7 +175,7 @@ sub xact_commit { 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"); } @@ -392,7 +418,7 @@ sub runmethod { } 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"; -- 2.11.0