Run unit tests
[ric-plt/appmgr.git] / pkg / resthooks / resthooks.go
index 5076b06..471eec1 100755 (executable)
@@ -32,13 +32,17 @@ import (
        "gerrit.oran-osc.org/r/ric-plt/appmgr/pkg/models"
 )
 
-func NewResthook() *Resthook {
+func NewResthook(restoreData bool) *Resthook {
        rh := &Resthook{
                client: &http.Client{},
                db:     sdl.NewSdlInstance("appmgr", sdl.NewDatabase()),
        }
 
-       rh.subscriptions = rh.RestoreSubscriptions()
+       if restoreData {
+               rh.subscriptions = rh.RestoreSubscriptions()
+       } else {
+               rh.subscriptions = cmap.New()
+       }
        return rh
 }
 
@@ -122,7 +126,14 @@ func (rh *Resthook) NotifyClients(xapps models.AllDeployedXapps, et models.Event
 }
 
 func (rh *Resthook) notify(xapps models.AllDeployedXapps, et models.EventType, s SubscriptionInfo, seq int64) error {
-       notif := models.SubscriptionNotification{ID: s.Id, Version: seq, EventType: et, XApps: xapps}
+       xappData, err := json.Marshal(xapps)
+       if err != nil {
+               appmgr.Logger.Info("json.Marshal failed: %v", err)
+               return err
+       }
+
+       // TODO: Use models.SubscriptionNotification instead of internal ...
+       notif := SubscriptionNotification{ID: s.Id, Version: seq, Event: string(et), XApps: string(xappData)}
        jsonData, err := json.Marshal(notif)
        if err != nil {
                appmgr.Logger.Info("json.Marshal failed: %v", err)