Skip to content

Commit

Permalink
update pr comment on demo3 ams
Browse files Browse the repository at this point in the history
  • Loading branch information
mikimoqi committed Dec 10, 2021
1 parent 521551a commit 69fbc40
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 69fbc40

Please sign in to comment.