Search in sources :

Example 1 with SetHitPolicyCommand

use of org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetHitPolicyCommand in project kie-wb-common by kiegroup.

the class DecisionTableGrid method setHitPolicy.

@Override
public void setHitPolicy(final HitPolicy hitPolicy, final Command onSuccess) {
    expression.ifPresent(dtable -> {
        final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<>();
        commandBuilder.addCommand(new SetBuiltinAggregatorCommand(dtable, null, gridLayer::batch));
        commandBuilder.addCommand(new SetHitPolicyCommand(dtable, hitPolicy, () -> {
            gridLayer.batch();
            onSuccess.execute();
        }));
        sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), commandBuilder.build());
    });
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) SetHitPolicyCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetHitPolicyCommand) SetBuiltinAggregatorCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetBuiltinAggregatorCommand) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)

Example 2 with SetHitPolicyCommand

use of org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetHitPolicyCommand in project kie-wb-common by kiegroup.

the class DecisionTableGridTest method testSetHitPolicy.

@Test
public void testSetHitPolicy() {
    final HitPolicy hitPolicy = HitPolicy.ANY;
    setupGrid(makeHasNameForDecision(), 0);
    grid.setHitPolicy(hitPolicy, command);
    verify(sessionCommandManager).execute(eq(canvasHandler), setHitPolicyCommandCaptor.capture());
    final CompositeCommand<AbstractCanvasHandler, CanvasViolation> setHitPolicyCommand = setHitPolicyCommandCaptor.getValue();
    assertEquals(2, setHitPolicyCommand.getCommands().size());
    assertTrue(setHitPolicyCommand.getCommands().get(0) instanceof SetBuiltinAggregatorCommand);
    assertTrue(setHitPolicyCommand.getCommands().get(1) instanceof SetHitPolicyCommand);
    setHitPolicyCommand.execute(canvasHandler);
    verify(gridLayer, atLeast(1)).batch();
    verify(command).execute();
    assertEquals(hitPolicy, expression.get().getHitPolicy());
    assertNull(expression.get().getAggregation());
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) HitPolicy(org.kie.workbench.common.dmn.api.definition.v1_1.HitPolicy) SetHitPolicyCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetHitPolicyCommand) SetBuiltinAggregatorCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetBuiltinAggregatorCommand) Test(org.junit.Test)

Aggregations

SetBuiltinAggregatorCommand (org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetBuiltinAggregatorCommand)2 SetHitPolicyCommand (org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetHitPolicyCommand)2 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)2 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)2 Test (org.junit.Test)1 HitPolicy (org.kie.workbench.common.dmn.api.definition.v1_1.HitPolicy)1 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)1