| 1 | package ETLp::Audit::Browser::Model::Job; | ||
| 2 | |||
| 3 | use MooseX::Declare; | ||
| 4 | |||
| 5 | class ETLp::Audit::Browser::Model::Job with | ||
| 6 | (ETLp::Role::Config, ETLp::Role::Schema, ETLp::Role::Audit, | ||
| 7 | ETLp::Role::Browser) { | ||
| 8 | use DateTime; | ||
| 9 | use DateTime::Format::Strptime; | ||
| 10 | |||
| 11 | method get_jobs(Maybe[Int] :$page?, Maybe[Str] :$section_name?, Maybe[Int] :$config_id?, Maybe[Int ]:$status_id?, Maybe[Str] :$minimum_date?, Maybe[Str] :$maximum_date?) { | ||
| 12 | my ($criteria, $jobs, $join); | ||
| 13 | |||
| 14 | my $strp = DateTime::Format::Strptime->new(pattern => '%d/%m/%Y'); | ||
| 15 | |||
| 16 | if ($section_name) { | ||
| 17 | $criteria->{'section_name'} = $section_name; | ||
| 18 | $join++; | ||
| 19 | } | ||
| 20 | |||
| 21 | if ($config_id) { | ||
| 22 | $criteria->{'config_id'} = $config_id; | ||
| 23 | $join++; | ||
| 24 | } | ||
| 25 | |||
| 26 | if ($status_id) { | ||
| 27 | $criteria->{'me.status_id'} = $status_id; | ||
| 28 | } | ||
| 29 | |||
| 30 | if ($minimum_date && $maximum_date) { | ||
| 31 | $criteria->{'me.date_created'} = { | ||
| 32 | '>=' => $self->db_time($strp->parse_datetime($minimum_date)), | ||
| 33 | '<' => $self->db_time($strp->parse_datetime($maximum_date)) | ||
| 34 | }; | ||
| 35 | } elsif ($minimum_date) { | ||
| 36 | $criteria->{'me.date_created'} = | ||
| 37 | {'>=' => $self->db_time($strp->parse_datetime($minimum_date)) | ||
| 38 | }; | ||
| 39 | } elsif ($maximum_date) { | ||
| 40 | $criteria->{'me.date_created'} = | ||
| 41 | {'<' => $self->db_time($strp->parse_datetime($maximum_date))}; | ||
| 42 | } | ||
| 43 | |||
| 44 | my $attributes = { | ||
| 45 | page => $page, | ||
| 46 | rows => $self->pagesize, | ||
| 47 | order_by => 'me.date_updated desc' | ||
| 48 | }; | ||
| 49 | |||
| 50 | if ($join) { | ||
| 51 | $attributes->{join} = 'section'; | ||
| 52 | } | ||
| 53 | |||
| 54 | $jobs = $self->EtlpJob()->search($criteria, $attributes); | ||
| 55 | |||
| 56 | return $jobs; | ||
| 57 | } | ||
| 58 | |||
| 59 | method get_config_list(Maybe[Str] $section_name?) { | ||
| 60 | my $criteria; | ||
| 61 | my $attributes = {order_by => 'config_name'}; | ||
| 62 | |||
| 63 | if ($section_name) { | ||
| 64 | $criteria->{section_name} = $section_name; | ||
| 65 | $attributes->{join} = 'etlp_section'; | ||
| 66 | } | ||
| 67 | |||
| 68 | return $self->EtlpConfiguration()->search($criteria, $attributes); | ||
| 69 | } | ||
| 70 | |||
| 71 | method get_section_list(Maybe[Int] $config_id?) { | ||
| 72 | my $attributes = { | ||
| 73 | select => 'section_name', | ||
| 74 | distinct => '1', | ||
| 75 | order_by => 'section_name', | ||
| 76 | }; | ||
| 77 | |||
| 78 | my $criteria; | ||
| 79 | |||
| 80 | if ($config_id) { | ||
| 81 | $criteria->{config_id} = $config_id; | ||
| 82 | } | ||
| 83 | |||
| 84 | return $self->EtlpSection()->search($criteria, $attributes); | ||
| 85 | } | ||
| 86 | |||
| 87 | method get_config_section_options(Maybe[Int] $config_id?) { | ||
| 88 | my $option_text = '<option value=""/>'; | ||
| 89 | my $criteria; | ||
| 90 | |||
| 91 | $criteria = {config_id => $config_id} if $config_id; | ||
| 92 | |||
| 93 | my $section_rs = | ||
| 94 | $self->EtlpSection()->search($criteria, {order_by => 'section_name',}); | ||
| 95 | |||
| 96 | while (my $section = $section_rs->next) { | ||
| 97 | $option_text .= | ||
| 98 | '<option value ="' | ||
| 99 | . $section->section_name . '">' | ||
| 100 | . $section->section_name | ||
| 101 | . '</option>'; | ||
| 102 | } | ||
| 103 | |||
| 104 | return $option_text; | ||
| 105 | } | ||
| 106 | |||
| 107 | method get_section_config_options(Maybe[Str] $section_name?) { | ||
| 108 | my $option_text = '<option value=""/>'; | ||
| 109 | my $criteria; | ||
| 110 | |||
| 111 | $criteria = {section_name => $section_name} if $section_name; | ||
| 112 | |||
| 113 | my $config_rs = $self->EtlppConfig->search( | ||
| 114 | $criteria, | ||
| 115 | { | ||
| 116 | join => 'sections', | ||
| 117 | order_by => 'config_name' | ||
| 118 | } | ||
| 119 | ); | ||
| 120 | |||
| 121 | while (my $config = $config_rs->next) { | ||
| 122 | $option_text .= | ||
| 123 | '<option value ="' | ||
| 124 | . $config->config_id . '">' | ||
| 125 | . $config->config_name | ||
| 126 | . '</option>'; | ||
| 127 | } | ||
| 128 | |||
| 129 | return $option_text; | ||
| 130 | |||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | =head1 NAME | ||
| 135 | |||
| 136 | ETLp::Audit::Browser::Model::Job - Model Class for interacting | ||
| 137 | with Runtime Process Audit Records | ||
| 138 | |||
| 139 | =head1 SYNOPSIS | ||
| 140 | |||
| 141 | use ETLp::Audit::Browser::Model::Job; | ||
| 142 | |||
| 143 | my $model = ETLp::Audit::Browser::Model::Job->new(); | ||
| 144 | my $jobs = $model->get_jobs(page => 3); | ||
| 145 | |||
| 146 | =head1 METHODS | ||
| 147 | |||
| 148 | =head2 get_jobs | ||
| 149 | |||
| 150 | Returns a resultset on the etlpp_job table. It will a page at | ||
| 151 | a time, and is ordered by date_updated descending | ||
| 152 | |||
| 153 | =head3 Parameters | ||
| 154 | |||
| 155 | All of the following parameters are optional: | ||
| 156 | |||
| 157 | * page. Integer. The page you wish to return. Defaults to one | ||
| 158 | * section_name. The section the job belongs to | ||
| 159 | * config_id. The configuration file that the section belongs to | ||
| 160 | * status_id. The status to filter the results by | ||
| 161 | * minimum_date. The earliest date that the job ran | ||
| 162 | * maximum_date. The latest data that the job ran | ||
| 163 | |||
| 164 | =head3 Returns | ||
| 165 | |||
| 166 | * A DBIx::Class resultset | ||
| 167 | |||
| 168 | =head2 get_config_list | ||
| 169 | |||
| 170 | Return a list of all configuration files | ||
| 171 | |||
| 172 | =head3 Parameters | ||
| 173 | |||
| 174 | * section_name. Optional. Will filter the configuration file to those | ||
| 175 | that have the section name | ||
| 176 | |||
| 177 | =head3 Returns | ||
| 178 | |||
| 179 | * DBIx::Class resultset | ||
| 180 | |||
| 181 | =head2 get_section_list | ||
| 182 | |||
| 183 | Get an alphabetical list of all sections. | ||
| 184 | |||
| 185 | =head3 Parameters | ||
| 186 | |||
| 187 | * config_id. Optional. The requests\ will filter on config_id if one | ||
| 188 | is supplied | ||
| 189 | |||
| 190 | =head3 Returns | ||
| 191 | |||
| 192 | * DBIx::Class resultset | ||
| 193 | |||
| 194 | =head2 get_config_section_options | ||
| 195 | |||
| 196 | Given a config id, construct an HTML option list comprisng of sections that | ||
| 197 | belong to the config | ||
| 198 | |||
| 199 | =head3 Parameters | ||
| 200 | |||
| 201 | * A config_id. | ||
| 202 | |||
| 203 | =head3 Returns | ||
| 204 | |||
| 205 | * A list of all sections that belong to the config_id as a string of | ||
| 206 | HTML <option> tags | ||
| 207 | |||
| 208 | =head2 get_section_config_options | ||
| 209 | |||
| 210 | Given a section, construct an HTML option list comprisng of sections that | ||
| 211 | belong to the config | ||
| 212 | |||
| 213 | =head3 Parameters | ||
| 214 | |||
| 215 | * A section name. | ||
| 216 | |||
| 217 | =head3 Returns | ||
| 218 | |||
| 219 | * A list of all configurations that have a section with the supplied | ||
| 220 | name as a string consisting of HTML <option> tages | ||
| 221 | |||
| 222 | =head1 LICENSE AND COPYRIGHT | ||
| 223 | |||
| 224 | Copyright 2010 Redbone Systems Ltd | ||
| 225 | |||
| 226 | This program is free software; you can redistribute it and/or modify it | ||
| 227 | under the terms of either: the GNU General Public License as published | ||
| 228 | by the Free Software Foundation; or the Artistic License. | ||
| 229 | |||
| 230 | The terms are in the LICENSE file that accompanies this application | ||
| 231 | |||
| 232 | =cut | ||
| 233 | |||
| 234 |