diff --git a/go-apps/meep-app-enablement/server/capif-mgmt/api_mec_service_mgmt.go b/go-apps/meep-app-enablement/server/capif-mgmt/api_mec_service_mgmt.go index 8f1fca70e6da72ed5b98d7fc4e0de04457ef69ec..e9e31a0abe5e8809104d0c8ed26e1bab1a5194b2 100644 --- a/go-apps/meep-app-enablement/server/capif-mgmt/api_mec_service_mgmt.go +++ b/go-apps/meep-app-enablement/server/capif-mgmt/api_mec_service_mgmt.go @@ -66,7 +66,9 @@ func ApplicationsSubscriptionsGET(w http.ResponseWriter, r *http.Request) { func ApplicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { applicationsSubscriptionsPOST(w, r) } - +func ApplicationsSubscriptionsPUT(w http.ResponseWriter, r *http.Request) { + applicationsSubscriptionsPUT(w, r) +} func ServicesGET(w http.ResponseWriter, r *http.Request) { servicesGET(w, r) } diff --git a/go-apps/meep-app-enablement/server/capif-mgmt/convert.go b/go-apps/meep-app-enablement/server/capif-mgmt/convert.go index 73bd9fc98932326839af40d0fc4b476cba5918e7..cd72190c95bac10df72e5b52aac252a15d7ed84e 100644 --- a/go-apps/meep-app-enablement/server/capif-mgmt/convert.go +++ b/go-apps/meep-app-enablement/server/capif-mgmt/convert.go @@ -87,6 +87,23 @@ func convertJsonToSerAvailabilityNotifSub(jsonData string) *SerAvailabilityNotif return &obj } +func convertEventFiltersToStrings(filters []CapifEventFilter) []string { + var stringFilters []string + for _, filter := range filters { + stringFilters = append(stringFilters, filter.ApiIds...) + } + return stringFilters +} + +func convertEventToStrings(events []CapifEvent) []string { + var stringEvents []string + if len(events) > 0 { + // Directly convert CapifEvent to string and append + stringEvents = append(stringEvents, string(events[0])) + } + return stringEvents +} + func convertJsonToSerAvailabilityNotifSub_1(jsonData string) *EventSubscription { var obj EventSubscription err := json.Unmarshal([]byte(jsonData), &obj) diff --git a/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go b/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go index 50f27bb6299b6c783770e5ad02ae3eb210e1a503..eb6d0f93c8b895bdf741cdb5f50a0295f40ac02b 100644 --- a/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go +++ b/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go @@ -882,6 +882,92 @@ func servicesGET(w http.ResponseWriter, r *http.Request) { } } +func applicationsSubscriptionsPUT(w http.ResponseWriter, r *http.Request) { + log.Info("applicationsSubscriptionsPUT") + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + vars := mux.Vars(r) + subId := vars["subscriptionId"] + appId := vars["subscriberId"] + + mutex.Lock() + defer mutex.Unlock() + + // Get App instance + appInfo, err := getAppInfo(appId) + if err != nil { + errHandlerProblemDetails(w, err.Error(), http.StatusNotFound) + return + } + + // Validate App info + code, problemDetails, err := validateAppInfo(appInfo) + if err != nil { + log.Error(err.Error()) + if problemDetails != "" { + w.WriteHeader(code) + fmt.Fprint(w, problemDetails) + } else { + errHandlerProblemDetails(w, err.Error(), code) + } + return + } + sub, err := subMgr.GetSubscription(subId) + if err != nil { + log.Error("Subscription not found: ", err.Error()) + errHandlerProblemDetails(w, "Subscription not found", http.StatusNotFound) + return + } + // Retrieve the update request + if r.Body == nil { + err := errors.New("Request body is missing") + errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) + return + } + var updatedSub EventSubscription + decoder := json.NewDecoder(r.Body) + err = decoder.Decode(&updatedSub) + if err != nil { + log.Error(err.Error()) + errHandlerProblemDetails(w, "Failed to decode request body", http.StatusInternalServerError) + return + } + if updatedSub.NotificationDestination == "" { + log.Error("Either NotificationDestination must be set") + errHandlerProblemDetails(w, "Either NotificationDestination must be set", http.StatusBadRequest) + return + } + // Update the subscription object + if updatedSub.NotificationDestination != "" { + sub.Cfg.NotifyUrl = updatedSub.NotificationDestination + } + if updatedSub.RequestTestNotification { + sub.Cfg.RequestTestNotif = true + } + // if updatedSub.RequestWebsocketUri { + // sub.Cfg.RequestWebsocketUri = true + // } else { + // sub.Cfg.RequestWebsocketUri = false + // } + // Update event filters if provided + if updatedSub.EventFilters != nil { + sub.Cfg.EventFilters = convertEventFiltersToStrings(updatedSub.EventFilters) + } + if updatedSub.Events != nil { + sub.Cfg.CapifEvent = convertEventToStrings(updatedSub.Events) + } + // Update the subscription in the manager + err = subMgr.UpdateSubscription(sub) + if err != nil { + log.Error("Failed to update subscription: ", err.Error()) + errHandlerProblemDetails(w, "Failed to update subscription", http.StatusInternalServerError) + return + } + jsonSub := convertSerAvailabilityNotifSubToJson_1(&updatedSub) + // Send success response + w.WriteHeader(http.StatusOK) + fmt.Fprint(w, jsonSub) +} + func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { log.Info("applicationsSubscriptionsPOST") @@ -2040,6 +2126,12 @@ func newSerAvailabilityNotifSubCfg(sub *SerAvailabilityNotificationSubscription, } func newSerAvailabilityNotifSubCfg_1(sub *EventSubscription, subId string, appId string) *subs.SubscriptionCfg { + var eventFilters []string + for _, filter := range sub.EventFilters { + eventFilters = append(eventFilters, filter.ApiIds...) + } + var capifEvent []string + capifEvent = append(capifEvent, string(sub.Events[0])) subCfg := &subs.SubscriptionCfg{ Id: subId, AppId: appId, @@ -2050,6 +2142,8 @@ func newSerAvailabilityNotifSubCfg_1(sub *EventSubscription, subId string, appId PeriodicInterval: 0, RequestTestNotif: false, RequestWebsocketUri: false, + EventFilters: eventFilters, + CapifEvent: capifEvent, } return subCfg } diff --git a/go-apps/meep-app-enablement/server/routers.go b/go-apps/meep-app-enablement/server/routers.go index 9ce35bb86c3453618da4dcc580c3919554afcadb..23926cef89e733d2db93fb725ba774dcf58a1da8 100644 --- a/go-apps/meep-app-enablement/server/routers.go +++ b/go-apps/meep-app-enablement/server/routers.go @@ -392,6 +392,13 @@ var routes = Routes{ capifMgmt.ApplicationsSubscriptionsPOST, }, + Route{ + "ApplicationsSubscriptionsPUT", + strings.ToUpper("Put"), + "/capif-events/v1/{subscriberId}/subscriptions/{subscriptionId} ", + capifMgmt.ApplicationsSubscriptionsPUT, + }, + Route{ "Index", "GET", diff --git a/go-packages/meep-subscriptions/subscription.go b/go-packages/meep-subscriptions/subscription.go index a679912af4171942a021297f2aae4beec4425465..d167455a98a0926b1f7514090ab17d3e20246086 100644 --- a/go-packages/meep-subscriptions/subscription.go +++ b/go-packages/meep-subscriptions/subscription.go @@ -40,6 +40,8 @@ type SubscriptionCfg struct { PeriodicInterval int32 `json:"periodicInterval"` RequestTestNotif bool `json:"reqTestNotif"` RequestWebsocketUri bool `json:"reqWebsockUri"` + EventFilters []string `json:"eventFilters"` + CapifEvent []string `json:"capifEvent"` } type Subscription struct {