use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.
the class AccountBalanceManagementSbb method handleRequest.
// ---------------------------- Helper Methods ----------------------------
private void handleRequest(CreditControlInfo ccInfo) {
if (tracer.isInfoEnabled()) {
tracer.info("[><] SID<" + ccInfo.getSessionId() + "> Handling Credit-Control-Request...");
}
if (bypass) {
if (tracer.isInfoEnabled()) {
tracer.info("[><] SID<" + ccInfo.getSessionId() + "> Bypassing Unit Reservation...");
}
ccInfo.setSuccess(true);
((DiameterChargingServer) sbbContext.getSbbLocalObject().getParent()).resumeOnCreditControlRequest(ccInfo);
} else {
DataSource ds = null;
try {
ds = getDatasource();
if (ccInfo.getRequestedAction() == RequestedActionType.DIRECT_DEBITING) {
ds.directDebitUnits(ccInfo);
} else {
ds.requestUnits(ccInfo);
}
} catch (Exception e) {
tracer.severe("[xx] Unable to obtain Datasource Child SBB", e);
}
}
}
use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.
the class AccountBalanceManagementSbb method getDatasource.
protected DataSource getDatasource() throws IllegalArgumentException, NullPointerException, SLEEException, CreateException {
ChildRelationExt cre = (ChildRelationExt) getDatasourceChildRelation();
SbbLocalObjectExt sbbLocalObject = cre.get(DATASOURCE_CHILD_NAME);
if (sbbLocalObject == null) {
sbbLocalObject = cre.create(DATASOURCE_CHILD_NAME);
}
return (DataSource) sbbLocalObject;
}
use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.
the class DiameterChargingServerSbb method getDatasource.
protected DataSource getDatasource() throws IllegalArgumentException, NullPointerException, SLEEException, CreateException {
ChildRelationExt cre = (ChildRelationExt) getDatasourceChildRelation();
SbbLocalObjectExt sbbLocalObject = cre.get(DATASOURCE_CHILD_NAME);
if (sbbLocalObject == null) {
sbbLocalObject = cre.create(DATASOURCE_CHILD_NAME);
}
return (DataSource) sbbLocalObject;
}
use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.
the class DiameterChargingServerSbb method onServiceStartedEvent.
// ---------------------------- Event Handlers ----------------------------
public void onServiceStartedEvent(ServiceStartedEvent event, ActivityContextInterface aci) {
if (tracer.isInfoEnabled()) {
tracer.info("==============================================================================");
tracer.info("== Mobicents Charging Server v1.0 [STARTED] ==");
tracer.info("== - . - ==");
tracer.info("== Thank you for running Mobicents Community code ==");
tracer.info("== For Commercial Grade Support, please request a TelScale Subscription ==");
tracer.info("== http://www.telestax.com/ ==");
tracer.info("==============================================================================");
}
DataSource ds;
try {
ds = getDatasource();
if (tracer.isInfoEnabled()) {
tracer.info("[><] Got DataSource Child SBB Local Interface [" + ds + "]");
}
ds.init();
} catch (Exception e) {
tracer.severe("[xx] Unable to fetch Datasource Child SBB .");
return;
}
AccountBalanceManagement am;
try {
am = getAccountManager();
if (tracer.isInfoEnabled()) {
tracer.info("[><] Got Account Balance Management Child SBB Local Interface [" + am + "]");
}
} catch (Exception e) {
tracer.severe("[xx] Unable to fetch Account and Balance Management Child SBB .");
return;
}
try {
Context ctx = (Context) new InitialContext().lookup("java:comp/env");
boolean loadUsersFromCSV = (Boolean) loadEnvEntry(ctx, "loadUsersFromCSV", false);
performRating = (Boolean) loadEnvEntry(ctx, "performRating", false);
generateCDR = (Boolean) loadEnvEntry(ctx, "generateCDR", false);
String abmfAVPsProp = (String) loadEnvEntry(ctx, "ABMF_AVPs", "");
try {
String[] avps = abmfAVPsProp.trim().split(",");
for (String avp : avps) {
String[] codeName = avp.trim().split("=");
if (tracer.isInfoEnabled()) {
tracer.info("[><] Mapping AVP with Code " + codeName[0] + " as '" + codeName[1] + "' on received CCRs for ABMF Data.");
}
abmfAVPs.put(codeName[0], codeName[1]);
}
} catch (Exception e) {
tracer.warning("[!!] Error reading ABMF Data AVPs. Format should be: code=name,code2=name2,... No custom data will be passed.");
}
if (loadUsersFromCSV) {
try {
Properties props = new Properties();
props.load(this.getClass().getClassLoader().getResourceAsStream("users.properties"));
for (Object key : props.keySet()) {
String msisdn = (String) key;
// am.addUser(imsi, Long.valueOf(props.getProperty(imsi)));
// TODO: remove the properties to database mapping later on. useful for now
ds.updateUser(msisdn, Long.valueOf(props.getProperty(msisdn)));
}
if (tracer.isInfoEnabled()) {
tracer.info("[--] Loaded users from properties file.");
}
} catch (Exception e) {
tracer.warning("[!!] Unable to load users from properties file. Allowing everything!");
am.setBypass(true);
} finally {
if (tracer.isFineEnabled()) {
tracer.fine("[--] Dumping users state...");
am.dump("%");
}
}
}
} catch (Exception e) {
tracer.warning("[!!] Unable to retrieve InitialContext. The env-entry properties were not loaded and defaults will be used.");
}
}
use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.
the class AccountBalanceManagementSbb method dump.
public void dump(String usersRegExp) {
if (tracer.isInfoEnabled()) {
DataSource ds = null;
try {
ds = getDatasource();
ds.getUserAccountData(usersRegExp);
} catch (Exception e) {
tracer.severe("[xx] Unable to obtain Datasource Child SBB", e);
}
}
}
Aggregations