Search in sources :

Example 11 with JSITExpression

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression in project kie-wb-common by kiegroup.

the class DecisionConverter method nodeFromDMN.

@Override
public Node<View<Decision>, ?> nodeFromDMN(final NodeEntry nodeEntry) {
    final JSITDecision dmn = Js.uncheckedCast(nodeEntry.getDmnElement());
    @SuppressWarnings("unchecked") final Node<View<Decision>, ?> node = (Node<View<Decision>, ?>) factoryManager.newElement(nodeEntry.getId(), getDefinitionId(Decision.class)).asNode();
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final Name name = new Name(dmn.getName());
    final InformationItemPrimary informationItem = InformationItemPrimaryPropertyConverter.wbFromDMN(dmn.getVariable(), dmn);
    Expression expression = null;
    final JSITExpression jsiWrapped = dmn.getExpression();
    if (Objects.nonNull(jsiWrapped)) {
        final JSITExpression jsiExpression = Js.uncheckedCast(JsUtils.getUnwrappedElement(jsiWrapped));
        expression = ExpressionPropertyConverter.wbFromDMN(jsiExpression, Js.uncheckedCast(dmn), nodeEntry.getComponentWidthsConsumer());
    }
    final Decision decision = new Decision(id, description, name, new Question(), new AllowedAnswers(), informationItem, expression, new StylingSet(), new GeneralRectangleDimensionsSet());
    decision.setDiagramId(nodeEntry.getDiagramId());
    decision.setQuestion(QuestionPropertyConverter.wbFromDMN(dmn.getQuestion()));
    decision.setAllowedAnswers(AllowedAnswersPropertyConverter.wbFromDMN(dmn.getAllowedAnswers()));
    node.getContent().setDefinition(decision);
    if (Objects.nonNull(informationItem)) {
        informationItem.setParent(decision);
    }
    if (Objects.nonNull(expression)) {
        expression.setParent(decision);
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, decision);
    return node;
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Node(org.kie.workbench.common.stunner.core.graph.Node) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) GeneralRectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.GeneralRectangleDimensionsSet) AllowedAnswers(org.kie.workbench.common.dmn.api.property.dmn.AllowedAnswers) 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) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) Question(org.kie.workbench.common.dmn.api.property.dmn.Question) 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) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)

Example 12 with JSITExpression

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression in project kie-wb-common by kiegroup.

the class FunctionDefinitionPropertyConverter method wbFromDMN.

public static FunctionDefinition wbFromDMN(final JSITFunctionDefinition dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    if (Objects.isNull(dmn)) {
        return null;
    }
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    Expression expression = null;
    final JSITExpression jsiWrapped = dmn.getExpression();
    if (Objects.nonNull(jsiWrapped)) {
        final JSITExpression jsiExpression = Js.uncheckedCast(JsUtils.getUnwrappedElement(jsiWrapped));
        expression = ExpressionPropertyConverter.wbFromDMN(jsiExpression, Js.uncheckedCast(dmn), hasComponentWidthsConsumer);
    }
    final FunctionDefinition result = new FunctionDefinition(id, description, typeRef, expression);
    if (Objects.nonNull(expression)) {
        expression.setParent(result);
    }
    // JSITFunctionKind is a String JSO so convert into the real type
    final String sKind = Js.uncheckedCast(dmn.getKind());
    final Kind kind = Kind.fromValue(sKind);
    switch(kind) {
        case FEEL:
            result.setKind(Kind.FEEL);
            break;
        case JAVA:
            result.setKind(Kind.JAVA);
            break;
        case PMML:
            result.setKind(Kind.PMML);
            convertPMMLFunctionExpression(result, hasComponentWidthsConsumer);
            break;
        default:
            result.setKind(Kind.FEEL);
            break;
    }
    final List<JSITInformationItem> jsiInformationItems = dmn.getFormalParameter();
    for (int i = 0; i < jsiInformationItems.size(); i++) {
        final JSITInformationItem jsiInformationItem = Js.uncheckedCast(jsiInformationItems.get(i));
        final InformationItem iiConverted = InformationItemPropertyConverter.wbFromDMN(jsiInformationItem);
        if (Objects.nonNull(iiConverted)) {
            iiConverted.setParent(result);
        }
        result.getFormalParameter().add(iiConverted);
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) JSITFunctionKind(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionKind) Kind(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition.Kind) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)

Example 13 with JSITExpression

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression in project kie-wb-common by kiegroup.

the class BindingPropertyConverter method wbFromDMN.

public static Binding wbFromDMN(final JSITBinding dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    if (Objects.isNull(dmn)) {
        return null;
    }
    final InformationItem parameter = InformationItemPropertyConverter.wbFromDMN(dmn.getParameter());
    Expression expression = null;
    final JSITExpression jsiWrapped = dmn.getExpression();
    if (Objects.nonNull(jsiWrapped)) {
        final JSITExpression jsiExpression = Js.uncheckedCast(JsUtils.getUnwrappedElement(jsiWrapped));
        expression = ExpressionPropertyConverter.wbFromDMN(jsiExpression, Js.uncheckedCast(dmn), hasComponentWidthsConsumer);
    }
    final Binding result = new Binding();
    if (Objects.nonNull(parameter)) {
        parameter.setParent(result);
    }
    result.setParameter(parameter);
    if (Objects.nonNull(expression)) {
        expression.setParent(result);
    }
    result.setExpression(expression);
    return result;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) JSITBinding(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBinding) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)

Example 14 with JSITExpression

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression in project kie-wb-common by kiegroup.

the class ContextPropertyConverter method wbFromDMN.

public static Context wbFromDMN(final JSITContext dmn, final JSITExpression parent, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    final Context result = new Context(id, description, typeRef);
    final List<JSITContextEntry> jsiContextEntries = dmn.getContextEntry();
    for (int i = 0; i < jsiContextEntries.size(); i++) {
        final JSITContextEntry jsiContextentry = Js.uncheckedCast(jsiContextEntries.get(i));
        final ContextEntry ceConverted = ContextEntryPropertyConverter.wbFromDMN(jsiContextentry, hasComponentWidthsConsumer);
        if (Objects.nonNull(ceConverted)) {
            ceConverted.setParent(result);
            result.getContextEntry().add(ceConverted);
        }
    }
    // No need to append a _default_ row if the Context is part of a JAVA or PMML FunctionDefinition
    if (JSITFunctionDefinition.instanceOf(parent)) {
        final JSITFunctionDefinition functionDefinition = Js.uncheckedCast(parent);
        final String sKind = Js.uncheckedCast(functionDefinition.getKind());
        final Kind kind = Kind.fromValue(sKind);
        if (!Objects.equals(Kind.FEEL, kind)) {
            return result;
        }
    }
    // The UI requires a ContextEntry for the _default_ result even if none has been defined
    final int contextEntriesCount = result.getContextEntry().size();
    if (contextEntriesCount == 0) {
        result.getContextEntry().add(new ContextEntry());
    } else if (!Objects.isNull(result.getContextEntry().get(contextEntriesCount - 1).getVariable())) {
        result.getContextEntry().add(new ContextEntry());
    }
    return result;
}
Also used : JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Kind(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition.Kind) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry)

Aggregations

JSITExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)11 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)6 JSITInformationItem (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem)6 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)5 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)4 WrapperUtils.getWrappedJSITLiteralExpression (org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression)4 JSITBinding (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBinding)4 JSITFunctionDefinition (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition)4 JSITInvocation (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation)4 JSITList (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList)4 JSITLiteralExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression)4 Binding (org.kie.workbench.common.dmn.api.definition.model.Binding)3 Context (org.kie.workbench.common.dmn.api.definition.model.Context)3 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)3 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)3 Invocation (org.kie.workbench.common.dmn.api.definition.model.Invocation)3 List (org.kie.workbench.common.dmn.api.definition.model.List)3 JSITContext (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext)3 JSITContextEntry (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry)3