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

Add Post Method to create zone-location-event-subscription

parent 17cc4190
Loading
Loading
Loading
Loading
+157 −5
Original line number Diff line number Diff line
@@ -1493,6 +1493,109 @@ paths:
                      resourceURL:
                          href: 'http://meAppServer.example.com/location/v2/subscriptions/zones'

    post:
      tags:
        - 'location'
      summary: 'Creates a subscription to zone notifications'
      description: 'The POST method is used to create a new subscription to zone notifications.'
      operationId: zoneSubPOST
      requestBody:
        description: 'Subscription to be created'
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                zoneLocationEventSubscription:
                  $ref: '#/components/schemas/InlineZoneLocationEventSubscription'
                zoneStatusSubscription:
                  $ref: '#/components/schemas/InlineZoneStatusSubscription'
              example:
                - zoneLocationEventSubscription:
                    subscriptionType: 'ZoneLocationEventSubscription'
                    callbackReference:
                      notifyURL: 'http://my.callback.com/location_notifications/some-id'
                    zoneId: 'zone01'
                    locationEventCriteria: 
                      - ENTERING_AREA_EVENT
                    expiryDeadline:
                      seconds: 1977836800
                      nanoseconds: 0
      responses:
        '201':
          description: 'Indicates successful resource creation'
          content:
            application/json:
              schema:
                type: object
                properties:
                  zoneLocationEventSubscription:
                    $ref: '#/components/schemas/InlineZoneLocationEventSubscription'
                  zoneStatusSubscription:
                    $ref: '#/components/schemas/InlineZoneStatusSubscription'
                example:
                  - zoneLocationEventSubscription:
                      subscriptionType: 'ZoneLocationEventSubscription'
                      callbackReference:
                        notifyURL: 'http://my.callback.com/location_notifications/some-id'
                      zoneId: 'zone01'
                      locationEventCriteria: 
                        - ENTERING_AREA_EVENT
                      expiryDeadline:
                        seconds: 1977836800
                        nanoseconds: 0
        '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#/zoneLocationEventSubscription.callbackReference}':
            post:
              summary: 'Callback POST used to send a notification'
              description: 'Notification from Location service, content based on subscription type'
              operationId: zoneNotificationPOST
              requestBody:
                description: 'Subscription notification'
                required: true
                content:
                  application/json:
                    schema:
                      type: object
                      properties:
                        zoneLocationEventNotification:
                          $ref: '#/components/schemas/InlineZoneLocationEventNotification'
                        zoneStatusNotification:
                          $ref: '#/components/schemas/InlineZoneStatusNotification'
                      example:
                        - zoneLocationEventNotification:
                            notificationType: 'ZoneLocationEventNotification'
                            timestamp:
                              seconds: 1673507343
                              nanoseconds: 0
                            address: 'acr:10.0.0.1'
                            zoneId: 'zone01'
                            _links:
                              subscription:
                                href: "http://meAppServer.example.com/location/v3/subscriptions/zone/subscription123"
              responses:
                '204':
                  $ref: '#/components/responses/204'
      x-swagger-router-controller: 'subscriptions'

  /subscriptions/zonalTraffic:
    get:
      tags:
@@ -2385,11 +2488,7 @@ components:
          x-etsi-mec-cardinality: 0..N
          x-etsi-mec-origin-type: Array(Uri)
        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
          $ref: '#/components/schemas/CallbackReference'
        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
@@ -3848,6 +3947,48 @@ components:
      required:
        - resourceURL
      type: object

    ZoneLocationEventNotification:
      properties:
        # _links:
        #   $ref: '#/components/schemas/_links'
        address:
          description: "Address of user (e.g. \u2018sip\u2019 URI, \u2018tel\u2019 URI, \u2018acr\u2019 URI)."
          format: uri
          type: string
          x-etsi-mec-cardinality: '1'
          x-etsi-mec-origin-type: Uri
        notificationType:
          description: Shall be set to "ZoneLocationEventNotification".
          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'
        userLocationEvent:
          description': The specific event triggering this notification, e.g. "ENTERING_AREA_EVENT","LEAVING_AREA_EVENT".
          x-etsi-mec-cardinality': '1'
          x-etsi-mec-origin-type': LocationEventType
          $ref: '#/components/schemas/LocationEventType'
        zoneId:
          description: 'The identity of the zone. '
          type: string
          x-etsi-mec-cardinality: '1'
          x-etsi-mec-origin-type: String
      required:
      - notificationType
      - address
      - userLocationEvent
      - zoneId
      - _links
      type: object
      x-etsi-ref: 6.4.6



    ZoneStatusNotification:
      description: A type containing zone status notification.
      properties:
@@ -3987,6 +4128,12 @@ components:
      properties:
        zonalTrafficSubscription:
          $ref: '#/components/schemas/ZonalTrafficSubscription'
    InlineZoneLocationEventSubscription:
      type: object
      properties:
        ZoneLocationEventSubscription:
          $ref: '#/components/schemas/ZoneLocationEventSubscription'

    InlineZoneStatusSubscription:
      type: object
      properties:
@@ -4029,6 +4176,11 @@ components:
      properties:
        userLocationEventNotification:
          $ref: '#/components/schemas/UserLocationEventNotification'
    InlineZoneLocationEventNotification:
      type: object
      properties:
        userLocationPeriodicNotification:
          $ref: '#/components/schemas/ZoneLocationEventNotification'
    InlineZoneStatusNotification:
      type: object
      properties:
+4 −0
Original line number Diff line number Diff line
@@ -161,6 +161,10 @@ func ZoneSubListGET(w http.ResponseWriter, r *http.Request) {
	zoneSubListGET(w, r)
}

func ZoneSubPOST(w http.ResponseWriter, r *http.Request) {
	zoneSubPOST(w, r)
}

func ZonalTrafficSubPOST(w http.ResponseWriter, r *http.Request) {
	zonalTrafficSubPost(w, r)
}
+11 −0
Original line number Diff line number Diff line
@@ -126,6 +126,17 @@ func convertJsonToZoneStatusSubscription(jsonInfo string) *ZoneStatusSubscriptio
	return &zonal
}

func convertZonalSubscriptionToJson1(zonalSubs *ZoneLocationEventSubscription) string {

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

	return string(jsonInfo)
}

func convertZonalSubscriptionToJson(zonalSubs *ZonalTrafficSubscription) string {

	jsonInfo, err := json.Marshal(*zonalSubs)
+71 −0
Original line number Diff line number Diff line
@@ -650,7 +650,32 @@ func deregisterZonal(subsIdStr string) {
	zonalSubscriptionLeavingMap[subsId] = ""
	zonalSubscriptionTransferringMap[subsId] = ""
}
func registerZonal1(zoneId string, event []LocationEventType, subsIdStr string) {

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

	mutex.Lock()
	defer mutex.Unlock()
	if event != nil {
		for i := 0; i < len(event); i++ {
			switch event[i] {
			case ENTERING_AREA_EVENT:
				zonalSubscriptionEnteringMap[subsId] = zoneId
			case LEAVING_AREA_EVENT:
				zonalSubscriptionLeavingMap[subsId] = zoneId
			default:
			}
		}
	} else {
		zonalSubscriptionEnteringMap[subsId] = zoneId
		zonalSubscriptionLeavingMap[subsId] = zoneId
		zonalSubscriptionTransferringMap[subsId] = zoneId
	}
	zonalSubscriptionMap[subsId] = zoneId
}
func registerZonal(zoneId string, event []UserEventType, subsIdStr string) {

	subsId, err := strconv.Atoi(subsIdStr)
@@ -3760,6 +3785,52 @@ func zonalTrafficSubGet(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, string(jsonResponse))
}

func zoneSubPOST(w http.ResponseWriter, r *http.Request) {
	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) {
	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 InlineZoneLocationEventSubscription struct {
	ZoneLocationEventSubscription *ZoneLocationEventSubscription `json:"ZoneLocationEventSubscription,omitempty"`
}
Loading