use of org.kie.workbench.common.dmn.api.definition.model.Expression 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;
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class FunctionDefinitionPropertyConverter method convertContextEntryExpression.
private static void convertContextEntryExpression(final ContextEntry contextEntry, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
final Expression expression = contextEntry.getExpression();
if (expression instanceof LiteralExpression) {
final LiteralExpression le = (LiteralExpression) expression;
final String variableName = contextEntry.getVariable().getName().getValue();
if (Objects.equals(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT, variableName)) {
final LiteralExpressionPMMLDocument e = convertLiteralExpressionToPMMLDocument(le);
// Ensure ComponentWidths are updated for the converted LiteralExpression
hasComponentWidthsConsumer.accept(e.getId().getValue(), e);
contextEntry.setExpression(e);
} else if (Objects.equals(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL, variableName)) {
final LiteralExpressionPMMLDocumentModel e = convertLiteralExpressionToPMMLDocumentModel(le);
// Ensure ComponentWidths are updated for the converted LiteralExpression
hasComponentWidthsConsumer.accept(e.getId().getValue(), e);
contextEntry.setExpression(e);
}
}
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class BoxedExpressionHelperTest method testGetExpression.
@Test
public void testGetExpression() {
final View content = mock(View.class);
final Decision decision = mock(Decision.class);
final Expression expectedExpression = mock(Expression.class);
when(node.getContent()).thenReturn(content);
when(content.getDefinition()).thenReturn(decision);
when(decision.getExpression()).thenReturn(expectedExpression);
final Expression actualExpression = helper.getExpression(node);
assertEquals(expectedExpression, actualExpression);
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class BoxedExpressionHelperTest method testGetOptionalExpressionWhenIsPresent.
@Test
public void testGetOptionalExpressionWhenIsPresent() {
final View content = mock(View.class);
final Decision decision = mock(Decision.class);
final Expression expectedExpression = mock(Expression.class);
when(node.getContent()).thenReturn(content);
when(content.getDefinition()).thenReturn(decision);
when(decision.getExpression()).thenReturn(expectedExpression);
final Optional<Expression> optionalExpression = helper.getOptionalExpression(node);
assertTrue(optionalExpression.isPresent());
assertEquals(expectedExpression, optionalExpression.get());
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression 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);
}
Aggregations