navnorth/LRJavaLib — pull request #11 by martinq (2014-01-22 00:06:06+00:00)
Title: Added "replaces" property and pre-bencode normalization

I started this by adding a new "replaces" property to handle document replacement. I refactored property initialization into a private helper function and added a new constructor signature so that users could optionally provide a String array of IDs to replace and leave the existing constructors intact.

However upon testing I found that documents must pass signature verification otherwise the Learning Registry node will reject the submission. This applies both for the document that is being submitted and the one that is being replaced. The hash computations coming out of LRJavaLib and the LRSignature module in the Learning Registry server software were different, and I tracked it down to the omission of a normalization step, per the spec here:

http://docs.learningregistry.org/en/latest/spec/Identity_Trust_Auth_and_Security/index.html#signing-a-resource-data-description-document

The main issues were String conversion of booleans and dropping of numeric values. Note however that the spec says that all numeric values should be dropped but the actual Python implementation only drops numeric values in arrays, so I copied the implementation so as to work properly with real-world servers. I've tested against the LR sandbox and have set up integration tests for our project which depends on LRJavaLib, but have not added any unit or integration tests to LRJavaLib proper.

While I was in there, I also refactored the generation of signable and sendable data maps -- these are essentially the same modulo signing information and excluded fields, so I thought it best to have one defer to the other for the sake of DRY.