Newer
Older
newSubsId := nextUserSubscriptionIdAvailable
nextUserSubscriptionIdAvailable++
subsIdStr := strconv.Itoa(newSubsId)
registerUser(userTrackingSub.Address, userTrackingSub.UserEventCriteria, subsIdStr)
Kevin Di Lallo
committed
userTrackingSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/userTracking/" + subsIdStr
Kevin Di Lallo
committed
_ = rc.JSONSetEntry(baseKey+typeUserSubscription+":"+subsIdStr, ".", convertUserSubscriptionToJson(userTrackingSub))
response.UserTrackingSubscription = userTrackingSub
jsonResponse, err := json.Marshal(response)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, string(jsonResponse))
}
func userTrackingSubPut(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
vars := mux.Vars(r)
var response InlineUserTrackingSubscription
var body InlineUserTrackingSubscription
decoder := json.NewDecoder(r.Body)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
userTrackingSub := body.UserTrackingSubscription
if userTrackingSub == nil {
log.Error("Body not present")
http.Error(w, "Body not present", http.StatusBadRequest)
Simon Pastor
committed
//checking for mandatory properties
if userTrackingSub.CallbackReference == nil || userTrackingSub.CallbackReference.NotifyURL == "" {
log.Error("Mandatory CallbackReference parameter not present")
http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
if userTrackingSub.Address == "" {
log.Error("Mandatory Address parameter not present")
http.Error(w, "Mandatory Address parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
if userTrackingSub.ResourceURL == "" {
log.Error("Mandatory ResourceURL parameter not present")
http.Error(w, "Mandatory ResourceURL parameter not present", http.StatusBadRequest)
subsIdParamStr := vars["subscriptionId"]
selfUrl := strings.Split(userTrackingSub.ResourceURL, "/")
subsIdStr := selfUrl[len(selfUrl)-1]
log.Error("SubscriptionId in endpoint and in body not matching")
http.Error(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest)
Kevin Di Lallo
committed
userTrackingSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/userTracking/" + subsIdStr
subsId, err := strconv.Atoi(subsIdStr)
if err != nil {
log.Error(err)
w.WriteHeader(http.StatusBadRequest)
return
}
if userSubscriptionMap[subsId] == "" {
w.WriteHeader(http.StatusNotFound)
return
}
Kevin Di Lallo
committed
_ = rc.JSONSetEntry(baseKey+typeUserSubscription+":"+subsIdStr, ".", convertUserSubscriptionToJson(userTrackingSub))
deregisterUser(subsIdStr)
registerUser(userTrackingSub.Address, userTrackingSub.UserEventCriteria, subsIdStr)
response.UserTrackingSubscription = userTrackingSub
jsonResponse, err := json.Marshal(response)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, string(jsonResponse))
Kevin Di Lallo
committed
func populateUserTrackingList(key string, jsonInfo string, userData interface{}) error {
var userInfo UserTrackingSubscription
// Format response
err := json.Unmarshal([]byte(jsonInfo), &userInfo)
if err != nil {
return err
}
userList.UserTrackingSubscription = append(userList.UserTrackingSubscription, userInfo)
return nil
}
func zonalTrafficSubDelete(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
vars := mux.Vars(r)
present, _ := rc.JSONGetEntry(baseKey+typeZonalSubscription+":"+vars["subscriptionId"], ".")
if present == "" {
w.WriteHeader(http.StatusNotFound)
return
}
Kevin Di Lallo
committed
err := rc.JSONDelEntry(baseKey+typeZonalSubscription+":"+vars["subscriptionId"], ".")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
deregisterZonal(vars["subscriptionId"])
w.WriteHeader(http.StatusNoContent)
func zonalTrafficSubListGet(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
var response InlineNotificationSubscriptionList
Kevin Di Lallo
committed
zonalTrafficSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zonalTraffic"
response.NotificationSubscriptionList = &zonalTrafficSubList
Kevin Di Lallo
committed
keyName := baseKey + typeZonalSubscription + "*"
err := rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zonalTrafficSubList)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
jsonResponse, err := json.Marshal(response)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, string(jsonResponse))
}
func zonalTrafficSubGet(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
vars := mux.Vars(r)
var response InlineZonalTrafficSubscription
var zonalTrafficSub ZonalTrafficSubscription
response.ZonalTrafficSubscription = &zonalTrafficSub
Kevin Di Lallo
committed
jsonZonalTrafficSub, _ := rc.JSONGetEntry(baseKey+typeZonalSubscription+":"+vars["subscriptionId"], ".")
if jsonZonalTrafficSub == "" {
w.WriteHeader(http.StatusNotFound)
return
}
err := json.Unmarshal([]byte(jsonZonalTrafficSub), &zonalTrafficSub)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
jsonResponse, err := json.Marshal(response)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, string(jsonResponse))
}
func zonalTrafficSubPost(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
var response InlineZonalTrafficSubscription
var body InlineZonalTrafficSubscription
decoder := json.NewDecoder(r.Body)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
zonalTrafficSub := body.ZonalTrafficSubscription
if zonalTrafficSub == nil {
log.Error("Body not present")
http.Error(w, "Body not present", http.StatusBadRequest)
Simon Pastor
committed
//checking for mandatory properties
if zonalTrafficSub.CallbackReference == nil || zonalTrafficSub.CallbackReference.NotifyURL == "" {
log.Error("Mandatory CallbackReference parameter not present")
http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
if zonalTrafficSub.ZoneId == "" {
log.Error("Mandatory ZoneId parameter not present")
http.Error(w, "Mandatory ZoneId parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
newSubsId := nextZonalSubscriptionIdAvailable
nextZonalSubscriptionIdAvailable++
subsIdStr := strconv.Itoa(newSubsId)
/*
if zonalTrafficSub.Duration > 0 {
//TODO start a timer mecanism and expire subscription
}
//else, lasts forever or until subscription is deleted
*/
if zonalTrafficSub.Duration != 0 { //used to be string -> zonalTrafficSub.Duration != "" && zonalTrafficSub.Duration != "0" {
//TODO start a timer mecanism and expire subscription
log.Info("Non zero duration")
}
//else, lasts forever or until subscription is deleted
Kevin Di Lallo
committed
zonalTrafficSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/zonalTraffic/" + subsIdStr
Kevin Di Lallo
committed
_ = rc.JSONSetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".", convertZonalSubscriptionToJson(zonalTrafficSub))
registerZonal(zonalTrafficSub.ZoneId, zonalTrafficSub.UserEventCriteria, subsIdStr)
response.ZonalTrafficSubscription = zonalTrafficSub
jsonResponse, err := json.Marshal(response)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, string(jsonResponse))
}
func zonalTrafficSubPut(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
vars := mux.Vars(r)
var response InlineZonalTrafficSubscription
var body InlineZonalTrafficSubscription
decoder := json.NewDecoder(r.Body)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
zonalTrafficSub := body.ZonalTrafficSubscription
if zonalTrafficSub == nil {
log.Error("Body not present")
http.Error(w, "Body not present", http.StatusBadRequest)
Simon Pastor
committed
//checking for mandatory properties
if zonalTrafficSub.CallbackReference == nil || zonalTrafficSub.CallbackReference.NotifyURL == "" {
log.Error("Mandatory CallbackReference parameter not present")
http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
if zonalTrafficSub.ZoneId == "" {
log.Error("Mandatory ZoneId parameter not present")
http.Error(w, "Mandatory ZoneId parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
if zonalTrafficSub.ResourceURL == "" {
log.Error("Mandatory ResourceURL parameter not present")
http.Error(w, "Mandatory ResourceURL parameter not present", http.StatusBadRequest)
subsIdParamStr := vars["subscriptionId"]
selfUrl := strings.Split(zonalTrafficSub.ResourceURL, "/")
subsIdStr := selfUrl[len(selfUrl)-1]
log.Error("SubscriptionId in endpoint and in body not matching")
http.Error(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest)
Kevin Di Lallo
committed
zonalTrafficSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/zonalTraffic/" + subsIdStr
if err != nil {
log.Error(err)
w.WriteHeader(http.StatusBadRequest)
return
}
if zonalSubscriptionMap[subsId] == "" {
w.WriteHeader(http.StatusNotFound)
return
}
Kevin Di Lallo
committed
_ = rc.JSONSetEntry(baseKey+typeZonalSubscription+":"+subsIdStr, ".", convertZonalSubscriptionToJson(zonalTrafficSub))
deregisterZonal(subsIdStr)
registerZonal(zonalTrafficSub.ZoneId, zonalTrafficSub.UserEventCriteria, subsIdStr)
response.ZonalTrafficSubscription = zonalTrafficSub
jsonResponse, err := json.Marshal(response)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, string(jsonResponse))
Kevin Di Lallo
committed
func populateZonalTrafficList(key string, jsonInfo string, userData interface{}) error {
var zoneInfo ZonalTrafficSubscription
// Format response
err := json.Unmarshal([]byte(jsonInfo), &zoneInfo)
if err != nil {
return err
}
zoneList.ZonalTrafficSubscription = append(zoneList.ZonalTrafficSubscription, zoneInfo)
return nil
}
func zoneStatusSubDelete(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
Simon Pastor
committed
vars := mux.Vars(r)
present, _ := rc.JSONGetEntry(baseKey+typeZoneStatusSubscription+":"+vars["subscriptionId"], ".")
if present == "" {
w.WriteHeader(http.StatusNotFound)
return
}
Kevin Di Lallo
committed
err := rc.JSONDelEntry(baseKey+typeZoneStatusSubscription+":"+vars["subscriptionId"], ".")
Simon Pastor
committed
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
deregisterZoneStatus(vars["subscriptionId"])
w.WriteHeader(http.StatusNoContent)
func zoneStatusSubListGet(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
var response InlineNotificationSubscriptionList
Kevin Di Lallo
committed
zoneStatusSubList.ResourceURL = hostUrl.String() + basePath + "subscriptions/zoneStatus"
response.NotificationSubscriptionList = &zoneStatusSubList
Kevin Di Lallo
committed
keyName := baseKey + typeZoneStatusSubscription + "*"
err := rc.ForEachJSONEntry(keyName, populateZoneStatusList, &zoneStatusSubList)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
jsonResponse, err := json.Marshal(response)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, string(jsonResponse))
}
func zoneStatusSubGet(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
Simon Pastor
committed
vars := mux.Vars(r)
var response InlineZoneStatusSubscription
var zoneStatusSub ZoneStatusSubscription
response.ZoneStatusSubscription = &zoneStatusSub
Simon Pastor
committed
Kevin Di Lallo
committed
jsonZoneStatusSub, _ := rc.JSONGetEntry(baseKey+typeZoneStatusSubscription+":"+vars["subscriptionId"], ".")
if jsonZoneStatusSub == "" {
Simon Pastor
committed
w.WriteHeader(http.StatusNotFound)
return
}
err := json.Unmarshal([]byte(jsonZoneStatusSub), &zoneStatusSub)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
jsonResponse, err := json.Marshal(response)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, string(jsonResponse))
func zoneStatusSubPost(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
Simon Pastor
committed
var response InlineZoneStatusSubscription
Simon Pastor
committed
var body InlineZoneStatusSubscription
decoder := json.NewDecoder(r.Body)
Simon Pastor
committed
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
zoneStatusSub := body.ZoneStatusSubscription
if zoneStatusSub == nil {
log.Error("Body not present")
http.Error(w, "Body not present", http.StatusBadRequest)
Simon Pastor
committed
Simon Pastor
committed
//checking for mandatory properties
if zoneStatusSub.CallbackReference == nil || zoneStatusSub.CallbackReference.NotifyURL == "" {
log.Error("Mandatory CallbackReference parameter not present")
http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
if zoneStatusSub.ZoneId == "" {
log.Error("Mandatory ZoneId parameter not present")
http.Error(w, "Mandatory ZoneId parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
Simon Pastor
committed
newSubsId := nextZoneStatusSubscriptionIdAvailable
nextZoneStatusSubscriptionIdAvailable++
subsIdStr := strconv.Itoa(newSubsId)
Kevin Di Lallo
committed
zoneStatusSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/zoneStatus/" + subsIdStr
Simon Pastor
committed
Kevin Di Lallo
committed
_ = rc.JSONSetEntry(baseKey+typeZoneStatusSubscription+":"+subsIdStr, ".", convertZoneStatusSubscriptionToJson(zoneStatusSub))
Simon Pastor
committed
registerZoneStatus(zoneStatusSub.ZoneId, zoneStatusSub.NumberOfUsersZoneThreshold, zoneStatusSub.NumberOfUsersAPThreshold,
zoneStatusSub.OperationStatus, subsIdStr)
Simon Pastor
committed
response.ZoneStatusSubscription = zoneStatusSub
jsonResponse, err := json.Marshal(response)
Simon Pastor
committed
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
Simon Pastor
committed
fmt.Fprintf(w, string(jsonResponse))
func zoneStatusSubPut(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
Simon Pastor
committed
vars := mux.Vars(r)
var response InlineZoneStatusSubscription
Simon Pastor
committed
var body InlineZoneStatusSubscription
Simon Pastor
committed
decoder := json.NewDecoder(r.Body)
Simon Pastor
committed
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
zoneStatusSub := body.ZoneStatusSubscription
if zoneStatusSub == nil {
log.Error("Body not present")
http.Error(w, "Body not present", http.StatusBadRequest)
Simon Pastor
committed
//checking for mandatory properties
if zoneStatusSub.CallbackReference == nil || zoneStatusSub.CallbackReference.NotifyURL == "" {
log.Error("Mandatory CallbackReference parameter not present")
http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
if zoneStatusSub.ZoneId == "" {
log.Error("Mandatory ZoneId parameter not present")
http.Error(w, "Mandatory ZoneId parameter not present", http.StatusBadRequest)
Simon Pastor
committed
return
}
if zoneStatusSub.ResourceURL == "" {
log.Error("Mandatory ResourceURL parameter not present")
http.Error(w, "Mandatory ResourceURL parameter not present", http.StatusBadRequest)
subsIdParamStr := vars["subscriptionId"]
selfUrl := strings.Split(zoneStatusSub.ResourceURL, "/")
subsIdStr := selfUrl[len(selfUrl)-1]
log.Error("SubscriptionId in endpoint and in body not matching")
http.Error(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest)
Simon Pastor
committed
Kevin Di Lallo
committed
zoneStatusSub.ResourceURL = hostUrl.String() + basePath + "subscriptions/zoneStatus/" + subsIdStr
Simon Pastor
committed
subsId, err := strconv.Atoi(subsIdStr)
if err != nil {
log.Error(err)
w.WriteHeader(http.StatusBadRequest)
if zoneStatusSubscriptionMap[subsId] == nil {
w.WriteHeader(http.StatusNotFound)
return
}
Kevin Di Lallo
committed
_ = rc.JSONSetEntry(baseKey+typeZoneStatusSubscription+":"+subsIdStr, ".", convertZoneStatusSubscriptionToJson(zoneStatusSub))
Simon Pastor
committed
deregisterZoneStatus(subsIdStr)
registerZoneStatus(zoneStatusSub.ZoneId, zoneStatusSub.NumberOfUsersZoneThreshold, zoneStatusSub.NumberOfUsersAPThreshold,
zoneStatusSub.OperationStatus, subsIdStr)
Simon Pastor
committed
response.ZoneStatusSubscription = zoneStatusSub
jsonResponse, err := json.Marshal(response)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, string(jsonResponse))
Kevin Di Lallo
committed
func populateZoneStatusList(key string, jsonInfo string, userData interface{}) error {
var zoneInfo ZoneStatusSubscription
// Format response
err := json.Unmarshal([]byte(jsonInfo), &zoneInfo)
if err != nil {
return err
}
zoneList.ZoneStatusSubscription = append(zoneList.ZoneStatusSubscription, zoneInfo)
return nil
}
Kevin Di Lallo
committed
rc.DBFlush(baseKey)
nextZonalSubscriptionIdAvailable = 1
nextUserSubscriptionIdAvailable = 1
nextZoneStatusSubscriptionIdAvailable = 1
zonalSubscriptionEnteringMap = map[int]string{}
zonalSubscriptionLeavingMap = map[int]string{}
zonalSubscriptionTransferringMap = map[int]string{}
zonalSubscriptionMap = map[int]string{}
userSubscriptionEnteringMap = map[int]string{}
userSubscriptionLeavingMap = map[int]string{}
userSubscriptionTransferringMap = map[int]string{}
userSubscriptionMap = map[int]string{}
zoneStatusSubscriptionMap = map[int]*ZoneStatusCheck{}
updateStoreName("")
}
func updateStoreName(storeName string) {
if currentStoreName != storeName {
currentStoreName = storeName
_ = httpLog.ReInit(logModuleLocServ, sandboxName, storeName, redisAddr, influxAddr)
}
Kevin Di Lallo
committed
func updateUserInfo(address string, zoneId string, accessPointId string, longitude *float32, latitude *float32) {
Kevin Di Lallo
committed
var oldZoneId string
var oldApId string
Kevin Di Lallo
committed
// Get User Info from DB
Kevin Di Lallo
committed
jsonUserInfo, _ := rc.JSONGetEntry(baseKey+typeUser+":"+address, ".")
Kevin Di Lallo
committed
userInfo := convertJsonToUserInfo(jsonUserInfo)
Kevin Di Lallo
committed
// Create new user info if necessary
if userInfo == nil {
userInfo = new(UserInfo)
userInfo.Address = address
userInfo.ResourceURL = hostUrl.String() + basePath + "queries/users?address=" + address
Kevin Di Lallo
committed
} else {
// Get old zone & AP IDs
oldZoneId = userInfo.ZoneId
oldApId = userInfo.AccessPointId
Kevin Di Lallo
committed
}
userInfo.ZoneId = zoneId
userInfo.AccessPointId = accessPointId
Kevin Di Lallo
committed
// Update position
if longitude == nil || latitude == nil {
userInfo.LocationInfo = nil
} else {
if userInfo.LocationInfo == nil {
userInfo.LocationInfo = new(LocationInfo)
}
//we only support shape == 2 in locationInfo, so we ignore any conditional parameters based on shape
userInfo.LocationInfo.Shape = 2
userInfo.LocationInfo.Longitude = nil
userInfo.LocationInfo.Longitude = append(userInfo.LocationInfo.Longitude, *longitude)
userInfo.LocationInfo.Latitude = nil
userInfo.LocationInfo.Latitude = append(userInfo.LocationInfo.Latitude, *latitude)
seconds := time.Now().Unix()
var timeStamp TimeStamp
timeStamp.Seconds = int32(seconds)
userInfo.LocationInfo.Timestamp = &timeStamp
Kevin Di Lallo
committed
}
Kevin Di Lallo
committed
// Update User info in DB & Send notifications
_ = rc.JSONSetEntry(baseKey+typeUser+":"+address, ".", convertUserInfoToJson(userInfo))
checkNotificationRegisteredUsers(oldZoneId, zoneId, oldApId, accessPointId, address)
checkNotificationRegisteredZones(oldZoneId, zoneId, oldApId, accessPointId, address)
func updateZoneInfo(zoneId string, nbAccessPoints int, nbUnsrvAccessPoints int, nbUsers int) {
Kevin Di Lallo
committed
// Get Zone Info from DB
Kevin Di Lallo
committed
jsonZoneInfo, _ := rc.JSONGetEntry(baseKey+typeZone+":"+zoneId, ".")
Kevin Di Lallo
committed
zoneInfo := convertJsonToZoneInfo(jsonZoneInfo)
Kevin Di Lallo
committed
// Create new zone info if necessary
if zoneInfo == nil {
zoneInfo = new(ZoneInfo)
zoneInfo.ZoneId = zoneId
zoneInfo.ResourceURL = hostUrl.String() + basePath + "queries/zones/" + zoneId
Kevin Di Lallo
committed
}
Kevin Di Lallo
committed
// Update info
if nbAccessPoints != -1 {
zoneInfo.NumberOfAccessPoints = int32(nbAccessPoints)
Kevin Di Lallo
committed
}
if nbUnsrvAccessPoints != -1 {
zoneInfo.NumberOfUnserviceableAccessPoints = int32(nbUnsrvAccessPoints)
Kevin Di Lallo
committed
}
if nbUsers != -1 {
zoneInfo.NumberOfUsers = int32(nbUsers)
Kevin Di Lallo
committed
// Update Zone info in DB & Send notifications
_ = rc.JSONSetEntry(baseKey+typeZone+":"+zoneId, ".", convertZoneInfoToJson(zoneInfo))
checkNotificationRegisteredZoneStatus(zoneId, "", int32(-1), int32(nbUsers), int32(-1), previousNbUsers)
Kevin Di Lallo
committed
func updateAccessPointInfo(zoneId string, apId string, conTypeStr string, opStatusStr string, nbUsers int, longitude *float32, latitude *float32) {
Kevin Di Lallo
committed
// Get AP Info from DB
Kevin Di Lallo
committed
jsonApInfo, _ := rc.JSONGetEntry(baseKey+typeZone+":"+zoneId+":"+typeAccessPoint+":"+apId, ".")
Kevin Di Lallo
committed
apInfo := convertJsonToAccessPointInfo(jsonApInfo)
Kevin Di Lallo
committed
// Create new AP info if necessary
if apInfo == nil {
apInfo = new(AccessPointInfo)
apInfo.AccessPointId = apId
apInfo.ResourceURL = hostUrl.String() + basePath + "queries/zones/" + zoneId + "/accessPoints/" + apId
Kevin Di Lallo
committed
}
Kevin Di Lallo
committed
// Update info
if opStatusStr != "" {
opStatus := convertStringToOperationStatus(opStatusStr)
apInfo.OperationStatus = &opStatus
Kevin Di Lallo
committed
}
if conTypeStr != "" {
conType := convertStringToConnectionType(conTypeStr)
apInfo.ConnectionType = &conType
}
Kevin Di Lallo
committed
if nbUsers != -1 {
apInfo.NumberOfUsers = int32(nbUsers)
Kevin Di Lallo
committed
Kevin Di Lallo
committed
// Update position
if longitude == nil || latitude == nil {
apInfo.LocationInfo = nil
} else {
if apInfo.LocationInfo == nil {
apInfo.LocationInfo = new(LocationInfo)
apInfo.LocationInfo.Accuracy = 1
}
apInfo.LocationInfo.Longitude = nil
apInfo.LocationInfo.Longitude = append(apInfo.LocationInfo.Longitude, *longitude)
apInfo.LocationInfo.Latitude = nil
apInfo.LocationInfo.Latitude = append(apInfo.LocationInfo.Latitude, *latitude)
seconds := time.Now().Unix()
var timeStamp TimeStamp
timeStamp.Seconds = int32(seconds)
apInfo.LocationInfo.Timestamp = &timeStamp
Kevin Di Lallo
committed
}
Kevin Di Lallo
committed
// Update AP info in DB & Send notifications
_ = rc.JSONSetEntry(baseKey+typeZone+":"+zoneId+":"+typeAccessPoint+":"+apId, ".", convertAccessPointInfoToJson(apInfo))
checkNotificationRegisteredZoneStatus(zoneId, apId, int32(nbUsers), int32(-1), previousNbUsers, int32(-1))
Simon Pastor
committed
func zoneStatusReInit() {
//reusing the object response for the get multiple zoneStatusSubscription
Simon Pastor
committed
Kevin Di Lallo
committed
keyName := baseKey + typeZoneStatusSubscription + "*"
_ = rc.ForEachJSONEntry(keyName, populateZoneStatusList, &zoneList)
Simon Pastor
committed
maxZoneStatusSubscriptionId := 0
Simon Pastor
committed
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
for _, zone := range zoneList.ZoneStatusSubscription {
resourceUrl := strings.Split(zone.ResourceURL, "/")
subscriptionId, err := strconv.Atoi(resourceUrl[len(resourceUrl)-1])
if err != nil {
log.Error(err)
} else {
if subscriptionId > maxZoneStatusSubscriptionId {
maxZoneStatusSubscriptionId = subscriptionId
}
var zoneStatus ZoneStatusCheck
opStatus := zone.OperationStatus
if opStatus != nil {
for i := 0; i < len(opStatus); i++ {
switch opStatus[i] {
case SERVICEABLE:
zoneStatus.Serviceable = true
case UNSERVICEABLE:
zoneStatus.Unserviceable = true
case OPSTATUS_UNKNOWN:
zoneStatus.Unknown = true
default:
}
}
}
zoneStatus.NbUsersInZoneThreshold = zone.NumberOfUsersZoneThreshold
zoneStatus.NbUsersInAPThreshold = zone.NumberOfUsersAPThreshold
Simon Pastor
committed
zoneStatus.ZoneId = zone.ZoneId
zoneStatusSubscriptionMap[subscriptionId] = &zoneStatus
}
}
nextZoneStatusSubscriptionIdAvailable = maxZoneStatusSubscriptionId + 1
}
func zonalTrafficReInit() {
//reusing the object response for the get multiple zonalSubscription
Kevin Di Lallo
committed
keyName := baseKey + typeZonalSubscription + "*"
_ = rc.ForEachJSONEntry(keyName, populateZonalTrafficList, &zoneList)
maxZonalSubscriptionId := 0
for _, zone := range zoneList.ZonalTrafficSubscription {
resourceUrl := strings.Split(zone.ResourceURL, "/")
subscriptionId, err := strconv.Atoi(resourceUrl[len(resourceUrl)-1])
if err != nil {
log.Error(err)
} else {
if subscriptionId > maxZonalSubscriptionId {
maxZonalSubscriptionId = subscriptionId
}
for i := 0; i < len(zone.UserEventCriteria); i++ {
switch zone.UserEventCriteria[i] {
zonalSubscriptionEnteringMap[subscriptionId] = zone.ZoneId
zonalSubscriptionLeavingMap[subscriptionId] = zone.ZoneId
zonalSubscriptionTransferringMap[subscriptionId] = zone.ZoneId
zonalSubscriptionMap[subscriptionId] = zone.ZoneId
}
}
nextZonalSubscriptionIdAvailable = maxZonalSubscriptionId + 1
}
func userTrackingReInit() {
//reusing the object response for the get multiple zonalSubscription
Kevin Di Lallo
committed
keyName := baseKey + typeUserSubscription + "*"
_ = rc.ForEachJSONEntry(keyName, populateUserTrackingList, &userList)
maxUserSubscriptionId := 0
for _, user := range userList.UserTrackingSubscription {
resourceUrl := strings.Split(user.ResourceURL, "/")
subscriptionId, err := strconv.Atoi(resourceUrl[len(resourceUrl)-1])
if err != nil {
log.Error(err)
} else {
if subscriptionId > maxUserSubscriptionId {
maxUserSubscriptionId = subscriptionId
}
for i := 0; i < len(user.UserEventCriteria); i++ {
switch user.UserEventCriteria[i] {
userSubscriptionEnteringMap[subscriptionId] = user.Address
userSubscriptionLeavingMap[subscriptionId] = user.Address
userSubscriptionTransferringMap[subscriptionId] = user.Address
userSubscriptionMap[subscriptionId] = user.Address
}
}
nextUserSubscriptionIdAvailable = maxUserSubscriptionId + 1
}