Updating singleton things in Android: a better way than RemoveThings/PutThings?

Jul 19, 2012 at 2:24 PM
Edited Jul 19, 2012 at 5:36 PM

Hi everyone,

I'm trying to update the Personal Image on HealthVault from an android app.  Because Personal Image is a singleton, the only way I've found is to do a RemoveThings followed by a PutThings (v2).  Does anyone know a better way to get this working?  Thank you for any suggestions.

Coordinator
Jul 19, 2012 at 9:24 PM

Hi,

You should be able to update the personal image.  You need to specify the thing-id and version-stamp in the PutThings call to make it an update.

--Rob

Jul 20, 2012 at 12:58 PM
Edited Jul 20, 2012 at 4:20 PM

Hi Rob, thank you very much for your reply.

Following your suggestion, I tested by modifying the "info" string in my android app to include the "thing-id" tag and tried again using the one command:

PutThings (v2) // info string has thing-id

instead of the two commands:

RemoveThings   // info string has thing-id
PutThings (v2) // info string doesn't have thing-id

But the server didn't like it:

The XML request format is invalid. -- 
The element 'thing' has invalid child element 'thing-id'. List of possible elements expected:
'thing-state, flags, eff-date, created, updated, data-xml, blob-payload, eff-permissions, tags, signature-info'
.

(Everything I'm doing is based on my (possibly erroneous) understanding that android is a bit behind the curve and is unable to use the technique demonstrated in a separate discussion topic on this forum of building up e.g. a "GetThingsRequest" object.  So instead I am building up the "info" request string manually as per the "Weighter" sample android app -- apologies if my approach is fundamentally flawed!)

Thank you again

Coordinator
Jul 20, 2012 at 8:10 PM
Edited Jul 20, 2012 at 8:15 PM

Hi,

For an update, your info section will look like this:

<info>
  <thing>
    <thing-id version-stamp="db6d0ca4-3305-49d6-a6cc-600c02116d6a">8fca65a2-0d6f-4119-af11-f819a1753656</thing-id>
    <type-id>52bf9104-2c5e-4f1f-a66d-552ebcc53df7</type-id>
    <data-xml>
      <allergy>
        <name>
          <text>everything</text>
          </name>
      </allergy>
    </data-xml>
  </thing>
</info>

Note the thing-d and version stamp.  Both are necessary to identify the specific thing you are updating.  From your error, you might have added it after <type-id>.

 

There is nothing wrong with using the xml directly.  I would love to add automatic marshalling to the Android library.  I'm just not sure about the best way to do it.

--Rob

Jul 23, 2012 at 1:54 PM

Thank you for another prompt reply, I will give this a try as soon as I'm back to a stable place (off in the weeds right now)

Jul 24, 2012 at 4:43 PM
Edited Jul 24, 2012 at 4:44 PM

Found time to try again, same result unfortunately; for some reason the server is rejecting this:

<thing><thing-id...</thing>

throwing the error

The element 'thing' has invalid child element 'thing-id'. List of possible elements expected: 'thing-state, flags, eff-date, created, updated, data-xml, blob-payload, eff-permissions, tags, signature-info'.

Could it be that the thing-id needs to be nested differently, maybe in one of the other tags mentioned in the error message?  (Or used instead of <thing>?)

Coordinator
Jul 24, 2012 at 6:45 PM

Hi,

I added a unit test to the trunk under sdk/src/test/java/com/microsoft/hsg/PutThingsTest.java that shows how to do an update.  I'm sorry I didn't demonstrate it with PersonalImage but I recently broke my wrist and am typing very slowly these days with one hand.  You should be abl4e to cut and paste your xml into there to see what is going wrong.

--Rob

Aug 2, 2012 at 2:01 PM
Edited Aug 3, 2012 at 8:54 AM

Thanks Rob, I downloaded the latest SDK and had a look at PutThingsTest.java.  Unfortunately (and while I very much appreciate your effort to help) I don't think the technique used in that particular file will be of use here; element <thing> still has a nested <thing-id ...> which would be expected to cause the same error I had previously.  Are you sure that the Personal Image (a singleton) doesn't require a slightly different approach?  Thank you

Coordinator
Aug 14, 2012 at 11:14 PM
Edited Aug 15, 2012 at 12:08 AM

Hi,

Sorry, but I've got a couple more months in a cast and development has been grinding to a halt.

I added a test to demonstrate updating a personal image type.  You can find it in the same class as before.  Without your code I may not be able to see what is going wrong for you.  The sample I uploaded shows that update is the same for singleton and non-singletons.

 

--Rob

Sep 21, 2012 at 2:09 PM
Edited Sep 21, 2012 at 2:17 PM

Duh.  Had tag order reversed; <thing-id> needs to go before <type-id>, this became apparent instantly on looking at your test code.  Sorry for my stubborn failure to see this, thank you again!