Search in sources :

Example 1 with IsLiteralExpression

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

the class ExpressionPropertyConverter method dmnFromWB.

public static org.kie.dmn.model.api.Expression dmnFromWB(final Expression wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final String uuid = wb.getId().getValue();
    if (Objects.nonNull(uuid)) {
        final ComponentWidths componentWidths = new ComponentWidths();
        componentWidths.setDmnElementRef(new QName(uuid));
        componentWidths.setWidths(new ArrayList<>(wb.getComponentWidths()));
        componentWidthsConsumer.accept(componentWidths);
    }
    if (wb instanceof IsLiteralExpression) {
        return LiteralExpressionPropertyConverter.dmnFromWB((IsLiteralExpression) wb);
    } else if (wb instanceof Context) {
        return ContextPropertyConverter.dmnFromWB((Context) wb, componentWidthsConsumer);
    } else if (wb instanceof Relation) {
        return RelationPropertyConverter.dmnFromWB((Relation) wb, componentWidthsConsumer);
    } else if (wb instanceof List) {
        return ListPropertyConverter.dmnFromWB((List) wb, componentWidthsConsumer);
    } else if (wb instanceof Invocation) {
        return InvocationPropertyConverter.dmnFromWB((Invocation) wb, componentWidthsConsumer);
    } else if (wb instanceof FunctionDefinition) {
        return FunctionDefinitionPropertyConverter.dmnFromWB((FunctionDefinition) wb, componentWidthsConsumer);
    } else if (wb instanceof DecisionTable) {
        return DecisionTablePropertyConverter.dmnFromWB((DecisionTable) wb);
    }
    return null;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) QName(javax.xml.namespace.QName) List(org.kie.workbench.common.dmn.api.definition.model.List) ArrayList(java.util.ArrayList) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths)

Example 2 with IsLiteralExpression

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

the class ExpressionPropertyConverter method dmnFromWB.

public static JSITExpression dmnFromWB(final Expression wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final String uuid = wb.getId().getValue();
    if (Objects.nonNull(uuid)) {
        final JSITComponentWidths componentWidths = new JSITComponentWidths();
        componentWidths.setDmnElementRef(uuid);
        wb.getComponentWidths().stream().filter(Objects::nonNull).forEach(w -> componentWidths.addWidth(new Float(w)));
        componentWidthsConsumer.accept(componentWidths);
    }
    if (wb instanceof IsLiteralExpression) {
        final JSITLiteralExpression unwrappedJSITLiteralExpression = LiteralExpressionPropertyConverter.dmnFromWB((IsLiteralExpression) wb);
        final JSITLiteralExpression wrappedJSITLiteralExpression = getWrappedJSITLiteralExpression(unwrappedJSITLiteralExpression, "dmn", "literalExpression");
        return wrappedJSITLiteralExpression;
    } else if (wb instanceof Context) {
        final JSITContext unwrappedJSITContext = ContextPropertyConverter.dmnFromWB((Context) wb, componentWidthsConsumer);
        final JSITContext wrappedJSITContext = getWrappedJSITContext(unwrappedJSITContext, "dmn", "context");
        return wrappedJSITContext;
    } else if (wb instanceof Relation) {
        final JSITRelation unwrappedJSITRelation = RelationPropertyConverter.dmnFromWB((Relation) wb, componentWidthsConsumer);
        final JSITRelation wrappedJSITRelation = getWrappedJSITRelation(unwrappedJSITRelation, "dmn", "relation");
        return wrappedJSITRelation;
    } else if (wb instanceof List) {
        final JSITList unwrappedJSITList = ListPropertyConverter.dmnFromWB((List) wb, componentWidthsConsumer);
        final JSITList wrappedJSITList = getWrappedJSITList(unwrappedJSITList, "dmn", "list");
        return wrappedJSITList;
    } else if (wb instanceof Invocation) {
        final JSITInvocation unwrappedJSITInvocation = InvocationPropertyConverter.dmnFromWB((Invocation) wb, componentWidthsConsumer);
        final JSITInvocation wrappedJSITInvocation = getWrappedJSITInvocation(unwrappedJSITInvocation, "dmn", "invocation");
        return wrappedJSITInvocation;
    } else if (wb instanceof FunctionDefinition) {
        final JSITFunctionDefinition unwrappedJSITFunctionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB((FunctionDefinition) wb, componentWidthsConsumer);
        final JSITFunctionDefinition wrappedJSITFunctionDefinition = getWrappedJSITFunctionDefinition(unwrappedJSITFunctionDefinition, "dmn", "functionDefinition");
        return wrappedJSITFunctionDefinition;
    } else if (wb instanceof DecisionTable) {
        final JSITDecisionTable unwrappedJSITDecisionTable = DecisionTablePropertyConverter.dmnFromWB((DecisionTable) wb);
        final JSITDecisionTable wrappedJSITDecisionTable = getWrappedJSITDecisionTable(unwrappedJSITDecisionTable, "dmn", "decisionTable");
        return wrappedJSITDecisionTable;
    }
    return null;
}
Also used : JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) 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) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) List(org.kie.workbench.common.dmn.api.definition.model.List) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) JSITComponentWidths(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentWidths) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable)

Example 3 with IsLiteralExpression

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

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

the class LiteralExpressionPropertyConverter method dmnFromWB.

public static JSITLiteralExpression dmnFromWB(final IsLiteralExpression wb) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final JSITLiteralExpression result = LITERAL_EXPRESSION_PROVIDER.make();
    result.setId(wb.getId().getValue());
    final String description = wb.getDescription().getValue();
    if (StringUtils.nonEmpty(description)) {
        result.setDescription(description);
    }
    if (wb instanceof LiteralExpression) {
        final String expressionLanguage = ((LiteralExpression) wb).getExpressionLanguage().getValue();
        if (StringUtils.nonEmpty(expressionLanguage)) {
            result.setExpressionLanguage(expressionLanguage);
        }
    }
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    result.setText(wb.getText().getValue());
    final JSITImportedValues importedValues = ImportedValuesConverter.dmnFromWB(wb.getImportedValues());
    if (Objects.nonNull(importedValues)) {
        result.setImportedValues(importedValues);
    }
    return result;
}
Also used : JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) JSITImportedValues(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImportedValues)

Aggregations

IsLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression)4 Context (org.kie.workbench.common.dmn.api.definition.model.Context)3 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)3 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)2 Invocation (org.kie.workbench.common.dmn.api.definition.model.Invocation)2 List (org.kie.workbench.common.dmn.api.definition.model.List)2 Relation (org.kie.workbench.common.dmn.api.definition.model.Relation)2 JSITLiteralExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)1 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)1 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)1 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)1 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)1 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)1 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)1 ComponentWidths (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths)1 WrapperUtils.getWrappedJSITContext (org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext)1