Commit 4eb359be authored by Ikram Haq's avatar Ikram Haq
Browse files

Implement the logic to handle zone status subscriptions

parent b13714ba
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -3987,8 +3987,6 @@ components:
      type: object
      x-etsi-ref: 6.4.6



    ZoneStatusNotification:
      description: A type containing zone status notification.
      properties:
+58 −13
Original line number Diff line number Diff line
@@ -3787,8 +3787,8 @@ func zonalTrafficSubGet(w http.ResponseWriter, r *http.Request) {

func zoneSubPOST(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	var response InlineZoneLocationEventSubscription
	var body InlineZoneLocationEventSubscription
	var response InlineZoneStatusSubscription
	var body InlineZoneStatusSubscription
	decoder := json.NewDecoder(r.Body)
	err := decoder.Decode(&body)
	if err != nil {
@@ -3796,31 +3796,31 @@ func zoneSubPOST(w http.ResponseWriter, r *http.Request) {
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}
	zonalSub := body.ZoneLocationEventSubscription

	if zonalSub == nil {
	zoneStatusSub := body.ZoneStatusSubscription
	if zoneStatusSub == nil {
		log.Error("Body not present")
		errHandlerProblemDetails(w, "Body not present", http.StatusBadRequest)
		return
	}
	//checking for mandatory properties
	if zonalSub.CallbackReference == nil || zonalSub.CallbackReference.NotifyURL == "" {
	if zoneStatusSub.CallbackReference == nil || zoneStatusSub.CallbackReference.NotifyURL == "" {
		log.Error("Mandatory CallbackReference parameter not present")
		errHandlerProblemDetails(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
		return
	}
	if zonalSub.ZoneId == "" {
	if zoneStatusSub.ZoneId == "" {
		log.Error("Mandatory ZoneId parameter not present")
		errHandlerProblemDetails(w, "Mandatory ZoneId parameter not present", http.StatusBadRequest)
		return
	}
	newSubsId := nextZonalSubscriptionIdAvailable
	nextZonalSubscriptionIdAvailable++
	newSubsId := nextZoneStatusSubscriptionIdAvailable
	nextZoneStatusSubscriptionIdAvailable++
	subsIdStr := strconv.Itoa(newSubsId)
	zonalSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/zones/" + subsIdStr
	_ = rc.JSONSetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".", convertZonalSubscriptionToJson1(zonalSub))
	registerZonal1(zonalSub.ZoneId, zonalSub.LocationEventCriteria, subsIdStr)
	response.ZoneLocationEventSubscription = zonalSub
	zoneStatusSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/zones/" + subsIdStr
	_ = rc.JSONSetEntry(baseKey+typeZoneStatusSubscription+":"+subsIdStr, ".", convertZoneStatusSubscriptionToJson(zoneStatusSub))
	registerZoneStatus(zoneStatusSub.ZoneId, zoneStatusSub.UpperNumberOfUsersZoneThreshold, zoneStatusSub.UpperNumberOfUsersAPThreshold,
		zoneStatusSub.OperationStatus, subsIdStr)
	response.ZoneStatusSubscription = zoneStatusSub
	jsonResponse, err := json.Marshal(response)
	if err != nil {
		log.Error(err.Error())
@@ -3829,6 +3829,51 @@ func zoneSubPOST(w http.ResponseWriter, r *http.Request) {
	}
	w.WriteHeader(http.StatusCreated)
	fmt.Fprint(w, string(jsonResponse))

	// *****************************Zone *************************Event	********************
	// w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	// var response InlineZoneLocationEventSubscription
	// var body InlineZoneLocationEventSubscription
	// decoder := json.NewDecoder(r.Body)
	// err := decoder.Decode(&body)
	// if err != nil {
	// 	log.Error(err.Error())
	// 	errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
	// 	return
	// }
	// zonalSub := body.ZoneLocationEventSubscription

	// if zonalSub == nil {
	// 	log.Error("Body not present")
	// 	errHandlerProblemDetails(w, "Body not present", http.StatusBadRequest)
	// 	return
	// }
	// //checking for mandatory properties
	// if zonalSub.CallbackReference == nil || zonalSub.CallbackReference.NotifyURL == "" {
	// 	log.Error("Mandatory CallbackReference parameter not present")
	// 	errHandlerProblemDetails(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
	// 	return
	// }
	// if zonalSub.ZoneId == "" {
	// 	log.Error("Mandatory ZoneId parameter not present")
	// 	errHandlerProblemDetails(w, "Mandatory ZoneId parameter not present", http.StatusBadRequest)
	// 	return
	// }
	// newSubsId := nextZonalSubscriptionIdAvailable
	// nextZonalSubscriptionIdAvailable++
	// subsIdStr := strconv.Itoa(newSubsId)
	// zonalSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/zones/" + subsIdStr
	// _ = rc.JSONSetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".", convertZonalSubscriptionToJson1(zonalSub))
	// registerZonal1(zonalSub.ZoneId, zonalSub.LocationEventCriteria, subsIdStr)
	// response.ZoneLocationEventSubscription = zonalSub
	// jsonResponse, err := json.Marshal(response)
	// if err != nil {
	// 	log.Error(err.Error())
	// 	errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
	// 	return
	// }
	// w.WriteHeader(http.StatusCreated)
	// fmt.Fprint(w, string(jsonResponse))
}

func zonalTrafficSubPost(w http.ResponseWriter, r *http.Request) {
+33 −30
Original line number Diff line number Diff line
/*
 * Copyright (c) 2022  The AdvantEDGE Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
* 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).
@@ -23,19 +9,36 @@
 */
package server

// A type containing zone status subscription.
type ZoneStatusSubscription struct {
	ResourceURL string `json:"resourceURL,omitempty"`
	// URI exposed by the client on which to receive notifications via HTTP. See note 1.
	CallbackReference *CallbackReference `json:"callbackReference"`
	// A correlator that the client can use to tag this particular resource representation during a request to create a resource on the server.
	// A correlator that the client can use to tag this particular resource representation during a request to create a resource on the server. See note 2.
	ClientCorrelator string `json:"clientCorrelator,omitempty"`
	// Threshold number of users in an access point which if crossed shall cause a notification

	ExpiryDeadline *TimeStamp `json:"expiryDeadline,omitempty"`
	// Threshold number of users in an access point which if crossed downward shall cause a notification
	LowerNumberOfUsersAPThreshold int32 `json:"lowerNumberOfUsersAPThreshold,omitempty"`
	// Threshold number of users in a zone which if crossed downward shall cause a notification
	LowerNumberOfUsersZoneThreshold int32 `json:"lowerNumberOfUsersZoneThreshold,omitempty"`
	// List of operation status values to generate notifications for (these apply to all access points within a zone). See note 3.
	OperationStatus []OperationStatus `json:"operationStatus,omitempty"`

	NumberOfUsersAPThreshold int32 `json:"numberOfUsersAPThreshold,omitempty"`
	// Threshold number of users in a zone which if crossed shall cause a notification

	NumberOfUsersZoneThreshold int32 `json:"numberOfUsersZoneThreshold,omitempty"`
	// List of operation status values to generate notifications for (these apply to all access points within a zone).
	OperationStatus []OperationStatus `json:"operationStatus,omitempty"`
	// Self referring URL
	ResourceURL string `json:"resourceURL,omitempty"`
	// Identifier of zone

	ReportingCtrl *ReportingCtrl `json:"reportingCtrl,omitempty"`
	// Set to TRUE by the service consumer to request a test notification via HTTP on the callbackReference URI, as specified in ETSI GS MEC 009 [4], clause 6.12a.
	RequestTestNotification bool `json:"requestTestNotification,omitempty"`
	// Shall be set to \"ZoneStatusSubscription\".
	SubscriptionType string `json:"subscriptionType"`
	// Threshold number of users in an access point which if crossed upward shall cause a notification.
	UpperNumberOfUsersAPThreshold int32 `json:"upperNumberOfUsersAPThreshold,omitempty"`
	// Threshold number of users in a zone which if crossed upward shall cause a notification.
	UpperNumberOfUsersZoneThreshold int32 `json:"upperNumberOfUsersZoneThreshold,omitempty"`

	WebsockNotifConfig *WebsockNotifConfig `json:"websockNotifConfig,omitempty"`
	// Identifier of zone (e.g. zone001) to monitor.
	ZoneId string `json:"zoneId"`
}