APIs & services / Firebase

Write sync-failure copies (every 10th attempt), crop-photo fallback metadata and attachment issues.

Endpointtoday's app
Call
SDK Firestore SYNC_LOG / PLI_IMAGE / URVI_ATTACHMENT_ISSUE
Service
Firebase
Features
Sync error log
When
On sync errors
Auth
Firebase app credentials
In the App Service

Use case

Writes diagnostic copies to Cloud Firestore (FireStoreUtil). Offline persistence is on in the main process, so writes are queued until the device is online. (1) urvi_sync_log/{operationIdentifier}: BaseResponseHandler writes it on every 10th failed attempt (attemptCount % 10 == 0, up to 5000) of any queued operation, and also when a worknodeietag POST gets 403 after more than 2 attempts. (2) pli_image_meta/{userId}: PortfolioLineItemPicRH writes metadata after a crop photo fell back to Firebase Storage. Because the document key is the user id, each new photo overwrites the previous record. (3) urvi_attachment_issue/{operationIdentifier}: ClearSyncQueueWorker writes it before deleting assessment uploads whose file is missing. Other collections in the same class: ap_gov_federation_migration/{userName} and old_season_value_updated (auto ids). Failures are only logged.

Headers

HeaderValueNotes
(Firebase SDK)<Firebase app credentials from google-services.json>Not HTTP headers. Uses the Firebase project config; no user auth. Access depends on Firestore security rules (not in the repo).

Parameters

ParamInRequiredExampleNotes
collectionpathYesurvi_sync_logurvi_sync_log | pli_image_meta | urvi_attachment_issue | ap_gov_federation_migration | old_season_value_updated.
documentIdpathYesop-0000-4000-8000-000000000001operationIdentifier, or userId for pli_image_meta, or userName for the migration log. Written with set(), which overwrites.

Request

Example request body (synthetic data)
{
  "urvi_sync_log/{operationIdentifier}": {
    "url": "/gateway/asset-service/api/v1/assets/",
    "headers": "{X-SESSIONID=<session id>, X-REQUESTID=<uuid>}",
    "rawResponse": "{\"errorCode\":\"ERR_...\",\"errorMessage\":\"...\"}",
    "queryParam": "{}",
    "user": "1001",
    "method": "POST",
    "attemptCount": "10",
    "statusCode": "500",
    "appVersion": "3.2.1",
    "body": "{\"owningEntityId\":\"880001\",...}",
    "operationIdentifier": "op-0000-4000-8000-000000000001",
    "createdAt": "Mon Jun 02 10:00:00 IST 2025"
  },
  "pli_image_meta/{userId}": {
    "imageUrl": "https://firebasestorage.googleapis.com/v0/b/<bucket>/o/1001%2F880001%2F7001%2F7001.jpg?alt=media&token=<redacted>",
    "pliId": "7001",
    "pliUUID": "pli-0000-4000-8000-000000007001",
    "farmerId": "880001",
    "userId": "1001",
    "portfolioLineItemMonth": "2025/06/01",
    "portfolioId": "6001",
    "createdAt": "02-Jun-2025 10:15 AM",
    "appVersion": "3.2.1",
    "isMigrated": false
  },
  "urvi_attachment_issue/{operationIdentifier}": {
    "url": "/gateway/assessment-service/api/v1/aiadefaultresponses/attachment/uuid",
    "headers": "{X-SESSIONID=<session id>, X-REQUESTID=<uuid>}",
    "rawResponse": null,
    "queryParam": "{}",
    "user": "1001",
    "method": "POST",
    "attemptCount": "10",
    "statusCode": "500",
    "appVersion": "3.2.1",
    "body": "{\"owningEntityId\":\"880001\",...}",
    "operationIdentifier": "op-0000-4000-8000-000000000001",
    "createdAt": "Mon Jun 02 10:00:00 IST 2025"
  }
}
FieldTypeRequiredNotes
FireStoreSyncLog.url / method / statusCode / attemptCount / queryParam / operationIdentifier / createdAt / appVersionstringYesOperation metadata.
FireStoreSyncLog.headersstringNoPII/secret: requestHeaders.toString(), which includes the X-SESSIONID session token.
FireStoreSyncLog.bodystringNoPII: Gson of the full raw request message (farmer profile, land, crop or endorsement data).
FireStoreSyncLog.rawResponsestringNoServer error body. Not set for urvi_attachment_issue.
FireStoreSyncLog.userstringNoPII: operation user id.
PLIImageMeta.*string/booleanYesCrop photo fallback record: Storage URL (contains an access token), line item ids, farmerId, userId, month, portfolioId, createdAt, appVersion, isMigrated=false (presumably used by a back-office migration).

Response

FieldTypeRequiredNotes
(none)n/aFire-and-forget. Success and failure listeners only log. urvi_attachment_issue success triggers deletion of the queued operation.

Errors

StatusWhenWhat the app does
SDK failurePermission denied or no networkLogged. Persistence retries automatically. For the attachment issue the queued operation is not deleted.

Source

  • data/src/main/java/org/mindtree/app/agricultor/data/utils/FireStoreUtil.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/rh/BaseResponseHandler.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/rh/PortfolioLineItemPicRH.kt
  • app/src/main/java/org/platformcommons/urvi/datasource/service/ClearSyncQueueWorker.kt