-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSV secondary instance support #452
Conversation
Codecov Report
@@ Coverage Diff @@
## master #452 +/- ##
============================================
- Coverage 48.91% 48.79% -0.12%
+ Complexity 2930 2913 -17
============================================
Files 245 241 -4
Lines 13683 13634 -49
Branches 2645 2645
============================================
- Hits 6693 6653 -40
+ Misses 6146 6132 -14
- Partials 844 849 +5
Continue to review full report at Codecov.
|
@dcbriccetti @ggalmazor I'll let you fight over who wants to review this with me. 😉 |
I'm up for that! |
@ggalmazor do you want to talk through it or do an async review? |
Thanks! I'll have a fist go at it by myself today and write any idea that pops up :) |
I'm going through each commit. I think I'll work at two levels of detail:
|
src/test/java/org/javarosa/xform/parse/ExternalSecondaryInstanceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/javarosa/xform/parse/ExternalSecondaryInstanceTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass done!
src/test/java/org/javarosa/xform/parse/ExternalSecondaryInstanceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/javarosa/xform/parse/ExternalSecondaryInstanceTest.java
Outdated
Show resolved
Hide resolved
src/test/resources/org/javarosa/xform/parse/external-select-csv.xml
Outdated
Show resolved
Hide resolved
Extra stuff about the tests
Regarding the static call to
|
I think this is neat, @lognaturel! I don't see anything important and, overall, I think that the end result is much more clear and easy to follow. We can argue about style and small details, but the tests are great too. 👍👍👍 |
b5bdc55
to
6007a9f
Compare
No functional changes, only rearranging
Previously external secondary instances were still parsed as internal instances.
To remove redundant mapFileToResourcePath
Remove now-redundant test
This doesn't guarantee that the two form definitions are identical but at least it makes it so the tests have assertions. Typically the failure mode will be a crash if serialization wasn't implemented properly for a class.
Thanks for the thorough review, @ggalmazor! 🙏 I believe I have addressed all of your comments and suggestions. I suggest going through commit by commit one more time since I did force push to keep the history coherent. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for considering my suggestions!
@JohnTheBeloved I know this will cause some conflicts with what you've been working on. I really hope they won't be too painful to resolve. 🙏 |
Closes #417
Closes #451
CC @musamusa
What has been done to verify that this works as intended?
Wrote and ran tests. Built a jar, added to Collect and ensured that I could fill a form with an external secondary instance declaration straight from a pyxform conversion without having to remove dummy nodes (e.g. nigeria_wards_external). Also tried the test CSV form and the
search
/pulldata
form from #417.Why is this the best possible solution? Were any other approaches considered?
cc77b2e, 138429e and bfc97c7 are the fix for #417. The approach is to maintain a set of instance IDs seen used as arguments to the
instance
XPath function. This set is cleared for every new form definition parsed. A secondary instance is only made part of theFormDef
if it is referred to in this way. This is as performant as possible within the existing code structure because it takes advantage of an existing pass over theElement
tree. The static call to populate the set is not ideal but I think it's much better than setting up a complex maze of listeners. There are a lot of static calls already so it doesn't establish a new anti-pattern. Note that bfc97c7 also means internal secondary instances are ignored if they're not explicitly referenced. That change is not part of the fix for #417 but I think it's an improvement where applicable.I made various testing changes so I could understand more of the context. In particular, I split out all tests related to external secondary instances in
0029f80.
I ran into a couple of simple bugs with the CSV parsing implementation that I fixed in 1ddbbd5 and 203241e. There are still a number of issues like not handling escaped commas that I want to think more about. I think I'll probably suggest introducing a CSV parsing library.
4bd58fc is the fix for #451. It made sense to me to add while in the same brain space and hopefully that will help with review as well. I simply ignored child nodes when the instance declaration has a source. I think that's the simplest solution. I do think we'll want to review it (as I wrote in the TODO) and perhaps combine child nodes and external instance nodes while more narrowly ignoring just items with a name of
_
.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
Intentional changes are:
instance()
callThis touches a lot of the instance parsing code and though I think the test suite give us a pretty high level of confidence that the changes don't have unintended consequences, I suggest we issue a snapshot and a Collect beta as soon as this is merged.
Do we need any specific form for testing your changes? If so, please attach one.
See test forms.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
Not yet. We should do a pass at performance improvements first.