Search in sources :

Example 16 with Context

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

the class ExpressionPropertyConverterTest method testDMNFromWB_ContextConversion.

@Test
public void testDMNFromWB_ContextConversion() {
    final Context wb = new Context();
    final List<Double> wbComponentWidths = wb.getComponentWidths();
    wbComponentWidths.set(0, 100.0);
    wbComponentWidths.set(1, 200.0);
    wbComponentWidths.set(2, 300.0);
    wb.getId().setValue(EXPRESSION_UUID);
    assertDMNFromWBConversion(wb, TContext.class, 100.0, 200.0, 300.0);
}
Also used : TContext(org.kie.dmn.model.v1_2.TContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) Test(org.junit.Test)

Example 17 with Context

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

the class PMMLIncludedModelHandler method destroy.

@Override
public void destroy(final String oldModelName) {
    final List<Decision> decisions = getDecisions();
    final List<BusinessKnowledgeModel> businessKnowledgeModels = getBusinessKnowledgeModels();
    final List<FunctionDefinition> functions = getPMMLFunctionDefinitions(decisions, businessKnowledgeModels);
    final Map<FunctionDefinition, Context> contexts = getPMMLContexts(functions);
    // The values in the DMN model are stored with quotes
    final String quotedOldModelName = StringUtils.createQuotedString(oldModelName);
    for (final Map.Entry<FunctionDefinition, Context> entry : contexts.entrySet()) {
        final Context context = entry.getValue();
        for (final ContextEntry contextEntry : context.getContextEntry()) {
            if (Objects.equals(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT, contextEntry.getVariable().getName().getValue())) {
                final Expression expression = contextEntry.getExpression();
                if (expression instanceof IsLiteralExpression) {
                    final IsLiteralExpression ile = (IsLiteralExpression) expression;
                    if (Objects.nonNull(ile.getText())) {
                        final Text text = ile.getText();
                        if (Objects.equals(quotedOldModelName, text.getValue())) {
                            clearContextValues(context);
                            entry.getKey().getFormalParameter().clear();
                        }
                    }
                }
            }
        }
    }
    // Refresh cached grids from the DMN model
    refreshCachedExpressionGrids(decisions, businessKnowledgeModels);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Map(java.util.Map)

Example 18 with Context

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

the class DMNDeepCloneProcessTest method buildFunctionDefinition.

private FunctionDefinition buildFunctionDefinition() {
    final FunctionDefinition encapsulatedLogic = new FunctionDefinition(new Id(FUNCTION_ID), new Description(), new QName(BuiltInType.BOOLEAN), new Context(new Id(CONTEXT_ID), new Description(), new QName(BuiltInType.NUMBER)));
    encapsulatedLogic.setKind(JAVA);
    return encapsulatedLogic;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 19 with Context

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

the class AddContextEntryCommandTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    this.context = new Context();
    this.contextEntry = new ContextEntry() {

        {
            setVariable(new InformationItem() {

                {
                    setName(new Name("variable"));
                }
            });
        }
    };
    this.defaultResultContextEntry = new ContextEntry();
    this.context.getContextEntry().add(defaultResultContextEntry);
    this.uiModel = new BaseGridData();
    this.uiModelRow = new BaseGridRow();
    this.uiDefaultResultModelRow = new BaseGridRow();
    this.uiModel.appendRow(uiDefaultResultModelRow);
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiNameColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    doReturn(uiModel).when(gridWidget).getModel();
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiNameColumn).getIndex();
    doReturn(2).when(uiExpressionEditorColumn).getIndex();
    this.uiModel.setCellValue(0, 2, new ExpressionCellValue(Optional.of(undefinedExpressionEditor)));
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    doReturn(parent).when(undefinedExpressionEditor).getParentInformation();
    doReturn(Optional.empty()).when(undefinedExpressionEditorDefinition).getModelClass();
    doReturn(Optional.of(undefinedExpressionEditor)).when(undefinedExpressionEditorDefinition).getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt());
    this.uiModelMapper = new ContextUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(context), () -> false, () -> expressionEditorDefinitions, listSelector, 0);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) ContextUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ContextUIModelMapper) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 20 with Context

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

the class DeleteContextEntryCommandTest method setup.

@Before
public void setup() {
    this.context = new Context();
    this.context.getContextEntry().add(new ContextEntry());
    this.uiModel = new BaseGridData(false);
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiModelColumn).getIndex();
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Before(org.junit.Before)

Aggregations

Context (org.kie.workbench.common.dmn.api.definition.model.Context)49 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)21 Test (org.junit.Test)20 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)15 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)13 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)12 TContext (org.kie.dmn.model.v1_2.TContext)9 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)7 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 NamespaceContext (javax.xml.namespace.NamespaceContext)6 Before (org.junit.Before)6 DMNContext (org.kie.dmn.api.core.DMNContext)6 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)5 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)5 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)5 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 ArrayList (java.util.ArrayList)4