mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update tp suppliers to consider tenant
This commit is contained in:
committed by
Dan Christian Bogos
parent
c9ce2f6bc5
commit
b466b60238
@@ -23,28 +23,23 @@ import (
|
||||
)
|
||||
|
||||
// Creates a new SupplierProfile within a tariff plan
|
||||
func (self *ApierV1) SetTPSupplierProfile(attrs utils.TPSupplierProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
func (self *ApierV1) SetTPSupplierProfile(attrs *utils.TPSupplierProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.SetTPSuppliers([]*utils.TPSupplierProfile{&attrs}); err != nil {
|
||||
if err := self.StorDb.SetTPSuppliers([]*utils.TPSupplierProfile{attrs}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrGetTPSupplierProfile struct {
|
||||
TPid string // Tariff plan id
|
||||
ID string // Filter id
|
||||
}
|
||||
|
||||
// Queries specific SupplierProfile on tariff plan
|
||||
func (self *ApierV1) GetTPSupplierProfile(attr AttrGetTPSupplierProfile, reply *utils.TPSupplierProfile) error {
|
||||
if missing := utils.MissingStructFields(&attr, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
func (self *ApierV1) GetTPSupplierProfile(attr *utils.TPTntID, reply *utils.TPSupplierProfile) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if spp, err := self.StorDb.GetTPSuppliers(attr.TPid, attr.ID); err != nil {
|
||||
if spp, err := self.StorDb.GetTPSuppliers(attr.TPid, attr.Tenant, attr.ID); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
@@ -61,11 +56,12 @@ type AttrGetTPSupplierProfileIDs struct {
|
||||
}
|
||||
|
||||
// Queries SupplierProfile identities on specific tariff plan.
|
||||
func (self *ApierV1) GetTPSupplierProfileIDs(attrs AttrGetTPSupplierProfileIDs, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
func (self *ApierV1) GetTPSupplierProfileIDs(attrs *AttrGetTPSupplierProfileIDs, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPSuppliers, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPSuppliers, utils.TPDistinctIds{"id"},
|
||||
nil, &attrs.Paginator); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
@@ -76,18 +72,13 @@ func (self *ApierV1) GetTPSupplierProfileIDs(attrs AttrGetTPSupplierProfileIDs,
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrRemTPSupplierProfile struct {
|
||||
TPid string // Tariff plan id
|
||||
Tenant string
|
||||
ID string // LCR id
|
||||
}
|
||||
|
||||
// Removes specific SupplierProfile on Tariff plan
|
||||
func (self *ApierV1) RemTPSupplierProfile(attrs AttrRemTPSupplierProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
func (self *ApierV1) RemTPSupplierProfile(attrs *utils.TPTntID, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBLTPSuppliers, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBLTPSuppliers, attrs.TPid,
|
||||
map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -82,12 +82,8 @@ func testTPSplPrfInitCfg(t *testing.T) {
|
||||
}
|
||||
tpSplPrfCfg.DataFolderPath = tpSplPrfDataDire // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(tpSplPrfCfg)
|
||||
switch tpSplPrfConfigDIR {
|
||||
case "tutmongo": // Mongo needs more time to reset db, need to investigate
|
||||
tpSplPrfDelay = 2000
|
||||
default:
|
||||
tpSplPrfDelay = 1000
|
||||
}
|
||||
tpSplPrfDelay = 1000
|
||||
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
@@ -116,7 +112,7 @@ func testTPSplPrfRPCConn(t *testing.T) {
|
||||
func testTPSplPrfGetTPSplPrfBeforeSet(t *testing.T) {
|
||||
var reply *utils.TPSupplier
|
||||
if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile",
|
||||
&AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"},
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"},
|
||||
&reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -161,7 +157,7 @@ func testTPSplPrfSetTPSplPrf(t *testing.T) {
|
||||
func testTPSplPrfGetTPSplPrfAfterSet(t *testing.T) {
|
||||
var reply *utils.TPSupplierProfile
|
||||
if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile",
|
||||
&AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err != nil {
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpSplPr, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpSplPr), utils.ToJSON(reply))
|
||||
@@ -241,18 +237,18 @@ func testTPSplPrfGetTPSplPrfAfterUpdate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile",
|
||||
&AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err != nil {
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpSplPr.Suppliers, reply.Suppliers) &&
|
||||
!reflect.DeepEqual(tpSplPr.Suppliers, reverseSuppliers) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tpSplPr), utils.ToJSON(reply))
|
||||
t.Errorf("Expecting: %+v,\n received: %+v", utils.ToJSON(tpSplPr), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPSplPrfRemTPSplPrf(t *testing.T) {
|
||||
var resp string
|
||||
if err := tpSplPrfRPC.Call("ApierV1.RemTPSupplierProfile",
|
||||
&AttrRemTPSupplierProfile{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"},
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"},
|
||||
&resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.OK {
|
||||
@@ -263,7 +259,7 @@ func testTPSplPrfRemTPSplPrf(t *testing.T) {
|
||||
func testTPSplPrfGetTPSplPrfAfterRemove(t *testing.T) {
|
||||
var reply *utils.TPSupplierProfile
|
||||
if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile",
|
||||
&AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"},
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"},
|
||||
&reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -2249,6 +2249,7 @@ func APItoModelTPSuppliers(st *utils.TPSupplierProfile) (mdls TpSuppliers) {
|
||||
}
|
||||
mdl.SupplierWeight = supl.Weight
|
||||
mdl.SupplierParameters = supl.SupplierParameters
|
||||
mdl.SupplierBlocker = supl.Blocker
|
||||
mdls = append(mdls, mdl)
|
||||
}
|
||||
return
|
||||
|
||||
@@ -649,7 +649,7 @@ func (csvs *CSVStorage) GetTPFilters(tpid, tenant, id string) ([]*utils.TPFilter
|
||||
return tpFilter.AsTPFilter(), nil
|
||||
}
|
||||
|
||||
func (csvs *CSVStorage) GetTPSuppliers(tpid, id string) ([]*utils.TPSupplierProfile, error) {
|
||||
func (csvs *CSVStorage) GetTPSuppliers(tpid, tenant, id string) ([]*utils.TPSupplierProfile, error) {
|
||||
csvReader, fp, err := csvs.readerFunc(csvs.suppProfilesFn, csvs.sep, getColumnCount(TpSupplier{}))
|
||||
if err != nil {
|
||||
//log.Print("Could not load lcrProfile file: ", err)
|
||||
|
||||
@@ -186,7 +186,7 @@ type LoadReader interface {
|
||||
GetTPStats(string, string, string) ([]*utils.TPStats, error)
|
||||
GetTPThresholds(string, string, string) ([]*utils.TPThreshold, error)
|
||||
GetTPFilters(string, string, string) ([]*utils.TPFilterProfile, error)
|
||||
GetTPSuppliers(string, string) ([]*utils.TPSupplierProfile, error)
|
||||
GetTPSuppliers(string, string, string) ([]*utils.TPSupplierProfile, error)
|
||||
GetTPAttributes(string, string, string) ([]*utils.TPAttributeProfile, error)
|
||||
GetTPChargers(string, string) ([]*utils.TPChargerProfile, error)
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func (ms *MapStorage) GetTPThresholds(tpid, tenant, id string) (ths []*utils.TPT
|
||||
func (ms *MapStorage) GetTPFilters(tpid, tenant, id string) (fltrs []*utils.TPFilterProfile, err error) {
|
||||
return nil, utils.ErrNotImplemented
|
||||
}
|
||||
func (ms *MapStorage) GetTPSuppliers(tpid, id string) (supps []*utils.TPSupplierProfile, err error) {
|
||||
func (ms *MapStorage) GetTPSuppliers(tpid, tenant, id string) (supps []*utils.TPSupplierProfile, err error) {
|
||||
return nil, utils.ErrNotImplemented
|
||||
}
|
||||
func (ms *MapStorage) GetTPAttributes(tpid, tenant, id string) (attrs []*utils.TPAttributeProfile, err error) {
|
||||
|
||||
@@ -1473,11 +1473,14 @@ func (ms *MongoStorage) SetTPFilters(tpTHs []*utils.TPFilterProfile) (err error)
|
||||
})
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetTPSuppliers(tpid, id string) ([]*utils.TPSupplierProfile, error) {
|
||||
func (ms *MongoStorage) GetTPSuppliers(tpid, tenant, id string) ([]*utils.TPSupplierProfile, error) {
|
||||
filter := bson.M{"tpid": tpid}
|
||||
if id != "" {
|
||||
filter["id"] = id
|
||||
}
|
||||
if tenant != "" {
|
||||
filter["tenant"] = tenant
|
||||
}
|
||||
var results []*utils.TPSupplierProfile
|
||||
err := ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur, err := ms.getCol(utils.TBLTPSuppliers).Find(sctx, filter)
|
||||
|
||||
@@ -1550,12 +1550,15 @@ func (self *SQLStorage) GetTPFilters(tpid, tenant, id string) ([]*utils.TPFilter
|
||||
return aths, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetTPSuppliers(tpid, id string) ([]*utils.TPSupplierProfile, error) {
|
||||
func (self *SQLStorage) GetTPSuppliers(tpid, tenant, id string) ([]*utils.TPSupplierProfile, error) {
|
||||
var sps TpSuppliers
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(id) != 0 {
|
||||
q = q.Where("id = ?", id)
|
||||
}
|
||||
if len(tenant) != 0 {
|
||||
q = q.Where("tenant = ?", tenant)
|
||||
}
|
||||
if err := q.Find(&sps).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1379,7 +1379,7 @@ func (tpr *TpReader) LoadFilters() error {
|
||||
}
|
||||
|
||||
func (tpr *TpReader) LoadSupplierProfilesFiltered(tag string) (err error) {
|
||||
rls, err := tpr.lr.GetTPSuppliers(tpr.tpid, tag)
|
||||
rls, err := tpr.lr.GetTPSuppliers(tpr.tpid, "", tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ func (self *TPExporter) Run() error {
|
||||
}
|
||||
}
|
||||
|
||||
storDataSuppliers, err := self.storDb.GetTPSuppliers(self.tpID, "")
|
||||
storDataSuppliers, err := self.storDb.GetTPSuppliers(self.tpID, "", "")
|
||||
if err != nil && err.Error() != utils.ErrNotFound.Error() {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ func (self *TPCSVImporter) importSuppliers(fn string) error {
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
rls, err := self.csvr.GetTPSuppliers(self.TPid, "")
|
||||
rls, err := self.csvr.GetTPSuppliers(self.TPid, "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func (m *Migrator) migrateCurrentTPSuppliers() (err error) {
|
||||
}
|
||||
for _, id := range ids {
|
||||
|
||||
suppliers, err := m.storDBIn.StorDB().GetTPSuppliers(tpid, id)
|
||||
suppliers, err := m.storDBIn.StorDB().GetTPSuppliers(tpid, "", id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ func testTpSplITMove(t *testing.T) {
|
||||
|
||||
func testTpSplITCheckData(t *testing.T) {
|
||||
result, err := tpSplMigrator.storDBOut.StorDB().GetTPSuppliers(
|
||||
tpSuppliers[0].TPid, tpSuppliers[0].ID)
|
||||
tpSuppliers[0].TPid, "", tpSuppliers[0].ID)
|
||||
if err != nil {
|
||||
t.Error("Error when getting TpSuppliers ", err.Error())
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func testTpSplITCheckData(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tpSuppliers[0]), utils.ToJSON(result[0]))
|
||||
}
|
||||
result, err = tpSplMigrator.storDBIn.StorDB().GetTPSuppliers(
|
||||
tpSuppliers[0].TPid, tpSuppliers[0].ID)
|
||||
tpSuppliers[0].TPid, "", tpSuppliers[0].ID)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user