From 06e08dcb56827947d5086aa19da7e2ca8ffcd9be Mon Sep 17 00:00:00 2001 From: Alex Zorkin Date: Tue, 14 Jan 2025 13:31:53 -0800 Subject: [PATCH] fix: etl buy transfer --- etl/nifi_scripts/transfer.groovy | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/etl/nifi_scripts/transfer.groovy b/etl/nifi_scripts/transfer.groovy index f3f87cdd8..35868be77 100644 --- a/etl/nifi_scripts/transfer.groovy +++ b/etl/nifi_scripts/transfer.groovy @@ -41,6 +41,7 @@ def SOURCE_QUERY = """ ct.date_of_written_agreement AS agreement_date, ct.trade_effective_date AS transaction_effective_date, ct.fair_market_value_per_credit AS price_per_unit, + ctt.the_type as the_type, ct.number_of_credits AS quantity, ct.create_user_id as create_user, ct.update_user_id as update_user, @@ -146,6 +147,7 @@ def SOURCE_QUERY = """ ctc.category, cts.status, ctzr.description, + ctt.the_type, internal_comment.role_names; """ @@ -354,15 +356,27 @@ def processTransactions(String currentStatus, ResultSet rs, PreparedStatement st def fromTransactionId = null def toTransactionId = null + def transferType = rs.getString('the_type') + def isBuy = (transferType == 'Buy') + switch (currentStatus) { case ['Draft', 'Deleted', 'Refused', 'Declined', 'Rescinded']: break case ['Sent', 'Submitted', 'Recommended']: - fromTransactionId = insertTransaction(stmt, rs, 'Reserved', rs.getInt('from_organization_id'), true) + if (isBuy) { + fromTransactionId = insertTransaction(stmt, rs, 'Reserved', rs.getInt('from_organization_id'), false) + } else { + fromTransactionId = insertTransaction(stmt, rs, 'Reserved', rs.getInt('from_organization_id'), true) + } break case 'Recorded': - fromTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('from_organization_id'), true) - toTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('to_organization_id'), false) + if (isBuy) { + fromTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('from_organization_id'), false) + toTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('to_organization_id'), true) + } else { + fromTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('from_organization_id'), true) + toTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('to_organization_id'), false) + } break }