use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverterTest method testWBFromDMNWithFEELFunctionDefinitionAsParent.
@Test
public void testWBFromDMNWithFEELFunctionDefinitionAsParent() {
when(functionDefinition.getKind()).thenReturn(FunctionKind.FEEL);
final org.kie.dmn.model.api.Context dmn = setupWBFromDMN(functionDefinition);
final Context wb = ContextPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
assertDefaultContextEntry(wb);
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class HasExpressionTest method testWrapNull.
@Test
public void testWrapNull() {
final HasExpression hasExpression = HasExpression.wrap(parent, null);
assertNull(hasExpression.getExpression());
assertEquals(parent, hasExpression.asDMNModelInstrumentedBase());
final Context context = new Context();
hasExpression.setExpression(context);
assertNotNull(hasExpression.getExpression());
assertEquals(context, hasExpression.getExpression());
assertEquals(parent, hasExpression.asDMNModelInstrumentedBase());
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class HasExpressionTest method testNOP.
@Test
public void testNOP() {
final HasExpression hasExpression = HasExpression.NOP;
assertNull(hasExpression.getExpression());
assertNull(hasExpression.asDMNModelInstrumentedBase());
final Context context = new Context();
hasExpression.setExpression(context);
assertNull(hasExpression.getExpression());
assertNull(hasExpression.asDMNModelInstrumentedBase());
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverter method wbFromDMN.
public static Context wbFromDMN(final org.kie.dmn.model.api.Context dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
final Context result = new Context(id, description, typeRef);
for (org.kie.dmn.model.api.ContextEntry ce : dmn.getContextEntry()) {
final ContextEntry ceConverted = ContextEntryPropertyConverter.wbFromDMN(ce, hasComponentWidthsConsumer);
if (ceConverted != null) {
ceConverted.setParent(result);
}
result.getContextEntry().add(ceConverted);
}
// No need to append a _default_ row if the Context is part of a JAVA or PMML FunctionDefinition
if (dmn.getParent() instanceof FunctionDefinition) {
final FunctionDefinition functionDefinition = (FunctionDefinition) dmn.getParent();
if (!functionDefinition.getKind().equals(FunctionKind.FEEL)) {
return result;
}
}
// The UI requires a ContextEntry for the _default_ result even if none has been defined
final int contextEntriesCount = result.getContextEntry().size();
if (contextEntriesCount == 0) {
result.getContextEntry().add(new ContextEntry());
} else if (!Objects.isNull(result.getContextEntry().get(contextEntriesCount - 1).getVariable())) {
result.getContextEntry().add(new ContextEntry());
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class FunctionDefinitionPropertyConverter method convertPMMLFunctionExpression.
private static void convertPMMLFunctionExpression(final FunctionDefinition function) {
final Expression expression = function.getExpression();
if (expression instanceof Context) {
final Context context = (Context) expression;
context.getContextEntry().forEach(FunctionDefinitionPropertyConverter::convertContextEntryExpression);
}
}
Aggregations