added some report object events, added reporter-store modification to cstoreeditor...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 28 Sep 2006 04:57:51 +0000 (04:57 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 28 Sep 2006 04:57:51 +0000 (04:57 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6241 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/OpenILS/Application/Reporter.pm
Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm

index b3f5d20..f64ddcc 100644 (file)
        <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>
+
 
 
 
index 3cf9d3b..36ff88b 100644 (file)
@@ -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;
index be38c61..dcb85c9 100644 (file)
@@ -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";