Search in sources :

Example 6 with DRGElement

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

the class DecisionComponentsItemView method decisionComponentItemMouseDown.

@EventHandler("decision-component-item")
public void decisionComponentItemMouseDown(final MouseDownEvent mouseDownEvent) {
    final DRGElement drgElement = presenter.getDrgElement();
    final ShapeFactory factory = dmnShapeSet.getShapeFactory();
    final Glyph glyph = factory.getGlyph(drgElement.getClass().getName());
    final ShapeGlyphDragHandler.Item item = makeDragHandler(glyph);
    final Callback proxy = makeDragProxyCallbackImpl(drgElement, factory);
    shapeGlyphDragHandler.show(item, mouseDownEvent.getX(), mouseDownEvent.getY(), proxy);
}
Also used : Callback(org.kie.workbench.common.stunner.client.lienzo.components.glyph.ShapeGlyphDragHandler.Callback) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) ShapeGlyphDragHandler(org.kie.workbench.common.stunner.client.lienzo.components.glyph.ShapeGlyphDragHandler) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) EventHandler(org.jboss.errai.ui.shared.api.annotations.EventHandler)

Example 7 with DRGElement

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

the class BusinessKnowledgeModelConverter method dmnFromNode.

@Override
@SuppressWarnings("unchecked")
public JSITBusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node);
    final JSITBusinessKnowledgeModel result = new JSITBusinessKnowledgeModel();
    result.setId(source.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    description.ifPresent(result::setDescription);
    result.setName(source.getName().getValue());
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getKnowledgeRequirement())) {
        result.setKnowledgeRequirement(new ArrayList<>());
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getAuthorityRequirement())) {
        result.setAuthorityRequirement(new ArrayList<>());
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result);
    final JSITInformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
    result.setVariable(variable);
    final JSITFunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB(source.getEncapsulatedLogic(), componentWidthsConsumer);
    final FunctionDefinition wbFunctionDefinition = source.getEncapsulatedLogic();
    if (Objects.nonNull(wbFunctionDefinition)) {
        final String uuid = wbFunctionDefinition.getId().getValue();
        if (Objects.nonNull(uuid)) {
            final JSITComponentWidths componentWidths = new JSITComponentWidths();
            componentWidths.setDmnElementRef(uuid);
            source.getEncapsulatedLogic().getComponentWidths().stream().filter(Objects::nonNull).forEach(w -> componentWidths.addWidth(new Float(w)));
            componentWidthsConsumer.accept(componentWidths);
        }
    }
    result.setEncapsulatedLogic(functionDefinition);
    // DMN spec table 2: Requirements connection rules
    final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
    for (Edge<?, ?> e : inEdges) {
        final Node<?, ?> sourceNode = e.getSourceNode();
        if (sourceNode.getContent() instanceof View<?>) {
            final View<?> view = (View<?>) sourceNode.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                final DRGElement drgElement = (DRGElement) view.getDefinition();
                if (drgElement instanceof BusinessKnowledgeModel) {
                    final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
                    iReq.setId(getRawId(e.getUUID()));
                    final JSITDMNElementReference ri = new JSITDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredKnowledge(ri);
                    result.addKnowledgeRequirement(iReq);
                } else if (drgElement instanceof KnowledgeSource) {
                    final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
                    iReq.setId(getRawId(e.getUUID()));
                    final JSITDMNElementReference ri = new JSITDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredAuthority(ri);
                    result.addAuthorityRequirement(iReq);
                } else if (drgElement instanceof DecisionService) {
                    if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
                        final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
                        iReq.setId(getRawId(e.getUUID()));
                        final JSITDMNElementReference ri = new JSITDMNElementReference();
                        ri.setHref(getHref(drgElement));
                        iReq.setRequiredKnowledge(ri);
                        result.addKnowledgeRequirement(iReq);
                    } else {
                        throw new UnsupportedOperationException("wrong model definition.");
                    }
                } else {
                    throw new UnsupportedOperationException("wrong model definition.");
                }
            }
        }
    }
    return result;
}
Also used : JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) JSITBusinessKnowledgeModel(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBusinessKnowledgeModel) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) JSITAuthorityRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAuthorityRequirement) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) ArrayList(java.util.ArrayList) List(java.util.List) JSITComponentWidths(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentWidths) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) View(org.kie.workbench.common.stunner.core.graph.content.view.View) KnowledgeRequirement(org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement) JSITKnowledgeRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeRequirement) JSITKnowledgeRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeRequirement) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) JSITBusinessKnowledgeModel(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBusinessKnowledgeModel) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 8 with DRGElement

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

the class DecisionConverter method dmnFromNode.

@Override
@SuppressWarnings("unchecked")
public JSITDecision dmnFromNode(final Node<View<Decision>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    final Decision source = (Decision) DefinitionUtils.getElementDefinition(node);
    final JSITDecision d = new JSITDecision();
    d.setId(source.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    description.ifPresent(d::setDescription);
    d.setName(source.getName().getValue());
    final JSITInformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
    d.setVariable(variable);
    final JSITExpression expression = ExpressionPropertyConverter.dmnFromWB(source.getExpression(), componentWidthsConsumer);
    d.setExpression(expression);
    final String question = QuestionPropertyConverter.dmnFromWB(source.getQuestion());
    if (!StringUtils.isEmpty(question)) {
        d.setQuestion(question);
    }
    final String allowedAnswers = AllowedAnswersPropertyConverter.dmnFromWB(source.getAllowedAnswers());
    if (!StringUtils.isEmpty(allowedAnswers)) {
        d.setAllowedAnswers(allowedAnswers);
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(d.getInformationRequirement())) {
        d.setInformationRequirement(new ArrayList<>());
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(d.getKnowledgeRequirement())) {
        d.setKnowledgeRequirement(new ArrayList<>());
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(d.getAuthorityRequirement())) {
        d.setAuthorityRequirement(new ArrayList<>());
    }
    // DMN spec table 2: Requirements connection rules
    final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
    for (Edge<?, ?> e : inEdges) {
        final Node<?, ?> sourceNode = e.getSourceNode();
        if (sourceNode.getContent() instanceof View<?>) {
            final View<?> view = (View<?>) sourceNode.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                final DRGElement drgElement = (DRGElement) view.getDefinition();
                if (drgElement instanceof Decision) {
                    final JSITInformationRequirement iReq = new JSITInformationRequirement();
                    iReq.setId(getRawId(e.getUUID()));
                    final JSITDMNElementReference ri = new JSITDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredDecision(ri);
                    d.addInformationRequirement(iReq);
                } else if (drgElement instanceof BusinessKnowledgeModel) {
                    final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
                    iReq.setId(getRawId(e.getUUID()));
                    final JSITDMNElementReference ri = new JSITDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredKnowledge(ri);
                    d.addKnowledgeRequirement(iReq);
                } else if (drgElement instanceof KnowledgeSource) {
                    final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
                    iReq.setId(getRawId(e.getUUID()));
                    final JSITDMNElementReference ri = new JSITDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredAuthority(ri);
                    d.addAuthorityRequirement(iReq);
                } else if (drgElement instanceof InputData) {
                    final JSITInformationRequirement iReq = new JSITInformationRequirement();
                    iReq.setId(getRawId(e.getUUID()));
                    final JSITDMNElementReference ri = new JSITDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredInput(ri);
                    d.addInformationRequirement(iReq);
                } else if (drgElement instanceof DecisionService) {
                    if (e.getContent() instanceof Child) {
                    // Stunner relationship of this Decision be encapsulated by the DecisionService, not managed here.
                    } else if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
                        final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
                        iReq.setId(getRawId(e.getUUID()));
                        final JSITDMNElementReference ri = new JSITDMNElementReference();
                        ri.setHref(getHref(drgElement));
                        iReq.setRequiredKnowledge(ri);
                        d.addKnowledgeRequirement(iReq);
                    } else {
                        throw new UnsupportedOperationException("wrong model definition.");
                    }
                } else {
                    throw new UnsupportedOperationException("wrong model definition.");
                }
            }
        }
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, d);
    return d;
}
Also used : JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) JSITAuthorityRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAuthorityRequirement) ArrayList(java.util.ArrayList) List(java.util.List) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) JSITInformationRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationRequirement) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) IdUtils.getRawId(org.kie.workbench.common.dmn.client.marshaller.common.IdUtils.getRawId) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) View(org.kie.workbench.common.stunner.core.graph.content.view.View) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) KnowledgeRequirement(org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement) JSITKnowledgeRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeRequirement) JSITKnowledgeRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeRequirement) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 9 with DRGElement

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

the class DMNElementsSynchronizer method synchronizeElementsFrom.

public void synchronizeElementsFrom(final DRGElement drgElement) {
    final String contentDefinitionId = drgElement.getContentDefinitionId();
    final List<Node> nodes = getElementsWithContentId(contentDefinitionId);
    for (final Node node : nodes) {
        updateText(drgElement, node);
        final DRGElement element = getDRGElementFromContentDefinition(node);
        synchronizeBaseDRGProperties(drgElement, element);
        synchronizeSpecializedProperties(drgElement, element);
    }
    refreshDecisionComponentsEvent.fire(new RefreshDecisionComponents());
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) RefreshDecisionComponents(org.kie.workbench.common.dmn.client.docks.navigator.events.RefreshDecisionComponents) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 10 with DRGElement

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

the class DMNElementsSynchronizer method synchronizeFromNode.

public void synchronizeFromNode(final Optional<Node> node) {
    node.ifPresent(n -> {
        if (n.getContent() instanceof Definition) {
            final Definition definition = (Definition) n.getContent();
            if (definition.getDefinition() instanceof DRGElement) {
                final DRGElement drgElement = (DRGElement) definition.getDefinition();
                synchronizeElementsFrom(drgElement);
            }
        }
    });
}
Also used : Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Aggregations

DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)72 Test (org.junit.Test)45 Node (org.kie.workbench.common.stunner.core.graph.Node)27 ArrayList (java.util.ArrayList)25 Edge (org.kie.workbench.common.stunner.core.graph.Edge)17 View (org.kie.workbench.common.stunner.core.graph.content.view.View)17 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)16 List (java.util.List)15 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)15 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)15 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)15 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)13 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)10 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)9 Import (org.kie.workbench.common.dmn.api.definition.model.Import)9 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)8 KnowledgeRequirement (org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement)7 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)7 Optional (java.util.Optional)6