Commit 3d718305 authored by Ikram Haq's avatar Ikram Haq
Browse files

Remove the unnecessary code and add the subscription ID in event notification

parent 38eeef2b
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -12,4 +12,6 @@ package server
type EventNotification struct {
type EventNotification struct {
	// The values SERVICE_API_AVAILABLE, SERVICE_API_UNAVAILABLE, and SERVICE_API_UPDATE defined in the type \"CAPIFEvent\" shall be supported. The remaining values of that type need not be supported.
	// The values SERVICE_API_AVAILABLE, SERVICE_API_UNAVAILABLE, and SERVICE_API_UPDATE defined in the type \"CAPIFEvent\" shall be supported. The remaining values of that type need not be supported.
	Events []CapifEvent `json:"events,omitempty"`
	Events []CapifEvent `json:"events,omitempty"`
	// Identifier of the subscription resource to which the notification is related
	SubscriptionId string `json:"subscriptionId"`
}
}
+8 −86
Original line number Original line Diff line number Diff line
@@ -933,16 +933,16 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) {
		errHandlerProblemDetails(w, "Mandatory NotificationDestination parameter not present", http.StatusBadRequest)
		errHandlerProblemDetails(w, "Mandatory NotificationDestination parameter not present", http.StatusBadRequest)
		return
		return
	}
	}
	// if serAvailNotifSub.SubscriptionType != SER_AVAILABILITY_NOTIF_SUB_TYPE {
	// 	log.Error("SubscriptionType shall be SerAvailabilityNotificationSubscription")
	// 	errHandlerProblemDetails(w, "SubscriptionType shall be SerAvailabilityNotificationSubscription", http.StatusBadRequest)
	// 	return
	// }


	// Validate Service filter params
	// Validate Service filter params
	if serAvailNotifSub.EventFilters != nil {
	if serAvailNotifSub.EventFilters != nil {
		nbMutuallyExclusiveParams := 0
		nbMutuallyExclusiveParams := 0
		for _, filter := range serAvailNotifSub.EventFilters {
		for _, filter := range serAvailNotifSub.EventFilters {
			if len(filter.ApiIds) == 0 {
				log.Error("Mandatory ApiIds(serInstanceIds) parameter not present")
				errHandlerProblemDetails(w, "Mandatory ApiIds(serInstanceIds) parameter not present", http.StatusBadRequest)
				return
			}
			if filter.ApiIds != nil && len(filter.ApiIds) > 0 {
			if filter.ApiIds != nil && len(filter.ApiIds) > 0 {
				nbMutuallyExclusiveParams++
				nbMutuallyExclusiveParams++
			}
			}
@@ -958,13 +958,6 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) {
	// Get a new subscription ID
	// Get a new subscription ID
	subId := subMgr.GenerateSubscriptionId()
	subId := subMgr.GenerateSubscriptionId()


	// // Set resource link
	// serAvailNotifSub.Links = &Self{
	// 	Self: &LinkType{
	// 		Href: hostUrl.String() + basePath + "applications/" + appId + "/subscriptions/" + subId,
	// 	},
	// }

	// Create & store subscription
	// Create & store subscription
	subCfg := newSerAvailabilityNotifSubCfg_1(&serAvailNotifSub, subId, appId)
	subCfg := newSerAvailabilityNotifSubCfg_1(&serAvailNotifSub, subId, appId)
	jsonSub := convertSerAvailabilityNotifSubToJson_1(&serAvailNotifSub)
	jsonSub := convertSerAvailabilityNotifSubToJson_1(&serAvailNotifSub)
@@ -974,10 +967,6 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) {
		errHandlerProblemDetails(w, "Failed to create subscription", http.StatusInternalServerError)
		errHandlerProblemDetails(w, "Failed to create subscription", http.StatusInternalServerError)
		return
		return
	}
	}
	// Self:
	// 	&LinkType{
	// 		Href: hostUrl.String() + basePath + "applications/" + appId + "/subscriptions/" + subId,
	// 	}
	hrefUrl := hostUrl.String() + basePath + "applications/" + appId + "/subscriptions/" + subId
	hrefUrl := hostUrl.String() + basePath + "applications/" + appId + "/subscriptions/" + subId
	// Send response
	// Send response
	w.Header().Set("Location", hrefUrl)
	w.Header().Set("Location", hrefUrl)
@@ -1858,59 +1847,11 @@ func checkSerAvailNotification(sInfo *ServiceInfo, mep string, changeType CapifE
					continue
					continue
				}
				}
			}
			}

			// Service Names
			// if origSub.FilteringCriteria.SerNames != nil && len(origSub.FilteringCriteria.SerNames) > 0 {
			// 	found := false
			// 	for _, serName := range origSub.FilteringCriteria.SerNames {
			// 		if serName == sInfo.SerName {
			// 			found = true
			// 			break
			// 		}
			// 	}
			// 	if !found {
			// 		continue
			// 	}
			// }

			// Service Categories
			// if origSub.FilteringCriteria.SerCategories != nil && len(origSub.FilteringCriteria.SerCategories) > 0 {
			// 	found := false
			// 	for _, serCategory := range origSub.FilteringCriteria.SerCategories {
			// 		if serCategory.Href == sInfo.SerCategory.Href &&
			// 			serCategory.Id == sInfo.SerCategory.Id &&
			// 			serCategory.Name == sInfo.SerCategory.Name &&
			// 			serCategory.Version == sInfo.SerCategory.Version {
			// 			found = true
			// 			break
			// 		}
			// 	}
			// 	if !found {
			// 		continue
			// 	}
			// }

			// Service states
			// if origSub.FilteringCriteria.States != nil && len(origSub.FilteringCriteria.States) > 0 {
			// 	found := false
			// 	for _, serState := range origSub.FilteringCriteria.States {
			// 		if serState == *sInfo.State {
			// 			found = true
			// 			break
			// 		}
			// 	}
			// 	if !found {
			// 		continue
			// 	}
			// }

			// // Service locality
			// if origSub.FilteringCriteria.IsLocal && !sInfo.IsLocal {
			// 	continue
			// }
		}
		}
		// Create a new EventNotification instance
		// Create a new EventNotification instance
		notif := &EventNotification{}
		notif := &EventNotification{
			SubscriptionId: sub.Cfg.Id,
		}


		// Set the event type based on changeType
		// Set the event type based on changeType
		var eventType CapifEvent
		var eventType CapifEvent
@@ -1929,25 +1870,6 @@ func checkSerAvailNotification(sInfo *ServiceInfo, mep string, changeType CapifE
		if eventType != "" {
		if eventType != "" {
			notif.Events = append(notif.Events, eventType)
			notif.Events = append(notif.Events, eventType)
		}
		}
		// // Create notification payload
		// notif := &ServiceAvailabilityNotification{
		// 	NotificationType: SER_AVAILABILITY_NOTIF_TYPE,
		// 	Links: &Subscription{
		// 		Subscription: &LinkType{
		// 			Href: sub.Cfg.Self,
		// 		},
		// 	},
		// }
		// serAvailabilityRef := ServiceAvailabilityNotificationServiceReferences{
		// 	Link: &LinkType{
		// 		Href: hostUrl.String() + basePath + "services/" + sInfo.SerInstanceId,
		// 	},
		// 	SerName:       sInfo.SerName,
		// 	SerInstanceId: sInfo.SerInstanceId,
		// 	State:         sInfo.State,
		// 	ChangeType:    &changeType,
		// }
		// notif.ServiceReferences = append(notif.ServiceReferences, serAvailabilityRef)


		// Send notification
		// Send notification
		go func(sub *subs.Subscription) {
		go func(sub *subs.Subscription) {