Skip to content

Code Reference — extraction

High-level, class-by-class guide. All paths relative to st-integration/extraction/src/main/java/com/maktix/jb/extraction/.

ClassResponsibility
ExtractionApplication@SpringBootApplication and the production entry point. Defines the Lambda bean Function<SQSEvent,String> loadInvoices(): parses each SQS record body into a Tenant (Gson) and delegates to JbDataLoadService.loadInvoices.
controller/InvoiceController@RestController, POST /api/invoices/load. HTTP mirror of the Lambda bean for local/dev invocation — accepts an SQSEvent-shaped JSON body.
ClassResponsibility
service/JbDataLoadServiceThin orchestrator. Calls InvoiceService.loadInvoices(tenant), then persists the audit: updates tblTransmissionDetails for the tenant and inserts a tblTransmissionDetailsHistory row including the captured run log.
service/InvoiceServiceThe core (~1,300 lines). Everything ServiceTitan: paged invoice extraction and mapping to entities, contact enrichment (batched, 250 location ids per call), installed-equipment pulls, and the outbound callServiceTitan(...) push (agreements → location tags/custom fields/notes + equipment warranty dates; claims → job PATCHes). Also applies the inbound transforms (name splitting, truncation, price summation, missingEquipment / isSeaCoast flags).
service/TokenServiceServiceTitan OAuth2 client-credentials flow. Builds the token request against ST_AUTH_URL, adds the ST-App-key header from ST_APP_KEY, and produces authenticated headers for all subsequent calls.
ClassResponsibility
config/JpaConfigurationBuilds the real (Lambda) datasource in code: MySQL URL from DATABASE_ENDPOINT/DATABASE_PORT, username from the Secrets Manager secret (SECRET_NAME), password from a generated RDS IAM auth token. Also configures the JPA entity manager (Hibernate, MySQL dialect, entity scan of this package).
config/PersistenceConfigJPA/transaction wiring companion to JpaConfiguration.
config/RestConfigRestTemplate bean using the Apache HttpClient 5 request factory.
ClassResponsibility
repository/InvoiceRepository, InvoiceItemRepositorySpring Data JPA repos for tblInvoice / tblInvoiceItem (upsert flow diffs existing vs new by id).
repository/AgreementRepository, AgreementEquipmentsRepositoryJPA repos for tblAgreement / tblAgreementEquipments.
repository/TransmissionDetailsRepository, TransmissionDetailsHistoryRepositoryAudit tables.
repository/JbRepositoryRaw JdbcTemplate queries that don’t fit JPA: batch phone/email UPDATEs, location/agreement id lookups for equipment pulls, and the outbound read queries (getAgreementDetails — join of tblAgreement+tblAgreementEquipments+tblProducts filtered to agreementStatus='PAID' AND isSentToST=0; getClaimsDetailsisReadyForST=1 AND isSentToST=0; custom tag/field lookups from tblTenantCustomTags/tblTenantCustomFields).

JPA entities (map 1:1 to jbwst tables — standard physical naming)

Section titled “JPA entities (map 1:1 to jbwst tables — standard physical naming)”
EntityTableNotes
Invoice / InvoiceItemtblInvoice / tblInvoiceItemInbound invoice landing zone
Agreement / AgreementEquipmentstblAgreement / tblAgreementEquipmentsWarranty agreements + equipment rows (dataReceivedFromST flag gates ST pulls)
ClaimstblClaimsisReadyForST / isSentToST flags gate the outbound push
TransmissionDetails / TransmissionDetailsHistoryaudit tablesCounts, sync status, start/end, stored run log
DTOPurpose
TenantSQS message body: tenantId, dealerId, ST OAuth clientId/clientSecret, batchId, syncStartDate, invoiceStatus
AccessToken, AwsSecretOAuth token response; Secrets Manager secret shape
AgreementDetails, AgreementUpdate, AgreementEquipmentUpdate, AgreementLocationNotesUpdateOutbound agreement push payloads
ClaimsUpdate, ServiceTitanUpdateInfoOutbound claim push payloads
CustomField, CustomFieldDetails, CustomTagDetailsServiceTitan tag/custom-field merge structures
InvoiceResponsePaged ST invoice response wrapper
ClassResponsibility
util/JbConstantsStatus constants: BATCH_PROCESS, SUCCESS, FAILED, SERVICE_TITAN.
util/JsonUtilsNull-safe Gson helpers (getStringValue, getIntegerValue, getDateTimeValue, getAsBigDecimal).
util/LogContextIn-memory per-run log buffer (“INFO:”/“ERROR:” lines) that ends up stored in tblTransmissionDetails.logDetails.