Commit cca043da authored by Ikram Haq's avatar Ikram Haq
Browse files

Implement logic to handle addresslist attribute in zoneLocationEventSubscription

parent 9297d3a0
Loading
Loading
Loading
Loading
+103 −251
Original line number Diff line number Diff line
@@ -2321,8 +2321,66 @@ func checkNotificationRegisteredZones1(oldZoneId string, newZoneId string, oldAp
			}
			continue
		}
		if zonalSubscriptionMapLink[subsId].Subscription.AddressList == nil {
			// Check if the current zone matches the subscription zone
			if value == newZoneId {
				if newZoneId != oldZoneId {
					// Check if entering event subscription exists
					if zonalSubscriptionEnteringMap[subsId] != "" {
						// Check if reporting control parameters are provided
						// if zonalSubscriptionMapLink[subsId].Reporting_amount > 0 && zonalSubscriptionMapLink[subsId].Reporting_interval > 0 {
						if zonalSubscriptionMapLink[subsId].Subscription.ReportingCtrl != nil {
							// If NextTts has passed, send notification

							if currentTime >= int64(zonalSubscriptionMapLink[subsId].NextTts) {
								// Update NextTts for the next notification
								zonalSubscriptionMapLink[subsId].NextTts = int32(currentTime + int64(zonalSubscriptionMapLink[subsId].Reporting_interval))
								// Check if reporting amount is reached
								if zonalSubscriptionMapLink[subsId].Reporting_amount <= 0 {
									// If reporting amount is zero, no more notifications should be sent
									continue
								}
								// Decrement reporting amount
								zonalSubscriptionMapLink[subsId].Reporting_amount--
								sendNotification_1(subsId, newZoneId, userId, ENTERING_AREA_EVENT)
							}
						} else {
							// If no reporting control parameters, send notification without conditions
							sendNotification_1(subsId, newZoneId, userId, ENTERING_AREA_EVENT)
						}
					}
				}
			} else {
				// Check if leaving event subscription exists
				if value == oldZoneId {
					if zonalSubscriptionLeavingMap[subsId] != "" {

						// if zonalSubscriptionMapLink[subsId].Reporting_amount > 0 && zonalSubscriptionMapLink[subsId].Reporting_interval > 0 {
						if zonalSubscriptionMapLink[subsId].Subscription.ReportingCtrl != nil {
							// If NextTts has passed, send notification
							if currentTime >= int64(zonalSubscriptionMapLink[subsId].NextTts) {
								// Update NextTts for the next notification
								zonalSubscriptionMapLink[subsId].NextTts = int32(currentTime + int64(zonalSubscriptionMapLink[subsId].Reporting_interval))
								// Check if reporting amount is reached
								if zonalSubscriptionMapLink[subsId].Reporting_amount <= 0 {
									// If reporting amount is zero, no more notifications should be sent
									continue
								}
								// Decrement reporting amount
								zonalSubscriptionMapLink[subsId].Reporting_amount--
								sendNotification_1(subsId, oldZoneId, userId, LEAVING_AREA_EVENT)
							}
						} else {
							// If no reporting control parameters, send notification without conditions
							sendNotification_1(subsId, oldZoneId, userId, LEAVING_AREA_EVENT)
						}
					}
				}
			}
		} else {
			// Check if the current zone matches the subscription zone
			for _, addr := range zonalSubscriptionMapLink[subsId].Subscription.AddressList {
				if addr == userId {
					if value == newZoneId {
						if newZoneId != oldZoneId {
							// Check if entering event subscription exists
@@ -2379,6 +2437,9 @@ func checkNotificationRegisteredZones1(oldZoneId string, newZoneId string, oldAp
					}
				}
			}
		}
	}
}
func sendNotification_1(subsId int, zoneId string, userId string, eventType LocationEventType) {
	subsIdStr := strconv.Itoa(subsId)
	jsonInfo, _ := rc.JSONGetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".")
@@ -2415,215 +2476,6 @@ func sendNotification_1(subsId int, zoneId string, userId string, eventType Loca
	}
}

// func checkNotificationRegisteredZones1(oldZoneId string, newZoneId string, oldApId string, newApId string, userId string) {
// 	mutex.Lock()
// 	defer mutex.Unlock()
// 	currentTime := time.Now().Unix()
// 	//check all that applies
// 	for subsId, value := range zonalSubscriptionMap {

// 		subsIdStr := strconv.Itoa(subsId)
// 		if zonalSubscriptionMapLink[subsId].Subscription.ExpiryDeadline != nil && time.Now().Unix() > int64(zonalSubscriptionMapLink[subsId].TimeStamp) {
// 			log.Info("Expiry deadline passed for subscription: " + subsIdStr)
// 			// Optionally, you can remove the subscription from the map or perform other cleanup actions
// 			err := rc.JSONDelEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".")
// 			if err != nil {
// 				log.Error(err.Error())
// 			}
// 			continue
// 		}
// 		if value == newZoneId {

// 			if newZoneId != oldZoneId {

// 				if zonalSubscriptionEnteringMap[subsId] != "" {
// 					// subscription := zonalSubscriptionMapLink[subsId].Subscription
// 					if currentTime >= int64(zonalSubscriptionMapLink[subsId].NextTts) {
// 						// Update NextTts for the next notification
// 						zonalSubscriptionMapLink[subsId].NextTts = int32(currentTime + int64(zonalSubscriptionMapLink[subsId].Reporting_interval))
// 						// Check if reporting amount is reached
// 						if zonalSubscriptionMapLink[subsId].Reporting_amount <= 0 {
// 							// If reporting amount is zero, no more notifications should be sent
// 							continue
// 						}
// 						// Decrement reporting amount
// 						zonalSubscriptionMapLink[subsId].Reporting_amount--
// 						subsIdStr := strconv.Itoa(subsId)

// 						jsonInfo, _ := rc.JSONGetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".")
// 						if jsonInfo != "" {
// 							subscription := convertJsonToZonalSubscription_1(jsonInfo)

// 							var zonal ZoneLocationEventNotification
// 							zonal.Links = &Links{} // Initialize Links outside the loop
// 							for _, value_ := range zonalSubscriptionMapLink {
// 								zonal.Links.Self = &LinkType{
// 									Href: value_.Subscription.Links.Self.Href,
// 								}
// 							}
// 							zonal.ZoneId = newZoneId
// 							// zonal.CurrentAccessPointId = newApId
// 							zonal.Address = userId
// 							zonal.NotificationType = "ZoneLocationEventNotification"
// 							event := new(LocationEventType)
// 							*event = ENTERING_AREA_EVENT
// 							zonal.UserLocationEvent = event
// 							seconds := time.Now().Unix()
// 							var timestamp TimeStamp
// 							timestamp.Seconds = int32(seconds)
// 							zonal.TimeStamp = &timestamp
// 							var inlineZonal InlineZoneLocationEventNotification
// 							inlineZonal.ZoneLocationEventNotification = &zonal
// 							sendZonalPresenceNotification_L(subscription.CallbackReference, inlineZonal)
// 							log.Info("Zonal Notify Entering event in zone " + newZoneId + " for user " + userId)
// 						}
// 					}
// 				}
// 			}
// 		} else {
// 			if value == oldZoneId {
// 				if zonalSubscriptionLeavingMap[subsId] != "" {
// 					// Check if it's time to send the next notification
// 					if currentTime >= int64(zonalSubscriptionMapLink[subsId].NextTts) {

// 						// Update NextTts for the next notification
// 						zonalSubscriptionMapLink[subsId].NextTts = int32(currentTime + int64(zonalSubscriptionMapLink[subsId].Reporting_interval))
// 						// Check if reporting amount is reached
// 						if zonalSubscriptionMapLink[subsId].Reporting_amount <= 0 {
// 							// If reporting amount is zero, no more notifications should be sent
// 							continue
// 						}
// 						// Decrement reporting amount
// 						zonalSubscriptionMapLink[subsId].Reporting_amount--
// 						subsIdStr := strconv.Itoa(subsId)

// 						jsonInfo, _ := rc.JSONGetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".")
// 						if jsonInfo != "" {

// 							subscription := convertJsonToZonalSubscription_1(jsonInfo)

// 							var zonal ZoneLocationEventNotification
// 							zonal.ZoneId = oldZoneId
// 							zonal.Address = userId
// 							event := new(LocationEventType)
// 							*event = LEAVING_AREA_EVENT
// 							zonal.UserLocationEvent = event
// 							seconds := time.Now().Unix()
// 							var timestamp TimeStamp
// 							timestamp.Seconds = int32(seconds)
// 							zonal.TimeStamp = &timestamp
// 							var inlineZonal InlineZoneLocationEventNotification
// 							inlineZonal.ZoneLocationEventNotification = &zonal
// 							sendZonalPresenceNotification_L(subscription.CallbackReference, inlineZonal)
// 							log.Info("Zonal Notify Leaving event in zone " + oldZoneId + " for user " + userId)
// 						}
// 					}
// 				}
// 			}
// 		}
// 	}
// }

// func checkNotificationRegisteredZones(oldZoneId string, newZoneId string, oldApId string, newApId string, userId string) {

// 	mutex.Lock()
// 	defer mutex.Unlock()

// 	//check all that applies
// 	for subsId, value := range zonalSubscriptionMap {

// 		if value == newZoneId {

// 			if newZoneId != oldZoneId {

// 				if zonalSubscriptionEnteringMap[subsId] != "" {
// 					subsIdStr := strconv.Itoa(subsId)

// 					jsonInfo, _ := rc.JSONGetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".")
// 					if jsonInfo != "" {
// 						subscription := convertJsonToZonalSubscription(jsonInfo)

// 						var zonal ZonalPresenceNotification
// 						zonal.ZoneId = newZoneId
// 						zonal.CurrentAccessPointId = newApId
// 						zonal.Address = userId
// 						event := new(UserEventType)
// 						*event = ENTERING_UserEventType
// 						zonal.UserEventType = event
// 						seconds := time.Now().Unix()
// 						var timestamp TimeStamp
// 						timestamp.Seconds = int32(seconds)
// 						zonal.Timestamp = &timestamp
// 						zonal.CallbackData = subscription.CallbackReference.CallbackData
// 						var inlineZonal InlineZonalPresenceNotification
// 						inlineZonal.ZonalPresenceNotification = &zonal
// 						sendZonalPresenceNotification(subscription.CallbackReference.NotifyURL, inlineZonal)
// 						log.Info("Zonal Notify Entering event in zone " + newZoneId + " for user " + userId)
// 					}
// 				}
// 			} else {
// 				if newApId != oldApId {
// 					if zonalSubscriptionTransferringMap[subsId] != "" {
// 						subsIdStr := strconv.Itoa(subsId)

// 						jsonInfo, _ := rc.JSONGetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".")
// 						if jsonInfo != "" {
// 							subscription := convertJsonToZonalSubscription(jsonInfo)

// 							var zonal ZonalPresenceNotification
// 							zonal.ZoneId = newZoneId
// 							zonal.CurrentAccessPointId = newApId
// 							zonal.PreviousAccessPointId = oldApId
// 							zonal.Address = userId
// 							event := new(UserEventType)
// 							*event = TRANSFERRING_UserEventType
// 							zonal.UserEventType = event
// 							seconds := time.Now().Unix()
// 							var timestamp TimeStamp
// 							timestamp.Seconds = int32(seconds)
// 							zonal.Timestamp = &timestamp
// 							zonal.CallbackData = subscription.CallbackReference.CallbackData
// 							var inlineZonal InlineZonalPresenceNotification
// 							inlineZonal.ZonalPresenceNotification = &zonal
// 							sendZonalPresenceNotification(subscription.CallbackReference.NotifyURL, inlineZonal)
// 							log.Info("Zonal Notify Transferring event in zone " + newZoneId + " for user " + userId + " from Ap " + oldApId + " to " + newApId)
// 						}
// 					}
// 				}
// 			}
// 		} else {
// 			if value == oldZoneId {
// 				if zonalSubscriptionLeavingMap[subsId] != "" {
// 					subsIdStr := strconv.Itoa(subsId)

// 					jsonInfo, _ := rc.JSONGetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".")
// 					if jsonInfo != "" {

// 						subscription := convertJsonToZonalSubscription(jsonInfo)

// 						var zonal ZonalPresenceNotification
// 						zonal.ZoneId = oldZoneId
// 						zonal.CurrentAccessPointId = oldApId
// 						zonal.Address = userId
// 						event := new(UserEventType)
// 						*event = LEAVING_UserEventType
// 						zonal.UserEventType = event
// 						seconds := time.Now().Unix()
// 						var timestamp TimeStamp
// 						timestamp.Seconds = int32(seconds)
// 						zonal.Timestamp = &timestamp
// 						zonal.CallbackData = subscription.CallbackReference.CallbackData
// 						var inlineZonal InlineZonalPresenceNotification
// 						inlineZonal.ZonalPresenceNotification = &zonal
// 						sendZonalPresenceNotification(subscription.CallbackReference.NotifyURL, inlineZonal)
// 						log.Info("Zonal Notify Leaving event in zone " + oldZoneId + " for user " + userId)
// 					}
// 				}
// 			}
// 		}
// 	}
// }

func usersGet(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	var userData UeUserData