Commit 5c33343a authored by Yann Garcia's avatar Yann Garcia
Browse files

Bug fixed in meep-dai/obtain_app_loc_availability during TTFT043 validation

parent abe9c76f
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -825,7 +825,7 @@ func devAppContextDELETE(w http.ResponseWriter, r *http.Request) {
	err := sbi.DeleteAppContext(contextId)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		errHandlerProblemDetails(w, err.Error(), http.StatusNotFound)
		return
	}

@@ -853,7 +853,7 @@ func devAppContextPUT(w http.ResponseWriter, r *http.Request) {
	if appContext.ContextId != contextId {
		err = errors.New("ContextId mismatch")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

@@ -863,7 +863,7 @@ func devAppContextPUT(w http.ResponseWriter, r *http.Request) {
	if appContext.AppInfo == nil {
		err = errors.New("AppInfo shall be present")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	appContextSbi.AppInfo.AppDId = appContext.AppInfo.AppDId
@@ -929,13 +929,13 @@ func appLocationAvailabilityPOST(w http.ResponseWriter, r *http.Request) {
	if applicationLocationAvailability.AppInfo == nil {
		err = errors.New("AppInfo mismatch")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	if applicationLocationAvailability.AppInfo.AppPackageSource == "" { // Check presence of the filed AppPackageSource in te request
		err = errors.New("AppPackageSource mismatch")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

@@ -982,20 +982,18 @@ func appLocationAvailabilityPOST(w http.ResponseWriter, r *http.Request) {
				log.Debug("devAppContextsPOST: *(*item.AppLocation).CountryCode: ", *(*item.AppLocation).CountryCode)
				applicationLocationAvailability.AppInfo.AvailableLocations[i].AppLocation.CountryCode = *(*item.AppLocation).CountryCode
			}
			log.Debug("devAppContextsPOST: applicationLocationAvailability.AppInfo.AvailableLocations[i].AppLocation: ", applicationLocationAvailability.AppInfo.AvailableLocations[i].AppLocation)
			log.Debug("devAppContextsPOST: applicationLocationAvailability.AppInfo.AvailableLocations[", i, "].AppLocation: ", applicationLocationAvailability.AppInfo.AvailableLocations[i].AppLocation)
		} // End of 'for' statement
	}
	log.Debug("devAppContextsPOST: applicationLocationAvailability.AppInfo.AvailableLocations: ", applicationLocationAvailability.AppInfo.AvailableLocations)
	log.Debug("devAppContextsPOST: applicationLocationAvailability.AppInfo.AvailableLocations: ", *applicationLocationAvailability.AppInfo.AvailableLocations)

	// Build the response
	var jsonResponse string = convertApplicationLocationAvailabilityToJson(&applicationLocationAvailability)
	log.Info("json response: ", jsonResponse)

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusCreated)
	fmt.Fprintf(w, string(jsonResponse))

	w.WriteHeader(http.StatusOK)
	fmt.Fprintf(w, string(jsonResponse))
}

func notifyAppContextDeletion(notifyUrl string, contextId string) {
+49 −40
Original line number Diff line number Diff line
@@ -1134,54 +1134,63 @@ func (am *DaiMgr) CreateAppContext(appContext *AppContext, remoteUrl string, san
}

func (am *DaiMgr) PutAppContext(appContext AppContext) (err error) {
	// if profiling {
	// 	profilingTimers["PutAppContext"] = time.Now()
	// }

	// // Sanity checks
	// if appContext.ContextId == nil || *appContext.ContextId == "" { // ETSI GS MEC 016 Clause 6.2.3 Type: AppContext.
	// 	return errors.New("ContextId shall be set")
	// }
	// log.Debug("PutAppContext: appContext: ", appContext)
	if profiling {
		profilingTimers["PutAppContext"] = time.Now()
	}

	// // Retrieve the existing AppContext
	// curAppContext, err := am.GetAppContextRecord(*appContext.ContextId)
	// if err != nil {
	// 	return errors.New("ContextId not found")
	// }
	// log.Debug("PutAppContext: curAppContext: ", curAppContext)
	// Retrieve the existing AppContext
	curAppContext, err := am.GetAppContextRecord(appContext.ContextId)
	if err != nil {
		return errors.New("ContextId not found")
	}
	log.Debug("PutAppContext: curAppContext: ", curAppContext)

	// // Update the curAppContext
	// update := false
	// Update the curAppContext
	update := false
	// if curAppContext.CallbackReference != appContext.CallbackReference {
	// 	curAppContext.CallbackReference = appContext.CallbackReference
	// 	update = true
	// }

	// if update {
	// 	query := `UPDATE ` + AppContextTable + ` SET callbackReference = ($1) WHERE contextId = ($2)`
	// 	result, err := am.db.Exec(query, curAppContext.CallbackReference, *curAppContext.ContextId)
	// 	if err != nil {
	// 		log.Error(err.Error())
	// 		return err
	// 	}
	// 	rowCnt, err := result.RowsAffected()
	// 	if err != nil {
	// 		log.Fatal(err)
	// 		return err
	// 	}
	// 	if rowCnt == 0 {
	// 		return errors.New("Failed to update record")
	// 	}
	if update {
		txn := am.db.Txn(false)
		raw, err := txn.First("AppContextTable", "ContextId", curAppContext.ContextId)
		if err != nil {
			txn.Abort()
			log.Error(err.Error())
			return err
		}
		txn.Abort()
		if raw == nil {
			err = errors.New("Wrong ContextId")
			log.Error(err.Error())
			return err
		}

	// 	// Notify listener
	// 	am.notifyListener(*curAppContext.ContextId)
	// }
		txn = am.db.Txn(true)
		record := &AppContextTable{
			ContextId:            curAppContext.ContextId,
			AssociateDevAppId:    curAppContext.AssociateDevAppId,
			CallbackReference:    NilToEmptyUri(curAppContext.CallbackReference),
			AppLocationUpdates:   curAppContext.AppLocationUpdates,
			AppAutoInstantiation: curAppContext.AppAutoInstantiation,
			AppDId:               curAppContext.AppInfo.AppDId,
		}
		err = txn.Insert("AppContextTable", record)
		if err != nil {
			txn.Abort()
			log.Error(err.Error())
			return err
		}

	// if profiling {
	// 	now := time.Now()
	// 	log.Debug("PutAppContext: ", now.Sub(profilingTimers["PutAppContext"]))
	// }
		// Notify listener
		am.notifyListener(curAppContext.ContextId)
	}

	if profiling {
		now := time.Now()
		log.Debug("PutAppContext: ", now.Sub(profilingTimers["PutAppContext"]))
	}

	return nil
}