From 38978645b2b51d1b61767a83d403583d28bc2055 Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 2 Mar 2020 18:01:40 +0200 Subject: [PATCH] Add method AttributeProfile to TPAttributeProfile --- config/rsrparser.go | 11 +++++++++++ engine/model_helpers.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/config/rsrparser.go b/config/rsrparser.go index a3e38805e..282cfbb7e 100644 --- a/config/rsrparser.go +++ b/config/rsrparser.go @@ -63,6 +63,17 @@ func NewRSRParsersMustCompile(parsersRules string, allFiltersMatch bool, rsrSepa // RSRParsers is a set of RSRParser type RSRParsers []*RSRParser +func (prsrs RSRParsers) GetRule() (out string) { + for i, prsr := range prsrs { + if i == 0 { + out = prsr.Rules + } else { + out = out + utils.NestingSep + prsr.Rules + } + } + return +} + func (prsrs RSRParsers) Compile() (err error) { for _, prsr := range prsrs { if err = prsr.Compile(); err != nil { diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 23e173587..1f499cdeb 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2174,6 +2174,38 @@ func APItoAttributeProfile(tpAttr *utils.TPAttributeProfile, timezone string) (a return attrPrf, nil } +func AttributeProfileToAPI(attrPrf *AttributeProfile, tpid string) (tpAttr *utils.TPAttributeProfile) { + tpAttr = &utils.TPAttributeProfile{ + TPid: tpid, + Tenant: attrPrf.Tenant, + ID: attrPrf.ID, + FilterIDs: make([]string, len(attrPrf.FilterIDs)), + Contexts: make([]string, len(attrPrf.Contexts)), + Attributes: make([]*utils.TPAttribute, len(tpAttr.Attributes)), + Blocker: attrPrf.Blocker, + Weight: attrPrf.Weight, + } + for i, fli := range attrPrf.FilterIDs { + tpAttr.FilterIDs[i] = fli + } + for i, fli := range attrPrf.Contexts { + tpAttr.Contexts[i] = fli + } + for i, attr := range attrPrf.Attributes { + tpAttr.Attributes[i] = &utils.TPAttribute{ + FilterIDs: attr.FilterIDs, + Path: attr.Path, + Type: attr.Type, + Value: attr.Value.GetRule(), + } + } + tpAttr.ActivationInterval = &utils.TPActivationInterval{ + ActivationTime: attrPrf.ActivationInterval.ActivationTime.Format(time.RFC3339), + ExpiryTime: attrPrf.ActivationInterval.ExpiryTime.Format(time.RFC3339), + } + return +} + type TPChargers []*TPCharger func (tps TPChargers) AsTPChargers() (result []*utils.TPChargerProfile) {