use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class BoxedExpressionHelperTest method testGetOptionalHasExpressionWhenNodeIsOtherDRGElement.
@Test
public void testGetOptionalHasExpressionWhenNodeIsOtherDRGElement() {
final View content = mock(View.class);
final InputData expectedHasExpression = mock(InputData.class);
when(node.getContent()).thenReturn(content);
when(content.getDefinition()).thenReturn(expectedHasExpression);
final Optional<HasExpression> actualHasExpression = helper.getOptionalHasExpression(node);
assertFalse(actualHasExpression.isPresent());
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class DMNEditBusinessKnowledgeModelToolboxActionTest method testAction.
@Test
public void testAction() {
final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, mouseClickEvent);
assertEquals(tested, cascade);
final ArgumentCaptor<EditExpressionEvent> eventCaptor = ArgumentCaptor.forClass(EditExpressionEvent.class);
verify(editExpressionEvent, times(1)).fire(eventCaptor.capture());
final EditExpressionEvent editExprEvent = eventCaptor.getValue();
assertEquals(E_UUID, editExprEvent.getNodeUUID());
final HasExpression hasExpression = editExprEvent.getHasExpression();
assertEquals(bkm.getEncapsulatedLogic(), hasExpression.getExpression());
assertEquals(bkm, hasExpression.asDMNModelInstrumentedBase());
assertFalse(hasExpression.isClearSupported());
assertEquals(bkm, editExprEvent.getHasName().get());
assertEquals(session, editExprEvent.getSession());
assertFalse(editExprEvent.isOnlyVisualChangeAllowed());
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class HasTypeRefHelperTest method testGetFlatHasTypeRefsFromExpressions.
@Test
public void testGetFlatHasTypeRefsFromExpressions() {
final Expression expression1 = mock(Expression.class);
final Expression expression2 = mock(Expression.class);
final DMNModelInstrumentedBase parent = mock(DMNModelInstrumentedBase.class);
final HasExpression hasExpression1 = HasExpression.wrap(parent, expression1);
final HasExpression hasExpression2 = HasExpression.wrap(parent, expression2);
final List<HasExpression> hasExpressions = asList(hasExpression1, hasExpression2);
final HasTypeRef hasTypeRef1 = mock(HasTypeRef.class);
final HasTypeRef hasTypeRef2 = mock(HasTypeRef.class);
final HasTypeRef hasTypeRef3 = mock(HasTypeRef.class);
final HasTypeRef hasTypeRef4 = mock(HasTypeRef.class);
final List<HasTypeRef> typeRefList1 = asList(hasTypeRef1, hasTypeRef2);
final List<HasTypeRef> typeRefList2 = asList(hasTypeRef3, hasTypeRef4);
when(expression1.getHasTypeRefs()).thenReturn(typeRefList1);
when(expression2.getHasTypeRefs()).thenReturn(typeRefList2);
final List<HasTypeRef> actual = HasTypeRefHelper.getFlatHasTypeRefsFromExpressions(hasExpressions);
final List<HasTypeRef> expected = asList(hasTypeRef1, hasTypeRef2, hasTypeRef3, hasTypeRef4);
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class UndefinedExpressionGrid method onExpressionTypeChanged.
public void onExpressionTypeChanged(final ExpressionType type) {
final Optional<Expression> expression = expressionEditorDefinitionsSupplier.get().stream().filter(e -> e.getType().equals(type)).map(ExpressionEditorDefinition::getModelClass).findFirst().get();
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(ed -> {
sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new SetCellValueCommand(parent, nodeUUID, hasExpression, () -> expression, expressionGridCache, (editor) -> {
resize(BaseExpressionGrid.RESIZE_EXISTING);
editor.ifPresent(BaseExpressionGrid::selectFirstCell);
}, () -> {
resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
selectCell(0, 0, false, false);
}, () -> {
Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = Optional.empty();
if (nodeUUID.isPresent()) {
final String uuid = nodeUUID.get();
editor = expressionGridCache.getExpressionGrid(uuid);
}
if (!editor.isPresent()) {
ed.enrich(nodeUUID, hasExpression, expression);
editor = ed.getEditor(parent, nodeUUID, hasExpression, hasName, isOnlyVisualChangeAllowed, nesting);
}
return editor;
}));
});
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class LiteralExpressionPMMLDocumentModelEditorDefinition method getEditor.
@Override
public Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> getEditor(final GridCellTuple parent, final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<HasName> hasName, final boolean isOnlyVisualChangeAllowed, final int nesting) {
return Optional.of(new LiteralExpressionPMMLGrid(parent, nodeUUID, hasExpression, hasName, getGridPanel(), getGridLayer(), makeGridData(() -> Optional.ofNullable((LiteralExpressionPMMLDocumentModel) hasExpression.getExpression())), definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, getCellEditorControls(), listSelector, translationService, isOnlyVisualChangeAllowed, nesting, headerEditor, readOnlyProvider) {
@Override
protected String getPlaceHolder() {
return translationService.getTranslation(DMNEditorConstants.LiteralExpressionPMMLDocumentModelEditorDefinition_Placeholder);
}
@Override
protected void loadValues(final Consumer<List<String>> consumer) {
final String pmmlDocumentName = getExpressionPMMLValue(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT);
consumer.accept(pmmlDocumentMetadataProvider.getPMMLDocumentModels(pmmlDocumentName));
}
@Override
public Function<GridCellValueTuple, Command> newCellHasValueCommand() {
return (gridCellValueTuple) -> {
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<>();
// Command to set the PMMLDocumentModel value
builder.addCommand(new SetCellValueCommand(gridCellValueTuple, () -> uiModelMapper, gridLayer::batch));
// Command to set PMMLDocumentModel parameters
getParentFunctionGrid().ifPresent(parentFunctionGrid -> {
final String pmmlDocumentName = getExpressionPMMLValue(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT);
final String pmmlDocumentModelName = StringUtils.createUnquotedString((String) gridCellValueTuple.getValue().getValue());
final List<String> parameters = pmmlDocumentMetadataProvider.getPMMLDocumentModelParameterNames(pmmlDocumentName, pmmlDocumentModelName);
parentFunctionGrid.getExpression().get().ifPresent(function -> {
builder.addCommand(new SetParametersCommand(function, convertParametersToInformationItems(parameters), gridLayer::batch));
});
});
return builder.build();
};
}
private List<InformationItem> convertParametersToInformationItems(final List<String> parameters) {
final List<InformationItem> informationItems = new ArrayList<>();
parameters.forEach(parameter -> informationItems.add(new InformationItem(new Id(), new Description(), new Name(parameter), BuiltInType.ANY.asQName())));
return informationItems;
}
});
}
Aggregations