Skip to content

Commit

Permalink
Improve add params type handling in hid.Hydra class
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dolfinus committed Nov 30, 2019
1 parent 3d224a5 commit 206c0cf
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 13 deletions.
56 changes: 56 additions & 0 deletions docs/org/camunda/latera/bss/connectors/hid/hydra/AddParam.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ <h3>Methods Summary</h3>
<td class="colLast"><code><strong><a href="#getAddParamDataType(java.util.Map)">getAddParamDataType</a></strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> param)</code><br></td>
</tr>

<tr class="rowColor">
<td class="colFirst"><code></code></td>
<td class="colLast"><code><a href='http://download.oracle.com/javase/6/docs/api/java/util/List.html' title='List'>List</a></code></td>
<td class="colLast"><code><strong><a href="#getAddParamDataType(java.util.Map, def)">getAddParamDataType</a></strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> param, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/Object.html' title='def'>def</a> value)</code><br></td>
</tr>

<tr class="altColor">
<td class="colFirst"><code></code></td>
<td class="colLast"><code><a href='http://download.oracle.com/javase/6/docs/api/java/lang/Object.html' title='def'>def</a></code></td>
<td class="colLast"><code><strong><a href="#getAddParamValue(java.util.Map, java.lang.Boolean, java.lang.Boolean)">getAddParamValue</a></strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> value, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html' title='Boolean'>Boolean</a> withType = true, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html' title='Boolean'>Boolean</a> visualRefValue = false)</code><br></td>
</tr>

<tr class="rowColor">
<td class="colFirst"><code></code></td>
<td class="colLast"><code><a href='http://download.oracle.com/javase/6/docs/api/java/lang/Object.html' title='def'>def</a></code></td>
<td class="colLast"><code><strong><a href="#getAddParamValue(java.util.Map, java.util.Map)">getAddParamValue</a></strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> input, <a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> value)</code><br></td>
</tr>

<tr class="altColor">
<td class="colFirst"><code></code></td>
<td class="colLast"><code><a href='http://download.oracle.com/javase/6/docs/api/java/lang/Object.html' title='def'>def</a></code></td>
<td class="colLast"><code><strong><a href="#getAddParamValueRaw(java.util.Map, java.lang.Boolean)">getAddParamValueRaw</a></strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> value, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html' title='Boolean'>Boolean</a> visualRefValue = false)</code><br></td>
</tr>

</table>
</ul>
</li>
Expand Down Expand Up @@ -181,6 +205,38 @@ <h4><a href='http://download.oracle.com/javase/6/docs/api/java/lang/String.html'
</li>
</ul>

<a name="getAddParamDataType(java.util.Map, def)"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4><a href='http://download.oracle.com/javase/6/docs/api/java/util/List.html' title='List'>List</a> <strong>getAddParamDataType</strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> param, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/Object.html' title='def'>def</a> value)</h4>
<p></p>
</li>
</ul>

<a name="getAddParamValue(java.util.Map, java.lang.Boolean, java.lang.Boolean)"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4><a href='http://download.oracle.com/javase/6/docs/api/java/lang/Object.html' title='def'>def</a> <strong>getAddParamValue</strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> value, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html' title='Boolean'>Boolean</a> withType = true, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html' title='Boolean'>Boolean</a> visualRefValue = false)</h4>
<p></p>
</li>
</ul>

<a name="getAddParamValue(java.util.Map, java.util.Map)"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4><a href='http://download.oracle.com/javase/6/docs/api/java/lang/Object.html' title='def'>def</a> <strong>getAddParamValue</strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> input, <a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> value)</h4>
<p></p>
</li>
</ul>

<a name="getAddParamValueRaw(java.util.Map, java.lang.Boolean)"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4><a href='http://download.oracle.com/javase/6/docs/api/java/lang/Object.html' title='def'>def</a> <strong>getAddParamValueRaw</strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/util/Map.html' title='Map'>Map</a> value, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html' title='Boolean'>Boolean</a> visualRefValue = false)</h4>
<p></p>
</li>
</ul>

</li>
</ul>

Expand Down
70 changes: 70 additions & 0 deletions src/org/camunda/latera/bss/connectors/hid/hydra/AddParam.groovy
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/org/camunda/latera/bss/connectors/hid/hydra/Good.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/org/camunda/latera/bss/connectors/hid/hydra/Param.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ 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')
} else if (input.containsKey('paramId')) {
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
Expand Down Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 206c0cf

Please sign in to comment.