Skip to content

Commit

Permalink
Merge pull request #337 from supermikii/my_sp47_prcommentupdate
Browse files Browse the repository at this point in the history
Demo3 duplicate tracked devices fix
  • Loading branch information
dilallkx authored Dec 10, 2021
2 parents 521551a + 69fbc40 commit e33de4d
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions examples/demo3/src/backend/server/demo3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,13 +858,14 @@ func addToTrackingDevices(device string) bool {
return false
}

func addToAmsKey(device string) {
func addToAmsKey(device string) bool {
for _, v := range orderedAmsAdded {
if device == v {
return
return true
}
}
orderedAmsAdded = append(orderedAmsAdded, device)
return false
}

// Rest API handle context state transfer
Expand All @@ -885,37 +886,40 @@ func stateTransferPOST(w http.ResponseWriter, r *http.Request) {
return
}

// Retrieve AMS Resource
amsResourceBody, _, err := amsClient.AmsiApi.AppMobilityServiceByIdGET(context.TODO(), amsResourceId)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Check if device is part of ams
res := addToAmsKey(targetContextState.Device)
if !res {
// Retrieve AMS Resource
amsResourceBody, _, err := amsClient.AmsiApi.AppMobilityServiceByIdGET(context.TODO(), amsResourceId)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// Update AMS Resource
_, err = amsAddDevice(amsResourceId, amsResourceBody, targetContextState.Device)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Update AMS Resource
_, err = amsAddDevice(amsResourceId, amsResourceBody, targetContextState.Device)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// Update ams subscription
amsSubscription, _, err := amsClient.AmsiApi.SubByIdGET(context.TODO(), demoAppInfo.Subscriptions.AmsLinkListSubscription.SubId)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Update ams subscription
amsSubscription, _, err := amsClient.AmsiApi.SubByIdGET(context.TODO(), demoAppInfo.Subscriptions.AmsLinkListSubscription.SubId)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

_, err = updateAmsSubscription(demoAppInfo.Subscriptions.AmsLinkListSubscription.SubId, targetContextState.Device, amsSubscription)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
_, err = updateAmsSubscription(demoAppInfo.Subscriptions.AmsLinkListSubscription.SubId, targetContextState.Device, amsSubscription)
if err != nil {
log.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
addToAmsKey(targetContextState.Device)
addToTrackingDevices(targetContextState.Device)

terminalDeviceState[targetContextState.Device] = targetContextState.Counter
Expand Down

0 comments on commit e33de4d

Please sign in to comment.