Commit 851dac4b authored by Ikram Haq's avatar Ikram Haq
Browse files

Implement test function to check the user distance subscription

parent 45a08883
Loading
Loading
Loading
Loading
+279 −0
Original line number Diff line number Diff line
@@ -463,6 +463,147 @@ paths:
        '429':
          $ref: '#/components/responses/429'
      x-swagger-router-controller: 'subscriptions'

  /subscriptions/distance/test:
    get:
      tags:
        - 'location'
      summary: 'Retrieves all active subscriptions to distance change notifications'
      description: 'This operation is used for retrieving all active subscriptions to a distance change notifications.'
      operationId: distanceSubListGET_test
      responses:
        '200':
          description: "Upon success, a response body containing the list of links to requestor's subscriptions is returned."
          content:
            application/json:
              schema:
                type: object
                required:
                  - notificationSubscriptionList
                properties:
                  notificationSubscriptionList:
                    $ref: '#/components/schemas/NotificationSubscriptionList'
                example:
                  - notificationSubscriptionList:
                      subscription:
                        - href: 'http://meAppServer.example.com/location/v2/subscriptions/distance/subscription123'
                          subscriptionType: 'UserDistanceSubscription'
                      resourceURL:
                          href: 'http://meAppServer.example.com/location/v2/subscriptions/distance'
    post:
      tags:
        - 'location'
      summary: 'Creates a subscription for distance change notification'
      description: 'Creates a subscription to the Location Service for a distance change notification.'
      operationId: distanceSubPOST_test
      requestBody:
        description: 'The POST method is used to create a new subscription to user distance notifications.'
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                userDistanceSubscription:
                  $ref: '#/components/schemas/InlineUserDistanceSubscription'
              example:
                - userDistanceSubscription:
                    subscriptionType: 'UserDistanceSubscription'
                    clientCorrelator: '0123'
                    callbackReference: 'http://my.callback.com/user-distance/some-id'
                    referenceAddress:
                      - 'acr:10.0.0.3'
                    monitoredAddress:
                      - 'acr:10.0.0.1'
                      - 'acr:10.0.0.2'
                    distance: 100
                    trackingAccuracy: 10
                    criteria: 'AllWithinDistance'
                    checkImmediate: true
      responses:
        '201':
          description: 'Successful subscription'
          content:
            application/json:
              schema:
                type: object
                properties:
                  userDistanceSubscription:
                    $ref: '#/components/schemas/InlineUserDistanceSubscription'
                example:
                  - userDistanceSubscription:
                      subscriptionType: 'UserDistanceSubscription'
                      clientCorrelator: '0123'
                      callbackReference: 'http://my.callback.com/user-distance/some-id'
                      referenceAddress:
                        - 'acr:10.0.0.3'
                      monitoredAddress:
                        - 'acr:10.0.0.1'
                        - 'acr:10.0.0.2'
                      distance: 100
                      trackingAccuracy: 10
                      criteria: 'AllWithinDistance'
                      checkImmediate: true
        '400':
          $ref: '#/components/responses/400'
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/403'
        '404':
          $ref: '#/components/responses/404'
        '406':
          $ref: '#/components/responses/406'
        '415':
          $ref: '#/components/responses/415'
        '422':
          $ref: '#/components/responses/422'
        '429':
          $ref: '#/components/responses/429'
      callbacks:
        notification:
          '{$request.body#/userDistanceSubscription.callbackReference}':
            post:
              summary: 'Callback POST used to send a notification'
              description: 'Notification from Location service, content based user distance subscription type'
              operationId: distanceNotificationPOST
              requestBody:
                description: 'User Distance Notification'
                required: true
                content:
                  application/json:
                    schema:
                      type: object
                      properties:
                        userDistanceNotification:
                          $ref: '#/components/schemas/InlineUserDistanceNotification'
                      example:
                        - userDistanceNotification:
                            notificationType: 'UserDistanceNotification'
                            timestamp:
                              seconds: 1673507343
                              nanoSeconds": 0
                            monitoredUsers: 
                              - user:
                                  address: 'acr:10.0.0.1'
                                  accessPointId: '001010000000000000000000000000001'
                                  zoneId: 'zone01'
                                  timestamp:
                                    seconds: 1673507343
                                    nanoSeconds": 0
                                resourceURL: 'http://meAppServer.example.com/location/v3/queries/users'
                            distanceEvent: 'AllWithinDistance'
                            _links:
                              subscription:
                                href: 'http://meAppServer.example.com/location/v3/subscriptions/distance/subscription123'
              responses:
                '204':
                  $ref: '#/components/responses/204'
      x-swagger-router-controller: 'subscriptions'




  /subscriptions/distance:
    get:
      tags:
@@ -3170,6 +3311,131 @@ components:
        - XML
        - JSON
      type: string

    UserDistanceNotification:
      properties:
        # _links:
        #   $ref: '#/components/schemas/_links'
        distanceEvent:
          description': Indicates the distance event triggering the notification. See note.
          x-etsi-mec-cardinality': '1'
          x-etsi-mec-origin-type': DistanceCriteria
          $ref: '#/components/schemas/DistanceCriteria'
        monitoredUsers:
          description': Indicates the location information related to monitored users.
          x-etsi-mec-cardinality': '1'
          x-etsi-mec-origin-type': UserList
          $ref: '#/components/schemas/UserList'
        notificationType:
          description: Shall be set to "UserDistanceNotification".
          type: string
          x-etsi-mec-cardinality: '1'
          x-etsi-mec-origin-type: String
        timeStamp:
          description': Time stamp.
          x-etsi-mec-cardinality': 0..1
          x-etsi-mec-origin-type': TimeStamp
          $ref: '#/components/schemas/TimeStamp'
      required:
      - notificationType
      - monitoredUsers
      - distanceEvent
      - _links
      type: object
      x-etsi-notes: "NOTE:\tAs specified in [6], clause 5.2.3.2."
      x-etsi-ref: 6.4.9


    UserDistanceSubscription:
      properties:
        # _links:
        #   $ref: '#/components/schemas/_links'
        callbackReference:
          description: URI exposed by the client on which to receive notifications via HTTP. See note 1.
          format: uri
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: Uri
        checkImmediate:
          description: Check location immediately after establishing notification.
          x-etsi-mec-cardinality': '1'
          x-etsi-mec-origin-type': Bool
          type: boolean
        clientCorrelator:
          description: 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.
          type: string
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: String
        criteria:
          description': "Indicates whether the notification should occur when the geographical relationship between monitored and referenced users\u2019 changes. See note 3."
          x-etsi-mec-cardinality': '1'
          x-etsi-mec-origin-type': DistanceCriteria
          $ref: '#/components/schemas/DistanceCriteria'
        distance:
          description: Distance between users that shall be monitored. The unit is meter.
          format: float
          type: number
          x-etsi-mec-cardinality: '1'
          x-etsi-mec-origin-type: Float
        expiryDeadline:
          description': The expiration time of the subscription determined by the UE Distance Subscribe Service.
          x-etsi-mec-cardinality': 0..1
          x-etsi-mec-origin-type': TimeStamp
          $ref: '#/components/schemas/TimeStamp'
        monitoredAddress:
          description: "Contains addresses of users to monitor (e.g., \u2018sip\u2019 URI, \u2018tel\u2019 URI, \u2018acr\u2019 URI). Reference to a group could be provided here if supported by implementation.\nIf the ReferenceAddress is specified, then the distance between each monitored user and reference user(s) will be monitored.\nIf the ReferenceAddress is not present, then the distance between each pair of the monitored users will be monitored. Note that in that case there shall be at least two addresses specified here."
          items:
            type: string
          minItems: 1
          type: array
          x-etsi-mec-cardinality: 1..N
          x-etsi-mec-origin-type: Array(Uri)
        referenceAddress:
          description: "If specified, indicates address of each user that will be used as reference users from which the distances towards monitored users indicated in the Addresses will be monitored (e.g., \u2018sip\u2019 URI, \u2018tel\u2019 URI, \u2018acr\u2019 URI). Reference to a group could be provided here if supported by implementation."
          items:
            type: string
          minItems: 0
          type: array
          x-etsi-mec-cardinality: 0..N
          x-etsi-mec-origin-type: Array(Uri)
        reportingCtrl:
          description': Provides parameters that ctrl the reporting.
          x-etsi-mec-cardinality': 0..1
          x-etsi-mec-origin-type': ReportingCtrl
          $ref: '#/components/schemas/ReportingCtrl'
        requestTestNotification:
          description: "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."
          type: boolean
          x-etsi-mec-cardinality: 0..1
          x-etsi-mec-origin-type: Boolean
        subscriptionType:
          description: Shall be set to "UserDistanceSubscription".
          type: string
          x-etsi-mec-cardinality: '1'
          x-etsi-mec-origin-type: String
        trackingAccuracy:
          description: Number of meters of acceptable error in tracking distance.
          format: float
          type: number
          x-etsi-mec-cardinality: '1'
          x-etsi-mec-origin-type: Float
        websockNotifConfig:
          description': Provides details to negotiate and signal the use of a Websocket connection between the location server and the service consumer for notifications. See note 1.
          x-etsi-mec-cardinality': 0..1
          x-etsi-mec-origin-type': WebsockNotifConfig
          $ref: '#/components/schemas/WebsockNotifConfig'
      required:
      - subscriptionType
      - monitoredAddress
      - distance
      - trackingAccuracy
      - criteria
      - checkImmediate
      type: object
      x-etsi-notes: "NOTE 1:\tAt least one of callbackReference and websockNotifConfig shall be provided by the service consumer. If both are provided, it is up to location server to select an alternative and return only that alternative in the response, as specified in ETSI GS MEC 009 [4], clause 6.12a.\nNOTE 2:\tThis allows the client to recover from communication failures during resource creation and therefore avoids duplicate subscription creation in such situations. In case the element is present, the server shall not alter its value, and shall provide it as part of the representation of this resource. In case the element is not present, the server shall not generate it.\nNOTE 3:\tAs specified in [6], clause 5.2.3.2."
      x-etsi-ref: 6.3.9


    NotificationSubscriptionList:
      properties:
        zoneStatusSubscription:
@@ -4120,6 +4386,12 @@ components:
      properties:
        distanceNotificationSubscription:
          $ref: '#/components/schemas/DistanceNotificationSubscription'

    InlineUserDistanceSubscription:
      type: object
      properties:
        userDistanceSubscription:
          $ref: '#/components/schemas/UserDistanceSubscription'
    InlinePeriodicNotificationSubscription:
      type: object
      properties:
@@ -4163,6 +4435,13 @@ components:
      properties:
        notificationSubscriptionList:
          $ref: '#/components/schemas/NotificationSubscriptionList'

    InlineUserDistanceNotification:
      type: object
      properties:
        userDistanceNotification:
          $ref: '#/components/schemas/UserDistanceNotification'

    InlineSubscriptionNotification:
      type: object
      properties:
+3 −0
Original line number Diff line number Diff line
@@ -71,6 +71,9 @@ func DistanceSubListGET(w http.ResponseWriter, r *http.Request) {
	distanceSubListGet(w, r)
}

func DistanceSubPOST_test(w http.ResponseWriter, r *http.Request) {
	distanceSubPOST_test(w, r)
}
func DistanceSubPOST(w http.ResponseWriter, r *http.Request) {
	distanceSubPost(w, r)
}
+11 −0
Original line number Diff line number Diff line
@@ -292,6 +292,17 @@ func convertDistanceSubscriptionToJson(distanceSubs *DistanceNotificationSubscri
	return string(jsonInfo)
}

func convertDistanceSubscriptionToJson1(distanceSubs *UserDistanceSubscription) string {

	jsonInfo, err := json.Marshal(*distanceSubs)
	if err != nil {
		log.Error(err.Error())
		return ""
	}

	return string(jsonInfo)
}

/*
func convertJsonToDistanceSubscription(jsonInfo string) *DistanceNotificationSubscription {

+84 −0
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ var userSubscriptionMap = map[int]string{}

var zoneStatusSubscriptionMap = map[int]*ZoneStatusCheck{}
var distanceSubscriptionMap = map[int]*DistanceCheck{}
var distanceSubscriptionMap1 = map[int]*DistanceCheck_{}
var periodicTicker *time.Ticker
var areaCircleSubscriptionMap = map[int]*AreaCircleCheck{}
var periodicSubscriptionMap = map[int]*PeriodicCheck{}
@@ -131,6 +132,13 @@ type DistanceCheck struct {
	Subscription           *DistanceNotificationSubscription
}

type DistanceCheck_ struct {
	NextTts                int32 //next time to send, derived from frequency
	NbNotificationsSent    int32
	NotificationCheckReady bool
	Subscription           *UserDistanceSubscription
}

type AreaCircleCheck struct {
	NextTts                int32 //next time to send, derived from frequency
	AddrInArea             map[string]bool
@@ -1166,6 +1174,27 @@ func deregisterDistance(subsIdStr string) {
	distanceSubscriptionMap[subsId] = nil
}

func registerDistance1(distanceSub *UserDistanceSubscription, subsIdStr string) {

	subsId, err := strconv.Atoi(subsIdStr)
	if err != nil {
		log.Error(err)
	}

	mutex.Lock()
	defer mutex.Unlock()
	var distanceCheck DistanceCheck_
	distanceCheck.Subscription = distanceSub
	// distanceCheck.NbNotificationsSent = 0
	//checkImmediate ignored, will be hit on next check anyway
	//if distanceSub.CheckImmediate {
	//distanceCheck.NextTts = 0 //next time periodic trigger hits, will be forced to trigger
	//} else {
	//		distanceCheck.NextTts = distanceSub.Frequency
	//	}
	distanceSubscriptionMap1[subsId] = &distanceCheck
}

func registerDistance(distanceSub *DistanceNotificationSubscription, subsIdStr string) {

	subsId, err := strconv.Atoi(subsIdStr)
@@ -2244,6 +2273,61 @@ func distanceSubGet(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, string(jsonResponse))
}

func distanceSubPOST_test(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	var response InlineUserDistanceSubscription
	var body InlineUserDistanceSubscription
	decoder := json.NewDecoder(r.Body)
	err := decoder.Decode(&body)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}
	distanceSub := body.UserDistanceSubscription
	if distanceSub == nil {
		log.Error("Body not present")
		errHandlerProblemDetails(w, "Body not present", http.StatusBadRequest)
		return
	}
	//checking for mandatory properties
	if distanceSub.CallbackReference == nil || distanceSub.CallbackReference.NotifyURL == "" {
		log.Error("Mandatory CallbackReference parameter not present")
		errHandlerProblemDetails(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
		return
	}
	if distanceSub.Criteria == nil {
		log.Error("Mandatory DistanceCriteria parameter not present")
		errHandlerProblemDetails(w, "Mandatory DistanceCriteria parameter not present", http.StatusBadRequest)
		return
	}
	// if distanceSub.Frequency == 0 {
	// 	log.Error("Mandatory Frequency parameter not present")
	// 	errHandlerProblemDetails(w, "Mandatory Frequency parameter not present", http.StatusBadRequest)
	// 	return
	// }
	if distanceSub.MonitoredAddress == nil {
		log.Error("Mandatory MonitoredAddress parameter not present")
		errHandlerProblemDetails(w, "Mandatory MonitoredAddress parameter not present", http.StatusBadRequest)
		return
	}
	newSubsId := nextDistanceSubscriptionIdAvailable
	nextDistanceSubscriptionIdAvailable++
	subsIdStr := strconv.Itoa(newSubsId)
	distanceSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/distance/" + subsIdStr
	_ = rc.JSONSetEntry(baseKey+typeDistanceSubscription+":"+subsIdStr, ".", convertDistanceSubscriptionToJson1(distanceSub))
	registerDistance1(distanceSub, subsIdStr)
	response.UserDistanceSubscription = distanceSub
	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 distanceSubPost(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

+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 InlineUserDistanceSubscription struct {
	UserDistanceSubscription *UserDistanceSubscription `json:"userDistanceSubscription,omitempty"`
}
Loading