Skip to content
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

Store shared entities for follow up forms #6108

Merged
merged 41 commits into from
May 8, 2024

Conversation

seadowg
Copy link
Member

@seadowg seadowg commented Apr 24, 2024

Closes #6029
Blocked by getodk/javarosa#756

The big change here is that we now combine the server's entity list with locally created entities when downloading a form (or update). The EntitiesRepository is then used to create the secondary instance used in follow up forms (and the actual CSV is ignored).

As the issue mentions, the big caveat here is that you have to manually create the entity list via the entity browser (in experimental settings) to get anything working. In the future, this will likely not have to happen as which media files are entity lists will hopefully be flagged to us by the server.

Something else to point out here is that all entities (including the ones from the server) will be visible in the entity browser now. I could have filtered the "online" ones out, but it felt more useful to see them all anyway.

Why is this the best possible solution? Were any other approaches considered?

The approach here was discussed in the issue.

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?

This should only affect users with entity forms and only in the cases where they have manually added an entity list via experimental settings (Settings > Experimental > View entity lists > Options menu > Add entity list). As the issue points out, it's pretty hard to simulate the problems solved here without using manual form management (as match exactly will download all updates at once).

Do we need any specific form for testing your changes? If so, please attach one.

It'd be a good idea to test entity forms including create forms, update forms and follow up forms.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@seadowg seadowg removed the blocked label Apr 29, 2024
@seadowg seadowg marked this pull request as ready for review April 29, 2024 10:02
@seadowg seadowg requested a review from grzesiek2010 April 29, 2024 10:02
.clickRefresh()
.clickOnForm("One Question Entity Update")
.clickGetBlankForm()
.clickClearAll()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why those forms are both selected here? one-question-entity-update.xml is already downloaded here so you shouldn't need to click Clear all and select one-question-entity-follow-up.xml.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to specifically download 'one-question-entity-follow-up.xmlso that I check that downloadingupdated-people.csv` updates the list. I guess a potentially simpler way to test this is to just download both forms at once and check they have the same list, but I'd prefer to test the extreme case here: forms being downloaded individually with different entity lists. Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it makes sense but my question was about something else. Once you download the first form and open the list of forms to download again the one you already have should be unselected by default. It seems like both are selected as if the first one was removed or not downloaded at all yet. You shouldn't need to click the clear button and then select that form because the form you want to download should be the only one selected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got you! I think I'd still prefer the "clear all" to make it explicit I'm selecting that form.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got you!

No, I think you don't. Please run that test entityListSecondaryInstancesAreConsistentBetweenFollowUpForms and add a breakpoint in line 126 before you call clearAll(). I was asking if it's a bug that both forms are selected by default after opening the list of forms to download when one of them is already downloaded (line 119).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! That'll be the brain fog last week. I see what you mean: it's weird that both forms are selected. I'm guessing this is a problem with StubOpenRosaServer rather an actual bug, but I'll look into it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's because StubOpenRosaServer uses the file path as the form ID for the form list, whereas Collect doesn't trust the server and parses it out of the form itself. That means we end up in a scenario where the form gets downloaded and saved with the ID in the XML, but the server is still using the "fake form ID". I've fixed it so that StubOpenRosaServer will parse the form ID out of the XForm if it's not given an explicit form ID.

) {
formController.finalizeForm()
formController.getEntities().forEach { entity ->
if (entitiesRepository.getDatasets().contains(entity.dataset)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to check this on a repository level? I mean always call save but in save verify if the dataset exists.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted by that. I think the restriction of needing to have declared an entity list is probably temporary though. Later, you'll be able to have a registration form without any follow up forms and have entities created locally for that (that are only available via a browser). @lognaturel does that sound correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to block you because I will be off till the end of this week. It seems to be the last thing to fix but you can do that later.

.around(rule)

@Test
fun canViewLocallyCreatedEntitiesInBrowser() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we started using different names... online and offline entities are I think the clearest options but here we have local entities. The test title below is also not clear it's about online entities.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I ended up using local is because we know store both the "offline" and "online" entities in one place ("local"), but can create or update them locally (rather than those creates/updates coming from the server). It's definitely got me a little twisted up. Do you think we should use "offline" here?

I reckon this will become easier again with #6011, as we'll need to start tracking if local entities are "offline" or "online" so we know whether to delete them or not if they're not in the "online" lists any longer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be local instead of offline (maybe it's even better) but it would require reviewing the code and fixing other occurrences of offline.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we leave this for #6011? I think, it'll be best to consolidate the naming there.

@@ -21,15 +22,20 @@ class EntityFormTest {
.around(rule)

@Test
fun fillingEntityRegistrationForm_createsEntityInTheBrowser() {
fun fillingEntityRegistrationForm_beforeCreatingEntityList_doesNotCreateEntityForFollowUpForms() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This title sounds confusing to me similar to #6108 (comment)
I'm not sure what CreatingEntityList means. First, you create local entities using the registration form and then you open a form that has online entities. So CreatingEntityList means opening a form with online entities?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You "create an entity list" in the browser using the "Add entity list" flow. Does that make sense or do you think it needs updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You "create an entity list" in the browser using the "Add entity list" flow.

But you don't do that here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you don't do that here?

Right. That's the "beforeCreatingEntityList" part. I'm testing that we don't create entities if we haven't manually created an entity list yet.

@seadowg seadowg requested a review from grzesiek2010 May 2, 2024 15:29

<!-- Text for button that deletes all entities for the project -->
<string name="clear_entities">Clear all</string>

<!-- Text for button that adds a new entity list -->
<string name="add_entity_list">Add entity list</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entity list is the same as dataset right? Here the naming is also confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a change in terminology that's happened since we added the first entity code to Collect. The spec now states:

In this specification, collections of Entities are referred to as Datasets. The term “Entity List” is generally recommended instead of “Dataset” in text that is intended for users rather than developers.

We could just call them "entity lists" everywhere in Collect and avoid "datasets" entirely?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would be better to use consistent naming.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I think we should consolidate this in #6011. Agreed that we want to use "entity list" everywhere instead of data sets though.

@grzesiek2010
Copy link
Member

There is something wrong with the browser because if there are multiple elements in the list it looks like this:
Screenshot_1714668781

@seadowg
Copy link
Member Author

seadowg commented May 3, 2024

There is something wrong with the browser because if there are multiple elements in the list it looks like this

I'm not able to reproduce. Do you have more specific steps?

@seadowg seadowg requested a review from grzesiek2010 May 3, 2024 08:48
@grzesiek2010
Copy link
Member

I'm not able to reproduce. Do you have more specific steps?

I'm just adding 2 entity lists in the Experimental section.

Copy link
Member

@grzesiek2010 grzesiek2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a couple of new comments.

@seadowg seadowg requested a review from grzesiek2010 May 7, 2024 12:23
@grzesiek2010 grzesiek2010 merged commit 916629c into getodk:master May 8, 2024
6 checks passed
@seadowg seadowg deleted the entity-lists branch May 9, 2024 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sure that entity lists are consistent between follow up forms
2 participants