Commit d7e9202d authored by Mubeena Ishaq's avatar Mubeena Ishaq
Browse files

add commments in vis.go and vis_test.go in meep-vis

parent d19e49a5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -28,5 +28,5 @@ type SubscriptionLinkListLinksSubscriptions struct {
	// The URI referring to the subscription.
	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.
	SubscriptionType string `json:"subscriptionType,omitempty"`
	SubscriptionType string `json:"subscriptionType"`
}
+27 −7
Original line number Diff line number Diff line
@@ -1095,7 +1095,7 @@ func createSubscriptionLinkList(subType string) *SubscriptionLinkList {
	mutex.Lock()
	defer mutex.Unlock()

	//loop through cell_change map
	//loop through v2x_msg map
	if subType == "" || subType == "v2x_msg" {
		for _, v2xSubscription := range v2xMsgSubscriptionMap {
			if v2xSubscription != nil {
@@ -1111,10 +1111,12 @@ func createSubscriptionLinkList(subType string) *SubscriptionLinkList {
	return subscriptionLinkList
}

// subscriptionsGET is to retrieve information about all existing subscriptions at /subscriptions endpoint
func subscriptionsGET(w http.ResponseWriter, r *http.Request) {
	log.Info("subGet")
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	// get & validate query param values for subscription_type
	u, _ := url.Parse(r.URL.String())
	log.Info("url: ", u.RequestURI())
	q := u.Query()
@@ -1158,18 +1160,23 @@ func subscriptionsGET(w http.ResponseWriter, r *http.Request) {

	}

	// get the response against particular subscription type
	response := createSubscriptionLinkList(subType)

	// prepare & send response
	jsonResponse, err := json.Marshal(response)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// success response code
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, string(jsonResponse))
}

// individualSubscriptionGET is to retrive a specific subscriptionsInfo at /subscriptions/{subscriptionId} endpoint
func individualSubscriptionGET(w http.ResponseWriter, r *http.Request) {
	log.Info("individualSubGet")

@@ -1337,6 +1344,7 @@ func repopulateV2xMsgSubscriptionMap(key string, jsonInfo string, userData inter
	return nil
}

// individualSubscriptionPut updates the information about a specific subscriptionInfo at /subscriptions/{subscriptionId} endpoint
func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {
	log.Info("individualSubPut")

@@ -1345,7 +1353,9 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {
	subIdParamStr := vars["subscriptionId"]

	var subscriptionCommon SubscriptionCommon
	// read JSON input stream provided in the Request, and stores it in the bodyBytes as bytes
	bodyBytes, _ := ioutil.ReadAll(r.Body)
	// Unmarshal function to converts a JSON-formatted string into a SubscriptionCommon struct and store it in extractSubType
	err := json.Unmarshal(bodyBytes, &subscriptionCommon)
	if err != nil {
		log.Error(err.Error())
@@ -1355,7 +1365,7 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {
	// extract common body part
	subscriptionType := subscriptionCommon.SubscriptionType

	// Validating mandatory parameters provided in the request body
	// validating common mandatory parameters provided in the request body
	if subscriptionCommon.SubscriptionType == "" {
		log.Error("Mandatory SubscriptionType parameter should be present")
		errHandlerProblemDetails(w, "Mandatory attribute SubscriptionType is missing in the request body.", http.StatusBadRequest)
@@ -1364,7 +1374,7 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {

	if subscriptionCommon.CallbackReference == "" && subscriptionCommon.WebsockNotifConfig == nil {
		log.Error("At least one of callbackReference and websockNotifConfig parameters should be present")
		errHandlerProblemDetails(w, "At least one of callbackReference and websockNotifConfig parameters should be present.", http.StatusBadRequest)
		errHandlerProblemDetails(w, "Both callbackReference and websockNotifConfig parameters are missing in the request body.", http.StatusBadRequest)
		return
	}

@@ -1393,7 +1403,9 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {
	alreadyRegistered := false
	var jsonResponse []byte

	// switch statement is based on provided subscriptionType in the request body
	switch subscriptionType {
	// if subscription is of type V2xMsgSubscription
	case V2X_MSG:
		var v2xSubscription V2xMsgSubscription
		err = json.Unmarshal(bodyBytes, &v2xSubscription)
@@ -1405,6 +1417,7 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {

		v2xMsgSubscription, _ := rc.JSONGetEntry(baseKey+"subscriptions:"+subIdParamStr, ".")

		// Validating mandatory parameters specific to V2xMsgSubscription in the request body
		if v2xMsgSubscription == "" {
			log.Error("subscription not found against the provided subscriptionId")
			errHandlerProblemDetails(w, "subscription not found against the provided subscriptionId", http.StatusNotFound)
@@ -1441,10 +1454,13 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {
		// registration
		if isSubscriptionIdRegisteredV2x(subsIdStr) {
			registerV2x(&v2xSubscription, subsIdStr)
			// store subscription key in redis
			_ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertV2xMsgSubscriptionToJson(&v2xSubscription))
			alreadyRegistered = true
			jsonResponse, err = json.Marshal(v2xSubscription)
		}

	// if subscription is of type ProvChgUuUniSubscription
	case PROV_CHG_UU_UNI:
		//TODO

@@ -1466,6 +1482,7 @@ func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) {
	}
}

// individualSubscriptionDelete is to delete a specific subscriptionInfo at subscriptions/{subscriptionId} endpoint
func individualSubscriptionDelete(w http.ResponseWriter, r *http.Request) {
	log.Info("individualSubDel")

@@ -1473,20 +1490,23 @@ func individualSubscriptionDelete(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	subIdParamStr := vars["subscriptionId"]

	// Find subscriptionInfo entry in redis DB
	_, err := rc.JSONGetEntry(baseKey+"subscriptions:"+subIdParamStr, ".")
	if err != nil {
		err = errors.New("subscription not found against the provided sessionId")
		err = errors.New("subscription not found against the provided subscriptionId")
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusNotFound)
		return
	}

	// Delete subscriptionInfo entry from redis DB
	err = delSubscription(baseKey+"subscriptions", subIdParamStr, false)
	if err != nil {
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// Send response on successful deletion of subscription resource
	w.WriteHeader(http.StatusNoContent)
}

+0 −19
Original line number Diff line number Diff line
@@ -871,10 +871,6 @@ func testSubscriptionsGet(t *testing.T, subscriptionTypeQuery string, expectedRe
	 ******************************/
	//passed as a parameter since a POST had to be sent first

	/******************************
	 * request body section
	 ******************************/

	/******************************
	 * request queries section
	 ******************************/
@@ -917,14 +913,6 @@ func testIndividualSubscriptionGet(t *testing.T, expectedResponse string) {
	vars := make(map[string]string)
	vars["subscriptionId"] = "1"

	/******************************
	 * request body section
	 ******************************/

	/******************************
	 * request queries section
	 ******************************/

	/******************************
	 * request execution section
	 ******************************/
@@ -979,7 +967,6 @@ func testIndividualSubscriptionPut(t *testing.T, expectSuccess bool) string {

	expected_subscriptionType := "V2xMsgSubscription"
	expected_callbackReference := "MyCallback"

	expected_href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/123"}
	expected_self := Links{Self: &expected_href}
	//expected_link := V2xMsgSubscription{Links: &expected_self}
@@ -1008,7 +995,6 @@ func testIndividualSubscriptionPut(t *testing.T, expectSuccess bool) string {
	msgType := []string{"1", "3"}
	//expected_stdOrganization :=
	filterCriteria := V2xMsgSubscriptionFilterCriteria{StdOrganization: "ETSI", MsgType: msgType}

	testv2xMsgSubscription := V2xMsgSubscription{CallbackReference: callbackReference, FilterCriteria: &filterCriteria, RequestTestNotification: false, SubscriptionType: subscriptionType, WebsockNotifConfig: nil}
	body, err := json.Marshal(testv2xMsgSubscription)
	if err != nil {
@@ -1016,15 +1002,10 @@ func testIndividualSubscriptionPut(t *testing.T, expectSuccess bool) string {
	}
	fmt.Println("body: ", string(body))

	/******************************
	 * request queries section
	 ******************************/

	/******************************
	 * request execution section
	 ******************************/

	// TODO change status code
	rr, err := sendRequest(http.MethodPut, "/vis/v2/subscriptions/1", bytes.NewBuffer(body), nil, nil, http.StatusOK, IndividualSubscriptionPUT)
	if err != nil {
		t.Fatalf(err.Error())