From 206c0cf8f065ad39453f9302bdce1632c0f2f4f4 Mon Sep 17 00:00:00 2001 From: dolfinus Date: Sat, 30 Nov 2019 14:15:33 +0300 Subject: [PATCH] Improve add params type handling in hid.Hydra class hid.Hydra#getAddParamValue returns value of add param already converted to proper type hid.Hydra#getAddParamDataType now can handle ref as code instead of id --- .../bss/connectors/hid/hydra/AddParam.html | 56 +++++++++++++++ .../bss/connectors/hid/hydra/AddParam.groovy | 70 +++++++++++++++++++ .../bss/connectors/hid/hydra/Document.groovy | 4 +- .../bss/connectors/hid/hydra/Equipment.groovy | 6 +- .../bss/connectors/hid/hydra/Good.groovy | 4 +- .../bss/connectors/hid/hydra/Param.groovy | 13 ++-- .../bss/connectors/hid/hydra/Subject.groovy | 4 +- 7 files changed, 144 insertions(+), 13 deletions(-) diff --git a/docs/org/camunda/latera/bss/connectors/hid/hydra/AddParam.html b/docs/org/camunda/latera/bss/connectors/hid/hydra/AddParam.html index a4b20ebd..832bc376 100644 --- a/docs/org/camunda/latera/bss/connectors/hid/hydra/AddParam.html +++ b/docs/org/camunda/latera/bss/connectors/hid/hydra/AddParam.html @@ -141,6 +141,30 @@

Methods Summary

getAddParamDataType(Map param)
+ + + List + getAddParamDataType(Map param, def value)
+ + + + + def + getAddParamValue(Map value, Boolean withType = true, Boolean visualRefValue = false)
+ + + + + def + getAddParamValue(Map input, Map value)
+ + + + + def + getAddParamValueRaw(Map value, Boolean visualRefValue = false)
+ + @@ -181,6 +205,38 @@

+ + + + + + + + + + + + diff --git a/src/org/camunda/latera/bss/connectors/hid/hydra/AddParam.groovy b/src/org/camunda/latera/bss/connectors/hid/hydra/AddParam.groovy index 531535e3..d5141f05 100644 --- a/src/org/camunda/latera/bss/connectors/hid/hydra/AddParam.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/hydra/AddParam.groovy @@ -1,6 +1,9 @@ package org.camunda.latera.bss.connectors.hid.hydra +import static org.camunda.latera.bss.utils.Numeric.toIntStrict import static org.camunda.latera.bss.utils.Numeric.toIntSafe +import static org.camunda.latera.bss.utils.Numeric.toFloatSafe +import static org.camunda.latera.bss.utils.Oracle.decodeBool trait AddParam { String getAddParamDataType(Map param) { @@ -17,4 +20,71 @@ trait AddParam { return 'refId' } } + + List getAddParamDataType(Map param, def value) { + String dataType = getAddParamDataType(param) + if (dataType == 'refId') { + def val = toIntStrict(value) + if (val != null) { + return ['refId', val] + } else { + return ['ref', value] + } + } else { + return [dataType, value] + } + } + + def getAddParamValue(Map value, Boolean withType = true, Boolean visualRefValue = false) { + Map param = [:] + def val = null + if (value.n_doc_value_type_id) { + param = getDocumentAddParamType(value.n_doc_value_type_id) + } else if (value.n_subj_value_type_id) { + param = getSubjectAddParamType(value.n_subj_value_type_id) + } else if (value.n_good_value_type_id) { + param = getGoodAddParamType(value.n_good_value_type_id) + } + + String dataType = getAddParamDataType(param) + if (dataType == 'string') { + val = value.vc_value + } else if (dataType == 'bool') { + val = decodeBool(value.c_fl_value) + } else if (dataType == 'number') { + val = value.n_value?.replace(',', '.') + if (val?.contains('.')) { + val = toFloatSafe(val) + } else { + val = toIntSafe(val) + } + } else if (dataType == 'date') { + val = value.d_value + } else if (dataType == 'refId') { + if (visualRefValue) { + val = value.vc_visual_value + } else { + val = toIntSafe(value.n_ref_id) + } + } else { + val = value.vc_visual_value + } + if (withType) { + return [val, dataType] + } else { + return val + } + } + + def getAddParamValue(Map input, Map value) { + LinkedHashMap params = [ + withType : true, + visualRefValue : false + ] + input + return getAddParamValue(value, params.withType, params.visualRefValue) + } + + def getAddParamValueRaw(Map value, Boolean visualRefValue = false) { + return getAddParamValue(value, withType: false, visualRefValue: visualRefValue) + } } \ No newline at end of file diff --git a/src/org/camunda/latera/bss/connectors/hid/hydra/Document.groovy b/src/org/camunda/latera/bss/connectors/hid/hydra/Document.groovy index 992bedfc..ca6829ba 100644 --- a/src/org/camunda/latera/bss/connectors/hid/hydra/Document.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/hydra/Document.groovy @@ -559,8 +559,8 @@ trait Document { input.isMultiple = decodeBool(param.c_fl_multi) if (input.containsKey('value')) { - String valueType = getAddParamDataType(param) - input."${valueType}" = input.value + def (valueType, val) = getAddParamDataType(param, input.value) + input."${valueType}" = val input.remove('value') } return input diff --git a/src/org/camunda/latera/bss/connectors/hid/hydra/Equipment.groovy b/src/org/camunda/latera/bss/connectors/hid/hydra/Equipment.groovy index 1bf2d8f5..1046736d 100644 --- a/src/org/camunda/latera/bss/connectors/hid/hydra/Equipment.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/hydra/Equipment.groovy @@ -532,7 +532,7 @@ trait Equipment { Map prepareEquipmentAddParam(Map input) { LinkedHashMap param = null if (input.containsKey('param')) { - param = getEquipmentAddParamTypeBy(input.param.toString()) + param = getEquipmentAddParamTypeByCode(input.param.toString()) input.paramId = param?.n_good_value_type_id input.remove('param') } else if (input.containsKey('paramId')) { @@ -541,8 +541,8 @@ trait Equipment { input.isMultiple = decodeBool(param.c_fl_multi) if (input.containsKey('value')) { - String valueType = getAddParamDataType(param) - input."${valueType}" = input.value + def (valueType, val) = getAddParamDataType(param, input.value) + input."${valueType}" = val input.remove('value') } return input diff --git a/src/org/camunda/latera/bss/connectors/hid/hydra/Good.groovy b/src/org/camunda/latera/bss/connectors/hid/hydra/Good.groovy index c4ef8830..3d8133c2 100644 --- a/src/org/camunda/latera/bss/connectors/hid/hydra/Good.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/hydra/Good.groovy @@ -164,8 +164,8 @@ trait Good { input.isMultiple = decodeBool(param.c_fl_multi) if (input.containsKey('value')) { - String valueType = getAddParamDataType(param) - input."${valueType}" = input.value + def (valueType, val) = getAddParamDataType(param, input.value) + input."${valueType}" = val input.remove('value') } return input diff --git a/src/org/camunda/latera/bss/connectors/hid/hydra/Param.groovy b/src/org/camunda/latera/bss/connectors/hid/hydra/Param.groovy index 5ee2dcff..453bcb64 100644 --- a/src/org/camunda/latera/bss/connectors/hid/hydra/Param.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/hydra/Param.groovy @@ -172,7 +172,7 @@ trait Param { Map prepareParamValue(Map input) { LinkedHashMap param = null if (input.containsKey('param') || input.containsKey('code')) { - param = getParamByCode(input.param || input.code) + param = getParamByCode(input.param ?: input.code) input.paramId = param.n_par_id input.remove('param') input.remove('code') @@ -180,8 +180,8 @@ trait Param { param = getParam(input.paramId) } if (input.containsKey('value')) { - String valueType = getAddParamDataType(param) - input."${valueType}" = input.value + def (valueType, val) = getAddParamDataType(param, input.value) + input."${valueType}" = val input.remove('value') } return input @@ -238,6 +238,11 @@ trait Param { } Map getParamValueBy(Map input) { - return getParamValuesBy(input + [limit: 1])?.getAt(0) + List result = getParamValuesBy(input + [limit: 1]) + if (result) { + return result.getAt(0) + } else { + return null + } } } diff --git a/src/org/camunda/latera/bss/connectors/hid/hydra/Subject.groovy b/src/org/camunda/latera/bss/connectors/hid/hydra/Subject.groovy index ae68502e..a3cd364a 100644 --- a/src/org/camunda/latera/bss/connectors/hid/hydra/Subject.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/hydra/Subject.groovy @@ -273,8 +273,8 @@ trait Subject { input.isMultiple = decodeBool(param.c_fl_multi) if (input.containsKey('value')) { - String valueType = getAddParamDataType(param) - input."${valueType}" = input.value + def (valueType, val) = getAddParamDataType(param, input.value) + input."${valueType}" = val input.remove('value') } return input