use of org.mobicents.smsc.library.DbSmsRoutingRule in project smscgateway by RestComm.
the class DatabaseSmsRoutingRule method getSipClusterName.
@Override
public String getSipClusterName(int ton, int npi, String address, int networkId) {
String clusterName = null;
if (!dbOperations_C2.isDatabaseAvailable())
return null;
try {
DbSmsRoutingRule rr;
// if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
// return null;
// }
rr = dbOperations_C2.c2_getSipSmsRoutingRule(address, networkId);
if (rr != null) {
clusterName = rr.getClusterName();
}
} catch (PersistenceException e) {
logger.error("PersistenceException while selecting from table SmsRoutingRule", e);
}
return clusterName;
}
use of org.mobicents.smsc.library.DbSmsRoutingRule in project smscgateway by RestComm.
the class SMSCShellExecutor method databaseRuleGetRange.
/**
* smsc databaseRule getRange <SMPP|SIP> <address> or smsc databaseRule getRange <SMPP|SIP>
*
* @param args
* @return
*/
private String databaseRuleGetRange(String[] args) throws Exception {
DatabaseSmsRoutingRule smsRoutingRule = (DatabaseSmsRoutingRule) this.smscManagement.getSmsRoutingRule();
if (args.length < 4 || args.length > 5) {
return SMSCOAMMessages.INVALID_COMMAND;
}
String smsRoutingRuleType = args[3];
if (smsRoutingRuleType == null) {
return SMSCOAMMessages.INVALID_COMMAND;
}
String address = null;
if (args.length == 5) {
address = args[4];
if (address == null) {
return SMSCOAMMessages.INVALID_COMMAND;
}
}
List<DbSmsRoutingRule> res = smsRoutingRule.getSmsRoutingRulesRange(smsRoutingRuleType, address);
StringBuilder sb = new StringBuilder();
int i1 = 0;
for (DbSmsRoutingRule rr : res) {
if (i1 == 0)
i1 = 1;
else
sb.append("\n");
sb.append(rr.toString());
}
return sb.toString();
}
use of org.mobicents.smsc.library.DbSmsRoutingRule in project smscgateway by RestComm.
the class SMSCShellExecutor method databaseRuleGet.
/**
* smsc databaseRule get <address> <SMPP|SIP> networkid <network-id>
*
* @param args
* @return
*/
private String databaseRuleGet(String[] args) throws Exception {
DatabaseSmsRoutingRule smsRoutingRule = (DatabaseSmsRoutingRule) this.smscManagement.getSmsRoutingRule();
if (args.length < 4 || args.length > 7) {
return SMSCOAMMessages.INVALID_COMMAND;
}
String address = args[3];
if (address == null) {
return SMSCOAMMessages.INVALID_COMMAND;
}
int count = 4;
String command;
String smsRoutingRuleType = "SMPP";
int networkId = 0;
while (count < args.length && ((command = args[count++]) != null)) {
if (command.equals("SMPP") || command.equals("SIP")) {
smsRoutingRuleType = command;
} else if (command.equals("networkid")) {
if (count < args.length) {
String value = args[count++];
networkId = Integer.parseInt(value);
}
}
}
// while
DbSmsRoutingRule res = smsRoutingRule.getSmsRoutingRule(smsRoutingRuleType, address, networkId);
if (res == null) {
return String.format(SMSCOAMMessages.NO_ROUTING_RULE_DEFINED_YET, smsRoutingRuleType, address, networkId);
}
return res.toString();
}
use of org.mobicents.smsc.library.DbSmsRoutingRule in project smscgateway by RestComm.
the class TT_DbSmsRoutingRuleTest method testingDbSmsRoutingRule.
@Test(groups = { "cassandra" })
public void testingDbSmsRoutingRule() throws Exception {
if (!this.cassandraDbInited)
return;
this.clearDatabase();
DbSmsRoutingRule rl1 = this.sbb.c2_getSmppSmsRoutingRule("1111", 0);
DbSmsRoutingRule rl2 = this.sbb.c2_getSmppSmsRoutingRule("2222", 2);
assertNull(rl1);
assertNull(rl2);
DbSmsRoutingRule rla = new DbSmsRoutingRule(SmsRoutingRuleType.SMPP, "1111", 0, "AAA");
this.sbb.c2_updateSmppSmsRoutingRule(rla);
rl1 = this.sbb.c2_getSmppSmsRoutingRule("1111", 0);
rl2 = this.sbb.c2_getSmppSmsRoutingRule("2222", 2);
assertNotNull(rl1);
assertNull(rl2);
assertEquals(rl1.getAddress(), "1111");
assertEquals(rl1.getClusterName(), "AAA");
assertEquals(rl1.getNetworkId(), 0);
rla = new DbSmsRoutingRule(SmsRoutingRuleType.SMPP, "2222", 2, "BBB");
this.sbb.c2_updateSmppSmsRoutingRule(rla);
rl1 = this.sbb.c2_getSmppSmsRoutingRule("1111", 0);
rl2 = this.sbb.c2_getSmppSmsRoutingRule("2222", 2);
assertNotNull(rl1);
assertNotNull(rl2);
assertEquals(rl1.getAddress(), "1111");
assertEquals(rl1.getClusterName(), "AAA");
assertEquals(rl1.getNetworkId(), 0);
assertEquals(rl2.getAddress(), "2222");
assertEquals(rl2.getClusterName(), "BBB");
assertEquals(rl2.getNetworkId(), 2);
List<DbSmsRoutingRule> lst = this.sbb.c2_getSmppSmsRoutingRulesRange();
assertEquals(lst.size(), 2);
DbSmsRoutingRule rl = lst.get(0);
assertEquals(rl.getAddress(), "1111");
assertEquals(rl.getClusterName(), "AAA");
assertEquals(rl.getNetworkId(), 0);
rl = lst.get(1);
assertEquals(rl2.getAddress(), "2222");
assertEquals(rl2.getClusterName(), "BBB");
assertEquals(rl2.getNetworkId(), 2);
lst = this.sbb.c2_getSmppSmsRoutingRulesRange("1111");
assertEquals(lst.size(), 1);
rl = lst.get(0);
assertEquals(rl2.getAddress(), "2222");
assertEquals(rl2.getClusterName(), "BBB");
assertEquals(rl2.getNetworkId(), 2);
lst = this.sbb.c2_getSmppSmsRoutingRulesRange("2222");
assertEquals(lst.size(), 0);
this.sbb.c2_deleteSmppSmsRoutingRule("1111", 0);
rl1 = this.sbb.c2_getSmppSmsRoutingRule("1111", 0);
rl2 = this.sbb.c2_getSmppSmsRoutingRule("2222", 2);
assertNull(rl1);
assertNotNull(rl2);
assertEquals(rl2.getAddress(), "2222");
assertEquals(rl2.getClusterName(), "BBB");
}
use of org.mobicents.smsc.library.DbSmsRoutingRule in project smscgateway by RestComm.
the class DBOperations method c2_getSmppSmsRoutingRule.
/**
* Returns the SMPP Cluster name for passed address. If not found returns null
*
* @param address
* @return
* @throws PersistenceException
*/
public DbSmsRoutingRule c2_getSmppSmsRoutingRule(final String address, int networkId) throws PersistenceException {
try {
BoundStatement boundStatement = new BoundStatement(getSmppSmsRoutingRule);
boundStatement.bind(address, networkId);
ResultSet result = session.execute(boundStatement);
Row row = result.one();
if (row == null) {
return null;
} else {
String name = row.getString(Schema.COLUMN_CLUSTER_NAME);
DbSmsRoutingRule res = new DbSmsRoutingRule(SmsRoutingRuleType.SMPP, address, networkId, name);
return res;
}
} catch (Exception e) {
String msg = "Failed to getSmppSmsRoutingRule for address=" + address + " networkId=" + networkId + " !";
throw new PersistenceException(msg, e);
}
}
Aggregations