mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update tp charger to use tenant
This commit is contained in:
committed by
Dan Christian Bogos
parent
b466b60238
commit
8184f51738
@@ -23,29 +23,23 @@ import (
|
||||
)
|
||||
|
||||
// Creates a new ChargerProfile within a tariff plan
|
||||
func (self *ApierV1) SetTPCharger(attr utils.TPChargerProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
func (self *ApierV1) SetTPCharger(attr *utils.TPChargerProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.SetTPChargers([]*utils.TPChargerProfile{&attr}); err != nil {
|
||||
if err := self.StorDb.SetTPChargers([]*utils.TPChargerProfile{attr}); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrGetTPCharger struct {
|
||||
TPid string // Tariff plan id
|
||||
Tenant string
|
||||
ID string
|
||||
}
|
||||
|
||||
// Queries specific ChargerProfile on Tariff plan
|
||||
func (self *ApierV1) GetTPCharger(attr AttrGetTPCharger, reply *utils.TPChargerProfile) error {
|
||||
if missing := utils.MissingStructFields(&attr, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing
|
||||
func (self *ApierV1) GetTPCharger(attr *utils.TPTntID, reply *utils.TPChargerProfile) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if rls, err := self.StorDb.GetTPChargers(attr.TPid, attr.ID); err != nil {
|
||||
if rls, err := self.StorDb.GetTPChargers(attr.TPid, attr.Tenant, attr.ID); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
@@ -62,11 +56,12 @@ type AttrGetTPChargerIds struct {
|
||||
}
|
||||
|
||||
// Queries Resource identities on specific tariff plan.
|
||||
func (self *ApierV1) GetTPChargerIDs(attrs AttrGetTPChargerIds, reply *[]string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
func (self *ApierV1) GetTPChargerIDs(attrs *AttrGetTPChargerIds, 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.TBLTPChargers, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPChargers, utils.TPDistinctIds{"id"},
|
||||
nil, &attrs.Paginator); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
@@ -77,18 +72,13 @@ func (self *ApierV1) GetTPChargerIDs(attrs AttrGetTPChargerIds, reply *[]string)
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrRemTPCharger struct {
|
||||
TPid string // Tariff plan id
|
||||
Tenant string
|
||||
ID string // Attribute id
|
||||
}
|
||||
|
||||
// Removes specific Resource on Tariff plan
|
||||
func (self *ApierV1) RemTPCharger(attrs AttrRemTPCharger, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
func (self *ApierV1) RemTPCharger(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.TBLTPChargers, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBLTPChargers, attrs.TPid,
|
||||
map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -112,7 +112,7 @@ func testTPChrgsRPCConn(t *testing.T) {
|
||||
func testTPChrgsGetTPChrgsBeforeSet(t *testing.T) {
|
||||
var reply *utils.TPChargerProfile
|
||||
if err := tpChrgsRPC.Call("ApierV1.GetTPCharger",
|
||||
&AttrGetTPCharger{TPid: "TP1", ID: "Chrgs"}, &reply); err == nil ||
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func testTPChrgsSetTPChrgs(t *testing.T) {
|
||||
func testTPChrgsGetTPChrgsAfterSet(t *testing.T) {
|
||||
var reply *utils.TPChargerProfile
|
||||
if err := tpChrgsRPC.Call("ApierV1.GetTPCharger",
|
||||
&AttrGetTPCharger{TPid: "TP1", ID: "Chrgs"}, &reply); err != nil {
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpChrgs, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpChrgs, reply)
|
||||
@@ -174,7 +174,7 @@ func testTPChrgsUpdateTPChrgs(t *testing.T) {
|
||||
func testTPChrgsGetTPChrgsAfterUpdate(t *testing.T) {
|
||||
var reply *utils.TPChargerProfile
|
||||
if err := tpChrgsRPC.Call("ApierV1.GetTPCharger",
|
||||
&AttrGetTPCharger{TPid: "TP1", ID: "Chrgs"}, &reply); err != nil {
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(tpChrgs, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", tpChrgs, reply)
|
||||
@@ -184,7 +184,7 @@ func testTPChrgsGetTPChrgsAfterUpdate(t *testing.T) {
|
||||
func testTPChrgsRemTPChrgs(t *testing.T) {
|
||||
var resp string
|
||||
if err := tpChrgsRPC.Call("ApierV1.RemTPCharger",
|
||||
&AttrGetTPCharger{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"},
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"},
|
||||
&resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.OK {
|
||||
@@ -195,7 +195,7 @@ func testTPChrgsRemTPChrgs(t *testing.T) {
|
||||
func testTPChrgsGetTPChrgsAfterRemove(t *testing.T) {
|
||||
var reply *utils.TPChargerProfile
|
||||
if err := tpChrgsRPC.Call("ApierV1.GetTPCharger",
|
||||
&AttrGetTPCharger{TPid: "TP1", ID: "Chrgs"}, &reply); err == nil ||
|
||||
&utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -705,7 +705,7 @@ func (csvs *CSVStorage) GetTPAttributes(tpid, tenant, id string) ([]*utils.TPAtt
|
||||
return tpAls.AsTPAttributes(), nil
|
||||
}
|
||||
|
||||
func (csvs *CSVStorage) GetTPChargers(tpid, id string) ([]*utils.TPChargerProfile, error) {
|
||||
func (csvs *CSVStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPChargerProfile, error) {
|
||||
csvReader, fp, err := csvs.readerFunc(csvs.chargerProfilesFn, csvs.sep, getColumnCount(TPCharger{}))
|
||||
if err != nil {
|
||||
//log.Print("Could not load AttributeProfile file: ", err)
|
||||
|
||||
@@ -188,7 +188,7 @@ type LoadReader interface {
|
||||
GetTPFilters(string, string, string) ([]*utils.TPFilterProfile, error)
|
||||
GetTPSuppliers(string, string, string) ([]*utils.TPSupplierProfile, error)
|
||||
GetTPAttributes(string, string, string) ([]*utils.TPAttributeProfile, error)
|
||||
GetTPChargers(string, string) ([]*utils.TPChargerProfile, error)
|
||||
GetTPChargers(string, string, string) ([]*utils.TPChargerProfile, error)
|
||||
}
|
||||
|
||||
type LoadWriter interface {
|
||||
|
||||
@@ -91,7 +91,7 @@ func (ms *MapStorage) GetTPSuppliers(tpid, tenant, id string) (supps []*utils.TP
|
||||
func (ms *MapStorage) GetTPAttributes(tpid, tenant, id string) (attrs []*utils.TPAttributeProfile, err error) {
|
||||
return nil, utils.ErrNotImplemented
|
||||
}
|
||||
func (ms *MapStorage) GetTPChargers(tpid, id string) (attrs []*utils.TPChargerProfile, err error) {
|
||||
func (ms *MapStorage) GetTPChargers(tpid, tenant, id string) (attrs []*utils.TPChargerProfile, err error) {
|
||||
return nil, utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -1569,11 +1569,14 @@ func (ms *MongoStorage) SetTPAttributes(tpSPs []*utils.TPAttributeProfile) (err
|
||||
})
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetTPChargers(tpid, id string) ([]*utils.TPChargerProfile, error) {
|
||||
func (ms *MongoStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPChargerProfile, error) {
|
||||
filter := bson.M{"tpid": tpid}
|
||||
if id != "" {
|
||||
filter["id"] = id
|
||||
}
|
||||
if tenant != "" {
|
||||
filter["tenant"] = tenant
|
||||
}
|
||||
var results []*utils.TPChargerProfile
|
||||
err := ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur, err := ms.getCol(utils.TBLTPChargers).Find(sctx, filter)
|
||||
|
||||
@@ -1588,12 +1588,15 @@ func (self *SQLStorage) GetTPAttributes(tpid, tenant, id string) ([]*utils.TPAtt
|
||||
return arls, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetTPChargers(tpid, id string) ([]*utils.TPChargerProfile, error) {
|
||||
func (self *SQLStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPChargerProfile, error) {
|
||||
var cpps TPChargers
|
||||
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(&cpps).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1427,7 +1427,7 @@ func (tpr *TpReader) LoadAttributeProfiles() error {
|
||||
}
|
||||
|
||||
func (tpr *TpReader) LoadChargerProfilesFiltered(tag string) (err error) {
|
||||
rls, err := tpr.lr.GetTPChargers(tpr.tpid, tag)
|
||||
rls, err := tpr.lr.GetTPChargers(tpr.tpid, "", tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ func (self *TPExporter) Run() error {
|
||||
}
|
||||
}
|
||||
|
||||
storDataChargers, err := self.storDb.GetTPChargers(self.tpID, "")
|
||||
storDataChargers, err := self.storDb.GetTPChargers(self.tpID, "", "")
|
||||
if err != nil && err.Error() != utils.ErrNotFound.Error() {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ func (self *TPCSVImporter) importChargerProfiles(fn string) error {
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
rls, err := self.csvr.GetTPChargers(self.TPid, "")
|
||||
rls, err := self.csvr.GetTPChargers(self.TPid, "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (m *Migrator) migrateCurrentTPChargers() (err error) {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
chargers, err := m.storDBIn.StorDB().GetTPChargers(tpid, id)
|
||||
chargers, err := m.storDBIn.StorDB().GetTPChargers(tpid, "", id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user