Search in sources :

Example 11 with BusinessKnowledgeModel

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

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

the class DMNCommonActionsToolboxFactoryTest method testBuildToolboxForBusinessKnowledgeModelType.

@Test
@SuppressWarnings("unchecked")
public void testBuildToolboxForBusinessKnowledgeModelType() {
    final Node<View<BusinessKnowledgeModel>, Edge> bkmNode = new NodeImpl<>("bkmNode1");
    final BusinessKnowledgeModel bkm = new BusinessKnowledgeModel();
    final Bounds bounds = Bounds.create(0d, 0d, 100d, 150d);
    final View<BusinessKnowledgeModel> nodeContent = new ViewImpl<>(bkm, bounds);
    bkmNode.setContent(nodeContent);
    final Optional<Toolbox<?>> _toolbox = tested.build(canvasHandler, bkmNode);
    assertTrue(_toolbox.isPresent());
    Toolbox<?> toolbox = _toolbox.get();
    assertTrue(toolbox instanceof ActionsToolbox);
    final ActionsToolbox actionsToolbox = (ActionsToolbox) toolbox;
    assertEquals("bkmNode1", actionsToolbox.getElementUUID());
    assertEquals(3, actionsToolbox.size());
    final Iterator<ToolboxAction> actionsIt = actionsToolbox.iterator();
    assertEquals(deleteNodeAction, actionsIt.next());
    assertEquals(editBusinessKnowledgeModelToolboxActionInstance, actionsIt.next());
    assertTrue(actionsIt.hasNext());
    verify(viewInstance, times(1)).init(eq(actionsToolbox));
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) ActionsToolbox(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolbox) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ActionsToolboxView(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolboxView) ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) DeleteNodeToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.DeleteNodeToolboxAction) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) ActionsToolbox(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolbox) Toolbox(org.kie.workbench.common.stunner.core.client.components.toolbox.Toolbox) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 13 with BusinessKnowledgeModel

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

the class DMNCommonActionsToolboxFactoryTest method testAddEditBusinessKnowledgeModelAction.

@Test
public void testAddEditBusinessKnowledgeModelAction() {
    final List<ToolboxAction<AbstractCanvasHandler>> actions = new ArrayList<>();
    final Element element = mock(Element.class);
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final BusinessKnowledgeModel bkm = mock(BusinessKnowledgeModel.class);
    when(element.asNode()).thenReturn(node);
    when(element.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(bkm);
    tested.addEditAction(element, actions);
    assertEquals(1, actions.size());
    assertTrue(DMNEditBusinessKnowledgeModelToolboxAction.class.isInstance(actions.get(0)));
}
Also used : ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) DeleteNodeToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.DeleteNodeToolboxAction) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) ArrayList(java.util.ArrayList) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Test(org.junit.Test)

Example 14 with BusinessKnowledgeModel

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

the class DMNEditBusinessKnowledgeModelToolboxActionTest method setup.

@Before
public void setup() throws Exception {
    bkmNode = new NodeImpl<>(E_UUID);
    bkm = new BusinessKnowledgeModel();
    final Bounds bounds = Bounds.create(0d, 0d, 100d, 150d);
    final View<BusinessKnowledgeModel> nodeContent = new ViewImpl<>(bkm, bounds);
    bkmNode.setContent(nodeContent);
    when(canvasHandler.getGraphIndex()).thenReturn(graphIndex);
    when(graphIndex.get(eq(E_UUID))).thenReturn(bkmNode);
    when(sessionManager.getCurrentSession()).thenReturn(session);
    this.tested = new DMNEditBusinessKnowledgeModelToolboxAction(sessionManager, translationService, editExpressionEvent, readOnlyProvider);
}
Also used : BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Before(org.junit.Before)

Example 15 with BusinessKnowledgeModel

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

the class ObserverBuilderControlTest method testUpdateEncapsulatedLogicFromDefinition.

@Test
public void testUpdateEncapsulatedLogicFromDefinition() {
    final Element element = mock(Element.class);
    final View elementContent = mock(View.class);
    final BusinessKnowledgeModel newBusinessKnowledgeModel = mock(BusinessKnowledgeModel.class);
    final BusinessKnowledgeModel businessKnowledgeModel = mock(BusinessKnowledgeModel.class);
    final FunctionDefinition functionDefinition = mock(FunctionDefinition.class);
    when(element.getContent()).thenReturn(elementContent);
    when(elementContent.getDefinition()).thenReturn(newBusinessKnowledgeModel);
    when(businessKnowledgeModel.getEncapsulatedLogic()).thenReturn(functionDefinition);
    when(newBusinessKnowledgeModel.getName()).thenReturn(new Name());
    when(businessKnowledgeModel.getName()).thenReturn(new Name());
    when(newBusinessKnowledgeModel.getId()).thenReturn(new Id());
    when(businessKnowledgeModel.getId()).thenReturn(new Id());
    observerBuilderControl.updateElementFromDefinition(element, businessKnowledgeModel);
    verify(newBusinessKnowledgeModel).setEncapsulatedLogic(functionDefinition);
}
Also used : DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) Element(org.kie.workbench.common.stunner.core.graph.Element) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) HasName(org.kie.workbench.common.dmn.api.definition.HasName) Test(org.junit.Test)

Aggregations

BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)37 Test (org.junit.Test)19 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)17 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)16 View (org.kie.workbench.common.stunner.core.graph.content.view.View)15 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)14 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)11 TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)11 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)10 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)9 ArrayList (java.util.ArrayList)7 Edge (org.kie.workbench.common.stunner.core.graph.Edge)7 Node (org.kie.workbench.common.stunner.core.graph.Node)7 List (java.util.List)6 KnowledgeRequirement (org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement)5 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)5 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)4 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)4 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4