use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project kie-wb-common by kiegroup.
the class BaseExpressionGridRenderingTest method getGrid.
@Override
@SuppressWarnings("unchecked")
public BaseExpressionGrid getGrid() {
final GridCellTuple parent = new GridCellTuple(0, 0, null);
final HasExpression hasExpression = mock(HasExpression.class);
final Optional<LiteralExpression> expression = Optional.of(mock(LiteralExpression.class));
final Optional<HasName> hasName = Optional.of(mock(HasName.class));
return new BaseExpressionGrid(parent, Optional.empty(), hasExpression, expression, hasName, gridPanel, gridLayer, new GridDataCache.CacheResult(new DMNGridData(), false), renderer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, cellEditorControls, listSelector, translationService, 0) {
@Override
protected BaseUIModelMapper makeUiModelMapper() {
return mapper;
}
@Override
protected void initialiseUiColumns() {
// Nothing for this test
}
@Override
protected void initialiseUiModel() {
// Nothing for this test
}
@Override
protected boolean isHeaderHidden() {
return isHeaderHidden;
}
};
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method test_wrong_context.
@Test
public void test_wrong_context() throws IOException {
// DROOLS-2217
// SPECIAL CASE: to represent a partially edited DMN file.
// consider a LiteralExpression with null text as missing expression altogether.
final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/wrong_context.dmn"));
DMNModel dmnModel = runtime.getModels().get(0);
// the DMN file is schema valid but is not a valid-DMN (a context-entry value is a literal expression missing text, which is null)
assertTrue(dmnModel.hasErrors());
// identify the error message for context-entry "ciao":
DMNMessage m0 = dmnModel.getMessages(DMNMessage.Severity.ERROR).get(0);
assertTrue("expected a message identifying the problem on a context entry for 'ciao'", m0.getMessage().startsWith("No expression defined for name 'ciao'"));
DecisionNode d0 = dmnModel.getDecisionById("_653b3426-933a-4050-9568-ab2a66b43c36");
// the identified DMN Decision is composed of a DMN Context where the first context-entry value is a literal expression missing text (text is null).
org.kie.dmn.model.v1_1.Context d0c = (org.kie.dmn.model.v1_1.Context) d0.getDecision().getExpression();
org.kie.dmn.model.v1_1.Expression contextEntryValue = d0c.getContextEntry().get(0).getExpression();
assertTrue(contextEntryValue instanceof org.kie.dmn.model.v1_1.LiteralExpression);
assertEquals(null, ((org.kie.dmn.model.v1_1.LiteralExpression) contextEntryValue).getText());
// -- Stunner side.
DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/wrong_context.dmn"));
DiagramImpl diagram = new DiagramImpl("", null);
Node<?, ?> decisionNode = g.getNode("_653b3426-933a-4050-9568-ab2a66b43c36");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
View<Decision> view = ((View<Decision>) decisionNode.getContent());
// the identified DMN Decision is composed of a DMN Context where the first context-entry has missing Expression.
Context expression = (Context) view.getDefinition().getExpression();
assertEquals("a literalexpression with null text is threated as a missing expression altogether.", null, expression.getContextEntry().get(0).getExpression());
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project kie-wb-common by kiegroup.
the class ExpressionContainerUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
final GridData uiModel = this.uiModel.get();
final Optional<Expression> expression = dmnModel.get();
final Optional<HasName> hasName = this.hasName.get();
final HasExpression hasExpression = this.hasExpression.get();
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitions.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(definition -> {
final Optional<BaseExpressionGrid> oEditor = definition.getEditor(parent, Optional.of(nodeUUID.get()), hasExpression, expression, hasName, 0);
uiModel.setCell(0, 0, () -> new ContextGridCell<>(new ExpressionCellValue(oEditor), listSelector));
final GridColumn<?> uiColumn = uiModel.getColumns().get(columnIndex);
uiColumn.setWidth(uiColumn.getMinimumWidth());
});
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project kie-wb-common by kiegroup.
the class ContextUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
dmnModel.get().ifPresent(context -> {
final boolean isLastRow = isLastRow(rowIndex);
final ContextUIModelMapperHelper.ContextSection section = ContextUIModelMapperHelper.getSection(columnIndex);
switch(section) {
case ROW_INDEX:
if (!isLastRow) {
uiModel.get().setCell(rowIndex, columnIndex, () -> new ContextGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector));
} else {
uiModel.get().setCell(rowIndex, columnIndex, () -> new DMNGridCell<>(new BaseGridCellValue<>((Integer) null)));
}
uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
break;
case NAME:
if (!isLastRow) {
final InformationItem variable = context.getContextEntry().get(rowIndex).getVariable();
uiModel.get().setCell(rowIndex, columnIndex, () -> new InformationItemNameCell(() -> variable, listSelector));
} else {
uiModel.get().setCell(rowIndex, columnIndex, () -> new DMNGridCell<>(new BaseGridCellValue<>(DEFAULT_ROW_CAPTION)));
}
break;
case EXPRESSION:
final ContextEntry ce = context.getContextEntry().get(rowIndex);
final Optional<Expression> expression = Optional.ofNullable(ce.getExpression());
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(ed -> {
final Optional<BaseExpressionGrid> editor = ed.getEditor(new GridCellTuple(rowIndex, columnIndex, gridWidget), Optional.empty(), ce, expression, Optional.ofNullable(ce.getVariable()), nesting + 1);
if (!isLastRow) {
uiModel.get().setCell(rowIndex, columnIndex, () -> new ContextGridCell<>(new ExpressionCellValue(editor), listSelector));
} else {
uiModel.get().setCell(rowIndex, columnIndex, () -> new DMNGridCell<>(new ExpressionCellValue(editor)));
}
});
}
});
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project kie-wb-common by kiegroup.
the class ExpressionEditorColumnTest method mockEditor.
@SuppressWarnings("unchecked")
private BaseExpressionGrid mockEditor(final double padding, final double... widthOfCells) {
final GridColumn.HeaderMetaData headerMetaData = mock(GridColumn.HeaderMetaData.class);
final GridColumnRenderer gridColumnRenderer = mock(GridColumnRenderer.class);
final BaseExpressionGrid gridWidget = mock(BaseExpressionGrid.class);
final GridCellTuple parent = new GridCellTuple(0, 0, null);
final HasExpression hasExpression = mock(HasExpression.class);
final Optional<LiteralExpression> expression = Optional.of(mock(LiteralExpression.class));
final Optional<HasName> hasName = Optional.of(mock(HasName.class));
return new BaseExpressionGrid(parent, Optional.empty(), hasExpression, expression, hasName, gridPanel, gridLayer, new GridDataCache.CacheResult(new DMNGridData(), false), renderer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, cellEditorControls, listSelector, translationService, 0) {
@Override
protected BaseUIModelMapper makeUiModelMapper() {
return null;
}
@Override
protected void initialiseUiColumns() {
for (double width : widthOfCells) {
model.appendColumn(new DMNGridColumn<GridWidget, Object>(headerMetaData, gridColumnRenderer, gridWidget) {
{
setMinimumWidth(width);
setWidth(width);
}
});
}
}
@Override
protected void initialiseUiModel() {
// Nothing for this test
}
@Override
protected boolean isHeaderHidden() {
return false;
}
@Override
public double getPadding() {
return padding;
}
};
}
Aggregations