Search in sources :

Example 16 with BusinessKnowledgeModel

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

the class DMNDeepCloneProcess method clone.

/**
 * <p>It defines additive fields, specific to DMN domain, to be included in the target</p>
 * <p>Then, the "classic" clone operation, defined in {@link DeepCloneProcess} will be executed</p>
 * <p>Note that {@link DeepCloneProcess} is already taking care of aspects related to look&feel, such as background color, font, etc.</p>
 * <p>Every time we copy a node, in order to respect the name uniqueness logic, a new node will be created with a suffix {@code -X},
 * where {@code X} it is an incremental numeric value</p>
 *
 * @param source node to be cloned
 * @param target destination of the cloning operation
 * @return cloned instance, i.e. target element
 */
@Override
public <S, T> T clone(final S source, final T target) {
    super.clone(source, target);
    if (source instanceof DRGElement) {
        cloneDRGElementBasicInfo((DRGElement) source, (DRGElement) target);
    }
    if (source instanceof HasText) {
        cloneTextElementBasicInfo((HasText) source, (HasText) target);
    }
    if (source instanceof HasVariable) {
        final IsInformationItem sourceVariable = ((HasVariable) source).getVariable();
        final IsInformationItem targetVariable = ((HasVariable) target).getVariable();
        cloneTypeRefInfo(sourceVariable, targetVariable);
    }
    if (source instanceof Decision) {
        cloneDecision((Decision) source, (Decision) target);
    }
    if (source instanceof BusinessKnowledgeModel) {
        cloneBusinessKnowledgeModel((BusinessKnowledgeModel) source, (BusinessKnowledgeModel) target);
    }
    return target;
}
Also used : HasText(org.kie.workbench.common.dmn.api.definition.HasText) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 17 with BusinessKnowledgeModel

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

the class DMNEditBusinessKnowledgeModelToolboxAction method onMouseClick.

@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
    // Notice the toolbox factory ensure this action is only being included
    // for BusinessKnowledgeModel definitions, next cast is safe.
    final Node<View<? extends BusinessKnowledgeModel>, Edge> bkmNode = (Node<View<? extends BusinessKnowledgeModel>, Edge>) CanvasLayoutUtils.getElement(canvasHandler, uuid).asNode();
    final BusinessKnowledgeModel bkm = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(bkmNode);
    final boolean isReadOnly = bkm.isAllowOnlyVisualChange() || readOnlyProvider.isReadOnlyDiagram();
    editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, bkm.asHasExpression(), Optional.of(bkm), isReadOnly));
    return this;
}
Also used : BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) Node(org.kie.workbench.common.stunner.core.graph.Node) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 18 with BusinessKnowledgeModel

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

the class ObserverBuilderControl method updateElementFromDefinition.

@Override
@SuppressWarnings("unchecked")
protected void updateElementFromDefinition(final Element element, final Object definition) {
    final Object content = element.getContent();
    if (!(content instanceof View)) {
        return;
    }
    final Object newDefinition = ((View) content).getDefinition();
    if (newDefinition instanceof HasName && definition instanceof HasName) {
        ((HasName) newDefinition).getName().setValue(((HasName) definition).getName().getValue());
    }
    if (newDefinition instanceof DynamicReadOnly && definition instanceof DynamicReadOnly) {
        ((DynamicReadOnly) newDefinition).setAllowOnlyVisualChange(((DynamicReadOnly) definition).isAllowOnlyVisualChange());
    }
    if (newDefinition instanceof HasVariable && definition instanceof HasVariable) {
        ((HasVariable) newDefinition).setVariable(((HasVariable) definition).getVariable());
    }
    if (newDefinition instanceof BusinessKnowledgeModel && definition instanceof BusinessKnowledgeModel) {
        ((BusinessKnowledgeModel) newDefinition).setEncapsulatedLogic(((BusinessKnowledgeModel) definition).getEncapsulatedLogic());
    }
    if (newDefinition instanceof HasExpression && definition instanceof HasExpression) {
        ((HasExpression) newDefinition).setExpression(((HasExpression) definition).getExpression());
    }
    if (newDefinition instanceof DMNElement && definition instanceof DMNElement) {
        final DMNElement dmnElement = (DMNElement) definition;
        if (!StringUtils.isEmpty(dmnElement.getId().getValue())) {
            ((DMNElement) newDefinition).getId().setValue(dmnElement.getId().getValue());
        }
    }
    final Optional<DMNDiagramElement> currentDMNDiagramElement = getDMNDiagramsSession().getCurrentDMNDiagramElement();
    if (currentDMNDiagramElement.isPresent() && newDefinition instanceof HasContentDefinitionId) {
        ((HasContentDefinitionId) newDefinition).setDiagramId(currentDMNDiagramElement.get().getId().getValue());
    }
}
Also used : DynamicReadOnly(org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasContentDefinitionId(org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId) HasName(org.kie.workbench.common.dmn.api.definition.HasName) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 19 with BusinessKnowledgeModel

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

the class DefaultValueUtilitiesTest method testUpdateNewNodeName_DecisionService.

@Test
public void testUpdateNewNodeName_DecisionService() {
    // Add some existing nodes to ensure naming is not affected by existing content
    graph.addNode(makeMockNode(new BusinessKnowledgeModel()));
    graph.addNode(makeMockNode(new Decision()));
    graph.addNode(makeMockNode(new InputData()));
    graph.addNode(makeMockNode(new KnowledgeSource()));
    final DecisionService decisionService1 = new DecisionService();
    final DecisionService decisionService2 = new DecisionService();
    final DecisionService decisionService3 = new DecisionService();
    final DecisionService decisionService4 = new DecisionService();
    assertUpdateNewNodeName(decisionService1, decisionService2, (decisionService) -> decisionService.getName().getValue(), () -> DecisionService.class.getSimpleName() + "-1", () -> DecisionService.class.getSimpleName() + "-2");
    // Update existing names manually and add two more
    decisionService1.getName().setValue("decisionService");
    decisionService2.getName().setValue(DecisionService.class.getSimpleName() + "-5");
    assertUpdateNewNodeName(decisionService3, decisionService4, (decisionService) -> decisionService.getName().getValue(), () -> DecisionService.class.getSimpleName() + "-6", () -> DecisionService.class.getSimpleName() + "-7");
}
Also used : KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Example 20 with BusinessKnowledgeModel

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

the class DefaultValueUtilitiesTest method testUpdateNewNodeName_InputData.

@Test
public void testUpdateNewNodeName_InputData() {
    // Add some existing nodes to ensure naming is not affected by existing content
    graph.addNode(makeMockNode(new BusinessKnowledgeModel()));
    graph.addNode(makeMockNode(new Decision()));
    graph.addNode(makeMockNode(new KnowledgeSource()));
    graph.addNode(makeMockNode(new TextAnnotation()));
    final InputData inputData1 = new InputData();
    final InputData inputData2 = new InputData();
    final InputData inputData3 = new InputData();
    final InputData inputData4 = new InputData();
    assertUpdateNewNodeName(inputData1, inputData2, (inputData) -> inputData.getName().getValue(), () -> InputData.class.getSimpleName() + "-1", () -> InputData.class.getSimpleName() + "-2");
    // Update existing names manually and add two more
    inputData1.getName().setValue("inputData");
    inputData2.getName().setValue(InputData.class.getSimpleName() + "-5");
    assertUpdateNewNodeName(inputData3, inputData4, (inputData) -> inputData.getName().getValue(), () -> InputData.class.getSimpleName() + "-6", () -> InputData.class.getSimpleName() + "-7");
}
Also used : KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) 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