use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class RelationPropertyConverterTest method testDMNFromWB.
@Test
public void testDMNFromWB() {
final Relation wb = new Relation();
final InformationItem informationItem = new InformationItem();
final List list = new List();
final LiteralExpression literalExpression = new LiteralExpression();
final HasExpression hasExpression = HasExpression.wrap(wb, literalExpression);
literalExpression.getComponentWidths().set(0, 200.0);
literalExpression.getId().setValue(EXPRESSION_UUID);
list.getExpression().add(hasExpression);
wb.getId().setValue(RELATION_UUID);
wb.getDescription().setValue(RELATION_DESCRIPTION);
wb.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(org.kie.workbench.common.dmn.api.property.dmn.QName.NULL_NS_URI, RELATION_QNAME_LOCALPART));
wb.getColumn().add(informationItem);
wb.getRow().add(list);
final org.kie.dmn.model.api.Relation dmn = RelationPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
assertThat(dmn).isNotNull();
assertThat(dmn.getId()).isNotNull();
assertThat(dmn.getId()).isEqualTo(RELATION_UUID);
assertThat(dmn.getDescription()).isNotNull();
assertThat(dmn.getDescription()).isEqualTo(RELATION_DESCRIPTION);
assertThat(dmn.getTypeRef()).isNotNull();
assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(RELATION_QNAME_LOCALPART);
assertThat(dmn.getColumn()).isNotNull();
assertThat(dmn.getColumn().size()).isEqualTo(1);
assertThat(dmn.getColumn().get(0)).isNotNull();
assertThat(dmn.getRow()).isNotNull();
assertThat(dmn.getRow().size()).isEqualTo(1);
assertThat(dmn.getRow().get(0)).isNotNull();
assertThat(dmn.getRow().get(0).getExpression()).isNotNull();
assertThat(dmn.getRow().get(0).getExpression().size()).isEqualTo(1);
assertThat(dmn.getRow().get(0).getExpression().get(0).getId()).isEqualTo(EXPRESSION_UUID);
verify(componentWidthsConsumer).accept(componentWidthsCaptor.capture());
final ComponentWidths componentWidths = componentWidthsCaptor.getValue();
assertThat(componentWidths).isNotNull();
assertThat(componentWidths.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
assertThat(componentWidths.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
assertThat(componentWidths.getWidths().get(0)).isEqualTo(200.0);
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricher method buildOutputClausesByDataType.
void buildOutputClausesByDataType(final HasExpression hasExpression, final DecisionTable dTable, final DecisionRule decisionRule) {
final HasTypeRef hasTypeRef = getHasTypeRef(hasExpression, dTable);
final QName typeRef = !Objects.isNull(hasTypeRef) ? hasTypeRef.getTypeRef() : BuiltInType.UNDEFINED.asQName();
final String name = DecisionTableDefaultValueUtilities.getNewOutputClauseName(dTable);
final List<ClauseRequirement> outputClausesRequirement = generateOutputClauseRequirements(dmnGraphUtils.getModelDefinitions(), typeRef, name);
if (outputClausesRequirement.isEmpty()) {
dTable.getOutput().add(buildOutputClause(dTable, typeRef, name));
populateOutputEntries(decisionRule);
} else {
outputClausesRequirement.stream().sorted(Comparator.comparing(outputClauseRequirement -> outputClauseRequirement.text)).map(outputClauseRequirement -> buildOutputClause(dTable, outputClauseRequirement.typeRef, outputClauseRequirement.text)).forEach(outputClause -> {
dTable.getOutput().add(outputClause);
populateOutputEntries(decisionRule);
});
}
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class ListTest method testGetHasTypeRefs.
@Test
public void testGetHasTypeRefs() {
// added
final Expression expression1 = mock(Expression.class);
// added
final Expression expression2 = mock(Expression.class);
final List<HasExpression> hasExpressions = asList(HasExpression.wrap(list, expression1), HasExpression.wrap(list, expression2));
final HasTypeRef hasTypeRef1 = mock(HasTypeRef.class);
final HasTypeRef hasTypeRef2 = mock(HasTypeRef.class);
doReturn(hasExpressions).when(list).getExpression();
when(expression1.getHasTypeRefs()).thenReturn(asList(hasTypeRef1));
when(expression2.getHasTypeRefs()).thenReturn(asList(hasTypeRef2));
final List<HasTypeRef> actualHasTypeRefs = list.getHasTypeRefs();
final List<HasTypeRef> expectedHasTypeRefs = asList(list, hasTypeRef1, hasTypeRef2);
assertEquals(expectedHasTypeRefs, actualHasTypeRefs);
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class ContextGrid method clearExpressionType.
void clearExpressionType(final int uiRowIndex) {
final GridCellTuple gc = new GridCellTuple(uiRowIndex, ContextUIModelMapperHelper.EXPRESSION_COLUMN_INDEX, this);
getExpression().get().ifPresent(context -> {
final HasExpression hasExpression = context.getContextEntry().get(uiRowIndex);
sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new ClearExpressionTypeCommand(gc, hasExpression, uiModelMapper, () -> {
resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
selectExpressionEditorFirstCell(uiRowIndex, ContextUIModelMapperHelper.EXPRESSION_COLUMN_INDEX);
}, () -> {
resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
selectExpressionEditorFirstCell(uiRowIndex, ContextUIModelMapperHelper.EXPRESSION_COLUMN_INDEX);
}));
});
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class ExpressionContainerUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
final String uuid = nodeUUID.get();
final GridData uiModel = this.uiModel.get();
final Optional<Expression> expression = dmnModel.get();
final Optional<HasName> hasName = this.hasName.get();
final boolean isOnlyVisualChangeAllowed = this.isOnlyVisualChangeAllowedSupplier.get();
final HasExpression hasExpression = this.hasExpression.get();
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitions.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(definition -> {
Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = expressionGridCache.get().getExpressionGrid(uuid);
if (!editor.isPresent()) {
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> oEditor = definition.getEditor(parent, Optional.of(uuid), hasExpression, hasName, isOnlyVisualChangeAllowed, 0);
expressionGridCache.get().putExpressionGrid(uuid, oEditor);
editor = oEditor;
}
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> _editor = editor;
uiModel.setCell(0, 0, () -> new ContextGridCell<>(new ExpressionCellValue(_editor), listSelector));
});
}
Aggregations