use of org.kie.workbench.common.dmn.api.definition.model.Invocation in project kie-wb-common by kiegroup.
the class ExpressionPropertyConverter method wbFromDMN.
public static Expression wbFromDMN(final org.kie.dmn.model.api.Expression dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
if (dmn instanceof org.kie.dmn.model.api.LiteralExpression) {
final LiteralExpression e = LiteralExpressionPropertyConverter.wbFromDMN((org.kie.dmn.model.api.LiteralExpression) dmn);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.Context) {
final Context e = ContextPropertyConverter.wbFromDMN((org.kie.dmn.model.api.Context) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.Relation) {
final Relation e = RelationPropertyConverter.wbFromDMN((org.kie.dmn.model.api.Relation) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.List) {
final List e = ListPropertyConverter.wbFromDMN((org.kie.dmn.model.api.List) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.Invocation) {
final Invocation e = InvocationPropertyConverter.wbFromDMN((org.kie.dmn.model.api.Invocation) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.FunctionDefinition) {
final FunctionDefinition e = FunctionDefinitionPropertyConverter.wbFromDMN((org.kie.dmn.model.api.FunctionDefinition) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.DecisionTable) {
final DecisionTable e = DecisionTablePropertyConverter.wbFromDMN((org.kie.dmn.model.api.DecisionTable) dmn);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
}
return null;
}
use of org.kie.workbench.common.dmn.api.definition.model.Invocation in project kie-wb-common by kiegroup.
the class MoveRowsCommandTest method setup.
@Before
public void setup() {
this.invocation = new Invocation();
this.uiModel = new DMNGridData();
doReturn(ruleManager).when(handler).getRuleManager();
doReturn(0).when(uiRowNumberColumn).getIndex();
doReturn(1).when(uiNameColumn).getIndex();
doReturn(2).when(uiExpressionEditorColumn).getIndex();
addParameterBinding(II1);
addParameterBinding(II2);
addUiModelColumn(uiRowNumberColumn);
addUiModelColumn(uiNameColumn);
addUiModelColumn(uiExpressionEditorColumn);
addUiModelRow(0);
addUiModelRow(1);
}
use of org.kie.workbench.common.dmn.api.definition.model.Invocation in project kie-wb-common by kiegroup.
the class InvocationEditorDefinitionTest method testModelEnrichment.
@Test
public void testModelEnrichment() {
final Optional<Invocation> oModel = definition.getModelClass();
definition.enrich(Optional.empty(), hasExpression, oModel);
final Invocation model = oModel.get();
assertNotNull(model.getExpression());
assertTrue(model.getExpression() instanceof LiteralExpression);
assertEquals(1, model.getBinding().size());
assertNotNull(model.getBinding().get(0).getParameter());
assertEquals(InvocationDefaultValueUtilities.PREFIX + "1", model.getBinding().get(0).getParameter().getName().getValue());
assertNull(model.getBinding().get(0).getExpression());
assertNotNull(model.getId());
assertEquals(model, model.getExpression().getParent());
assertEquals(model, model.getBinding().get(0).getParent());
assertEquals(model.getBinding().get(0), model.getBinding().get(0).getParameter().getParent());
}
use of org.kie.workbench.common.dmn.api.definition.model.Invocation in project kie-wb-common by kiegroup.
the class InvocationUIModelMapperTest method setup.
@SuppressWarnings("unchecked")
public void setup(final boolean isOnlyVisualChangeAllowedSupplier) {
this.uiModel = new BaseGridData();
this.uiModel.appendRow(new BaseGridRow());
this.uiModel.appendRow(new BaseGridRow());
this.uiModel.appendColumn(uiRowNumberColumn);
this.uiModel.appendColumn(uiNameColumn);
this.uiModel.appendColumn(uiExpressionEditorColumn);
when(uiRowNumberColumn.getIndex()).thenReturn(0);
when(uiNameColumn.getIndex()).thenReturn(1);
when(uiExpressionEditorColumn.getIndex()).thenReturn(2);
when(gridWidget.getModel()).thenReturn(uiModel);
final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
expressionEditorDefinitions.add(literalExpressionEditorDefinition);
when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
when(literalExpressionEditor.getExpression()).thenReturn(() -> Optional.of(literalExpression));
when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
final LiteralExpression invocationExpression = new LiteralExpression();
invocationExpression.getText().setValue("invocation-expression");
final LiteralExpression bindingExpression = new LiteralExpression();
bindingExpression.getText().setValue("binding-expression");
final Binding binding = new Binding();
final InformationItem parameter = new InformationItem();
parameter.setName(new Name("p0"));
binding.setParameter(parameter);
binding.setExpression(bindingExpression);
this.invocation = new Invocation();
this.invocation.setExpression(invocationExpression);
this.invocation.getBinding().add(binding);
this.mapper = new InvocationUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(invocation), () -> isOnlyVisualChangeAllowedSupplier, expressionEditorDefinitionsSupplier, listSelector, 0);
this.cellValueSupplier = Optional::empty;
}
use of org.kie.workbench.common.dmn.api.definition.model.Invocation in project kie-wb-common by kiegroup.
the class InvocationPropertyConverter method wbFromDMN.
public static Invocation wbFromDMN(final JSITInvocation dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
if (Objects.isNull(dmn)) {
return null;
}
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
final Invocation result = new Invocation();
result.setId(id);
result.setDescription(description);
result.setTypeRef(typeRef);
Expression expression = null;
final JSITExpression jsiWrapped = dmn.getExpression();
if (Objects.nonNull(jsiWrapped)) {
final JSITExpression jsiExpression = Js.uncheckedCast(JsUtils.getUnwrappedElement(jsiWrapped));
expression = ExpressionPropertyConverter.wbFromDMN(jsiExpression, Js.uncheckedCast(dmn), hasComponentWidthsConsumer);
}
result.setExpression(expression);
if (Objects.nonNull(expression)) {
expression.setParent(result);
}
final List<JSITBinding> jsiBindings = dmn.getBinding();
for (int i = 0; i < jsiBindings.size(); i++) {
final JSITBinding jsiBinding = Js.uncheckedCast(jsiBindings.get(i));
final Binding bConverted = BindingPropertyConverter.wbFromDMN(jsiBinding, hasComponentWidthsConsumer);
if (Objects.nonNull(bConverted)) {
bConverted.setParent(result);
}
result.getBinding().add(bConverted);
}
return result;
}
Aggregations