Skip to content

Commit

Permalink
HCX-39 Allow to pass only specific fields into hid.Hydra#updateSubscr…
Browse files Browse the repository at this point in the history
…iption method
  • Loading branch information
dolfinus committed Feb 19, 2020
1 parent f654a00 commit 52c2f18
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
-------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -95,7 +97,7 @@ trait Subscription {
}

private Map putSubscription(Map input) {
LinkedHashMap params = mergeParams([
LinkedHashMap defaultParams = [
subscriptionId : null,
customerId : null,
accountId : null,
Expand All @@ -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()) {
Expand All @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 52c2f18

Please sign in to comment.