use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ExpressionPropertyConverter method dmnFromWB.
public static JSITExpression dmnFromWB(final Expression wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
if (Objects.isNull(wb)) {
return null;
}
final String uuid = wb.getId().getValue();
if (Objects.nonNull(uuid)) {
final JSITComponentWidths componentWidths = new JSITComponentWidths();
componentWidths.setDmnElementRef(uuid);
wb.getComponentWidths().stream().filter(Objects::nonNull).forEach(w -> componentWidths.addWidth(new Float(w)));
componentWidthsConsumer.accept(componentWidths);
}
if (wb instanceof IsLiteralExpression) {
final JSITLiteralExpression unwrappedJSITLiteralExpression = LiteralExpressionPropertyConverter.dmnFromWB((IsLiteralExpression) wb);
final JSITLiteralExpression wrappedJSITLiteralExpression = getWrappedJSITLiteralExpression(unwrappedJSITLiteralExpression, "dmn", "literalExpression");
return wrappedJSITLiteralExpression;
} else if (wb instanceof Context) {
final JSITContext unwrappedJSITContext = ContextPropertyConverter.dmnFromWB((Context) wb, componentWidthsConsumer);
final JSITContext wrappedJSITContext = getWrappedJSITContext(unwrappedJSITContext, "dmn", "context");
return wrappedJSITContext;
} else if (wb instanceof Relation) {
final JSITRelation unwrappedJSITRelation = RelationPropertyConverter.dmnFromWB((Relation) wb, componentWidthsConsumer);
final JSITRelation wrappedJSITRelation = getWrappedJSITRelation(unwrappedJSITRelation, "dmn", "relation");
return wrappedJSITRelation;
} else if (wb instanceof List) {
final JSITList unwrappedJSITList = ListPropertyConverter.dmnFromWB((List) wb, componentWidthsConsumer);
final JSITList wrappedJSITList = getWrappedJSITList(unwrappedJSITList, "dmn", "list");
return wrappedJSITList;
} else if (wb instanceof Invocation) {
final JSITInvocation unwrappedJSITInvocation = InvocationPropertyConverter.dmnFromWB((Invocation) wb, componentWidthsConsumer);
final JSITInvocation wrappedJSITInvocation = getWrappedJSITInvocation(unwrappedJSITInvocation, "dmn", "invocation");
return wrappedJSITInvocation;
} else if (wb instanceof FunctionDefinition) {
final JSITFunctionDefinition unwrappedJSITFunctionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB((FunctionDefinition) wb, componentWidthsConsumer);
final JSITFunctionDefinition wrappedJSITFunctionDefinition = getWrappedJSITFunctionDefinition(unwrappedJSITFunctionDefinition, "dmn", "functionDefinition");
return wrappedJSITFunctionDefinition;
} else if (wb instanceof DecisionTable) {
final JSITDecisionTable unwrappedJSITDecisionTable = DecisionTablePropertyConverter.dmnFromWB((DecisionTable) wb);
final JSITDecisionTable wrappedJSITDecisionTable = getWrappedJSITDecisionTable(unwrappedJSITDecisionTable, "dmn", "decisionTable");
return wrappedJSITDecisionTable;
}
return null;
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ExpressionPropertyConverter method wbFromDMN.
public static Expression wbFromDMN(final JSITExpression dmn, final JSITExpression parent, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
if (JSITLiteralExpression.instanceOf(dmn)) {
final JSITLiteralExpression jsiExpression = Js.uncheckedCast(dmn);
final LiteralExpression e = LiteralExpressionPropertyConverter.wbFromDMN(jsiExpression);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITContext.instanceOf(dmn)) {
final JSITContext jsiExpression = Js.uncheckedCast(dmn);
final Context e = ContextPropertyConverter.wbFromDMN(jsiExpression, parent, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITRelation.instanceOf(dmn)) {
final JSITRelation jsiExpression = Js.uncheckedCast(dmn);
final Relation e = RelationPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITList.instanceOf(dmn)) {
final JSITList jsiExpression = Js.uncheckedCast(dmn);
final List e = ListPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITInvocation.instanceOf(dmn)) {
final JSITInvocation jsiExpression = Js.uncheckedCast(dmn);
final Invocation e = InvocationPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITFunctionDefinition.instanceOf(dmn)) {
final JSITFunctionDefinition jsiExpression = Js.uncheckedCast(dmn);
final FunctionDefinition e = FunctionDefinitionPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITDecisionTable.instanceOf(dmn)) {
final JSITDecisionTable jsiExpression = Js.uncheckedCast(dmn);
final DecisionTable e = DecisionTablePropertyConverter.wbFromDMN(jsiExpression);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
}
return null;
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverterTest method testWBFromDMNWithPMMLFunctionDefinitionAsParent.
@Test
public void testWBFromDMNWithPMMLFunctionDefinitionAsParent() {
when(functionDefinition.getKind()).thenReturn(FunctionKind.PMML);
final org.kie.dmn.model.api.Context dmn = setupWBFromDMN(functionDefinition);
final Context wb = ContextPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
assertNoDefaultContextEntry(wb);
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class FunctionDefinitionPropertyConverterTest method doTestWBFromDMNWithContextEntry.
private void doTestWBFromDMNWithContextEntry(final FunctionKind kind, final String variableName, final Class<? extends IsLiteralExpression> literalExpressionClass) {
final org.kie.dmn.model.api.FunctionDefinition dmn = new TFunctionDefinition();
final org.kie.dmn.model.api.Context contextExpression = new TContext();
final org.kie.dmn.model.api.ContextEntry contextEntry = new TContextEntry();
final org.kie.dmn.model.api.InformationItem variable = new TInformationItem();
variable.setName(variableName);
contextEntry.setVariable(variable);
contextEntry.setExpression(new TLiteralExpression());
contextExpression.getContextEntry().add(contextEntry);
dmn.setKind(kind);
dmn.setExpression(contextExpression);
final FunctionDefinition wb = FunctionDefinitionPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
assertThat(wb.getExpression()).isInstanceOf(Context.class);
assertThat(((Context) wb.getExpression()).getContextEntry().get(0).getExpression()).isInstanceOf(literalExpressionClass);
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverterTest method setupDMNFromWB.
private Context setupDMNFromWB(final Optional<Expression> defaultExpression) {
final Context wb = new Context();
final ContextEntry contextEntry1 = new ContextEntry();
final ContextEntry contextEntry2 = new ContextEntry();
final InformationItem informationItem = new InformationItem();
literalExpression.getComponentWidths().set(0, 200.0);
literalExpression.getId().setValue(EXPRESSION_UUID);
contextEntry1.setExpression(literalExpression);
contextEntry1.setVariable(informationItem);
defaultExpression.ifPresent(contextEntry2::setExpression);
wb.getContextEntry().add(contextEntry1);
wb.getContextEntry().add(contextEntry2);
return wb;
}
Aggregations