From 52c2f18e658627f89fa4e5aa177835cb6a2970f0 Mon Sep 17 00:00:00 2001 From: dolfinus Date: Mon, 17 Feb 2020 13:51:23 +0300 Subject: [PATCH] HCX-39 Allow to pass only specific fields into hid.Hydra#updateSubscription method --- CHANGELOG.md | 1 + .../connectors/hid/hydra/Subscription.groovy | 52 ++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1affa6aa..d67eb408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ v1.4.2 [unreleased] ------------------- ### Features - [#25](https://github.com/latera/camunda-ext/pull/25) Add Planado APIv2 connector +- [#32](https://github.com/latera/camunda-ext/pull/32) Allow to pass only specific fields into hid.Hydra#updateSubscription method v1.4.1 [2020-02-14] ------------------- diff --git a/src/org/camunda/latera/bss/connectors/hid/hydra/Subscription.groovy b/src/org/camunda/latera/bss/connectors/hid/hydra/Subscription.groovy index 17123b1b..cf3193e6 100644 --- a/src/org/camunda/latera/bss/connectors/hid/hydra/Subscription.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/hydra/Subscription.groovy @@ -4,6 +4,8 @@ import static org.camunda.latera.bss.utils.Oracle.encodeBool import static org.camunda.latera.bss.utils.Oracle.encodeFlag import static org.camunda.latera.bss.utils.Oracle.encodeDateStr import static org.camunda.latera.bss.utils.DateTimeUtil.local +import static org.camunda.latera.bss.utils.StringUtil.notEmpty +import static org.camunda.latera.bss.utils.StringUtil.isEmpty import java.time.temporal.Temporal trait Subscription { @@ -95,7 +97,7 @@ trait Subscription { } private Map putSubscription(Map input) { - LinkedHashMap params = mergeParams([ + LinkedHashMap defaultParams = [ subscriptionId : null, customerId : null, accountId : null, @@ -110,10 +112,48 @@ trait Subscription { endDate : null, chargeLogEndDate : null, evaluateDiscounts : true - ], input) + ] - def unitId = getGoodUnitId(params.goodId) + LinkedHashMap existingSubscription = [:] + if (notEmpty(input.subscriptionId)) { + LinkedHashMap subscription = getSubscription(input.subscriptionId) + existingSubscription += [ + subscriptionId : subscription.n_subscription_id, + customerId : subscription.n_customer_id, + accountId : subscription.n_account_id, + docId : subscription.n_doc_id, + goodId : subscription.n_service_id, + equipmentId : subscription.n_object_id, + parSubscriptionId : subscription.n_par_subscription_id, + prevSubscriptionId : subscription.n_prev_subscription_id, + quant : subscription.n_quant, + payDay : subscription.n_pay_day, + beginDate : subscription.d_begin, + endDate : subscription.d_end, + chargeLogEndDate : subscription.d_charge_log_end + ] + } + if (notEmpty(input.parSubscriptionId)) { + LinkedHashMap parentSubscription = getSubscription(input.parSubscriptionId) + existingSubscription += [ + customerId : parentSubscription.n_customer_id, + accountId : parentSubscription.n_account_id, + docId : parentSubscription.n_doc_id, + equipmentId : parentSubscription.n_object_id + ] + } + + if (isEmpty(input.customerId) && !notEmpty(input.accountId)) { + LinkedHashMap account = getAccount(input.accountId) + existingSubscription += [ + customerId : account.n_subject_id + ] + } + + LinkedHashMap params = mergeParams(defaultParams, existingSubscription + input) + + def unitId = getGoodUnitId(params.goodId) if (unitId == getPieceUnitId() && params.quant == null) { params.quant = 1 } else if (unitId == getUnknownUnitId()) { @@ -122,7 +162,7 @@ trait Subscription { try { logger.info("Putting subscription with params ${params}") - LinkedHashMap subscription = hid.execute('SI_USERS_PKG.SI_USER_GOODS_PUT', [ + LinkedHashMap result = hid.execute('SI_USERS_PKG.SI_USER_GOODS_PUT', [ num_N_SUBJ_GOOD_ID : params.subscriptionId, num_N_GOOD_ID : params.goodId, num_N_SUBJECT_ID : params.customerId, @@ -139,8 +179,8 @@ trait Subscription { num_N_PREV_SUBSCRIPTION_ID : params.prevSubscriptionId, b_EvaluateDiscounts : encodeFlag(params.evaluateDiscounts) ]) - logger.info(" Subscription ${subscription.num_N_SUBJ_GOOD_ID} was put successfully!") - return subscription + logger.info(" Subscription ${result.num_N_SUBJ_GOOD_ID} was put successfully!") + return result } catch (Exception e){ logger.error(" Error while putting subscription!") logger.error_oracle(e)