TT#56100 add ${colnames} parameter for CSV_HEADER patterns

using the CSV_HEADER pattern parameter to print .csv-style
column names means to hardcode the columnnames in config.yml,
where they easily get out-of-sync with the actual configured
export_fields.

the new pattern parameter ${colnames} allows to print the
comma-separated list of the currently configured export_fields.

Change-Id: Iba4205584f2461e98357ced53b598520f838b5b2
mr11.2.1
Rene Krenn 3 years ago
parent c36782c0aa
commit 9191680732

@ -127,7 +127,7 @@ sub chownmod {
sub write_file {
my (
$lines, $dircomp, $prefix, $version, $ts, $lastseq, $suffix,
$format, $file_data, $csv_header, $csv_footer
$format, $file_data, $csv_header, $csv_footer, $colnames
) = @_;
my $fn = sprintf('%s/%s_%s_%s_%010i.%s', $dircomp, $prefix, $version, $ts, $lastseq, $suffix);
@ -143,6 +143,7 @@ sub write_file {
} else {
my $str =
apply_format($csv_header, {
colnames => join(',',@$colnames),
rows => $num,
lines => $num,
version => $version,
@ -169,6 +170,7 @@ sub write_file {
} else {
my $str =
apply_format($csv_footer, {
colnames => join(',',@$colnames),
rows => $num,
lines => $num,
version => $version,

@ -47,10 +47,13 @@ my $exporter_type = "exporter";
my $last_admin_field;
our @admin_fields;
our @admin_field_transformations;
our @admin_field_names;
our @reseller_fields;
our @reseller_field_transformations;
our @reseller_field_names;
our @data_fields;
our @data_field_transformations;
our @data_field_names;
my @joins;
my @conditions;
my $dbh;
@ -190,7 +193,7 @@ sub create_transformation_context {
}
sub get_export_fields {
my ($name,$transformations) = @_;
my ($name,$transformations,$colnames) = @_;
my @ret;
foreach my $f (config2array($name,1)) {
$f or next;
@ -201,6 +204,12 @@ sub get_export_fields {
$sql =~ s/^\'//;
$sql =~ s/\'$//;
push @ret, $sql;
push(@$colnames,$f->{name}) if (
not exists $f->{enable}
or (
length($f->{enable}) and 'yes' eq lc($f->{enable})
)
);
if ($transformations) {
if ($f->{code}) {
## no critic (BuiltinFunctions::ProhibitStringyEval)
@ -222,6 +231,7 @@ sub get_export_fields {
$f =~ s/^\'//;
$f =~ s/\'$//;
push @ret, $f;
push(@$colnames,$f);
if ($transformations) {
push(@$transformations,undef);
}
@ -339,11 +349,14 @@ sub prepare_config {
unless(-d $config{$stream . '.DESTDIR'});
@admin_field_transformations = ();
@admin_fields = get_export_fields('ADMIN_EXPORT_FIELDS',\@admin_field_transformations);
@admin_field_names = ();
@admin_fields = get_export_fields('ADMIN_EXPORT_FIELDS',\@admin_field_transformations,\@admin_field_names);
@reseller_field_transformations = ();
@reseller_fields = get_export_fields('RESELLER_EXPORT_FIELDS',\@reseller_field_transformations);
@reseller_field_names = ();
@reseller_fields = get_export_fields('RESELLER_EXPORT_FIELDS',\@reseller_field_transformations,\@reseller_field_names);
@data_field_transformations = ();
@data_fields = get_export_fields('DATA_FIELDS',\@data_field_transformations);
@data_field_names = ();
@data_fields = get_export_fields('DATA_FIELDS',\@data_field_transformations,\@data_field_names);
@joins = ();
foreach my $f (get_config_fields('EXPORT_JOINS')) {
@ -812,9 +825,13 @@ sub write_wrap {
($force == 1 && $rec_idx == 0) and return;
my $reseller_contract_id = "";
my $mark_query = undef;
my @colnames;
unless($reseller eq "system") {
$reseller_contract_id = "-".$reseller_ids{$reseller};
$mark_query = [ $reseller_ids{$reseller} ];
@colnames = @reseller_field_names;
} else {
@colnames = @admin_field_names;
}
if (!defined($mark{"lastseq".$reseller_contract_id})) {
my $tmpmark = NGCP::CDR::Export::get_mark($dbh,
@ -847,7 +864,7 @@ sub write_wrap {
\@filevals, $reseller_tempdir, confval('PREFIX'),
confval('VERSION'), $file_ts, $file_idx, confval('SUFFIX'),
confval('FILE_FORMAT') // 'default', $reseller_file_data{$reseller},
confval('CSV_HEADER'), confval('CSV_FOOTER')
confval('CSV_HEADER'), confval('CSV_FOOTER'), \@colnames
);
$rec_idx -= $recs;
delete($reseller_file_data{$reseller});

Loading…
Cancel
Save