From: naman.gupta Date: Mon, 12 Dec 2022 12:54:17 +0000 (+0530) Subject: Fixing Get policy instance api X-Git-Tag: 3.0.0~2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=78126f13ffb2d60be7964ad90e78c226bc1da1ee;p=ric-plt%2Fa1.git Fixing Get policy instance api Fixing Get policy instance api return type Signed-off-by: naman.gupta Change-Id: I42b5c87c41a2efc25ac1cd63bc53e969882de64e --- diff --git a/pkg/resthooks/resthooks.go b/pkg/resthooks/resthooks.go index dcffe2a..956ae47 100644 --- a/pkg/resthooks/resthooks.go +++ b/pkg/resthooks/resthooks.go @@ -414,7 +414,7 @@ func (rh *Resthook) CreatePolicyInstance(policyTypeId models.PolicyTypeID, polic return nil } -func (rh *Resthook) GetPolicyInstance(policyTypeId models.PolicyTypeID, policyInstanceID models.PolicyInstanceID) (interface{}, error) { +func (rh *Resthook) GetPolicyInstance(policyTypeId models.PolicyTypeID, policyInstanceID models.PolicyInstanceID) (map[string]interface{}, error) { a1.Logger.Debug("GetPolicyInstance1") var keys [1]string @@ -427,17 +427,17 @@ func (rh *Resthook) GetPolicyInstance(policyTypeId models.PolicyTypeID, policyIn valmap, err := rh.db.Get(a1MediatorNs, keys[:]) if len(valmap) == 0 { a1.Logger.Debug("policy type Not Present for policyid : %v", policyTypeId) - return "{}", policyTypeNotFoundError + return map[string]interface{}{}, policyTypeNotFoundError } if err != nil { a1.Logger.Error("error in retrieving policy type. err: %v", err) - return "{}", err + return map[string]interface{}{}, err } if valmap[typekey] == nil { a1.Logger.Debug("policy type Not Present for policyid : %v", policyTypeId) - return "{}", policyTypeNotFoundError + return map[string]interface{}{}, policyTypeNotFoundError } a1.Logger.Debug("keysmap : %+v", valmap[typekey]) @@ -453,10 +453,15 @@ func (rh *Resthook) GetPolicyInstance(policyTypeId models.PolicyTypeID, policyIn if instanceMap[instancekey] == nil { a1.Logger.Debug("policy instance Not Present for policyinstaneid : %v", policyInstanceID) - return "{}", policyInstanceNotFoundError + return map[string]interface{}{}, policyInstanceNotFoundError } - valStr := fmt.Sprint(instanceMap[instancekey]) + var valStr map[string]interface{} + err = json.Unmarshal([]byte(instanceMap[instancekey].(string)), &valStr) + if err != nil { + fmt.Println("error:", err) + } + fmt.Println(valStr) return valStr, nil } @@ -543,7 +548,7 @@ func (rh *Resthook) instanceValidity(policyTypeId models.PolicyTypeID, policyIns a1.Logger.Error("policy instance error : %v", err) return err } - if len(policyTypeInstances.(string)) == 0 { + if policyTypeInstances == nil { a1.Logger.Debug("policy instance Not Present ") return policyInstanceNotFoundError }