<commit_before>-- Gemeinschaft 5 routing test module
-- (c) AMOOMA GmbH 2013
--

require 'common.array';

local arguments = {};
local value = nil;

for index=1, #argv do
  if math.mod(index, 2) == 0 then
    common.array.set(arguments, argv[index], value);
  else
    value = argv[index];
  end
end

local caller = arguments.caller or {};
local channel_variables = arguments.chv or {};

function caller.to_s(variable)
  return common.str.to_s(arguments[variable])
end

-- initialize logging
require 'common.log';
log = common.log.Log:new{ disabled = true };

-- connect to database
require 'common.database';
local database = common.database.Database:new{ log = log }:connect();
if not database:connected() then
  log:critical('TEST_ROUTE - database connection failed');
  return;
end

-- dialplan object
require 'dialplan.dialplan'
local dialplan_object = dialplan.dialplan.Dialplan:new{ log = log, caller = caller, database = database };
dialplan_object:configuration_read();
caller.dialplan = dialplan_object;
caller.local_node_id = dialplan_object.node_id;

dialplan_object:retrieve_caller_data();

require 'dialplan.router';
local routes =  dialplan.router.Router:new{ log = log, database = database, caller = caller, variables = caller }:route_run(arguments.table or 'outbound');

local result = {
  routes = routes
}

stream:write(common.array.to_json(result));

-- release database handle
if database then
  database:release();
end
<commit_msg>retrieve destination and caller_id_numbers<commit_after>-- Gemeinschaft 5 routing test module
-- (c) AMOOMA GmbH 2013
--

require 'common.array';

local arguments = {};
local value = nil;

for index=1, #argv do
  if math.mod(index, 2) == 0 then
    common.array.set(arguments, argv[index], value);
  else
    value = argv[index];
  end
end

local caller = arguments.caller or {};
local channel_variables = arguments.chv or {};

function caller.to_s(variable)
  return common.str.to_s(arguments[variable])
end

local log_buffer = {};
-- initialize logging
require 'common.log';
log = common.log.Log:new{ buffer = log_buffer, prefix = '' };

-- connect to database
require 'common.database';
local database = common.database.Database:new{ log = log }:connect();
if not database:connected() then
  log:critical('TEST_ROUTE - database connection failed');
  return;
end

-- dialplan object
require 'dialplan.dialplan'
local dialplan_object = dialplan.dialplan.Dialplan:new{ log = log, caller = caller, database = database };
dialplan_object:configuration_read();
caller.dialplan = dialplan_object;
caller.local_node_id = dialplan_object.node_id;

dialplan_object:retrieve_caller_data();
local destination = arguments.destination or dialplan_object:destination_new{ number = caller.destination_number };
local routes = {};

if destination.type == 'unknown' then
  local clip_no_screening = common.array.try(caller, 'account.record.clip_no_screening');
  caller.caller_id_numbers = {}
  if not common.str.blank(clip_no_screening) then
    for index, number in ipairs(common.str.strip_to_a(clip_no_screening, ',')) do
      table.insert(caller.caller_id_numbers, number);
    end
  end
  if caller.caller_phone_numbers then
    for index, number in ipairs(caller.caller_phone_numbers) do
      table.insert(caller.caller_id_numbers, number);
    end
  end
  log:info('CALLER_ID_NUMBERS - clir: ', caller.clir, ', numbers: ', table.concat(caller.caller_id_numbers, ','));

  destination.callee_id_number = destination.number;
  destination.callee_id_name = nil;

  require 'dialplan.router';
  routes =  dialplan.router.Router:new{ log = log, database = database, caller = caller, variables = caller, log_details = true }:route_run(arguments.table or 'outbound');
end

local result = {
  routes = routes,
  destination = destination,
  log = log_buffer
}

stream:write(common.array.to_json(result));

-- release database handle
if database then
  database:release();
end

{'fraction_non_alphanumeric': 0.11877394636015326, 'fraction_numerical': 0.004086845466155811, 'mean_word_length': 4.98776758409786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3090437', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1227, 'n_words': 314}