ETLp/Audit/Item.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 61 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package ETLp::Audit::Item;
2  
3 use MooseX::Declare;
4  
5 =head1 NAME
6  
7 ETLp::Audit::Item - audit the execution of an ETLp job
8  
9 =head1 DESCRIPTION
10  
11 This class is used to manage an individual audit item
12  
13 =cut
14  
15 class ETLp::Audit::Item with (ETLp::Role::Config, ETLp::Role::Schema,
16 ETLp::Role::Audit) {
17  
18 use DateTime;
19 use Try::Tiny;
20 use ETLp::Types;
21 use ETLp::Audit::FileProcess;
22 use DateTime;
23
24 has 'job' =>
25 (is => 'ro', isa => 'ETLp::Audit::Job', required => 1, weak_ref => 1);
26 has 'name' => (is => 'ro', isa => 'Str', required => 1);
27 has 'phase' => (is => 'ro', isa => 'Str', required => 1);
28 has 'type' => (is => 'ro', isa => 'Str', required => 1);
29 has 'config' => (is => 'ro', isa => 'HashRef', required => 1);
30
31 method id {
32 return $self->{id};
33 }
34
35 =head2 update_message
36  
37 Sets the item message
38  
39 =cut
40  
41 method update_message(Str $message) {
42 my $item = $self->EtlpItem()->find($self->id);
43 $item->message($message);
44 $self->update($item, $self->now);
45 }
46
47 =head2 update_status
48  
49 Sets the status of the item
50  
51 =cut
52
53 method update_status(Str $status_name) {
54 my $item = $self->EtlpItem()->find($self->id);
55 $item->status_id($self->get_status_id($status_name));
56 $self->update($item, $self->now);
57 }
58
59 =head2 update
60  
61 Saves the supplied item to the database
62  
63 =cut
64  
65 method update(ETLp::Schema::Result::EtlpItem $item,
66 DateTime $date) {
67 $item->date_updated($date);
68 my $job = $self->EtlpJob->find($self->job->id);
69 try {
70 $self->schema->txn_do(
71 sub {
72 $item->update;
73 $self->job->update($job, $date);
74 }
75 )
76 }
77 catch {
78 $self->logger->logdie("Cannot update job item record: $_");
79 };
80 }
81
82 =head2 create_file_process
83  
84 Create a file process audit object
85  
86 =cut
87  
88 method create_file_process(Str $filename) {
89 my $file_process = ETLp::Audit::FileProcess->new(
90 filename => $filename,
91 item => $self,
92 config => $self->config,
93 );
94 $self->{file_process} = $file_process;
95 return $file_process;
96 }
97  
98 =head2 file_process
99  
100 Returns the file_process audit object
101  
102 =cut
103  
104 method file_process {
105 return $self->{file_process};
106 }
107
108 # Create a new item record
109 method _create {
110 my $now = $self->now;
111
112 try {
113 $self->schema->txn_do(
114 sub {
115 my $process_item = $self->EtlpItem()->create(
116 {
117 item_type => $self->type,
118 phase_id => $self->get_phase_id($self->phase),
119 status_id => $self->get_status_id('running'),
120 job_id => $self->job->id,
121 item_name => $self->name,
122 date_created => $now,
123 date_updated => $now,
124 }
125 );
126
127 $self->{id} = $process_item->item_id;
128 }
129 );
130 }
131 catch {
132 $self->logger->logdie("Cannot create job item record: $_");
133 };
134 }
135
136 # These attributes cannot be updated
137 method _protected_attributes {
138 return [qw/item_id job_id phase_id type_id date_created date_updated/];
139 }
140
141 method BUILD {
142 $self->_create;
143 }
144
145 }
146
147 =head1 LICENSE AND COPYRIGHT
148  
149 Copyright 2010 Redbone Systems Ltd
150  
151 This program is free software; you can redistribute it and/or modify it
152 under the terms of either: the GNU General Public License as published
153 by the Free Software Foundation; or the Artistic License.
154  
155 The terms are in the LICENSE file that accompanies this application
156  
157 =cut
158  
159 1;