Commit 81abe095 authored by Mubeena Ishaq's avatar Mubeena Ishaq
Browse files

add subscriptions GET method in meep-vis

parent 77bda78b
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -56,7 +56,7 @@ func ProvInfoUuUnicastGET(w http.ResponseWriter, r *http.Request) {
}
}


func SubGET(w http.ResponseWriter, r *http.Request) {
func SubGET(w http.ResponseWriter, r *http.Request) {
	notImplemented(w, r)
	subGET(w, r)
}
}


func V2xMessagePOST(w http.ResponseWriter, r *http.Request) {
func V2xMessagePOST(w http.ResponseWriter, r *http.Request) {
+29 −0
Original line number Original line Diff line number Diff line
@@ -57,3 +57,32 @@ func convertV2xMsgPublicationToJson(v2xMsgPublication *V2xMsgPublication) string
	}
	}
	return string(jsonInfo)
	return string(jsonInfo)
}
}

func convertSubscriptionLinkListToJson(subscriptionLinkList *SubscriptionLinkList) string {
	jsonInfo, err := json.Marshal(*subscriptionLinkList)
	if err != nil {
		log.Error(err.Error())
		return ""
	}
	return string(jsonInfo)
}

func convertJsonToUuUniSubscription(jsonInfo string) *ProvChgUuUniSubscription {
	var obj ProvChgUuUniSubscription
	err := json.Unmarshal([]byte(jsonInfo), &obj)
	if err != nil {
		log.Error(err.Error())
		return nil
	}
	return &obj
}

func convertJsonToV2xMsgSubscription(jsonInfo string) *V2xMsgSubscription {
	var obj V2xMsgSubscription
	err := json.Unmarshal([]byte(jsonInfo), &obj)
	if err != nil {
		log.Error(err.Error())
		return nil
	}
	return &obj
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -28,5 +28,5 @@ type SubscriptionLinkListLinksSubscriptions struct {
	// The URI referring to the subscription.
	// The URI referring to the subscription.
	Href string `json:"href"`
	Href string `json:"href"`
	// Type of the subscription. The values are as defined in the \"subscriptionType\" attribute for each different V2X information event subscription data type.
	// Type of the subscription. The values are as defined in the \"subscriptionType\" attribute for each different V2X information event subscription data type.
	SubscriptionType string `json:"subscriptionType"`
	SubscriptionType *SubscriptionType `json:"subscriptionType"`
}
}
+34 −0
Original line number Original line 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 Application Mobility API
 *
 * Application Mobility Service is AdvantEDGE's implementation of [ETSI MEC ISG MEC021 Application Mobility API](http://www.etsi.org/deliver/etsi_gs/MEC/001_099/021/02.02.01_60/gs_MEC021v020201p.pdf) <p>[Copyright (c) ETSI 2017](https://forge.etsi.org/etsi-forge-copyright-notice.txt) <p>**Micro-service**<br>[meep-ams](https://github.com/InterDigitalInc/AdvantEDGE/tree/master/go-apps/meep-ams) <p>**Type & Usage**<br>Edge Service used by edge applications that want to get information about application mobility in the network <p>**Note**<br>AdvantEDGE supports a selected subset of Application Mobility 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 SubscriptionType string

// List of SubscriptionType
const (
	PROV_CHG_UU_UNI_SubscriptionType  SubscriptionType = "UuUnicastSubscription"
	PROV_CHG_UU_MBMS_SubscriptionType SubscriptionType = "UuMbmsSubscription"
	PROV_CHG_PC5_SubscriptionType     SubscriptionType = "Pc5Subscription"
	V2X_MSG_SubscriptionType          SubscriptionType = "V2xMsgSubscription"
)
+112 −1
Original line number Original line Diff line number Diff line
@@ -218,6 +218,33 @@ func sendTerminationConfirmation(appInstanceId string) error {
	return nil
	return nil
}
}


func validateQueryParams(params url.Values, validParamList []string) bool {
	for param := range params {
		found := false
		for _, validParam := range validParamList {
			if param == validParam {
				found = true
				break
			}
		}
		if !found {
			log.Error("Invalid query param: ", param)
			return false
		}
	}
	return true
}

func validateQueryParamValue(val string, validValues []string) bool {
	for _, validVal := range validValues {
		if val == validVal {
			return true
		}
	}
	log.Error("Invalid query param value: ", val)
	return false
}

func subscribeAppTermination(appInstanceId string) error {
func subscribeAppTermination(appInstanceId string) error {
	var sub asc.AppTerminationNotificationSubscription
	var sub asc.AppTerminationNotificationSubscription
	sub.SubscriptionType = "AppTerminationNotificationSubscription"
	sub.SubscriptionType = "AppTerminationNotificationSubscription"
@@ -992,8 +1019,92 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, jsonResponse)
	fmt.Fprint(w, jsonResponse)
}
}


func individualSubscriptionGET(w http.ResponseWriter, r *http.Request) {
func subGET(w http.ResponseWriter, r *http.Request) {
	log.Info("subGet")
	log.Info("subGet")
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	// Validate query params
	u, _ := url.Parse(r.URL.String())
	q := u.Query()
	validQueryParams := []string{"subscriptionType"}
	if !validateQueryParams(q, validQueryParams) {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	// Get & validate query param values
	subType := q.Get("subscriptionType")
	if !validateQueryParamValue(subType, []string{"", "prov_chg_uu_uni", "prov_chg_uu_mbms", "prov_chg_pc5", "v2x_msg"}) {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	// Create subscription link list
	subscriptionLinkList := &SubscriptionLinkList{
		Links: &SubscriptionLinkListLinks{
			Self: &LinkType{
				Href: hostUrl.String() + basePath + "subscriptions",
			},
		},
	}

	var subscriptionLinkListLinks SubscriptionLinkListLinks

	// Find subscriptions by type
	subscriptionType := ""
	if subType != "" {
		if subType == "prov_chg_uu_uni" {
			subscriptionType = PROV_CHG_UU_UNI
		} else if subType == "prov_chg_uu_mbms" {
			subscriptionType = PROV_CHG_UU_MBMS
		} else if subType == "prov_chg_pc5" {
			subscriptionType = PROV_CHG_PC5
		} else if subType == "v2x_msg" {
			subscriptionType = V2X_MSG
		}
	}
	subList, err := subMgr.GetFilteredSubscriptions("", subscriptionType)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}
	// Prepare response
	for _, sub := range subList {
		// Add reference to link list
		var linkListSub SubscriptionLinkListLinksSubscriptions

		// Add type-specific link
		var subscriptionType SubscriptionType
		if sub.Cfg.Type == PROV_CHG_UU_UNI {
			subscriptionType = PROV_CHG_UU_UNI_SubscriptionType
			subOrig := convertJsonToUuUniSubscription(sub.JsonSubOrig)
			linkListSub.Href = subOrig.Links.Self.Href
		} else if sub.Cfg.Type == PROV_CHG_UU_MBMS {
			subscriptionType = PROV_CHG_UU_MBMS_SubscriptionType
			fmt.Print("Not supported")
		} else if sub.Cfg.Type == PROV_CHG_PC5 {
			subscriptionType = PROV_CHG_PC5_SubscriptionType
			fmt.Print("Not supported")
		} else if sub.Cfg.Type == V2X_MSG {
			subscriptionType = V2X_MSG_SubscriptionType
			subOrig := convertJsonToV2xMsgSubscription(sub.JsonSubOrig)
			linkListSub.Href = subOrig.Links.Self.Href
		}
		linkListSub.SubscriptionType = &subscriptionType

		// Add to link list
		subscriptionLinkListLinks.Subscriptions = append(subscriptionLinkListLinks.Subscriptions, linkListSub)
	}
	subscriptionLinkList.Links = &subscriptionLinkListLinks

	// Send response
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, convertSubscriptionLinkListToJson(subscriptionLinkList))
}

func individualSubscriptionGET(w http.ResponseWriter, r *http.Request) {
	log.Info("individualSubGet")


	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)
	vars := mux.Vars(r)