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

Implement Logic for zone location event notification

parent 8e768a6d
Loading
Loading
Loading
Loading
+142 −51
Original line number Diff line number Diff line
@@ -1461,6 +1461,26 @@ func sendZonalPresenceNotification1(notifyUrl string, notification InlineUserLoc
	defer resp.Body.Close()
}

func sendZonalPresenceNotification_L(notifyUrl string, notification InlineZoneLocationEventNotification) {
	startTime := time.Now()
	jsonNotif, err := json.Marshal(notification)
	if err != nil {
		log.Error(err)
		return
	}

	resp, err := http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
	duration := float64(time.Since(startTime).Microseconds()) / 1000.0
	_ = httpLog.LogNotification(notifyUrl, "POST", "", "", string(jsonNotif), resp, startTime)
	if err != nil {
		log.Error(err)
		met.ObserveNotification(sandboxName, serviceName, notifZonalPresence, notifyUrl, nil, duration)
		return
	}
	met.ObserveNotification(sandboxName, serviceName, notifZonalPresence, notifyUrl, resp, duration)
	defer resp.Body.Close()
}

func sendZonalPresenceNotification(notifyUrl string, notification InlineZonalPresenceNotification) {
	startTime := time.Now()
	jsonNotif, err := json.Marshal(notification)
@@ -1540,9 +1560,7 @@ func sendSubscriptionNotification(notifyUrl string, notification InlineSubscript
	met.ObserveNotification(sandboxName, serviceName, notifSubscription, notifyUrl, resp, duration)
	defer resp.Body.Close()
}

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

func checkNotificationRegisteredZones1(oldZoneId string, newZoneId string, oldApId string, newApId string, userId string) {
	mutex.Lock()
	defer mutex.Unlock()

@@ -1560,53 +1578,25 @@ func checkNotificationRegisteredZones(oldZoneId string, newZoneId string, oldApI
					if jsonInfo != "" {
						subscription := convertJsonToZonalSubscription(jsonInfo)

						var zonal ZonalPresenceNotification
						var zonal ZoneLocationEventNotification
						zonal.ZoneId = newZoneId
						zonal.CurrentAccessPointId = newApId
						// zonal.CurrentAccessPointId = newApId
						zonal.Address = userId
						event := new(UserEventType)
						*event = ENTERING_UserEventType
						zonal.UserEventType = event
						event := new(LocationEventType)
						*event = ENTERING_AREA_EVENT
						zonal.UserLocationEvent = event
						seconds := time.Now().Unix()
						var timestamp TimeStamp
						timestamp.Seconds = int32(seconds)
						zonal.Timestamp = &timestamp
						zonal.TimeStamp = &timestamp
						zonal.CallbackData = subscription.CallbackReference.CallbackData
						var inlineZonal InlineZonalPresenceNotification
						inlineZonal.ZonalPresenceNotification = &zonal
						sendZonalPresenceNotification(subscription.CallbackReference.NotifyURL, inlineZonal)
						var inlineZonal InlineZoneLocationEventNotification
						inlineZonal.ZoneLocationEventNotification = &zonal
						// sendZonalPresenceNotification(subscription.CallbackReference.NotifyURL, inlineZonal)
						sendZonalPresenceNotification_L(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 {
@@ -1618,21 +1608,21 @@ func checkNotificationRegisteredZones(oldZoneId string, newZoneId string, oldApI

						subscription := convertJsonToZonalSubscription(jsonInfo)

						var zonal ZonalPresenceNotification
						var zonal ZoneLocationEventNotification
						zonal.ZoneId = oldZoneId
						zonal.CurrentAccessPointId = oldApId
						// zonal.CurrentAccessPointId = oldApId
						zonal.Address = userId
						event := new(UserEventType)
						*event = LEAVING_UserEventType
						zonal.UserEventType = event
						event := new(LocationEventType)
						*event = LEAVING_AREA_EVENT
						zonal.UserLocationEvent = event
						seconds := time.Now().Unix()
						var timestamp TimeStamp
						timestamp.Seconds = int32(seconds)
						zonal.Timestamp = &timestamp
						zonal.TimeStamp = &timestamp
						zonal.CallbackData = subscription.CallbackReference.CallbackData
						var inlineZonal InlineZonalPresenceNotification
						inlineZonal.ZonalPresenceNotification = &zonal
						sendZonalPresenceNotification(subscription.CallbackReference.NotifyURL, inlineZonal)
						var inlineZonal InlineZoneLocationEventNotification
						inlineZonal.ZoneLocationEventNotification = &zonal
						sendZonalPresenceNotification_L(subscription.CallbackReference.NotifyURL, inlineZonal)
						log.Info("Zonal Notify Leaving event in zone " + oldZoneId + " for user " + userId)
					}
				}
@@ -1641,6 +1631,106 @@ func checkNotificationRegisteredZones(oldZoneId string, newZoneId string, oldApI
	}
}

// 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
@@ -4603,7 +4693,8 @@ func updateUserInfo(address string, zoneId string, accessPointId string, longitu
	_ = rc.JSONSetEntry(baseKey+typeUser+":"+address, ".", convertUserInfoToJson(userInfo))
	// checkNotificationRegisteredUsers(oldZoneId, zoneId, oldApId, accessPointId, address)
	checkNotificationRegisteredUsers1(oldZoneId, zoneId, oldApId, accessPointId, address)
	checkNotificationRegisteredZones(oldZoneId, zoneId, oldApId, accessPointId, address)
	checkNotificationRegisteredZones1(oldZoneId, zoneId, oldApId, accessPointId, address)
	// checkNotificationRegisteredZones(oldZoneId, zoneId, oldApId, accessPointId, address)
	checkNotificationAreaCircle(address)
}

+14 −0
Original line number Diff line number Diff line
/*
* ETSI GS MEC 013 - Location API
*
* The ETSI MEC ISG MEC013 Location API described using OpenAPI.
*
* API version: 3.1.1
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
package server

// Hyperlink related to the resource. This shall be only included in the HTTP responses and in HTTP PUT requests.
type Links struct {
	Self *LinkType `json:"self"`
}
+14 −0
Original line number Diff line number Diff line
/*
* AdvantEDGE Location API
*
* Location Service is AdvantEDGE's implementation of [ETSI MEC ISG MEC013 Location API](https://www.etsi.org/deliver/etsi_gs/MEC/001_099/013/02.02.01_60/gs_mec013v020201p.pdf) <p>The API is based on the Open Mobile Alliance's specification RESTful Network API for Zonal Presence <p>[Copyright (c) ETSI 2017](https://forge.etsi.org/etsi-forge-copyright-notice.txt) <p>**Micro-service**<br>[meep-loc-serv](https://github.com/InterDigitalInc/AdvantEDGE/tree/master/go-apps/meep-loc-serv) <p>**Type & Usage**<br>Edge Service used by edge applications that want to get information about Users (UE) and Zone locations <p>**Note**<br>AdvantEDGE supports all of Location API endpoints (see below).
*
* API version: 2.2.1
* Contact: AdvantEDGE@InterDigital.com
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
package server

type InlineZoneLocationEventNotification struct {
	ZoneLocationEventNotification *ZoneLocationEventNotification `json:"userLocationPeriodicNotification,omitempty"`
}
+1 −1
Original line number Diff line number Diff line
@@ -24,6 +24,6 @@
package server

type LinkType struct {
	// URI referring to a resource
	// URI referring to a resource.
	Href string `json:"href"`
}
+25 −0
Original line number Diff line number Diff line
/*
* ETSI GS MEC 013 - Location API
*
* The ETSI MEC ISG MEC013 Location API described using OpenAPI.
*
* API version: 3.1.1
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
package server

type ZoneLocationEventNotification struct {
	Links *Links `json:"_links"`
	// Address of user (e.g. ‘sip’ URI, ‘tel’ URI, ‘acr’ URI).
	Address string `json:"address"`
	// Shall be set to \"ZoneLocationEventNotification\".
	NotificationType string `json:"notificationType"`

	TimeStamp *TimeStamp `json:"timeStamp,omitempty"`

	UserLocationEvent *LocationEventType `json:"userLocationEvent"`
	// The identity of the zone.
	ZoneId string `json:"zoneId"`

	CallbackData string `json:"callbackData,omitempty"`
}