Search in sources :

Example 1 with JSITContextEntry

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

the class ContextEntryPropertyConverter method dmnFromWB.

public static JSITContextEntry dmnFromWB(final ContextEntry wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    final JSITContextEntry result = new JSITContextEntry();
    final JSITInformationItem variable = InformationItemPropertyConverter.dmnFromWB(wb.getVariable());
    JSITExpression expression = ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer);
    if (Objects.isNull(expression)) {
        final JSITLiteralExpression mockLiteralExpression = new JSITLiteralExpression();
        mockLiteralExpression.setText(ContextEntry.DEFAULT_EXPRESSION_VALUE);
        expression = getWrappedJSITLiteralExpression(mockLiteralExpression, "dmn", "literalExpression");
    }
    result.setVariable(variable);
    result.setExpression(expression);
    return result;
}
Also used : JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry) WrapperUtils.getWrappedJSITLiteralExpression(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)

Example 2 with JSITContextEntry

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

the class ContextEntryPropertyConverter method wbFromDMN.

public static ContextEntry wbFromDMN(final JSITContextEntry dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final InformationItem variable = InformationItemPropertyConverter.wbFromDMN(dmn.getVariable());
    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 ContextEntry result = new ContextEntry();
    if (Objects.nonNull(variable)) {
        variable.setParent(result);
        result.setVariable(variable);
    }
    if (Objects.nonNull(expression)) {
        expression.setParent(result);
        result.setExpression(expression);
    }
    return result;
}
Also used : JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) WrapperUtils.getWrappedJSITLiteralExpression(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) 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) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry)

Example 3 with JSITContextEntry

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry 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)

Example 4 with JSITContextEntry

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

the class ContextPropertyConverter method dmnFromWB.

public static JSITContext dmnFromWB(final Context wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    final JSITContext result = new JSITContext();
    result.setId(wb.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    for (ContextEntry ce : wb.getContextEntry()) {
        final JSITContextEntry ceConverted = ContextEntryPropertyConverter.dmnFromWB(ce, componentWidthsConsumer);
        result.addContextEntry(ceConverted);
    }
    // The UI appends a ContextEntry for the _default_ result that may contain an undefined Expression.
    // If this is the case then DMN does not require the ContextEntry to be written out to the XML.
    // Conversion of ContextEntries will always create a _mock_ LiteralExpression if no Expression has
    // been defined therefore remove the last entry from the org.kie.dmn.model if the WB had no Expression.
    final int contextEntriesCount = result.getContextEntry().size();
    if (contextEntriesCount > 0) {
        if (Objects.isNull(wb.getContextEntry().get(contextEntriesCount - 1).getExpression())) {
            result.removeContextEntry(contextEntriesCount - 1);
        }
    }
    return result;
}
Also used : JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry) JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry)

Aggregations

JSITContextEntry (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry)4 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)3 WrapperUtils.getWrappedJSITLiteralExpression (org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression)2 JSITContext (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext)2 JSITExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)2 JSITInformationItem (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem)2 JSITLiteralExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression)2 Context (org.kie.workbench.common.dmn.api.definition.model.Context)1 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)1 Kind (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition.Kind)1 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)1 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)1 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)1 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)1 JSITFunctionDefinition (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition)1