Ejemplo n.º 1
0
// Queries specific RatingProfile on tariff plan
func (self *ApierV1) GetTPRatingProfilesByLoadId(attrs utils.TPRatingProfile, reply *[]*utils.TPRatingProfile) error {
	mndtryFlds := []string{"TPid", "LoadId"}
	if len(attrs.Subject) != 0 { // If Subject provided as filter, make all related fields mandatory
		mndtryFlds = append(mndtryFlds, "Tenant", "TOR", "Direction", "Subject")
	}
	if missing := utils.MissingStructFields(&attrs, mndtryFlds); len(missing) != 0 { //Params missing
		return utils.NewErrMandatoryIeMissing(missing...)
	}
	rpf := engine.APItoModelRatingProfile(&attrs)
	if dr, err := self.StorDb.GetTpRatingProfiles(&rpf[0]); err != nil {
		return utils.NewErrServerError(err)
	} else if dr == nil {
		return utils.ErrNotFound
	} else {
		rpfMap, err := engine.TpRatingProfiles(dr).GetRatingProfiles()
		if err != nil {
			return err
		}
		var rpfs []*utils.TPRatingProfile
		if len(attrs.Subject) != 0 {
			rpfs = []*utils.TPRatingProfile{rpfMap[attrs.KeyId()]}
		} else {
			for _, rpfLst := range rpfMap {
				rpfs = append(rpfs, rpfLst)
			}
		}
		*reply = rpfs
	}
	return nil
}
Ejemplo n.º 2
0
// Queries specific RatingProfile on tariff plan
func (self *ApierV1) GetTPRatingProfile(attrs AttrGetTPRatingProfile, reply *utils.TPRatingProfile) error {
	if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingProfileId"}); len(missing) != 0 { //Params missing
		return utils.NewErrMandatoryIeMissing(missing...)
	}
	tmpRpf := &utils.TPRatingProfile{TPid: attrs.TPid}
	if err := tmpRpf.SetRatingProfilesId(attrs.RatingProfileId); err != nil {
		return err
	}
	rpf := engine.APItoModelRatingProfile(tmpRpf)
	if rpfs, err := self.StorDb.GetTpRatingProfiles(&rpf[0]); err != nil {
		return utils.NewErrServerError(err)
	} else if len(rpfs) == 0 {
		return utils.ErrNotFound
	} else {
		rpfMap, err := engine.TpRatingProfiles(rpfs).GetRatingProfiles()
		if err != nil {
			return err
		}
		rpf := rpfMap[tmpRpf.KeyId()]
		tpdc := utils.TPRatingProfile{
			TPid: attrs.TPid,
			RatingPlanActivations: rpf.RatingPlanActivations,
		}
		if err := tpdc.SetRatingProfilesId(attrs.RatingProfileId); err != nil {
			return err
		}
		*reply = tpdc
	}
	return nil
}