use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields.
@Test
public void testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields() {
final DMNGraphUtils dmnGraphUtils = mock(DMNGraphUtils.class);
final Definitions definitions = mock(Definitions.class);
final HasExpression hasExpression = mock(HasExpression.class);
final Decision decision = mock(Decision.class);
final InformationItemPrimary informationItemPrimary = mock(InformationItemPrimary.class);
final ItemDefinition tPerson = mockTPersonStructure();
when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions);
when(definitions.getItemDefinition()).thenReturn(Collections.singletonList(tPerson));
when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(decision);
when(decision.getVariable()).thenReturn(informationItemPrimary);
when(informationItemPrimary.getTypeRef()).thenReturn(new QName("", TYPE_PERSON));
final DecisionTableEditorDefinitionEnricher enricher = new DecisionTableEditorDefinitionEnricher(null, dmnGraphUtils, itemDefinitionUtils);
final Optional<DecisionTable> oModel = definition.getModelClass();
final DecisionTable model = oModel.get();
enricher.buildOutputClausesByDataType(hasExpression, model, new DecisionRule());
final List<OutputClause> outputClauses = model.getOutput();
assertThat(outputClauses.size()).isEqualTo(2);
final OutputClause outputClause1 = outputClauses.get(0);
final OutputClause outputClause2 = outputClauses.get(1);
assertEquals("age", outputClause1.getName());
assertEquals(NUMBER.asQName(), outputClause1.getTypeRef());
assertEquals("name", outputClause2.getName());
assertEquals(STRING.asQName(), outputClause2.getTypeRef());
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class ListPropertyConverter method dmnFromWB.
public static org.kie.dmn.model.api.List dmnFromWB(final List wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
final org.kie.dmn.model.api.List result = new org.kie.dmn.model.v1_2.TList();
result.setId(wb.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
for (HasExpression hasExpression : wb.getExpression()) {
final Expression e = hasExpression.getExpression();
final org.kie.dmn.model.api.Expression eConverted = ExpressionPropertyConverter.dmnFromWB(e, componentWidthsConsumer);
if (Objects.nonNull(eConverted)) {
eConverted.setParent(result);
}
result.getExpression().add(eConverted);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class ListPropertyConverter method wbFromDMN.
public static List wbFromDMN(final org.kie.dmn.model.api.List dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
final java.util.List<HasExpression> expression = new ArrayList<>();
final List result = new List(id, description, typeRef, expression);
for (org.kie.dmn.model.api.Expression e : dmn.getExpression()) {
final Expression eConverted = ExpressionPropertyConverter.wbFromDMN(e, hasComponentWidthsConsumer);
final HasExpression hasExpression = HasExpression.wrap(result, eConverted);
expression.add(hasExpression);
}
for (HasExpression hasExpression : expression) {
final Expression e = hasExpression.getExpression();
if (Objects.nonNull(e)) {
e.setParent(result);
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class LiteralExpressionPMMLDocumentEditorDefinitionTest method testEditor.
@Test
public void testEditor() {
when(hasExpression.getExpression()).thenReturn(definition.getModelClass().get());
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> oEditor = definition.getEditor(parent, Optional.empty(), hasExpression, hasName, false, 0);
assertTrue(oEditor.isPresent());
final GridWidget editor = oEditor.get();
assertTrue(editor instanceof LiteralExpressionPMMLGrid);
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class FunctionGridTest method assertSetKind.
@SuppressWarnings("unchecked")
private void assertSetKind(final ExpressionEditorDefinition definition, final BaseExpressionGrid editor, final FunctionDefinition.Kind expectedKind, final Class<?> expectedExpressionType, final Class<?> expectedEditorType) {
verify(grid).doSetKind(eq(expectedKind), eq(expression.get()), expressionDefinitionCaptor.capture());
verify(definition).enrich(any(Optional.class), eq(hasExpression), any(Optional.class));
final ExpressionEditorDefinition<Expression> expressionDefinition = expressionDefinitionCaptor.getValue().get();
assertThat(expectedExpressionType).isAssignableFrom(expressionDefinition.getModelClass().get().getClass());
verify(sessionCommandManager).execute(eq(canvasHandler), setKindCommandCaptor.capture());
final SetKindCommand setKindCommand = setKindCommandCaptor.getValue();
setKindCommand.execute(canvasHandler);
final GridCellValue<?> gcv = grid.getModel().getCell(0, 1).getValue();
assertTrue(gcv instanceof ExpressionCellValue);
final ExpressionCellValue ecv = (ExpressionCellValue) gcv;
assertThat(expectedEditorType).isAssignableFrom(ecv.getValue().get().getClass());
verify(editor).resize(eq(BaseExpressionGrid.RESIZE_EXISTING));
verify(editor).selectFirstCell();
verify(gridLayer).batch(redrawCommandCaptor.capture());
redrawCommandCaptor.getValue().execute();
verify(gridLayer).draw();
// Check undo operation
reset(grid, gridLayer);
setKindCommand.undo(canvasHandler);
verify(grid).resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
verify(grid).selectFirstCell();
verify(gridLayer).batch(redrawCommandCaptor.capture());
assertThat(redrawCommandCaptor.getAllValues()).hasSize(2);
redrawCommandCaptor.getAllValues().get(1).execute();
verify(gridLayer).draw();
}
Aggregations