diff --git a/apier/v1/tpaliases.go b/apier/v1/tpaliases.go
new file mode 100644
index 000000000..05ced89e7
--- /dev/null
+++ b/apier/v1/tpaliases.go
@@ -0,0 +1,108 @@
+/*
+Real-time Charging System for Telecom & ISP environments
+Copyright (C) 2012-2015 ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
+
+package v1
+
+import (
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/utils"
+)
+
+// Creates a new alias within a tariff plan
+func (self *ApierV1) SetTPAlias(attrs utils.AttrSetTPAlias, reply *string) error {
+ if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Direction", "Tenant", "Category", "Account", "Subject", "Group"}); len(missing) != 0 {
+ return utils.NewErrMandatoryIeMissing(missing...)
+ }
+ tm := engine.APItoModelAliases(&attrs)
+ if err := self.StorDb.SetTpAliases([]engine.TpAlias{*tm}); err != nil {
+ return utils.NewErrServerError(err)
+ }
+ *reply = "OK"
+ return nil
+}
+
+type AttrGetTPAlias struct {
+ TPid string // Tariff plan id
+ Direction string
+ Tenant string
+ Category string
+ Account string
+ Subject string
+ Group string
+}
+
+// Queries specific Alias on Tariff plan
+func (self *ApierV1) GetTPAlias(attr AttrGetTPAlias, reply *engine.Alias) error {
+ if missing := utils.MissingStructFields(&attr, []string{"TPid"}); len(missing) != 0 { //Params missing
+ return utils.NewErrMandatoryIeMissing(missing...)
+ }
+ al := &engine.TpAlias{
+ Tpid: attr.TPid,
+ Direction: attr.Direction,
+ Tenant: attr.Tenant,
+ Category: attr.Category,
+ Account: attr.Account,
+ Subject: attr.Subject,
+ Group: attr.Group,
+ }
+ if tms, err := self.StorDb.GetTpAliases(al); err != nil {
+ return utils.NewErrServerError(err)
+ } else if len(tms) == 0 {
+ return utils.ErrNotFound
+ } else {
+ tmMap, err := engine.TpAliases(tms).GetAliases()
+ if err != nil {
+ return err
+ }
+ *reply = *tmMap[al.GetId()]
+ }
+ return nil
+}
+
+type AttrGetTPAliasIds struct {
+ TPid string // Tariff plan id
+ utils.Paginator
+}
+
+// Queries alias identities on specific tariff plan.
+func (self *ApierV1) GetTPAliasIds(attrs AttrGetTPAliasIds, 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.TBL_TP_ALIASES, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
+ return utils.NewErrServerError(err)
+ } else if ids == nil {
+ return utils.ErrNotFound
+ } else {
+ *reply = ids
+ }
+ return nil
+}
+
+// Removes specific Alias on Tariff plan
+func (self *ApierV1) RemTPAlias(attrs AttrGetTPAlias, reply *string) error {
+ if missing := utils.MissingStructFields(&attrs, []string{"TPid", "AliasId"}); len(missing) != 0 { //Params missing
+ return utils.NewErrMandatoryIeMissing(missing...)
+ }
+ if err := self.StorDb.RemTpData(utils.TBL_TP_ALIASES, attrs.TPid); err != nil {
+ return utils.NewErrServerError(err)
+ } else {
+ *reply = "OK"
+ }
+ return nil
+}
diff --git a/apier/v1/tpusers.go b/apier/v1/tpusers.go
new file mode 100644
index 000000000..dfc12be00
--- /dev/null
+++ b/apier/v1/tpusers.go
@@ -0,0 +1,100 @@
+/*
+Real-time Charging System for Telecom & ISP environments
+Copyright (C) 2012-2015 ITsysCOM GmbH
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
+*/
+
+package v1
+
+import (
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/utils"
+)
+
+// Creates a new alias within a tariff plan
+func (self *ApierV1) SetTPUser(attrs utils.AttrSetTPUser, reply *string) error {
+ if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Direction", "Tenant", "Category", "Account", "Subject", "Group"}); len(missing) != 0 {
+ return utils.NewErrMandatoryIeMissing(missing...)
+ }
+ tm := engine.APItoModelUsers(&attrs)
+ if err := self.StorDb.SetTpUsers([]engine.TpUser{*tm}); err != nil {
+ return utils.NewErrServerError(err)
+ }
+ *reply = "OK"
+ return nil
+}
+
+type AttrGetTPUser struct {
+ TPid string // Tariff plan id
+ Tenant string
+ UserName string
+}
+
+// Queries specific User on Tariff plan
+func (self *ApierV1) GetTPUser(attr AttrGetTPUser, reply *engine.UserProfile) error {
+ if missing := utils.MissingStructFields(&attr, []string{"TPid"}); len(missing) != 0 { //Params missing
+ return utils.NewErrMandatoryIeMissing(missing...)
+ }
+ usr := &engine.TpUser{
+ Tpid: attr.TPid,
+ Tenant: attr.Tenant,
+ UserName: attr.UserName,
+ }
+ if tms, err := self.StorDb.GetTpUsers(usr); err != nil {
+ return utils.NewErrServerError(err)
+ } else if len(tms) == 0 {
+ return utils.ErrNotFound
+ } else {
+ tmMap, err := engine.TpUsers(tms).GetUsers()
+ if err != nil {
+ return err
+ }
+ *reply = *tmMap[usr.GetId()]
+ }
+ return nil
+}
+
+type AttrGetTPUserIds struct {
+ TPid string // Tariff plan id
+ utils.Paginator
+}
+
+// Queries alias identities on specific tariff plan.
+func (self *ApierV1) GetTPUserIds(attrs AttrGetTPUserIds, 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.TBL_TP_USERS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
+ return utils.NewErrServerError(err)
+ } else if ids == nil {
+ return utils.ErrNotFound
+ } else {
+ *reply = ids
+ }
+ return nil
+}
+
+// Removes specific User on Tariff plan
+func (self *ApierV1) RemTPUser(attrs AttrGetTPUser, reply *string) error {
+ if missing := utils.MissingStructFields(&attrs, []string{"TPid", "UserId"}); len(missing) != 0 { //Params missing
+ return utils.NewErrMandatoryIeMissing(missing...)
+ }
+ if err := self.StorDb.RemTpData(utils.TBL_TP_USERS, attrs.TPid); err != nil {
+ return utils.NewErrServerError(err)
+ } else {
+ *reply = "OK"
+ }
+ return nil
+}
diff --git a/engine/model_converters.go b/engine/model_converters.go
index 356ae8758..5f61cf7d4 100644
--- a/engine/model_converters.go
+++ b/engine/model_converters.go
@@ -358,14 +358,23 @@ func APItoModelCdrStat(stats *utils.TPCdrStats) (result []TpCdrstat) {
return
}
-func APItoModelApierAlias(t *utils.ApierTPTiming) (result *TpTiming) {
- return &TpTiming{
- Tpid: t.TPid,
- Tag: t.TimingId,
- Years: t.Years,
- Months: t.Months,
- MonthDays: t.MonthDays,
- WeekDays: t.WeekDays,
- Time: t.Time,
+func APItoModelAliases(attr *utils.AttrSetTPAlias) (result *TpAlias) {
+ return &TpAlias{
+ Tpid: attr.TPid,
+ Direction: attr.Direction,
+ Tenant: attr.Tenant,
+ Category: attr.Category,
+ Account: attr.Account,
+ Subject: attr.Subject,
+ Group: attr.Group,
+ }
+}
+
+func APItoModelUsers(attr *utils.AttrSetTPUser) (result *TpUser) {
+ return &TpUser{
+ Tpid: attr.TPid,
+ Tenant: attr.Tenant,
+ AttributeName: attr.AttributeName,
+ AttributeValue: attr.AttributeValue,
}
}
diff --git a/engine/storage_sql.go b/engine/storage_sql.go
index 826a62409..8c24cc692 100644
--- a/engine/storage_sql.go
+++ b/engine/storage_sql.go
@@ -163,7 +163,7 @@ func (self *SQLStorage) RemTpData(table, tpid string, args ...string) error {
tx := self.db.Begin()
if len(table) == 0 { // Remove tpid out of all tables
for _, tblName := range []string{utils.TBL_TP_TIMINGS, utils.TBL_TP_DESTINATIONS, utils.TBL_TP_RATES, utils.TBL_TP_DESTINATION_RATES, utils.TBL_TP_RATING_PLANS, utils.TBL_TP_RATE_PROFILES,
- utils.TBL_TP_SHARED_GROUPS, utils.TBL_TP_CDR_STATS, utils.TBL_TP_LCRS, utils.TBL_TP_ACTIONS, utils.TBL_TP_ACTION_PLANS, utils.TBL_TP_ACTION_TRIGGERS, utils.TBL_TP_ACCOUNT_ACTIONS, utils.TBL_TP_DERIVED_CHARGERS} {
+ utils.TBL_TP_SHARED_GROUPS, utils.TBL_TP_CDR_STATS, utils.TBL_TP_LCRS, utils.TBL_TP_ACTIONS, utils.TBL_TP_ACTION_PLANS, utils.TBL_TP_ACTION_TRIGGERS, utils.TBL_TP_ACCOUNT_ACTIONS, utils.TBL_TP_DERIVED_CHARGERS, utils.TBL_TP_ALIASES} {
if err := tx.Table(tblName).Where("tpid = ?", tpid).Delete(nil).Error; err != nil {
tx.Rollback()
return err
diff --git a/utils/apitpdata.go b/utils/apitpdata.go
index d98e5274a..e557a0aa8 100644
--- a/utils/apitpdata.go
+++ b/utils/apitpdata.go
@@ -519,6 +519,24 @@ type AttrGetAccounts struct {
Limit int // Limit number of items retrieved
}
+type AttrSetTPAlias struct {
+ TPid string
+ Direction string
+ Tenant string
+ Category string
+ Account string
+ Subject string
+ Group string
+}
+
+type AttrSetTPUser struct {
+ TPid string
+ Tenant string
+ UserName string
+ AttributeName string
+ AttributeValue string
+}
+
// Data used to do remote cache reloads via api
type ApiReloadCache struct {
DestinationIds []string
@@ -1095,3 +1113,19 @@ type AttrGetCallCost struct {
CgrId string // Unique id of the CDR
RunId string // Run Id
}
+
+type TpAlias struct {
+ Direction string
+ Tenant string
+ Category string
+ Account string
+ Subject string
+ Group string
+ Values []*AliasValue
+}
+
+type AliasValue struct {
+ DestinationId string
+ Alias string
+ Weight float64
+}
diff --git a/utils/consts.go b/utils/consts.go
index 48907e625..ce9685d57 100644
--- a/utils/consts.go
+++ b/utils/consts.go
@@ -60,6 +60,8 @@ const (
TBL_TP_ACTION_TRIGGERS = "tp_action_triggers"
TBL_TP_ACCOUNT_ACTIONS = "tp_account_actions"
TBL_TP_DERIVED_CHARGERS = "tp_derived_chargers"
+ TBL_TP_USERS = "tp_users"
+ TBL_TP_ALIASES = "tp_aliases"
TBL_CDRS_PRIMARY = "cdrs_primary"
TBL_CDRS_EXTRA = "cdrs_extra"
TBL_COST_DETAILS = "cost_details"