Add method AttributeProfile to TPAttributeProfile

This commit is contained in:
TeoV
2020-03-02 18:01:40 +02:00
committed by Dan Christian Bogos
parent 40f7486ac9
commit 38978645b2
2 changed files with 43 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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) {