Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCX-39 Allow to pass only some fields into hid.Hydra#updateSubscription method #32

Merged
merged 5 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ v1.4.2 [unreleased]
- [#33](https://github.com/latera/camunda-ext/pull/33) Allow to pass goodValueId into hid.Hydra#getGoodAddParamsBy
- [#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
- [#32](https://github.com/latera/camunda-ext/pull/32) Allow to pass only specific fields into hid.Hydra#updateSubscription method
dolfinus marked this conversation as resolved.
Show resolved Hide resolved

### Bugfixes
- [#27](https://github.com/latera/camunda-ext/pull/27) Remove redundant get methods from hid.Hydra class
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it is not used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is not used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually you don't need variable parentSubscription in such situations, in ruby it's something like

existingSubscription = existingSubscription.merge(getSubscription(input.parSubscriptionId).slice(:n_customer_id, :n_account_id, :n_doc_id, :n_object_id)) 

don't you have groovy way for this?

Copy link
Contributor Author

@dolfinus dolfinus Feb 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is subMap method in groovy which can be used for this.

But input arguments of updateSubscription have different names from output of SELECT - compare subscriptionId and n_subscription_id. And there is no way easier than currently one to convert them properly.

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