use of org.mobicents.smsc.library.DbSmsRoutingRule in project smscgateway by RestComm.
the class DBOperations method c2_getSipSmsRoutingRule.
/**
* Returns SIP Cluster name for passed address. If not found returns null
*
* @param address
* @return
* @throws PersistenceException
*/
public DbSmsRoutingRule c2_getSipSmsRoutingRule(final String address, int networkId) throws PersistenceException {
try {
BoundStatement boundStatement = new BoundStatement(getSipSmsRoutingRule);
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.SIP, address, networkId, name);
return res;
}
} catch (Exception e) {
String msg = "Failed to getSipSmsRoutingRule for address=" + address + " networkId=" + networkId + " !";
throw new PersistenceException(msg, e);
}
}
use of org.mobicents.smsc.library.DbSmsRoutingRule in project smscgateway by RestComm.
the class DBOperations method c2_getSipSmsRoutingRulesRange.
/**
* Returns 100 rows of SIP_SMS_ROUTING_RULE starting from passed lastAdress. If lastAdress, first 100 rows are returned
*
* @param lastAdress
* @return
* @throws PersistenceException
*/
public List<DbSmsRoutingRule> c2_getSipSmsRoutingRulesRange(String lastAdress) throws PersistenceException {
List<DbSmsRoutingRule> ress = new FastList<DbSmsRoutingRule>();
try {
PreparedStatement ps = lastAdress != null ? getSipSmsRoutingRulesRange : getSipSmsRoutingRulesRange2;
BoundStatement boundStatement = new BoundStatement(ps);
if (lastAdress != null) {
boundStatement.bind(lastAdress);
}
ResultSet result = session.execute(boundStatement);
int i1 = 0;
for (Row row : result) {
String address = row.getString(Schema.COLUMN_ADDRESS);
String name = row.getString(Schema.COLUMN_CLUSTER_NAME);
int networkId = row.getInt(Schema.COLUMN_NETWORK_ID);
DbSmsRoutingRule res = new DbSmsRoutingRule(SmsRoutingRuleType.SIP, address, networkId, name);
if (i1 == 0) {
i1 = 1;
if (lastAdress == null)
ress.add(res);
} else {
ress.add(res);
}
}
return ress;
} catch (Exception e) {
String msg = "Failed to getSmsRoutingRule DbSmsRoutingRule for all records: " + e;
throw new PersistenceException(msg, e);
}
}
use of org.mobicents.smsc.library.DbSmsRoutingRule in project smscgateway by RestComm.
the class 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");
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(rl2.getAddress(), "2222");
assertEquals(rl2.getClusterName(), "BBB");
List<DbSmsRoutingRule> lst = this.sbb.c2_getSmppSmsRoutingRulesRange();
assertEquals(lst.size(), 2);
DbSmsRoutingRule rl = lst.get(0);
assertEquals(rl.getAddress(), "1111");
assertEquals(rl.getClusterName(), "AAA");
rl = lst.get(1);
assertEquals(rl2.getAddress(), "2222");
assertEquals(rl2.getClusterName(), "BBB");
lst = this.sbb.c2_getSmppSmsRoutingRulesRange("1111");
assertEquals(lst.size(), 1);
rl = lst.get(0);
assertEquals(rl2.getAddress(), "2222");
assertEquals(rl2.getClusterName(), "BBB");
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 DatabaseSmsRoutingRule method updateDbSmsRoutingRule.
@Override
public void updateDbSmsRoutingRule(String dbSmsRoutingRuleTypeStr, String address, int networkId, String clusterName) throws PersistenceException {
SmsRoutingRuleType dbSmsRoutingRuleType = SmsRoutingRuleType.valueOf(dbSmsRoutingRuleTypeStr);
DbSmsRoutingRule dbSmsRoutingRule = new DbSmsRoutingRule(dbSmsRoutingRuleType, address, networkId, clusterName);
switch(dbSmsRoutingRuleType) {
case SMPP:
dbOperations_C2.c2_updateSmppSmsRoutingRule(dbSmsRoutingRule);
break;
case SIP:
dbOperations_C2.c2_updateSipSmsRoutingRule(dbSmsRoutingRule);
break;
default:
throw new PersistenceException("Unknown DbSmsRoutingRuleType=" + dbSmsRoutingRuleType);
}
// }
}
use of org.mobicents.smsc.library.DbSmsRoutingRule in project smscgateway by RestComm.
the class DatabaseSmsRoutingRule method getEsmeClusterName.
/*
* (non-Javadoc)
*
* @see org.mobicents.smsc.smpp.SmsRoutingRule#getSystemId(byte, byte, java.lang.String)
*/
@Override
public String getEsmeClusterName(int ton, int npi, String address, String name, int networkId) {
String clusterName = null;
if (!dbOperations_C2.isDatabaseAvailable())
return null;
try {
DbSmsRoutingRule rr;
// if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
// rr = dbOperations_C1.getSmsRoutingRule(address, networkId);
// } else {
rr = dbOperations_C2.c2_getSmppSmsRoutingRule(address, networkId);
// }
if (rr != null) {
clusterName = rr.getClusterName();
} else {
if (smscPropertiesManagement == null)
smscPropertiesManagement = SmscPropertiesManagement.getInstance();
if (smscPropertiesManagement != null) {
String dcn = smscPropertiesManagement.getEsmeDefaultClusterName();
if (dcn != null) {
if (esmeManagement.getEsmeByClusterName(dcn) != null) {
clusterName = dcn;
}
}
}
}
} catch (PersistenceException e) {
logger.error("PersistenceException while selecting from table SmsRoutingRule", e);
}
return clusterName;
}
Aggregations