/usr/share/perl5/Lire/ReportSchedule.pm is in lire 2:2.1.1-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | package Lire::ReportSchedule;
use strict;
use Carp;
use Locale::TextDomain 'lire';
use Lire::DlfSchema;
use Lire::ReportConfig;
use Lire::FilterSpec;
use Lire::FilterExpr;
use Lire::Utils qw/ check_param check_object_param /;
use Time::Local;
use Lire::WeekCalculator;
=pod
=head1 NAME
Lire::ReportSchedule - Object which reprents one periodical report generation.
=head1 SYNOPSIS
use Lire::ReportJob;
use Lire::ReportSchedule;
my $store = Lire::DlfStore->open( 'aStore' );
my $job = new Lire::ReportJob( "webServer" );
my $cfg = $store->get_report_config( 'daily_www_report' );
$job->add_schedule( new Lire::ReportSchedule( 'daily', $cfg );
$job->run( 'daily', $store );
=head1 DESCRIPTION
Lire::ReportSchedule objects together with Lire::OutputJob objects
make it possible to configure all kind of periodical report
generation. Whereas the Lire::OutputJob is used to represent the
formatting of one generated report, the Lire::ReportSchedule
represents such a generation. It will be use to generate periodically
one XML report in a DlfStore using one report configuration file.
ReportSchedules grouped together in one ReportJob are assumed to
generate compatible reports as far as merging is concerned. The idea
is that previous reports generated in one ReportJob (according to
different schedules) could be used as a data source when the DlfStore
doesn't contain all the DLF records for the whole period. For example,
if you don't keep one year of www DLF in your store, you could still
generate an yearly report using the daily reports generated during the
year.
=head2 new( $period, $cfg );
Creates a new Lire::ReportSchedule that will generates an XML report
using the Lire::ReportConfig $cfg on a $period period.
$period should be one of 'hourly', 'daily', 'weekly', 'monthly' or
'yearly'.
=cut
sub new {
my ( $class, $period, $cfg ) = @_;
check_param( $period, 'period', qr/^(hourly|daily|weekly|monthly|yearly)$/,
"'period' parameter should be one of 'hourly', 'daily', 'weekly', 'monthly' or 'yearly'" );
check_object_param( $cfg, 'cfg', 'Lire::ReportConfig' );
my $self = bless { '_period' => $period,
'_cfg' => $cfg,
'_output_jobs' => [],
}, $class;
return $self;
}
=pod
=head2 period()
Returns the period of this ReportSchedule.
=cut
sub period { $_[0]{'_period'} };
=pod
=head2 period_range( [ $time ] )
Returns the starting and ending boundaries of the schedule period
which includes $time. (Defaults to now). The ending boundary is
excluded from the period and the starting boundary is included.
=cut
sub period_range {
my ($self, $time) = @_;
return Lire::Utils::period_range( $self->{'_period'}, $time || time() );
}
=pod
=head2 report_config( [ $new_cfg ] )
Returns (and optionally change) the Lire::ReportConfig object to
use for this schedule.
=cut
sub report_config {
my ( $self, $new_cfg ) = @_;
if ( @_ == 2 ) {
check_object_param( $new_cfg, 'new_cfg', 'Lire::ReportConfig' );
$self->{'_cfg'} = $new_cfg;
}
return $self->{'_cfg'};
}
=pod
=head2 init_report_config( [ $time ] )
Returns the Lire::ReportConfig object with filters set. A FilterSpec
will have been added to each section of the ReportConfig object which
will restrict the reporting on the period defined for the scedule. The
boundaries of the period are determined according to $time which
defaults to now.
=cut
sub init_report_config {
my ( $self, $time ) = @_;
$time ||= time();
my $cfg = $self->{'_cfg'};
my $range = $self->period_range( $time );
foreach my $sect ( $cfg->sections() ) {
foreach my $spec ( $sect->reports() ) {
my $field = '$' .
$spec->schema()->timestamp_field()->name();
my $time_filter =
new Lire::FilterExpr::And( 'container' => $spec, );
my $start =
new Lire::FilterExpr::Ge( 'container' => $spec,
'arg1' => $field,
'arg2' => $range->[0] );
my $end = new Lire::FilterExpr::Lt( 'container' => $spec,
'arg1' => $field,
'arg2' => $range->[1] );
my $expr = [ $start, $end ];
push @$expr, $spec->filter_spec()
if $spec->filter_spec();
$time_filter->expr( $expr );
$spec->filter_spec( $time_filter );
}
}
return $cfg;
}
=pod
=head2 add_output_jobs( $job, ... )
Adds one or more Lire::OutputJob to the ReportSchedule object.
=cut
sub add_output_job {
my ( $self, @jobs ) = @_;
croak "missing one or more 'output_job' parameters"
unless @jobs;
foreach my $job ( @jobs ) {
check_object_param( $job, 'output_job', 'Lire::OutputJob' );
push @{$self->{'_output_jobs'}}, $job;
}
return;
}
=pod
=head2 output_jobs()
Returns the Lire::OutputJobs related to this object.
=cut
sub output_jobs {
return @{$_[0]{'_output_jobs'}};
}
=pod
=head2 run( $store, $report_job, [$time] )
Generate a XML report and save it in the $store Lire::DlfStore. The
report will be generated either using the DlfStreams or previously
generated reports. Preferences is giving to generating the report
using the Dlf data For more details, consult the documentation
of find_report_source() in Lire::DlfStore(3pm).
The period for which the report will be generated is done using the
$time parameter which defaults to now. For example, a 'daily' report
will generate a report for the whole day (midnight-midnidht based on
the day that $time represents).
Once the report is generated, all registered OutputJob will be run
with the new report.
=cut
sub run {
my ( $self, $store, $report_job, $time ) = @_;
my $source = $store->find_report_source( $report_job, $self, $time );
return if $source->{'source'} eq 'none';
my $cfg = $self->init_report_config( $time );
my $report;
if ( $source->{'source'} eq 'merging' ) {
$report = $cfg->merge_report_files( @{$source->{'reports'}} );
} else {
$report = $cfg->generate_report( $store );
}
$report->timespan_period( $self->period() );
$report->timespan_start( $source->{'start'} );
$report->timespan_end( $source->{'end'} );
my $report_file = $store->put_report( $report_job, $self, $report );
foreach my $job ( $self->output_jobs() ) {
$job->run( $report_file, $time );
}
return;
}
sub new_from_config {
my ( $pkg, $dict ) = @_;
$dict = $dict->Lire::Config::Dictionary::as_value();
my $sched = new Lire::ReportSchedule( $dict->{'period'},
$dict->{'report_config'});
$sched->add_output_job( @{$dict->{'output_jobs'}} )
if @{$dict->{'output_jobs'}};
return $sched;
}
1;
__END__
=pod
=head1 SEE ALSO
Lire::DlfStore(3pm) Lire::DlfConverter(3pm)
=head1 AUTHOR
Francis J. Lacoste <flacoste@logreport.org>
=head1 VERSION
$Id: ReportSchedule.pm,v 1.17 2006/07/23 13:16:29 vanbaal Exp $
=head1 COPYRIGHT
Copyright (C) 2004 Stichting LogReport Foundation LogReport@LogReport.org
This file is part of Lire.
Lire is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.
=cut
|