Adding LoadAll method to loader so we can compress the code from Apier

This commit is contained in:
DanB
2013-11-24 19:20:35 +01:00
parent fcb98adcf7
commit 5ff600fe18
4 changed files with 77 additions and 45 deletions

View File

@@ -120,44 +120,7 @@ func main() {
}
loader = engine.NewFileCSVReader(dataDb, ',', utils.DESTINATIONS_CSV, utils.TIMINGS_CSV, utils.RATES_CSV, utils.DESTINATION_RATES_CSV, utils.RATING_PLANS_CSV, utils.RATING_PROFILES_CSV, utils.ACTIONS_CSV, utils.ACTION_TIMINGS_CSV, utils.ACTION_TRIGGERS_CSV, utils.ACCOUNT_ACTIONS_CSV)
}
// ToDo: put these methods in loader package so we can properly test loads
err = loader.LoadDestinations()
if err != nil {
log.Fatal(err)
}
err = loader.LoadTimings()
if err != nil {
log.Fatal(err)
}
err = loader.LoadRates()
if err != nil {
log.Fatal(err)
}
err = loader.LoadDestinationRates()
if err != nil {
log.Fatal(err)
}
err = loader.LoadRatingPlans()
if err != nil {
log.Fatal(err)
}
err = loader.LoadRatingProfiles()
if err != nil {
log.Fatal(err)
}
err = loader.LoadActions()
if err != nil {
log.Fatal(err)
}
err = loader.LoadActionTimings()
if err != nil {
log.Fatal(err)
}
err = loader.LoadActionTriggers()
if err != nil {
log.Fatal(err)
}
err = loader.LoadAccountActions()
err = loader.LoadAll()
if err != nil {
log.Fatal(err)
}

View File

@@ -542,6 +542,42 @@ func (csvr *CSVReader) LoadAccountActions() (err error) {
return nil
}
// Automated loading
func (csvr *CSVReader) LoadAll() error {
var err error
if err = csvr.LoadDestinations(); err != nil {
return err
}
if err = csvr.LoadTimings(); err != nil {
return err
}
if err = csvr.LoadRates(); err != nil {
return err
}
if err = csvr.LoadDestinationRates(); err != nil {
return err
}
if err = csvr.LoadRatingPlans(); err != nil {
return err
}
if err = csvr.LoadRatingPlans(); err != nil {
return err
}
if err = csvr.LoadActions(); err != nil {
return err
}
if err = csvr.LoadActionTimings(); err != nil {
return err
}
if err = csvr.LoadActionTriggers(); err != nil {
return err
}
if err = csvr.LoadAccountActions(); err != nil {
return err
}
return nil
}
// Returns the identities loaded for a specific category, useful for cache reloads
func (csvr *CSVReader) GetLoadedIds(categ string) ([]string, error) {
switch categ {
@@ -570,3 +606,4 @@ func (csvr *CSVReader) GetLoadedIds(categ string) ([]string, error) {
}
return nil, errors.New("Unsupported category")
}

View File

@@ -606,6 +606,42 @@ func (dbr *DbReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions)
return nil
}
// Automated loading
func (dbr *DbReader) LoadAll() error {
var err error
if err = dbr.LoadDestinations(); err != nil {
return err
}
if err = dbr.LoadTimings(); err != nil {
return err
}
if err = dbr.LoadRates(); err != nil {
return err
}
if err = dbr.LoadDestinationRates(); err != nil {
return err
}
if err = dbr.LoadRatingPlans(); err != nil {
return err
}
if err = dbr.LoadRatingPlans(); err != nil {
return err
}
if err = dbr.LoadActions(); err != nil {
return err
}
if err = dbr.LoadActionTimings(); err != nil {
return err
}
if err = dbr.LoadActionTriggers(); err != nil {
return err
}
if err = dbr.LoadAccountActions(); err != nil {
return err
}
return nil
}
// Returns the identities loaded for a specific entity category
func (dbr *DbReader) GetLoadedIds(categ string) ([]string, error) {
switch categ {
@@ -634,3 +670,5 @@ func (dbr *DbReader) GetLoadedIds(categ string) ([]string, error) {
}
return nil, errors.New("Unsupported category")
}

View File

@@ -43,17 +43,11 @@ type TPLoader interface {
LoadActionTimings() error
LoadActionTriggers() error
LoadAccountActions() error
LoadAll() error
GetLoadedIds(string) ([]string, error)
WriteToDatabase(bool, bool) error
}
/*type LoadRate struct {
Tag string
ConnectFee, Price float64
RateUnit, RateIncrement, GroupIntervalStart time.Duration
RoundingMethod string
RoundingDecimals int
}*/
func NewLoadRate(tag, connectFee, price, ratedUnits, rateIncrements, groupInterval, roundingMethod, roundingDecimals string) (r *utils.TPRate, err error) {
cf, err := strconv.ParseFloat(connectFee, 64)
if err != nil {