use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.
the class ConversionUtilsTest method toOutputTypedValue.
@Test
void toOutputTypedValue() {
Output name = ConversionUtils.toOutput("name", new UnitValue("number", new DoubleNode(10d)));
assertNotNull(name);
assertEquals("name", name.getName());
assertEquals(Type.NUMBER, name.getType());
assertEquals(10d, name.getValue().getUnderlyingObject());
Output name1 = ConversionUtils.toOutput("name1", new StructureValue("complex", singletonMap("key", new UnitValue("string1", new TextNode("stringValue")))));
assertNotNull(name1);
assertEquals("name1", name1.getName());
assertEquals(Type.COMPOSITE, name1.getType());
assertTrue(name1.getValue().getUnderlyingObject() instanceof List);
@SuppressWarnings("unchecked") List<Output> outputs = (List<Output>) name1.getValue().getUnderlyingObject();
assertEquals(1, outputs.size());
assertEquals(Type.TEXT, outputs.get(0).getType());
assertEquals("stringValue", outputs.get(0).getValue().getUnderlyingObject());
List<TypedValue> values = List.of(new UnitValue("number", new DoubleNode(0d)), new UnitValue("number", new DoubleNode(1d)));
assertNotNull(ConversionUtils.toOutput("name", new CollectionValue("list", values)));
}
use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.
the class ConversionUtils method toFeatureList.
// //////////////////////////
// TO EXPLAINABILITY MODEL
// //////////////////////////
/*
* ---------------------------------------
* Feature conversion
* ---------------------------------------
*/
public static List<Feature> toFeatureList(Collection<? extends HasNameValue<TypedValue>> values, Collection<CounterfactualSearchDomain> searchDomains) {
if (searchDomains.isEmpty()) {
return toFeatureList(values);
} else {
AtomicInteger index = new AtomicInteger();
final List<FeatureDomain> featureDomains = toFeatureDomainList(searchDomains);
final List<Boolean> featureConstraints = toFeatureConstraintList(searchDomains);
return values.stream().map(hnv -> {
final String name = hnv.getName();
final TypedValue value = hnv.getValue();
final int i = index.getAndIncrement();
return toFeature(name, value, featureDomains.get(i), featureConstraints.get(i));
}).collect(Collectors.toList());
}
}
use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.
the class ConversionUtils method toTypedValue.
static TypedValue toTypedValue(Output output) {
String name = output.getName();
Type type = output.getType();
Value value = output.getValue();
return toTypedValue(name, type, value);
}
use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.
the class ConversionUtils method toOutputListForCollection.
static List<Output> toOutputListForCollection(String name, CollectionValue collectionValue) {
Collection<TypedValue> values = collectionValue.getValue();
List<Output> list = new ArrayList<>(values.size());
int index = 0;
for (TypedValue typedValue : values) {
list.add(toOutput(name + "_" + index, typedValue));
index++;
}
return list;
}
use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-runtimes by kiegroup.
the class EventUtilsTest method testTypedVariableFromJsonNodeWithDMNType.
@Test
void testTypedVariableFromJsonNodeWithDMNType() throws JsonProcessingException {
ObjectReader reader = new ObjectMapper().reader();
TypedValue value = EventUtils.typedValueFromJsonNode(mockDMNType("Any"), null, null);
assertNotNull(value);
assertSame(TypedValue.Kind.UNIT, value.getKind());
assertEquals(BuiltInType.UNKNOWN.getName(), value.getType());
value = EventUtils.typedValueFromJsonNode(mockDMNType("boolean"), reader.readTree("true"), null);
assertNotNull(value);
assertSame(TypedValue.Kind.UNIT, value.getKind());
assertEquals(BuiltInType.BOOLEAN.getName(), value.getType());
value = EventUtils.typedValueFromJsonNode(mockDMNType("number"), reader.readTree("12"), null);
assertNotNull(value);
assertSame(TypedValue.Kind.UNIT, value.getKind());
assertEquals(BuiltInType.NUMBER.getName(), value.getType());
value = EventUtils.typedValueFromJsonNode(mockDMNType("string"), reader.readTree("\"test\""), null);
assertNotNull(value);
assertSame(TypedValue.Kind.UNIT, value.getKind());
assertEquals(BuiltInType.STRING.getName(), value.getType());
value = EventUtils.typedValueFromJsonNode(mockDMNType("number"), reader.readTree("[1,2,3]"), null);
assertNotNull(value);
assertSame(TypedValue.Kind.COLLECTION, value.getKind());
assertEquals(BuiltInType.NUMBER.getName(), value.getType());
value = EventUtils.typedValueFromJsonNode(mockDMNType("Person"), reader.readTree("{\"name\": \"John\", \"age\": 45, \"married\": true}"), null);
assertNotNull(value);
assertSame(TypedValue.Kind.STRUCTURE, value.getKind());
assertEquals("Person", value.getType());
}
Aggregations