diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e467fc9..81b77b8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ v1.4.2 [unreleased] - [#24](https://github.com/latera/camunda-ext/pull/24) Add methods for files to document attaching - [#39](https://github.com/latera/camunda-ext/pull/39) Add custom fields in create and update methods in PlanadoV2 class - [#39](https://github.com/latera/camunda-ext/pull/39) Add html and Content-Disposition to file attachment to mail sender +- [#32](https://github.com/latera/camunda-ext/pull/32) Allow to pass only specific fields into hid.Hydra#updateSubscription method ### Bugfixes - [#27](https://github.com/latera/camunda-ext/pull/27) Remove redundant get methods from hid.Hydra class 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)