TT#111206 add mr1.0.3 openser.voicemail_spool DAO

Change-Id: Iec3bfd97e98a82f2633b2a184a2f677c5dd3ca2f
mr9.4.1
Rene Krenn 5 years ago
parent 57f323700e
commit 9c90f7998d

@ -0,0 +1,162 @@
package NGCP::BulkProcessor::Dao::mr103::openser::voicemail_spool;
use strict;
## no critic
use threads::shared;
use Locale::Recode qw();
use NGCP::BulkProcessor::Logging qw(
getlogger
);
use NGCP::BulkProcessor::ConnectorPool qw(
get_kamailio_db
);
use NGCP::BulkProcessor::SqlProcessor qw(
checktableinfo
copy_row
);
use NGCP::BulkProcessor::SqlRecord qw();
require Exporter;
our @ISA = qw(Exporter NGCP::BulkProcessor::SqlRecord);
our @EXPORT_OK = qw(
gettablename
check_table
source_findby_mailboxuser
);
my $tablename = 'voicemail_spool';
my $get_db = \&get_kamailio_db;
my $expected_fieldnames = [
'id',
'msgnum',
'dir',
'context',
'macrocontext',
'callerid',
'origtime',
'duration',
'mailboxuser',
'mailboxcontext',
'recording',
];
my $indexes = {};
sub new {
my $class = shift;
my $self = NGCP::BulkProcessor::SqlRecord->new($class,$get_db,
$tablename,$expected_fieldnames,$indexes);
copy_row($self,shift,$expected_fieldnames);
return $self;
}
sub buildrecords_fromrows {
my ($rows,$load_recursive) = @_;
my @records = ();
my $record;
if (defined $rows and ref $rows eq 'ARRAY') {
foreach my $row (@$rows) {
$record = __PACKAGE__->new($row);
# transformations go here ...
push @records,$record;
}
}
return \@records;
}
sub gettablename {
return $tablename;
}
sub check_table {
return checktableinfo(shift // $get_db,
__PACKAGE__,$tablename,
$expected_fieldnames,
$indexes);
}
sub source_new {
my $class = shift;
my $self = NGCP::BulkProcessor::SqlRecord->new_shared($class,shift,
$tablename,$expected_fieldnames,$indexes);
copy_row($self,shift,$expected_fieldnames);
return $self;
}
sub source_findby_mailboxuser {
my ($source_dbs,$mailboxuser) = @_;
my $source_db = $source_dbs->{openser_db};
check_table($source_db);
my $db = &$source_db();
my $table = $db->tableidentifier($tablename);
my $stmt = 'SELECT * FROM ' . $table . ' WHERE ' .
$db->columnidentifier('mailboxuser') . ' = ?';
my @params = ($mailboxuser);
my $rows = $db->db_get_all_arrayref($stmt,@params);
return source_buildrecords_fromrows($rows,$source_dbs);
}
sub source_buildrecords_fromrows {
my ($rows,$source_dbs) = @_;
my @records : shared = ();
my $record;
my $recoder = Locale::Recode->new( from => 'ISO-8859-1', to => 'UTF-8' );
if (defined $rows and ref $rows eq 'ARRAY') {
foreach my $row (@$rows) {
$record = __PACKAGE__->source_new($source_dbs->{openser_db},$row);
# transformations go here ...
foreach my $field (keys %$record) {
next if $field eq 'recording';
$record->{$field} = $recoder->recode($record->{$field}) if $record->{field};
}
push @records,$record;
}
}
return \@records;
}
1;

@ -19,6 +19,8 @@ use NGCP::BulkProcessor::SqlProcessor qw(
);
use NGCP::BulkProcessor::SqlRecord qw();
use NGCP::BulkProcessor::Dao::mr103::openser::voicemail_spool qw();
require Exporter;
our @ISA = qw(Exporter NGCP::BulkProcessor::SqlRecord);
our @EXPORT_OK = qw(
@ -113,6 +115,7 @@ sub source_buildrecords_fromrows {
# transformations go here ...
$record->{voicemail_spool} = NGCP::BulkProcessor::Dao::mr103::openser::voicemail_spool::source_findby_mailboxuser($source_dbs,$record->{username});
#delete $record->{domain_id};
#delete $record->{subscriber_id};
#delete $record->{id};

Loading…
Cancel
Save