Search in sources :

Example 6 with LiteralExpression

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

the class RelationUIModelMapper method toDMNModel.

@Override
public void toDMNModel(final int rowIndex, final int columnIndex, final Supplier<Optional<GridCellValue<?>>> cell) {
    dmnModel.get().ifPresent(relation -> {
        final RelationUIModelMapperHelper.RelationSection section = RelationUIModelMapperHelper.getSection(relation, columnIndex);
        switch(section) {
            case ROW_INDEX:
                break;
            case INFORMATION_ITEM:
                final org.kie.workbench.common.dmn.api.definition.v1_1.List row = relation.getRow().get(rowIndex);
                final int iiIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, columnIndex);
                final Expression e = row.getExpression().get(iiIndex);
                final Optional<Expression> expression = Optional.ofNullable(e);
                expression.ifPresent(ex -> {
                    // Whilst the DMN 1.1 specification allows for ANY expression to be used we have made the simplification
                    // to limit ourselves to LiteralExpressions. Our Grid-system supports ANY (nested) expression too; however
                    // the simplification has been made for the benefit of USERS.
                    final LiteralExpression le = (LiteralExpression) ex;
                    le.setText(cell.get().orElse(new BaseGridCellValue<>("")).getValue().toString());
                });
        }
    });
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 7 with LiteralExpression

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

the class RelationUIModelMapper method fromDMNModel.

@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
    dmnModel.get().ifPresent(relation -> {
        final RelationUIModelMapperHelper.RelationSection section = RelationUIModelMapperHelper.getSection(relation, columnIndex);
        switch(section) {
            case ROW_INDEX:
                uiModel.get().setCell(rowIndex, columnIndex, () -> new RelationGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector));
                uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
                break;
            case INFORMATION_ITEM:
                final org.kie.workbench.common.dmn.api.definition.v1_1.List row = relation.getRow().get(rowIndex);
                final int iiIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, columnIndex);
                final Expression e = row.getExpression().get(iiIndex);
                final Optional<Expression> expression = Optional.ofNullable(e);
                expression.ifPresent(ex -> {
                    // Whilst the DMN 1.1 specification allows for ANY expression to be used we have made the simplification
                    // to limit ourselves to LiteralExpressions. Our Grid-system supports ANY (nested) expression too; however
                    // the simplification has been made for the benefit of USERS.
                    final LiteralExpression le = (LiteralExpression) ex;
                    uiModel.get().setCell(rowIndex, columnIndex, () -> new RelationGridCell<>(new BaseGridCellValue<>(le.getText()), listSelector));
                });
        }
    });
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 8 with LiteralExpression

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

the class LiteralExpressionPropertyConverter method wbFromDMN.

public static LiteralExpression wbFromDMN(final org.kie.dmn.model.v1_1.LiteralExpression dmn) {
    if (dmn == null) {
        return null;
    }
    Id id = new Id(dmn.getId());
    Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    String text = dmn.getText();
    String expressionLanguage = dmn.getExpressionLanguage();
    ImportedValues importedValues = ImportedValuesConverter.wbFromDMN(dmn.getImportedValues());
    LiteralExpression result = new LiteralExpression(id, description, typeRef, text, importedValues, expressionLanguage);
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ImportedValues(org.kie.workbench.common.dmn.api.definition.v1_1.ImportedValues) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 9 with LiteralExpression

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

the class AddDecisionRuleCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            dtable.getRule().add(uiRowIndex, rule);
            for (int ie = 0; ie < dtable.getInput().size(); ie++) {
                final UnaryTests ut = new UnaryTests();
                ut.setText(AddInputClauseCommand.INPUT_CLAUSE_DEFAULT_VALUE);
                rule.getInputEntry().add(ut);
            }
            for (int oe = 0; oe < dtable.getOutput().size(); oe++) {
                final LiteralExpression le = new LiteralExpression();
                le.setText(AddOutputClauseCommand.OUTPUT_CLAUSE_DEFAULT_VALUE);
                rule.getOutputEntry().add(le);
            }
            final Description d = new Description();
            d.setValue(DESCRIPTION_DEFAULT_VALUE);
            rule.setDescription(d);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            dtable.getRule().remove(rule);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)

Example 10 with LiteralExpression

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

the class ContextEditorDefinition method getModelClass.

@Override
public Optional<Context> getModelClass() {
    // Add one ContextEntry for the User to start with
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    contextEntry.setVariable(new InformationItem());
    context.getContextEntry().add(contextEntry);
    // Add (default) "result" entry
    final ContextEntry resultEntry = new ContextEntry();
    resultEntry.setExpression(new LiteralExpression());
    context.getContextEntry().add(resultEntry);
    return Optional.of(context);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.v1_1.ContextEntry)

Aggregations

LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)60 Test (org.junit.Test)27 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)18 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)18 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)18 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)13 Before (org.junit.Before)11 Optional (java.util.Optional)10 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)10 UnaryTests (org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)10 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)10 HasName (org.kie.workbench.common.dmn.api.definition.HasName)9 LiteralExpression (org.kie.dmn.model.v1_1.LiteralExpression)8 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)8 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)8 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)8 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)7 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)7 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)7