-2
I have a Java function where I weigh a phone number and it returns me which trunk the call will exit according to the regular expression that is saved in database in a column called "exten_discador
".
If this query of mine can get n results, with it I will have to use an array storing $array[operadora] = id_tronco
.
Should my code enter the if
I need to see which operator was obtained from the database and search the id_tronco
array.
Example:
------------------------------------------------------------------------
exten_discador id_tronco Operadora
'^(00\d{2}[7-9]\d{7,8})$' 1 GVT
'^(00\d{2}[7-9]\d{7,8})$' 87 NET
---------------------------------------------------------------------------
My validation of the expression exten_discador
is working ok, my problem and time to store in an array the carrier with stem value:
$array[operadora] = id_tronco
.
Here is my code:
public Integer getTroncoChamada(String numero) throws SQLException {
Integer retorno = null;
String sqlExten = "SELECT "
+ " r.id_rota,"
+ " r.rota,"
+ " reo.exten_discador,"
+ " reot.remove_left,"
+ " reot.remove_right,"
+ " reot.add_left,"
+ " reot.add_right,"
+ " reot.operadora,"
+ " reot.prioridade,"
+ " t.id_tronco,"
+ " t.tronco,"
+ " t.dial"
+ " FROM asterisk.rota r"
+ " LEFT JOIN asterisk.rota_exten_out reo ON (r.id_rota = reo.id_rota)"
+ " LEFT JOIN asterisk.rota_exten_out_tronco reot ON (reo.id_rota_exten_out = reot.id_rota_exten_out)"
+ " LEFT JOIN asterisk.tronco t ON (t.id_tronco = reot.id_tronco)"
+ " WHERE r.habilitar = 1"
+ " AND reot.datahora_fim is null"
+ " AND reo.exten_discador is not null"
+ " AND t.habilitar = 1"
+ " AND r.tipo_rota = 'OUT' ";
PreparedStatement psExten = connection.prepareStatement(sqlExten);
ResultSet rsExten = psExten.executeQuery();
String exten_discador;
int i = 1;
int[] id_tronco = null;
String operadora;
String operadora_numero;
Integer prioridade = 0;
while (rsExten.next()) {
exten_discador = rsExten.getString("exten_discador");
id_tronco[Integer.parseInt(rsExten.getString("operadora"))] = rsExten.getInt("id_tronco"); /* PROBLEM */
if(numero.trim().matches(exten_discador)){
if(i>1){
operadora_numero = "GVT";
operadora = "^"+rsExten.getString("operadora")+"$";
prioridade = rsExten.getInt("prioridade");
if(operadora_numero.trim().matches(operadora)){
retorno = id_tronco[Integer.parseInt(rsExten.getString("operadora"))]; **/* PROBLEM */**
}
}else{
retorno = rsExten.getInt("id_tronco");
i++;
}
}
}
Excellent, thank you very much!
– Rafael Calino