Database / Crops & portfolio

portfolio_portfoliolineitem

Portfolio line item (PLI): the crop plan for one land in one season, with practices, photo, geofence and compact block link.

Table factsheetagri_db
Written by
  • Portfolio save (Repo.savePortfolioList)
  • Add/Edit crop plan (view/portfolio/*: savePortfolioLineItem, updatePortfolioLineItem)
  • Season rollover relabel
  • Response handlers PortfolioLineItemPutRH, PutWithCropChangeRH, DeleteRH, PicRH, GeofencingPostRH
Read by
  • Portfolio screens
  • Compact block crop pickers
  • Harvest
  • A-grade adapter
  • IEPortfolioMapper (legacy ie_portfolio)
Filled from
GET /gateway/portfolio-service/api/v1/portfolios/ownerEntities
GET /gateway/portfolio-service/api/v1/portfolios/line-items/portfoliosForLineItemIds
GET /gateway/portfolio-service/api/v1/portfolios/attachment/bulk
Sync
appId is a client UUID primary key. syncStatus starts at SYNC_DONE for downloaded rows, becomes SYNC_NOT_INITIALIZED when the row is created or edited on the device, and goes back to SYNC_DONE when the response handler writes the server id. opId holds the id of the last queued library operation. Sync entity IE_PORTFOLIO_LINE_ITEM (PUT, DELETE, picture, geofence). hasSyncError/syncErrorId record the last failure.
Source
data/src/main/java/org/mindtree/app/agricultor/data/entity/PortfolioLineItem.kt

Columns

ColumnTypeNullKeyMeaning
portfolioIdTEXTYesFK → portfolio.appIdPortfolio id. Link by convention only, no FK constraint.
idINTEGERYesServer id. Null or 0 until the row is synced.
assetTEXTYesFK → farmerassets.idLand server id stored as TEXT. Link by convention only, no FK constraint.
uuidTEXTYesIndexStable business UUID, also sent to the server. Index: unique.
practiceMasterCodesTEXTYesJSON list of practice codes.
portfolioLineItemTypeTEXTYesPORTFOLIO_LINE_ITEM.PLANNED | PORTFOLIO_LINE_ITEM.SEASON_ACTUAL.
imageUrlTEXTYesCrop photo URL/path.
isActiveINTEGERYesSoft-delete flag (1 = active).
currentSeasonTEXTYesSeason label currently applied.
appCreatedAtTEXTYesCreated on device. Stored as TEXT millis.
appLastModifiedAtTEXTYesLast modified on device (epoch millis).
createdAtTEXTYesCreated time from the server.
lastModifiedAtTEXTYesLast modified time from the server.
titleIdTEXTYesStable business key shared by all versions of the record.
assetIdINTEGERYesFK → farmerassets.idLand server id as INTEGER (parallel copy). Link by convention only, no FK constraint.
assetCheckSumTEXTYesContent hash of a land asset. Links this row to the land before the land has a server id.
hasSyncErrorINTEGERYes1 when the last sync of this row failed.
syncErrorIdINTEGERYesFK → sync_error_logs.idPoints to sync_error_logs.id for the last failure. Link by convention only, no FK constraint.
compactBlockIdINTEGERYesFK → compact_block.idCompact block id. Link by convention only, no FK constraint.
isLinkedToCompactBlockINTEGERYes1 when enrolled in a compact block.
createdByAppINTEGERYesAudit: app that created/last changed the row.
lastModifiedByAppINTEGERYesAudit: app that created/last changed the row.
createdFromDeviceTEXTYesAudit: device id that created/last changed the row.
lastUpdatedFromDeviceTEXTYesAudit: device id that created/last changed the row.
geoFencingFileNameTEXTYesFile name of the geofence polygon (KML/GeoJSON).
geoFencingCreatedOnTEXTYesWhen the geofence was captured.
geoFencingFilePathTEXTYesLocal path of the polygon file under filesDir/geofencing/.
geoFenceAttachmentsTEXTYesJSON list of server attachment ids for geofence files (LongListConverter).
isEditableINTEGERYes1 when the user may edit.
imageAttachmentIdINTEGERYesServer attachment id of the photo.
imageCreatedAtTEXTYesWhen the crop photo was taken (epoch millis as text), or the attachment's appCreatedAt from the server.
changeLogTEXTYesJSON list of crop changes (PortfolioProductLineItemChange).
cropSeasonTEXTYesSeason of the crop (Kharif, Rabi...).
isAttachmentFetchedINTEGERYes1 when images are downloaded.
appIdTEXTNoPKClient-side UUID. Defaults to a random UUID when the object is built, including when server JSON is parsed.
opIdTEXTYesId of the last queued operation in the library queue (SYNC_QUEUE_DB).
syncStatusTEXTNoSYNC_NOT_INITIALIZED | IN_SYNC_QUEUE | SYNC_DONE (default).
methodmaster_idINTEGERYesServer id of the embedded object.
methodmaster_uuidTEXTYesEmbedded method: uuid.
methodmaster_methodCodeTEXTYesReference data code.
methodmaster_appIdTEXTYesEmbedded copy of the nested object's local appId.
methodmaster_opIdTEXTYesEmbedded copy of the nested object's opId.
methodmaster_syncStatusTEXTYesEmbedded copy of the nested object's sync status.
practicemaster_practiceCodeTEXTYesReference data code.
practicemaster_idINTEGERYesServer id of the embedded object.
practicemaster_uuidTEXTYesEmbedded practice: uuid.
practicemaster_appIdTEXTYesEmbedded copy of the nested object's local appId.
practicemaster_opIdTEXTYesEmbedded copy of the nested object's opId.
practicemaster_syncStatusTEXTYesEmbedded copy of the nested object's sync status.

Notes

  • Season rollover: getPortfolioLineItemsWithOlderSeasonValue finds PLIs that started after the new season start but still carry an old season label, then relabels them.
  • getUnFetchedAttachmentPLIIdListByFarmerIds selects synced PLIs whose images are not downloaded.
  • inActiveLineItem is a soft delete; deletePortfolioLineItem is a hard delete.
  • Possible bug · unverified PortfolioLineItemDao.updatePortfolio sets currentSeason on every PLI in the table.
  • Possible bug · unverified getLatestPortfolioItemByTitleId orders by appCreatedAt, a TEXT column, so the order is lexicographic.
  • Possible bug · unverified multi-relation reads (getPLIWithAllDataByTitleId) lack @Transaction.
  • Missing indexes on portfolioId, titleId, asset and id.