use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields.
@Test
public void testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields() {
final DMNGraphUtils dmnGraphUtils = mock(DMNGraphUtils.class);
final Definitions definitions = mock(Definitions.class);
final HasExpression hasExpression = mock(HasExpression.class);
final Decision decision = mock(Decision.class);
final InformationItemPrimary informationItemPrimary = mock(InformationItemPrimary.class);
final ItemDefinition tPerson = mockTPersonStructure();
when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions);
when(definitions.getItemDefinition()).thenReturn(Collections.singletonList(tPerson));
when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(decision);
when(decision.getVariable()).thenReturn(informationItemPrimary);
when(informationItemPrimary.getTypeRef()).thenReturn(new QName("", TYPE_PERSON));
final DecisionTableEditorDefinitionEnricher enricher = new DecisionTableEditorDefinitionEnricher(null, dmnGraphUtils, itemDefinitionUtils);
final Optional<DecisionTable> oModel = definition.getModelClass();
final DecisionTable model = oModel.get();
enricher.buildOutputClausesByDataType(hasExpression, model, new DecisionRule());
final List<OutputClause> outputClauses = model.getOutput();
assertThat(outputClauses.size()).isEqualTo(2);
final OutputClause outputClause1 = outputClauses.get(0);
final OutputClause outputClause2 = outputClauses.get(1);
assertEquals("age", outputClause1.getName());
assertEquals(NUMBER.asQName(), outputClause1.getTypeRef());
assertEquals("name", outputClause2.getName());
assertEquals(STRING.asQName(), outputClause2.getTypeRef());
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenHasExpressionIsNotHasVariable.
@Test
public void testModelEnrichmentWhenHasExpressionIsNotHasVariable() {
final Optional<DecisionTable> oModel = definition.getModelClass();
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(BuiltInType.UNDEFINED.asQName());
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class OutputClausePropertyConverter method wbFromDMN.
public static OutputClause wbFromDMN(final JSITOutputClause dmn) {
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final OutputClauseUnaryTests outputValues = OutputClauseUnaryTestsPropertyConverter.wbFromDMN(dmn.getOutputValues());
final OutputClauseLiteralExpression defaultOutputEntry = OutputClauseLiteralExpressionPropertyConverter.wbFromDMN(dmn.getDefaultOutputEntry());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
final OutputClause result = new OutputClause();
result.setId(id);
result.setName(dmn.getName());
result.setDescription(description);
result.setOutputValues(outputValues);
result.setDefaultOutputEntry(defaultOutputEntry);
result.setTypeRef(typeRef);
if (Objects.nonNull(outputValues)) {
outputValues.setParent(result);
}
if (Objects.nonNull(defaultOutputEntry)) {
defaultOutputEntry.setParent(result);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTablePropertyConverter method wbFromDMN.
public static DecisionTable wbFromDMN(final JSITDecisionTable dmn) {
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
final DecisionTable result = new DecisionTable();
result.setId(id);
result.setDescription(description);
result.setTypeRef(typeRef);
final List<JSITRuleAnnotationClause> jsiRuleAnnotationClauses = dmn.getAnnotation();
if (jsiRuleAnnotationClauses.isEmpty()) {
final RuleAnnotationClause ruleAnnotationClause = new RuleAnnotationClause();
ruleAnnotationClause.setParent(result);
result.getAnnotations().add(ruleAnnotationClause);
} else {
for (int i = 0; i < jsiRuleAnnotationClauses.size(); i++) {
final JSITRuleAnnotationClause ruleAnnotationClause = Js.uncheckedCast(jsiRuleAnnotationClauses.get(i));
final RuleAnnotationClause converted = RuleAnnotationClausePropertyConverter.wbFromDMN(ruleAnnotationClause);
if (Objects.nonNull(converted)) {
converted.setParent(result);
result.getAnnotations().add(converted);
}
}
}
final List<JSITInputClause> jsiInputClauses = dmn.getInput();
for (int i = 0; i < jsiInputClauses.size(); i++) {
final JSITInputClause input = Js.uncheckedCast(jsiInputClauses.get(i));
final InputClause inputClauseConverted = InputClausePropertyConverter.wbFromDMN(input);
if (Objects.nonNull(inputClauseConverted)) {
inputClauseConverted.setParent(result);
result.getInput().add(inputClauseConverted);
}
}
final List<JSITOutputClause> jsiOutputClauses = dmn.getOutput();
for (int i = 0; i < jsiOutputClauses.size(); i++) {
final JSITOutputClause output = Js.uncheckedCast(jsiOutputClauses.get(i));
final OutputClause outputClauseConverted = OutputClausePropertyConverter.wbFromDMN(output);
if (Objects.nonNull(outputClauseConverted)) {
outputClauseConverted.setParent(result);
result.getOutput().add(outputClauseConverted);
}
}
if (result.getOutput().size() == 1) {
final OutputClause outputClause = result.getOutput().get(0);
// DROOLS-3281
outputClause.setName(null);
// DROOLS-5178
outputClause.setTypeRef(BuiltInType.UNDEFINED.asQName());
}
final List<JSITDecisionRule> jsiDecisionRules = dmn.getRule();
for (int i = 0; i < jsiDecisionRules.size(); i++) {
final JSITDecisionRule dr = Js.uncheckedCast(jsiDecisionRules.get(i));
final DecisionRule decisionRuleConverted = DecisionRulePropertyConverter.wbFromDMN(dr);
if (Objects.nonNull(decisionRuleConverted)) {
decisionRuleConverted.setParent(result);
}
result.getRule().add(decisionRuleConverted);
}
// JSITHitPolicy is a String JSO so convert into the real type
final String hitPolicy = Js.uncheckedCast(dmn.getHitPolicy());
if (Objects.nonNull(hitPolicy)) {
result.setHitPolicy(HitPolicy.fromValue(hitPolicy));
}
// JSITBuiltinAggregator is a String JSO so convert into the real type
final String aggregation = Js.uncheckedCast(dmn.getAggregation());
if (Objects.nonNull(aggregation)) {
result.setAggregation(BuiltinAggregator.fromValue(aggregation));
}
// JSITDecisionTableOrientation is a String JSO so convert into the real type
final String orientation = Js.uncheckedCast(dmn.getPreferredOrientation());
if (Objects.nonNull(orientation)) {
result.setPreferredOrientation(DecisionTableOrientation.fromValue(orientation));
}
result.setOutputLabel(dmn.getOutputLabel());
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTablePropertyConverterTest method testDMNFromWBMultipleOutputClauseTypeRef.
@Test
public void testDMNFromWBMultipleOutputClauseTypeRef() {
final DecisionTable wb = new DecisionTable();
final OutputClause wbOutputClause1 = new OutputClause();
final OutputClause wbOutputClause2 = new OutputClause();
wb.getId().setValue(UUID);
wb.getDescription().setValue(DESCRIPTION);
wb.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(NULL_NS_URI, QNAME_LOCALPART));
wbOutputClause1.setName(NAME + "-oc1");
wbOutputClause2.setName(NAME + "-oc2");
wbOutputClause1.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(NULL_NS_URI, QNAME_LOCALPART + "-oc1"));
wbOutputClause2.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(NULL_NS_URI, QNAME_LOCALPART + "-oc2"));
wb.getOutput().add(wbOutputClause1);
wb.getOutput().add(wbOutputClause2);
final org.kie.dmn.model.api.DecisionTable dmn = DecisionTablePropertyConverter.dmnFromWB(wb);
assertThat(dmn).isNotNull();
assertThat(dmn.getId()).isNotNull();
assertThat(dmn.getId()).isEqualTo(UUID);
assertThat(dmn.getDescription()).isNotNull();
assertThat(dmn.getDescription()).isEqualTo(DESCRIPTION);
assertThat(dmn.getTypeRef()).isNotNull();
assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART);
assertThat(dmn.getOutput()).hasSize(2);
final org.kie.dmn.model.api.OutputClause dmnOutputClause1 = dmn.getOutput().get(0);
final org.kie.dmn.model.api.OutputClause dmnOutputClause2 = dmn.getOutput().get(1);
assertThat(dmnOutputClause1.getName()).isEqualTo(NAME + "-oc1");
assertThat(dmnOutputClause2.getName()).isEqualTo(NAME + "-oc2");
assertThat(dmnOutputClause1.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART + "-oc1");
assertThat(dmnOutputClause2.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART + "-oc2");
}
Aggregations