Search in sources :

Example 16 with FunctionDefinition

use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition 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 17 with FunctionDefinition

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

the class RemoveParameterCommandTest method setup.

@Before
public void setup() {
    this.function = new FunctionDefinition();
    this.parameter = new InformationItem();
    this.function.getFormalParameter().add(parameter);
    this.command = new RemoveParameterCommand(function, parameter, canvasOperation);
    doReturn(ruleManager).when(handler).getRuleManager();
}
Also used : FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Before(org.junit.Before)

Example 18 with FunctionDefinition

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

the class SetParametersCommandTest method setup.

@Before
public void setup() {
    this.function = new FunctionDefinition();
    this.parameter1 = new InformationItem();
    this.parameter2 = new InformationItem();
    doReturn(ruleManager).when(handler).getRuleManager();
}
Also used : FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Before(org.junit.Before)

Example 19 with FunctionDefinition

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

the class SetKindCommandTest method setup.

@Before
public void setup() {
    this.function = new FunctionDefinition();
    this.function.setKind(originalKind);
    this.function.setExpression(originalExpression);
    this.uiModel = new BaseGridData();
    this.uiModel.appendColumn(mockColumn);
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.setCellValue(0, 0, new ExpressionCellValue(Optional.of(originalEditor)));
    doReturn(uiModel).when(gridWidget).getModel();
    doReturn(ruleManager).when(handler).getRuleManager();
}
Also used : BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Example 20 with FunctionDefinition

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

the class RegisterNodeCommandTest method testExecuteWithBusinessKnowledgeModelNodeWhenNodeIsNotNew.

@Test
public void testExecuteWithBusinessKnowledgeModelNodeWhenNodeIsNotNew() {
    final FunctionDefinition functionDefinition = new FunctionDefinition();
    final LiteralExpression literalExpression = makeLiteralExpression("123");
    when(candidateContent.getDefinition()).thenReturn(businessKnowledgeModel);
    doReturn(functionDefinition).when(businessKnowledgeModel).getEncapsulatedLogic();
    functionDefinition.setExpression(literalExpression);
    literalExpression.setParent(functionDefinition);
    assertThat(command.execute(graphCommandExecutionContext).getType()).isEqualTo(CommandResult.Type.INFO);
    final FunctionDefinition encapsulatedLogic = businessKnowledgeModel.getEncapsulatedLogic();
    final Expression expression = encapsulatedLogic.getExpression();
    assertThat(expression).isEqualTo(makeLiteralExpression("123"));
    assertThat(expression.getParent()).isEqualTo(encapsulatedLogic);
    assertThat(KindUtilities.getKind(encapsulatedLogic)).isEqualTo(FunctionDefinition.Kind.FEEL);
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Test(org.junit.Test) AbstractGraphCommandTest(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommandTest)

Aggregations

FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)40 Test (org.junit.Test)12 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)12 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)12 Context (org.kie.workbench.common.dmn.api.definition.model.Context)11 ArrayList (java.util.ArrayList)8 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)8 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)8 Before (org.junit.Before)7 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)7 TFunctionDefinition (org.kie.dmn.model.v1_2.TFunctionDefinition)5 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)5 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)5 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)5 IsLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 List (java.util.List)4 QName (javax.xml.namespace.QName)4 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)4