Starting removing RALs

This commit is contained in:
Trial97
2021-03-29 17:26:47 +03:00
committed by Dan Christian Bogos
parent 58ea63eac3
commit c0b66f42aa
52 changed files with 1143 additions and 13607 deletions

View File

@@ -308,129 +308,6 @@ func (sqls *SQLStorage) SetTPDestinations(dests []*utils.TPDestination) error {
return nil
}
func (sqls *SQLStorage) SetTPRates(rs []*utils.TPRateRALs) error {
if len(rs) == 0 {
return nil //Nothing to set
}
m := make(map[string]bool)
tx := sqls.db.Begin()
for _, rate := range rs {
if !m[rate.ID] {
m[rate.ID] = true
if err := tx.Where(&RateMdl{Tpid: rate.TPid, Tag: rate.ID}).Delete(RateMdl{}).Error; err != nil {
tx.Rollback()
return err
}
}
for _, r := range APItoModelRate(rate) {
if err := tx.Create(&r).Error; err != nil {
tx.Rollback()
return err
}
}
}
tx.Commit()
return nil
}
func (sqls *SQLStorage) SetTPDestinationRates(drs []*utils.TPDestinationRate) error {
if len(drs) == 0 {
return nil //Nothing to set
}
m := make(map[string]bool)
tx := sqls.db.Begin()
for _, dRate := range drs {
if !m[dRate.ID] {
m[dRate.ID] = true
if err := tx.Where(&DestinationRateMdl{Tpid: dRate.TPid, Tag: dRate.ID}).Delete(DestinationRateMdl{}).Error; err != nil {
tx.Rollback()
return err
}
}
for _, d := range APItoModelDestinationRate(dRate) {
if err := tx.Create(&d).Error; err != nil {
tx.Rollback()
return err
}
}
}
tx.Commit()
return nil
}
func (sqls *SQLStorage) SetTPRatingPlans(rps []*utils.TPRatingPlan) error {
if len(rps) == 0 {
return nil //Nothing to set
}
m := make(map[string]bool)
tx := sqls.db.Begin()
for _, rPlan := range rps {
if !m[rPlan.ID] {
m[rPlan.ID] = true
if err := tx.Where(&RatingPlanMdl{Tpid: rPlan.TPid, Tag: rPlan.ID}).Delete(RatingPlanMdl{}).Error; err != nil {
tx.Rollback()
return err
}
}
for _, r := range APItoModelRatingPlan(rPlan) {
if err := tx.Create(&r).Error; err != nil {
tx.Rollback()
return err
}
}
}
tx.Commit()
return nil
}
func (sqls *SQLStorage) SetTPRatingProfiles(rpfs []*utils.TPRatingProfile) error {
if len(rpfs) == 0 {
return nil //Nothing to set
}
tx := sqls.db.Begin()
for _, rpf := range rpfs {
if err := tx.Where(&RatingProfileMdl{Tpid: rpf.TPid, Loadid: rpf.LoadId,
Tenant: rpf.Tenant, Category: rpf.Category,
Subject: rpf.Subject}).Delete(RatingProfileMdl{}).Error; err != nil {
tx.Rollback()
return err
}
for _, r := range APItoModelRatingProfile(rpf) {
if err := tx.Create(&r).Error; err != nil {
tx.Rollback()
return err
}
}
}
tx.Commit()
return nil
}
func (sqls *SQLStorage) SetTPSharedGroups(sgs []*utils.TPSharedGroups) error {
if len(sgs) == 0 {
return nil //Nothing to set
}
m := make(map[string]bool)
tx := sqls.db.Begin()
for _, sGroup := range sgs {
if !m[sGroup.ID] {
m[sGroup.ID] = true
if err := tx.Where(&SharedGroupMdl{Tpid: sGroup.TPid, Tag: sGroup.ID}).Delete(SharedGroupMdl{}).Error; err != nil {
tx.Rollback()
return err
}
}
for _, s := range APItoModelSharedGroup(sGroup) {
if err := tx.Create(&s).Error; err != nil {
tx.Rollback()
return err
}
}
}
tx.Commit()
return nil
}
func (sqls *SQLStorage) SetTPActions(acts []*utils.TPActions) error {
if len(acts) == 0 {
return nil //Nothing to set
@@ -456,83 +333,6 @@ func (sqls *SQLStorage) SetTPActions(acts []*utils.TPActions) error {
return nil
}
func (sqls *SQLStorage) SetTPActionPlans(ats []*utils.TPActionPlan) error {
if len(ats) == 0 {
return nil //Nothing to set
}
m := make(map[string]bool)
tx := sqls.db.Begin()
for _, aPlan := range ats {
if !m[aPlan.ID] {
m[aPlan.ID] = true
if err := tx.Where(&ActionPlanMdl{Tpid: aPlan.TPid, Tag: aPlan.ID}).Delete(ActionPlanMdl{}).Error; err != nil {
tx.Rollback()
return err
}
}
for _, a := range APItoModelActionPlan(aPlan) {
if err := tx.Create(&a).Error; err != nil {
tx.Rollback()
return err
}
}
}
r := tx.Commit()
return r.Error
}
func (sqls *SQLStorage) SetTPActionTriggers(ats []*utils.TPActionTriggers) error {
if len(ats) == 0 {
return nil //Nothing to set
}
m := make(map[string]bool)
tx := sqls.db.Begin()
for _, aTrigger := range ats {
if !m[aTrigger.ID] {
m[aTrigger.ID] = true
if err := tx.Where(&ActionTriggerMdl{Tpid: aTrigger.TPid, Tag: aTrigger.ID}).Delete(ActionTriggerMdl{}).Error; err != nil {
tx.Rollback()
return err
}
}
for _, a := range APItoModelActionTrigger(aTrigger) {
if err := tx.Create(&a).Error; err != nil {
tx.Rollback()
return err
}
}
}
tx.Commit()
return nil
}
// Sets a group of account actions. Map key has the role of grouping within a tpid
func (sqls *SQLStorage) SetTPAccountActions(aas []*utils.TPAccountActions) error {
if len(aas) == 0 {
return nil //Nothing to set
}
m := make(map[string]bool)
tx := sqls.db.Begin()
for _, aa := range aas {
if !m[aa.GetId()] {
m[aa.GetId()] = true
if err := tx.Where(&AccountActionMdl{Tpid: aa.TPid, Loadid: aa.LoadId, Tenant: aa.Tenant, Account: aa.Account}).Delete(&AccountActionMdl{}).Error; err != nil {
tx.Rollback()
return err
}
}
sa := APItoModelAccountAction(aa)
if err := tx.Create(&sa).Error; err != nil {
tx.Rollback()
return err
}
}
tx.Commit()
return nil
}
func (sqls *SQLStorage) SetTPResources(rls []*utils.TPResourceProfile) error {
if len(rls) == 0 {
return nil
@@ -1251,49 +1051,6 @@ func (sqls *SQLStorage) GetTPDestinations(tpid, id string) (uTPDsts []*utils.TPD
return tpDests.AsTPDestinations(), nil
}
func (sqls *SQLStorage) GetTPRates(tpid, id string) ([]*utils.TPRateRALs, error) {
var tpRates RateMdls
q := sqls.db.Where("tpid = ?", tpid).Order("id")
if len(id) != 0 {
q = q.Where("tag = ?", id)
}
if err := q.Find(&tpRates).Error; err != nil {
return nil, err
}
if rs, err := tpRates.AsTPRates(); err != nil {
return nil, err
} else {
if len(rs) == 0 {
return rs, utils.ErrNotFound
}
return rs, nil
}
}
func (sqls *SQLStorage) GetTPDestinationRates(tpid, id string, pagination *utils.Paginator) ([]*utils.TPDestinationRate, error) {
var tpDestinationRates DestinationRateMdls
q := sqls.db.Where("tpid = ?", tpid)
if len(id) != 0 {
q = q.Where("tag = ?", id)
}
if pagination != nil {
if pagination.Limit != nil {
q = q.Limit(*pagination.Limit)
}
if pagination.Offset != nil {
q = q.Offset(*pagination.Offset)
}
}
if err := q.Find(&tpDestinationRates).Error; err != nil {
return nil, err
}
drs := tpDestinationRates.AsTPDestinationRates()
if len(drs) == 0 {
return drs, utils.ErrNotFound
}
return drs, nil
}
func (sqls *SQLStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) {
var tpTimings TimingMdls
q := sqls.db.Where("tpid = ?", tpid)
@@ -1310,73 +1067,6 @@ func (sqls *SQLStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, e
return ts, nil
}
func (sqls *SQLStorage) GetTPRatingPlans(tpid, id string, pagination *utils.Paginator) ([]*utils.TPRatingPlan, error) {
var tpRatingPlans RatingPlanMdls
q := sqls.db.Where("tpid = ?", tpid)
if len(id) != 0 {
q = q.Where("tag = ?", id)
}
if err := q.Find(&tpRatingPlans).Error; err != nil {
return nil, err
}
if pagination != nil {
if pagination.Limit != nil {
q = q.Limit(*pagination.Limit)
}
if pagination.Offset != nil {
q = q.Offset(*pagination.Offset)
}
}
rps := tpRatingPlans.AsTPRatingPlans()
if len(rps) == 0 {
return rps, utils.ErrNotFound
}
return rps, nil
}
func (sqls *SQLStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) {
var tpRpfs RatingProfileMdls
q := sqls.db.Where("tpid = ?", filter.TPid)
if len(filter.LoadId) != 0 {
q = q.Where("loadid = ?", filter.LoadId)
}
if len(filter.Tenant) != 0 {
q = q.Where("tenant = ?", filter.Tenant)
}
if len(filter.Category) != 0 {
q = q.Where("category = ?", filter.Category)
}
if len(filter.Subject) != 0 {
q = q.Where("subject = ?", filter.Subject)
}
if err := q.Find(&tpRpfs).Error; err != nil {
return nil, err
}
rps := tpRpfs.AsTPRatingProfiles()
if len(rps) == 0 {
return rps, utils.ErrNotFound
}
return rps, nil
}
func (sqls *SQLStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) {
var tpShareGroups SharedGroupMdls
q := sqls.db.Where("tpid = ?", tpid)
if len(id) != 0 {
q = q.Where("tag = ?", id)
}
if err := q.Find(&tpShareGroups).Error; err != nil {
return nil, err
}
sgs := tpShareGroups.AsTPSharedGroups()
if len(sgs) == 0 {
return sgs, utils.ErrNotFound
}
return sgs, nil
}
func (sqls *SQLStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error) {
var tpActions ActionMdls
q := sqls.db.Where("tpid = ?", tpid)
@@ -1393,60 +1083,6 @@ func (sqls *SQLStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error
return as, nil
}
func (sqls *SQLStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) {
var tpActionTriggers ActionTriggerMdls
q := sqls.db.Where("tpid = ?", tpid)
if len(id) != 0 {
q = q.Where("tag = ?", id)
}
if err := q.Find(&tpActionTriggers).Error; err != nil {
return nil, err
}
ats := tpActionTriggers.AsTPActionTriggers()
if len(ats) == 0 {
return ats, utils.ErrNotFound
}
return ats, nil
}
func (sqls *SQLStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) {
var tpActionPlans ActionPlanMdls
q := sqls.db.Where("tpid = ?", tpid)
if len(id) != 0 {
q = q.Where("tag = ?", id)
}
if err := q.Find(&tpActionPlans).Error; err != nil {
return nil, err
}
aps := tpActionPlans.AsTPActionPlans()
if len(aps) == 0 {
return aps, utils.ErrNotFound
}
return aps, nil
}
func (sqls *SQLStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]*utils.TPAccountActions, error) {
var tpAccActs AccountActionMdls
q := sqls.db.Where("tpid = ?", filter.TPid)
if len(filter.LoadId) != 0 {
q = q.Where("loadid = ?", filter.LoadId)
}
if len(filter.Tenant) != 0 {
q = q.Where("tenant = ?", filter.Tenant)
}
if len(filter.Account) != 0 {
q = q.Where("account = ?", filter.Account)
}
if err := q.Find(&tpAccActs).Error; err != nil {
return nil, err
}
aas := tpAccActs.AsTPAccountActions()
if len(aas) == 0 {
return aas, utils.ErrNotFound
}
return aas, nil
}
func (sqls *SQLStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPResourceProfile, error) {
var rls ResourceMdls
q := sqls.db.Where("tpid = ?", tpid)