use of org.mobicents.charging.server.account.AccountBalanceManagement in project charging-server by RestComm.
the class DiameterChargingServerSbb method getAccountManager.
protected AccountBalanceManagement getAccountManager() throws IllegalArgumentException, NullPointerException, SLEEException, CreateException {
ChildRelationExt cre = (ChildRelationExt) getAccountBalanceManagementChildRelation();
SbbLocalObjectExt sbbLocalObject = cre.get(ABMF_CHILD_NAME);
if (sbbLocalObject == null) {
sbbLocalObject = cre.create(ABMF_CHILD_NAME);
}
return (AccountBalanceManagement) sbbLocalObject;
}
use of org.mobicents.charging.server.account.AccountBalanceManagement 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.");
}
}
Aggregations