use of org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetParametersCommand in project kie-wb-common by kiegroup.
the class LiteralExpressionPMMLDocumentModelGridTest method testNewCellHasValueCommand.
@Test
public void testNewCellHasValueCommand() {
setupGrid(0);
final List<String> parameterNames = asList("param1", "param2");
final String modelName = (String) tupleWithValue.getValue().getValue();
when(pmmlDocumentMetadataProvider.getPMMLDocumentModelParameterNames(eq(DOCUMENT_NAME), eq(modelName))).thenReturn(parameterNames);
final Command command = grid.newCellHasValueCommand().apply(tupleWithValue);
verify(pmmlDocumentMetadataProvider).getPMMLDocumentModelParameterNames(eq(DOCUMENT_NAME), eq(modelName));
GridFactoryCommandUtils.assertCommands(command, SetCellValueCommand.class, SetParametersCommand.class);
final SetParametersCommand setParametersCommand = (SetParametersCommand) ((CompositeCommand) command).getCommands().get(1);
setParametersCommand.execute(canvasHandler);
assertThat(grandParentExpression.getFormalParameter().stream().map(ii -> ii.getName().getValue()).collect(Collectors.toList())).containsExactly("param1", "param2");
}
use of org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetParametersCommand 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