APIs & services / Common TLD (ctld)

Assign a role to a farmer.

Endpointtoday's app
Call
POST /ctld/api/ierolemap/v1
Service
Common TLD (ctld)
Features
Add/Edit farmer (IE profile)
When
Queued sync (IE_ROLE_MAP POST)
Auth
X-SESSIONID stamped when queued (CoreAPI dooWithRetry); X-REQUESTID idempotency key
In the App Service

Use case

Queued create of a farmer role (IE_ROLE_MAP POST via IERoleMapWorker), created by BridgeSyncHelper when a farmer is added/edited with roles; depends on the farmer create. isActive is forced true and iE.aliasId set from appMillMetadata. IERoleMapPostRH saves the returned ids (role map id, IE/person/profile ids). Failures retry.

Headers

HeaderValueNotes
X-SESSIONID<session token>Stamped when the operation is queued (dooWithRetry) and re-set by CoreAPI at send time; refreshed on 401.
X-REQUESTID<uuid v4>Idempotency key generated by OperationManagerImpl.createOperation for POST/PUT/PATCH when the op enters the offline queue.
X-ACK-REQUESTID<X-REQUESTID of an earlier completed op>Added by SyncQueueProcessor for POST/PUT/PATCH: acknowledges a request id the device already saw succeed.
Content-Typeapplication/jsonAdded by CoreAPI.

Request

Example request body (synthetic data)
{
  "isActive": true,
  "id": 0,
  "role": {
    "code": "ROLE.FARMER",
    "roleName": "Farmer",
    "description": "Farmer role",
    "roleType": "ROLE_TYPE.IE"
  },
  "iE": {
    "id": "40001",
    "isActive": true,
    "person": {
      "id": 50001,
      "personProfile": {
        "firstName": "Farmer",
        "id": 60001
      }
    },
    "caretakerTenant": {
      "loginName": "tenant_a",
      "id": 11
    },
    "aliasId": "ie-alias-0001"
  },
  "appMillMetadata": {
    "ie_appId": "ie-alias-0001"
  },
  "appId": "rm-0000-4000-8000-000000000801",
  "syncStatus": "SYNC_PENDING"
}
FieldTypeRequiredNotes
isActivebooleanYesAlways true on create.
role.code / roleName / description / roleTypestringYesRole chosen on the farmer form.
iE.id / iE.aliasId / iE.person.id / personProfile.id / firstName / caretakerTenantmixedYesFarmer reference (ids filled once the farmer synced).
appMillMetadata.ie_appId, appId, syncStatusstringNoLocal columns.

Response

Example response body (synthetic data)
{
  "isActive": true,
  "id": 801,
  "role": {
    "code": "ROLE.FARMER",
    "roleName": "Farmer",
    "description": "Farmer role",
    "roleType": "ROLE_TYPE.IE"
  },
  "iE": {
    "id": "40001",
    "isActive": true,
    "person": {
      "id": 50001,
      "personProfile": {
        "firstName": "Farmer",
        "id": 60001
      }
    },
    "caretakerTenant": {
      "loginName": "tenant_a",
      "id": 11
    },
    "aliasId": "ie-alias-0001"
  }
}
FieldTypeRequiredNotes
idintegerierolemap.id.
iE.id / iE.person.id / iE.person.personProfile.idmixedWritten to the ie_* embedded columns.

Errors

StatusWhenWhat the app does
401Session token expired or invalidCoreAPI invalidates the session id and retries once immediately; if still failing the op stays in the queue (TryAgain.LATER).
500Server error on a /gateway URLBaseResponseHandler fetches a new session id (first 5 attempts) and returns TryAgain.LATER; retried per RetryScheduler policy (retry threshold/delay come from app config).
503Service unavailableCoreAPI retries once immediately, then the op is retried later by the sync queue.
any non-2xxAny other failureHandler onError -> TryAgain.LATER (op stays queued and is visible in Pending Sync); a row is written to the local error_log table (Sync Error Log screen) with URL, body, headers and raw response; every 10th attempt the op is mirrored to Firestore for support.

Source

  • data/src/main/java/org/mindtree/app/agricultor/data/entity/IERoleMap.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/work/IERoleMapWorker.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/rh/IERoleMapPostRH.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/repo/DataRepository.kt
  • app/src/main/java/org/platformcommons/urvi/bridge/BridgeSyncHelper.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/manager/CoreAPIManager.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/rh/BaseResponseHandler.kt
  • offline-core/src/main/java/com/mindtree/bridge/coreapi/offline/SyncQueueProcessor.java
  • offline-core/src/main/java/com/mindtree/bridge/coreapi/offline/manager/OperationManagerImpl.java
  • core-api/src/main/java/com/mindtree/bridge/coreapi/impl/CoreAPIDefaultImpl.java