APIs & services / commons-report-service

Count farmers in the selected geography.

Endpointtoday's app
Call
GET /gateway/commons-report-service/api/v1/datasets/name/PlusOneWorkNodeFarmerListGeoWiseCount/execute
Service
commons-report-service
Features
Data download (Cadre)
When
Data download (cadre)
Auth
X-SESSIONID header (AuthInterceptor adds it; re-auth on 401/400)
In the App Service

Use case

First step of the cadre farmer download on the Data Setup screen (DataSetupViewModel). It counts farmers in the selected habitation / VO / village so the app can work out the number of pages (count / page size, page size from ref data or 250). Progress is saved so a failed download resumes from the failed page. A failed call or a count of 0 throws, and the screen shows the download as failed.

Headers

HeaderValueNotes
X-SESSIONID<session token>Not set by the call site. AuthInterceptor (OkHttpClientInterceptor) adds it from AndroidSessionManager. On a 401 or 400 it invalidates the token, gets a fresh one and retries once.

Parameters

ParamInRequiredExampleNotes
datasetNamepathYesPlusOneWorkNodeFarmerListGeoWiseCountDataset name in the path of commons-report-service /api/v1/datasets/name/{name}/execute.
versionqueryYes1Dataset version. Always 1.
formatqueryYesjsonResponse format. Always json, so the body is a JSON array of row objects.
paramsqueryYesWORK_NODE_HABITATION_ALIAS=H01--WORK_NODE_VO_ALIAS=VO-ALIAS-001--WORK_NODE_VILLAGE_ALIAS=V01Dataset input parameters as KEY=value pairs joined with "--". WORK_NODE_HABITATION_ALIAS = selected habitation alias; WORK_NODE_VO_ALIAS = selected VO alias; WORK_NODE_VILLAGE_ALIAS = selected village alias. Values are not quoted here.

Request

No body. WORK_NODE_HABITATION_ALIAS, WORK_NODE_VO_ALIAS, WORK_NODE_VILLAGE_ALIAS

Response

Example response body (synthetic data)
[
  {
    "TotalFarmer": 312
  }
]
FieldTypeRequiredNotes
TotalFarmerintTotal farmers for the geography (IeFlatSchemaCountResponse.totalFarmer); used to compute total pages, saved in PREF_KEY_FARMER_SYNC_TOTAL_PAGES.

Errors

StatusWhenWhat the app does
401 / 400Session token expired or rejectedAuthInterceptor refreshes the token and retries once; if the retry also fails, DataSetupViewModel throws "Failed to fetch farmer count"; the download status becomes failed and can be retried.
5xxDataset query failed on the serverDataSetupViewModel throws "Failed to fetch farmer count"; the download status becomes failed and can be retried.
network errorNo connectivity or timeoutDataSetupViewModel throws "Failed to fetch farmer count"; the download status becomes failed and can be retried.
200 with TotalFarmer 0No farmers in the geographyThrows "No farmers found for the selected work node".

Source

  • data/src/main/java/org/mindtree/app/agricultor/data/setup_new/SetupServiceNew.kt
  • app/src/main/java/org/platformcommons/urvi/view/datasetup/DataSetupViewModel.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/setup_new/IeFlatSchemaCountResponse.kt