Search in sources :

Example 1 with LiteralExpressionPMMLDocument

use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument in project kie-wb-common by kiegroup.

the class PMMLFunctionEditorDefinitionTest method testModelEnrichment.

@Test
public void testModelEnrichment() {
    final Optional<Context> oModel = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, oModel);
    final Context model = oModel.get();
    assertEquals(2, model.getContextEntry().size());
    assertEquals(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT, model.getContextEntry().get(0).getVariable().getName().getValue());
    assertTrue(model.getContextEntry().get(0).getExpression() instanceof LiteralExpressionPMMLDocument);
    assertEquals(model, model.getContextEntry().get(0).getParent());
    assertEquals(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL, model.getContextEntry().get(1).getVariable().getName().getValue());
    assertTrue(model.getContextEntry().get(1).getExpression() instanceof LiteralExpressionPMMLDocumentModel);
    assertEquals(model, model.getContextEntry().get(1).getParent());
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument) Test(org.junit.Test)

Example 2 with LiteralExpressionPMMLDocument

use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument in project kie-wb-common by kiegroup.

the class PMMLIncludedModelHandlerTest method assertPMMLContextDefinition.

private void assertPMMLContextDefinition(final FunctionDefinition function, final String expectedDocumentValue, final String expectedModelValue) {
    assertThat(function.getExpression()).isInstanceOf(Context.class);
    final Context context = (Context) function.getExpression();
    assertThat(context.getContextEntry().get(0).getExpression()).isInstanceOf(LiteralExpressionPMMLDocument.class);
    final LiteralExpressionPMMLDocument functionDocument = (LiteralExpressionPMMLDocument) context.getContextEntry().get(0).getExpression();
    assertThat(functionDocument.getText().getValue()).isEqualTo(wrap(expectedDocumentValue));
    assertThat(context.getContextEntry().get(1).getExpression()).isInstanceOf(LiteralExpressionPMMLDocumentModel.class);
    final LiteralExpressionPMMLDocumentModel functionDocumentModel = (LiteralExpressionPMMLDocumentModel) context.getContextEntry().get(1).getExpression();
    assertThat(functionDocumentModel.getText().getValue()).isEqualTo(wrap(expectedModelValue));
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument)

Example 3 with LiteralExpressionPMMLDocument

use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument in project kie-wb-common by kiegroup.

the class FunctionDefinitionPropertyConverter method convertContextEntryExpression.

private static void convertContextEntryExpression(final ContextEntry contextEntry, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final Expression expression = contextEntry.getExpression();
    if (expression instanceof LiteralExpression) {
        final LiteralExpression le = (LiteralExpression) expression;
        final String variableName = contextEntry.getVariable().getName().getValue();
        if (Objects.equals(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT, variableName)) {
            final LiteralExpressionPMMLDocument e = convertLiteralExpressionToPMMLDocument(le);
            // Ensure ComponentWidths are updated for the converted LiteralExpression
            hasComponentWidthsConsumer.accept(e.getId().getValue(), e);
            contextEntry.setExpression(e);
        } else if (Objects.equals(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL, variableName)) {
            final LiteralExpressionPMMLDocumentModel e = convertLiteralExpressionToPMMLDocumentModel(le);
            // Ensure ComponentWidths are updated for the converted LiteralExpression
            hasComponentWidthsConsumer.accept(e.getId().getValue(), e);
            contextEntry.setExpression(e);
        }
    }
}
Also used : LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument)

Example 4 with LiteralExpressionPMMLDocument

use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument in project kie-wb-common by kiegroup.

the class PMMLFunctionEditorDefinition method enrich.

@Override
public void enrich(final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<Context> expression) {
    expression.ifPresent(context -> {
        final List<String> variableNames = getVariableNames();
        final ContextEntry contextEntryDocument = new ContextEntry();
        contextEntryDocument.setVariable(createVariable(variableNames.get(0)));
        contextEntryDocument.setExpression(new LiteralExpressionPMMLDocument());
        context.getContextEntry().add(contextEntryDocument);
        contextEntryDocument.setParent(context);
        final ContextEntry contextEntryDocumentModel = new ContextEntry();
        contextEntryDocumentModel.setVariable(createVariable(variableNames.get(1)));
        contextEntryDocumentModel.setExpression(new LiteralExpressionPMMLDocumentModel());
        context.getContextEntry().add(contextEntryDocumentModel);
        contextEntryDocumentModel.setParent(context);
    });
}
Also used : LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 5 with LiteralExpressionPMMLDocument

use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument in project kie-wb-common by kiegroup.

the class LiteralExpressionPMMLDocumentEditorDefinition 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((LiteralExpressionPMMLDocument) hasExpression.getExpression())), definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, getCellEditorControls(), listSelector, translationService, isOnlyVisualChangeAllowed, nesting, headerEditor, readOnlyProvider) {

        @Override
        protected String getPlaceHolder() {
            return translationService.getTranslation(DMNEditorConstants.LiteralExpressionPMMLDocumentEditorDefinition_Placeholder);
        }

        @Override
        protected void loadValues(final Consumer<List<String>> consumer) {
            consumer.accept(pmmlDocumentMetadataProvider.getPMMLDocumentNames());
        }

        @Override
        @SuppressWarnings("unchecked")
        public Function<GridCellValueTuple, Command> newCellHasValueCommand() {
            return (gridCellValueTuple) -> {
                final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<>();
                // Command to set the PMMLDocument value
                builder.addCommand(new SetCellValueCommand(gridCellValueTuple, () -> uiModelMapper, gridLayer::batch));
                // Command to clear the PMMLDocumentModel value. Unfortunately we need to reset the cells' placeholder too.
                getExpressionPMMLValueEditor(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL).ifPresent(editor -> {
                    if (editor instanceof LiteralExpressionPMMLGrid) {
                        final LiteralExpressionPMMLGrid pmmlModelEditor = (LiteralExpressionPMMLGrid) editor;
                        builder.addCommand(pmmlModelEditor.newCellHasValueCommand().apply(new GridCellValueTuple(0, 0, pmmlModelEditor, new BaseGridCellValue("", translationService.getTranslation(DMNEditorConstants.LiteralExpressionPMMLDocumentModelEditorDefinition_Placeholder)))));
                    }
                });
                return builder.build();
            };
        }
    });
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) LiteralExpressionPMMLGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.pmml.LiteralExpressionPMMLGrid) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple) Function(java.util.function.Function) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) SetCellValueCommand(org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand) List(java.util.List) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Aggregations

LiteralExpressionPMMLDocument (org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument)7 LiteralExpressionPMMLDocumentModel (org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel)5 Context (org.kie.workbench.common.dmn.api.definition.model.Context)3 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)2 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)2 List (java.util.List)1 Function (java.util.function.Function)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)1 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)1 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)1 SetCellValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand)1 ExpressionEditorDefinitions (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions)1 LiteralExpressionPMMLGrid (org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.pmml.LiteralExpressionPMMLGrid)1 GridCellValueTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple)1 JSITExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)1