Data download (Cadre)
Downloads master data and the selected VO's farmers with their land, crop plans and farming models. The user cannot reach Home until the five mandatory items succeed.
FactsheetOnboarding & setup
- Who uses it
- Cadre
- How you get here
- Automatically after VO selection or on relaunch when downloads are incomplete; in load-more mode via Settings > Load more data or the Home partial-data banner.
- Tables
sync_status,ie_flat_entity,ierolemap,cropdata,practicemaster,farmerassets,portfolio,portfolio_portfoliolineitem,farming_model- APIs
- 13 calls today, 4 App Service operations
- Offline
- Needs internet. Offline, every item ends in ERROR and the user stays on the screen with Retry.
Screens
| Screen | What it does | Source |
|---|---|---|
| Data Setup | List of 11 download items with status, last-fetched time, error text and Retry/Refresh; warning banner to stay on the screen; Logout in the toolbar. | app/src/main/java/org/platformcommons/urvi/view/datasetup/DataSetupActivity.kt |
Rules
Conditions from the code, rewritten as plain decision rules.
| When | Then |
|---|---|
| The screen opens | A PENDING status row is created for every missing item. |
| A row was just created or any row is not SUCCESS/PARTIAL_SUCCESS, and not in load-more mode | Downloads start automatically. |
| In load-more mode | Downloads do not auto-start, a Back arrow is shown, the app does not move to Home by itself, and a row shows the current VO with a Change button. |
| Change is tapped | Ask "Do you really want to navigate to Select WorkNode?" (adding "Sync is pending." if the queue is not empty) and open VO selection. |
| Downloads run | In order: App Configs, Product Master, Practice Master, Farmers, IE Role Map; then Farmer Assets, Portfolio and Farming Model run in parallel, each followed by its attachments. |
| The farmer count is zero | Farmers fails with "No farmers found for the selected work node". |
| A farmer page fails after earlier pages succeeded | Farmers is PARTIAL_SUCCESS, which still counts as done; the next run with the same VO resumes from the failed page. |
| No farmers are in the database after the Farmers step | All remaining items are marked SUCCESS and downloading stops. |
| An attachment item's parent item is not SUCCESS | The attachment item fails. |
| Every item is SUCCESS or ERROR (Farmers may be PARTIAL_SUCCESS) and all mandatory items succeeded | Go to Home and set PREF_KEY_ALL_SYNCS_COMPLETE so later launches go straight to Home. |
| An item is ERROR or PARTIAL_SUCCESS | Show Retry to re-run that item. |
| An item is SUCCESS and all items are complete | Show Refresh. For App Configs, Product Master, Practice Master and IE Role Map, Refresh is silently ignored if the last fetch was less than SETUP_CACHE_DURATION_IN_MINUTES ago. |
| An item is PENDING or IN_PROGRESS | Show a spinner, no button. |
| Logout is tapped | Confirm "You sure want to log out? Any un-synced data will be lost", clear everything (and device binding if configured) and return to the splash. |
| ENABLE_CURRENT_MONTH_PORTFOLIO_FETCH is on | Only crop-plan line items starting in the current or previous month are downloaded. |
API contracts
Each call opens to its use case, headers, request and response bodies, and errors.
| App Service v2: operation | Use |
|---|---|
POST /auth/logout | Log out and revoke tokens |
GET /config | Typed config bundle (ETag) |
GET /farmers/snapshot | Cursor-paged hydrated farmer snapshot |
GET /assessments | Assessment definitions and past submissions |
Behaviour notes
- Mandatory items: App Configs, Product Master, Practice Master, Farmers, IE Role Map.
- App Configs: HTTP 206 means more pages follow; saved as JSON in preferences.
- Farmer params: WORK_NODE_HABITATION_ALIAS, WORK_NODE_VO_ALIAS, WORK_NODE_VILLAGE_ALIAS. Page size = FARMERS_PAGINATION config (default 250) using LIMIT_OFFSET and LIMIT_ROW_COUNT.
- Farmer rows are cleaned: empty SHG name becomes NON_SHG, ? in category becomes -, husband/father surname merged into the name.
- Chunk sizes: IE Role Map 30; assets ASSET_LAND_DETAILS_PAGINATION (default 30); asset attachments ASSET_ATTACHMENT_PAGINATION (default 50); portfolio 30; portfolio attachments 50; farming model 30.
- Assets no longer returned by the server are deleted locally; geofence KML is saved from attachment metadata.
- Practice display order comes from the bundled asset practicelocal.
- Exact base paths for asset/portfolio/farming-model endpoints are abbreviated in the source report; verify against the Retrofit interfaces.
- Possible bug · unverified the auto-start decision runs on a background thread, possibly before load-more mode is applied (race), and an observeForever is never removed (leak).
Improve in the rewrite
- Build one generic sync-item engine with role-specific item lists instead of two near-duplicate view models (about 1,300 and 980 lines).
- Show the pending sync count on the logout warning and offer Sync now.