use of org.kie.workbench.common.dmn.api.definition.model.Context 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;
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class DecisionTableGridTest method testSelectHeaderMultipleOutputClauseColumnNestedContextEntry.
@Test
@SuppressWarnings("unchecked")
public void testSelectHeaderMultipleOutputClauseColumnNestedContextEntry() {
// Mock nesting of DecisionTable in a ContextEntry
final Context context = new Context();
final ContextEntry contextEntry = new ContextEntry();
final InformationItem variable = new InformationItem();
contextEntry.setVariable(variable);
context.getContextEntry().add(contextEntry);
contextEntry.setExpression(expression.get());
this.hasExpression.setExpression(context);
this.grid = spy((DecisionTableGrid) definition.getEditor(parent, Optional.empty(), contextEntry, makeHasNameForDecision(), false, 1).get());
addOutputClause(2);
reset(domainObjectSelectionEvent);
grid.selectHeaderCell(0, DEFAULT_OUTPUT_CLAUSE_COLUMN_INDEX, false, false);
assertDomainObjectSelection(variable);
reset(domainObjectSelectionEvent);
grid.selectHeaderCell(1, DEFAULT_OUTPUT_CLAUSE_COLUMN_INDEX, false, false);
assertDomainObjectSelection(expression.get().getOutput().get(0));
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsContextEntryDefaultResult.
@Test
public void testModelEnrichmentWhenParentIsContextEntryDefaultResult() {
final String name = "decision";
final Context context = new Context();
final ContextEntry contextEntry = new ContextEntry();
context.getContextEntry().add(contextEntry);
contextEntry.setParent(context);
context.setParent(decision);
decision.setName(new Name(name));
decision.getVariable().setTypeRef(OUTPUT_DATA_QNAME);
final Optional<DecisionTable> oModel = definition.getModelClass();
oModel.get().setParent(contextEntry);
definition.enrich(Optional.empty(), decision, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
assertStandardInputClauseEnrichment(model);
final List<OutputClause> output = model.getOutput();
assertThat(output.size()).isEqualTo(1);
assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsNestedContextEntryDefaultResult.
@Test
public void testModelEnrichmentWhenParentIsNestedContextEntryDefaultResult() {
final Decision decision = mock(Decision.class);
final String name = "context-entry";
final Context innerContext = new Context();
final ContextEntry innerContextEntry = new ContextEntry();
innerContext.getContextEntry().add(innerContextEntry);
innerContextEntry.setParent(innerContext);
final Context outerContext = new Context();
final ContextEntry outerContextEntry = new ContextEntry();
outerContext.getContextEntry().add(outerContextEntry);
outerContextEntry.setParent(outerContext);
innerContext.setParent(outerContextEntry);
outerContext.setParent(decision);
outerContextEntry.setVariable(new InformationItem(new Id(), new Description(), new Name(name), OUTPUT_DATA_QNAME));
when(decision.asDMNModelInstrumentedBase()).thenReturn(outerContextEntry);
final Optional<DecisionTable> oModel = definition.getModelClass();
oModel.get().setParent(innerContextEntry);
definition.enrich(Optional.empty(), decision, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
assertStandardInputClauseEnrichment(model);
final List<OutputClause> output = model.getOutput();
assertThat(output.size()).isEqualTo(1);
assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsContextEntry.
@Test
public void testModelEnrichmentWhenParentIsContextEntry() {
final Decision decision = mock(Decision.class);
final String name = "context-entry";
final Context context = new Context();
final ContextEntry contextEntry = new ContextEntry();
context.getContextEntry().add(contextEntry);
contextEntry.setVariable(new InformationItem(new Id(), new Description(), new Name(name), OUTPUT_DATA_QNAME));
final Optional<DecisionTable> oModel = definition.getModelClass();
oModel.get().setParent(contextEntry);
contextEntry.setParent(context);
context.setParent(decision);
when(decision.asDMNModelInstrumentedBase()).thenReturn(contextEntry);
definition.enrich(Optional.empty(), decision, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
assertStandardInputClauseEnrichment(model);
final List<OutputClause> output = model.getOutput();
assertThat(output.size()).isEqualTo(1);
assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
Aggregations