Mercurial > pub > buggler
annotate lib/Benzin/Bugzilla/XmlWriter.pm @ 12:52b34ea50eff default tip
sync: work time projection doesn't seem to be working anyway
author | cin |
---|---|
date | Sun, 13 Sep 2015 19:37:16 +0300 |
parents | 4eb9fdf4efa9 |
children |
rev | line source |
---|---|
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
1 package Benzin::Bugzilla::XmlWriter; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
2 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
3 our %Transform = ( |
11 | 4 'Benzin::Bugzilla::Bug' => 'WriteBug', |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
5 'Benzin::Bugzilla::BugComment' => 'WriteBugComment', |
11 | 6 'HASH' => 'WriteHash', |
7 'DateTime' => 'WriteTJ3DateTime', | |
8 -plain => 'WriteValue', | |
9 -default => 'WriteValue' | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
10 ); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
11 |
12
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
12 use IMPL::lang qw(coarsen coarsen_dt is); |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
13 use IMPL::Const qw(:prop); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
14 use IMPL::declare { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
15 require => { |
11 | 16 XMLWriter => 'XML::Writer', |
17 Bug => 'Benzin::Bugzilla::Bug', | |
18 BugComment => 'Benzin::Bugzilla::BugComment', | |
12
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
19 Duration => 'DateTime::Duration', |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
20 }, |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
21 base => [ |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
22 'IMPL::Transform' => sub { %Transform } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
23 ], |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
24 props => [ |
11 | 25 _writer => PROP_RW, |
26 timereports => PROP_RW, | |
27 timeresolution => PROP_RW | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
28 ] |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
29 }; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
30 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
31 use fields qw(_writer); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
32 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
33 sub CTOR { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
34 my SELF $this = shift; |
11 | 35 |
36 $this->_writer( XMLWriter->new(@_) ); | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
37 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
38 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
39 sub WriteBugList { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
40 my SELF $this = shift; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
41 my $bugs = shift || []; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
42 my $writer = $this->_writer; |
11 | 43 |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
44 $writer->xmlDecl("UTF-8"); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
45 $writer->startTag("bugzilla"); |
11 | 46 |
12
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
47 my %timesheets; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
48 |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
49 foreach my $bug (@$bugs) { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
50 $writer->startTag("bug"); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
51 $this->WriteBug($bug); |
12
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
52 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
53 if ( $this->timereports ) { |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
54 my $time = $bug->GetTimeReports( $this->timeresolution ); |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
55 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
56 my $prevReportDate = $bug->{creation_time}; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
57 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
58 foreach my $item ( @{ $time->{report} || [] } ) { |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
59 $timesheets{ $item->{who} }{bugs}{ $bug->{id} }{work} += |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
60 $item->{work_time}; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
61 $timesheets{ $item->{who} }{bugs}{ $bug->{id} }{remaining} = |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
62 $time->{remaining}; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
63 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
64 $timesheets{ $item->{who} }{start} = $prevReportDate |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
65 unless $timesheets{ $item->{who} }{start} |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
66 and $timesheets{ $item->{who} }{start} <= $prevReportDate; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
67 $timesheets{ $item->{who} }{end} = $item->{when} |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
68 unless $timesheets{ $item->{who} }{end} |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
69 and $timesheets{ $item->{who} }{end} >= $item->{when}; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
70 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
71 $prevReportDate = $item->{when}; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
72 } |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
73 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
74 $this->WriteElement( 'time', $time ); |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
75 } |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
76 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
77 $writer->endTag(); |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
78 } |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
79 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
80 while ( my ( $who, $sheet ) = each %timesheets ) { |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
81 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
82 $writer->startTag( |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
83 'timesheet', |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
84 resource => $who, |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
85 start => $this->FormatTJ3DateTime( $sheet->{start} ), |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
86 end => $this->FormatTJ3DateTime( $sheet->{end} ) |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
87 ); |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
88 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
89 while ( my ( $bug, $info ) = each %{ $sheet->{bugs} } ) { |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
90 $writer->startTag( 'bug', id => $bug ); |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
91 $this->WriteElement( 'work', $info->{work} ); |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
92 $this->WriteElement( 'remaining', $info->{remaining} ); |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
93 $writer->endTag(); |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
94 } |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
95 |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
96 $writer->endTag(); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
97 } |
11 | 98 |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
99 $writer->endTag(); |
11 | 100 |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
101 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
102 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
103 sub WriteBug { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
104 my SELF $this = shift; |
11 | 105 my $value = shift; |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
106 my $writer = $this->_writer; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
107 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
108 foreach my $field ( @{ Bug->BUG_FIELDS } ) { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
109 next unless $value->{$field}; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
110 $this->WriteElement( $field, $value->{$field} ); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
111 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
112 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
113 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
114 sub WriteBugComment { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
115 my SELF $this = shift; |
11 | 116 my $value = shift; |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
117 my $writer = $this->_writer; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
118 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
119 foreach my $field ( @{ BugComment->COMMENT_FIELDS } ) { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
120 next unless $value->{$field}; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
121 $this->WriteElement( $field, $value->{$field} ); |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
122 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
123 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
124 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
125 sub WriteHash { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
126 my SELF $this = shift; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
127 my $value = shift; |
11 | 128 |
129 while ( my ( $k, $v ) = each %$value ) { | |
130 $this->WriteElement( $k, $v ); | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
131 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
132 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
133 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
134 sub WriteElement { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
135 my SELF $this = shift; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
136 my ( $name, $data ) = @_; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
137 my $writer = $this->_writer; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
138 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
139 my @values = |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
140 ref($data) |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
141 && ref($data) eq 'ARRAY' |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
142 ? @{$data} |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
143 : $data; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
144 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
145 foreach my $v (@values) { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
146 $writer->startTag($name); |
11 | 147 $this->Transform($v); |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
148 $writer->endTag; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
149 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
150 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
151 |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
152 sub WriteValue { |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
153 my SELF $this = shift; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
154 my $value = shift; |
11 | 155 |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
156 $this->_writer->characters($value) if defined $value; |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
157 } |
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
158 |
11 | 159 sub WriteTJ3DateTime { |
160 my SELF $this = shift; | |
12
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
161 my $value = shift; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
162 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
163 $this->_writer->characters( $this->FormatTJ3DateTime($value) ) |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
164 if defined $value; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
165 } |
11 | 166 |
12
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
167 sub FormatTJ3DateTime { |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
168 my SELF $this = shift; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
169 my $value = shift; |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
170 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
171 my $duration = |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
172 is( $this->timeresolution, Duration ) |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
173 ? $this->timeresolution |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
174 : Duration->new( %{ $this->timeresolution } ); |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
175 |
52b34ea50eff
sync: work time projection doesn't seem to be working anyway
cin
parents:
11
diff
changeset
|
176 return coarsen_dt( $value, $duration )->strftime('%F-%T'); |
11 | 177 } |
178 | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff
changeset
|
179 1; |