Commit 299d8d32 authored by Ikram Haq's avatar Ikram Haq
Browse files

Implement logic to handle expirydeadline attribute in Event and periodic subscription.

parent 87cd03c7
Loading
Loading
Loading
Loading
+87 −23
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ var userSubscriptionEnteringMap = map[int]string{}
var userSubscriptionLeavingMap = map[int]string{}
var userSubscriptionTransferringMap = map[int]string{}
var userSubscriptionMap = map[int]string{}

var userSubscriptionMapLink = map[int]*EventCheck{}
var zoneStatusSubscriptionMap = map[int]*ZoneStatusCheck{}
var distanceSubscriptionMap = map[int]*DistanceCheck{}
var distanceSubscriptionMap1 = map[int]*DistanceCheck_{}
@@ -152,8 +152,14 @@ type PeriodicCheck struct {
	Subscription *PeriodicNotificationSubscription
}

type EventCheck struct {
	TimeStamp    int64
	Subscription *UserLocationEventSubscription
}

type PeriodicCheck1 struct {
	NextTts            int32 //next time to send, derived from frequency
	TimeStamp          int64
	Reporting_amount   float64
	Reporting_interval float64
	Subscription       *UserLocationPeriodicSubscription
@@ -732,13 +738,19 @@ func deregisterUser(subsIdStr string) {
	userSubscriptionEnteringMap[subsId] = ""
	userSubscriptionLeavingMap[subsId] = ""
	userSubscriptionTransferringMap[subsId] = ""
	userSubscriptionMapLink[subsId] = nil
}

func registerUser1(userAddress string, event []LocationEventType, subsIdStr string) {
func registerUser1(userAddress string, event []LocationEventType, subsIdStr string, eventSub *UserLocationEventSubscription) {
	subsId, err := strconv.Atoi(subsIdStr)
	if err != nil {
		log.Error(err)
	}
	// Calculate expiry time by adding seconds to the current time
	var expiryTime int64
	if eventSub != nil && eventSub.ExpiryDeadline != nil {
		expiryTime = time.Now().Unix() + int64(eventSub.ExpiryDeadline.Seconds)
	}
	mutex.Lock()
	defer mutex.Unlock()
	if event != nil {
@@ -754,7 +766,11 @@ func registerUser1(userAddress string, event []LocationEventType, subsIdStr stri
		userSubscriptionEnteringMap[subsId] = userAddress
		userSubscriptionLeavingMap[subsId] = userAddress
	}
	var EventSub EventCheck
	EventSub.Subscription = eventSub
	userSubscriptionMap[subsId] = userAddress
	EventSub.TimeStamp = expiryTime
	userSubscriptionMapLink[subsId] = &EventSub
}

func registerUser(userAddress string, event []UserEventType, subsIdStr string) {
@@ -1244,6 +1260,17 @@ func checkNotificationPeriodicTrigger1() {
		if !addressConnectedMap[addr] {
			continue
		}
		// Check if the current time exceeds the expiry time
		if periodicCheck.Subscription.ExpiryDeadline != nil && time.Now().Unix() > int64(periodicSubscriptionMap1[subsId].TimeStamp) {
			subsIdStr := strconv.Itoa(subsId)
			log.Info("Expiry deadline passed for subscription: ")
			// Optionally, you can remove the subscription from the map or perform other cleanup actions
			err := rc.JSONDelEntry(baseKey+typePeriodicSubscription+":"+subsIdStr, ".")
			if err != nil {
				log.Error(err.Error())
			}
			continue
		}

		// Check if it's time to send the next notification
		timeDifference := currentTime - int64(periodicCheck.NextTts)
@@ -1524,6 +1551,10 @@ func registerPeriodic1(periodicSub *UserLocationPeriodicSubscription, subsIdStr
	if err != nil {
		log.Error(err)
	}
	var expiryTime int64
	if periodicSub != nil && periodicSub.ExpiryDeadline != nil {
		expiryTime = time.Now().Unix() + int64(periodicSub.ExpiryDeadline.Seconds)
	}

	mutex.Lock()
	defer mutex.Unlock()
@@ -1531,6 +1562,7 @@ func registerPeriodic1(periodicSub *UserLocationPeriodicSubscription, subsIdStr
	periodicCheck.Subscription = periodicSub
	periodicCheck.Reporting_amount = periodicSub.PeriodicEventInfo.ReportingAmount
	periodicCheck.Reporting_interval = periodicSub.PeriodicEventInfo.ReportingInterval
	periodicCheck.TimeStamp = expiryTime
	periodicSubscriptionMap1[subsId] = &periodicCheck
}

@@ -1700,9 +1732,25 @@ func checkNotificationRegisteredUsers1(oldZoneId string, newZoneId string, oldAp
				return
			}
			subscription := convertJsonToUserSubscription1(jsonInfo)

			// Check if the current time exceeds the expiry time
			if userSubscriptionMapLink[subsId].Subscription.ExpiryDeadline != nil && time.Now().Unix() > int64(userSubscriptionMapLink[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+typeUserSubscription+":"+subsIdStr, ".")
				if err != nil {
					log.Error(err.Error())
				}
				continue
			}
			var zonal UserLocationEventNotification
			zonal.Address = userId
			zonal.Links = &Links{} // Initialize Links outside the loop
			for _, value_ := range userSubscriptionMapLink {
				zonal.Links.Self = &LinkType{
					Href: value_.Subscription.Links.Self.Href,
				}
			}
			zonal.NotificationType = "UserLocationEventNotification"
			seconds := time.Now().Unix()
			var timestamp TimeStamp
			timestamp.Seconds = int32(seconds)
@@ -3754,11 +3802,12 @@ func handleUserLocationEventSubscription(w http.ResponseWriter, requestBody []ma
			nextUserSubscriptionIdAvailable = newSubsId + 2 // Increment by 2 to ensure the next even number
			subsIdStr := strconv.Itoa(newSubsId)

			registerUser1(userSubBody.Address, userSubBody.LocationEventCriteria, subsIdStr)
			userSubBody.Links = &Links{
				Self: &LinkType{
					Href: hostUrl.String() + basePath + "subscriptions/users/" + subsIdStr,
				},
			registerUser1(userSubBody.Address, userSubBody.LocationEventCriteria, subsIdStr, &userSubBody)
			// userSubBody.ResourceURL = hostUrl.String() + basePath + "subscriptions/user/" + subsIdStr
			userSubBody.Links = &Links{} // Initialize Links outside the loop

			userSubBody.Links.Self = &LinkType{
				Href: hostUrl.String() + basePath + "subscriptions/user/" + subsIdStr,
			}
			userSubBody.SubscriptionType = "userLocationEventSubscription"
			_ = rc.JSONSetEntry(baseKey+typeUserSubscription+":"+subsIdStr, ".", convertUserSubscriptionToJson1(&userSubBody))
@@ -3819,12 +3868,17 @@ func handleUserLocationPeriodicSubscription(w http.ResponseWriter, requestBody [
			newSubsId := nextPeriodicSubscriptionIdAvailable
			nextPeriodicSubscriptionIdAvailable += 2
			subsIdStr := strconv.Itoa(newSubsId)
			// periodicSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/user/" + subsIdStr
			periodicSub.Links = &Links{} // Initialize Links outside the loop

			periodicSub.Links = &Links{
				Self: &LinkType{
					Href: hostUrl.String() + basePath + "subscriptions/users/" + subsIdStr,
				},
			periodicSub.Links.Self = &LinkType{
				Href: hostUrl.String() + basePath + "subscriptions/user/" + subsIdStr,
			}
			// periodicSub.Links = &Links{
			// 	Self: &LinkType{
			// 		Href: hostUrl.String() + basePath + "subscriptions/users/" + subsIdStr,
			// 	},
			// }
			periodicSub.SubscriptionType = "userLocationPeriodicSubscription"
			_ = rc.JSONSetEntry(baseKey+typePeriodicSubscription+":"+subsIdStr, ".", convertPeriodicSubscriptionToJson1(&periodicSub))
			registerPeriodic1(&periodicSub, subsIdStr)
@@ -4171,12 +4225,17 @@ func handleUserLocationEventSubscriptionPut(w http.ResponseWriter, requestBody [
				errHandlerProblemDetails(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest)
				return
			}
			// userSubBody.ResourceURL = hostUrl.String() + basePath + "subscriptions/user/" + subsIdStr
			userSubBody.Links = &Links{} // Initialize Links outside the loop

			userSubBody.Links = &Links{
				Self: &LinkType{
					Href: hostUrl.String() + basePath + "subscriptions/users/" + subsIdStr,
				},
			userSubBody.Links.Self = &LinkType{
				Href: hostUrl.String() + basePath + "subscriptions/user/" + subsIdStr,
			}
			// userSubBody.Links = &Links{
			// 	Self: &LinkType{
			// 		Href: hostUrl.String() + basePath + "subscriptions/users/" + subsIdStr,
			// 	},
			// }
			userSubBody.SubscriptionType = "userLocationEventSubscription"

			subsId, err := strconv.Atoi(subsIdStr)
@@ -4195,7 +4254,7 @@ func handleUserLocationEventSubscriptionPut(w http.ResponseWriter, requestBody [

			deregisterUser(subsIdStr)

			registerUser1(userSubBody.Address, userSubBody.LocationEventCriteria, subsIdStr)
			registerUser1(userSubBody.Address, userSubBody.LocationEventCriteria, subsIdStr, &userSubBody)
			var response InlineUserLocationEventSubscription
			response.UserLocationEventSubscription = &userSubBody

@@ -4209,7 +4268,7 @@ func handleUserLocationEventSubscriptionPut(w http.ResponseWriter, requestBody [

			// Write response
			w.Header().Set("Content-Type", "application/json; charset=UTF-8")
			w.WriteHeader(http.StatusCreated)
			w.WriteHeader(http.StatusOK)
			fmt.Fprint(w, string(jsonResponse))
			return

@@ -4249,12 +4308,17 @@ func handleUserLocationPeriodicSubscriptionPut(w http.ResponseWriter, requestBod
				errHandlerProblemDetails(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest)
				return
			}
			// periodicSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/user/" + subsIdStr
			periodicSub.Links = &Links{} // Initialize Links outside the loop

			periodicSub.Links = &Links{
				Self: &LinkType{
					Href: hostUrl.String() + basePath + "subscriptions/users/" + subsIdStr,
				},
			periodicSub.Links.Self = &LinkType{
				Href: hostUrl.String() + basePath + "subscriptions/user/" + subsIdStr,
			}
			// periodicSub.Links = &Links{
			// 	Self: &LinkType{
			// 		Href: hostUrl.String() + basePath + "subscriptions/users/" + subsIdStr,
			// 	},
			// }
			periodicSub.SubscriptionType = "userLocationPeriodicSubscription"

			subsId, err := strconv.Atoi(subsIdStr)
@@ -4286,7 +4350,7 @@ func handleUserLocationPeriodicSubscriptionPut(w http.ResponseWriter, requestBod

			// Write response
			w.Header().Set("Content-Type", "application/json; charset=UTF-8")
			w.WriteHeader(http.StatusCreated)
			w.WriteHeader(http.StatusOK)
			fmt.Fprint(w, string(jsonResponse))
			return

+3 −3
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).
 * Location Service is AdvantEDGE's implementation of [ETSI MEC ISG MEC013 Location API](https://www.etsi.org/deliver/etsi_gs/MEC/001_099/013/03.01.01_60/gs_mec013v030101p.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
 * API version: 3.1.1
 * Contact: AdvantEDGE@InterDigital.com
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
@@ -30,5 +30,5 @@ type UserLocationEventNotification struct {
	UserLocationEvent *LocationEventType `json:"userLocationEvent"`
	// The identity of the zone.  For the events of \"ENTERING_AREA_EVENT\", it is the zone that the user is currently within.  For the event of \"LEAVING_AREA_EVENT\", it is the zone that the user used to be within. See note 2.
	ZoneId string `json:"zoneId,omitempty"`
	Links  *Links `json:"_links,omitempty"`
	Links  *Links `json:"links,omitempty"`
}
+4 −3
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).
 * Location Service is AdvantEDGE's implementation of [ETSI MEC ISG MEC013 Location API](https://www.etsi.org/deliver/etsi_gs/MEC/001_099/013/03.01.01_60/gs_mec013v030101p.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
 * API version: 3.1.1
 * Contact: AdvantEDGE@InterDigital.com
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
@@ -11,7 +11,8 @@ package server

// A type containing data for notifications, when the area is defined as a circle.
type UserLocationEventSubscription struct {
	Links *Links `json:"_links,omitempty"`
	// ResourceURL string `json:"resourceURL,omitempty"`
	Links *Links `json:"links,omitempty"`
	// Address of user (e.g. ‘sip’ URI, ‘tel’ URI, ‘acr’ URI) to monitor.
	Address string `json:"address,omitempty"`
	// URI exposed by the client on which to receive notifications via HTTP. See note 1.
+2 −2
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).
 * Location Service is AdvantEDGE's implementation of [ETSI MEC ISG MEC013 Location API](https://www.etsi.org/deliver/etsi_gs/MEC/001_099/013/03.01.01_60/gs_mec013v030101p.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
 * API version: 3.1.1
 * Contact: AdvantEDGE@InterDigital.com
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
+2 −1
Original line number Diff line number Diff line
@@ -10,7 +10,8 @@
package server

type UserLocationPeriodicSubscription struct {
	Links *Links `json:"_links,omitempty"`
	// ResourceURL string `json:"resourceURL,omitempty"`
	Links *Links `json:"links,omitempty"`
	// Address of user (e.g. ‘sip’ URI, ‘tel’ URI, ‘acr’ URI) to monitor.
	Address string `json:"address"`
	// URI exposed by the client on which to receive notifications via HTTP. See note 1.