Features / Onboarding & setup

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

ScreenWhat it doesSource
Data SetupList 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.

WhenThen
The screen opensA 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 modeDownloads start automatically.
In load-more modeDownloads 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 tappedAsk "Do you really want to navigate to Select WorkNode?" (adding "Sync is pending." if the queue is not empty) and open VO selection.
Downloads runIn 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 zeroFarmers fails with "No farmers found for the selected work node".
A farmer page fails after earlier pages succeededFarmers 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 stepAll remaining items are marked SUCCESS and downloading stops.
An attachment item's parent item is not SUCCESSThe attachment item fails.
Every item is SUCCESS or ERROR (Farmers may be PARTIAL_SUCCESS) and all mandatory items succeededGo to Home and set PREF_KEY_ALL_SYNCS_COMPLETE so later launches go straight to Home.
An item is ERROR or PARTIAL_SUCCESSShow Retry to re-run that item.
An item is SUCCESS and all items are completeShow 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_PROGRESSShow a spinner, no button.
Logout is tappedConfirm "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 onOnly 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.

Today: callUseReplaced by
GET /gateway/portfolio-service/api/v1/ref-data/class/CLASS.PORTFOLIO_APP_CONFIG?page&size=100&direction=ASCLoad app config: feature flags, current season, retry delay, pagination and chunk sizes.
GET /ie-registration/assets/json/inventory/crops-list.jsonLoad the static crop list.
GET /gateway/portfolio-service/api/v1/practices/active?direction=ASC&page=1&size=100Load the active farming practices master.
GET /gateway/commons-report-service/api/v1/datasets/name/PlusOneWorkNodeFarmerListGeoWiseCount/executeCount farmers in the selected geography.
GET /gateway/commons-report-service/api/v1/datasets/name/PlusOneWorkNodeFarmerListGeoWise/executeDownload the flattened farmer list, page by page (resumable).
GET /ctld/api/ierolemap/v1?criteria=isActive=true AND iE.id in (...)Download farmer role maps for a chunk of farmers.
GET /gateway/asset-service/api/v1/assets/ownerEntities?ownerEntityIdList=&ownerEntityType=OWNER_ENTITY.IEDownload land and cattle assets for a chunk of farmers (or the cadre, with OWNER_ENTITY.BRIDGE_USER).
GET /gateway/asset-service/api/v1/asset/attachment/bulk?assetIds=Download asset attachments (KML geofences, images) in bulk.
GET /gateway/portfolio-service/api/v1/portfolios/ownerEntities?ownerEntityIdList=&ownerEntityType=ENTITY_TYPE.IEDownload crop plans (portfolios with line items) for a chunk of farmers.
GET /gateway/portfolio-service/api/v1/portfolios/line-items/portfoliosForLineItemIds?portfolioLineItemIds=&returnAllMimeType=trueDownload crop line-item attachments (photos, geofences) in bulk.
GET /gateway/portfolio-service/api/v1/farming-model/ownerEntities?ownerEntityIds=&ownerEntityType=ENTITY_TYPE.IEDownload farming models (ATM/DKG) for a chunk of farmers.
GET /gateway/portfolio-service/api/v1/farming-model/attachment/bulk?farmingModelIds=Download farming-model attachments in bulk.
GET /ctld/api/inventory/inventoryproduct/v1?inventoryId=0&criteria=isActive=true AND inventory.supervisor.actorId in (...)Download inventory products for farmers (or the cadre).
App Service v2: operationUse
POST /auth/logoutLog out and revoke tokens
GET /configTyped config bundle (ETag)
GET /farmers/snapshotCursor-paged hydrated farmer snapshot
GET /assessmentsAssessment 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.