use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTablePropertyConverterTest method testWBFromDMNMultipleOutputClauseTypeRef.
@Test
public void testWBFromDMNMultipleOutputClauseTypeRef() {
final org.kie.dmn.model.api.DecisionTable dmn = new TDecisionTable();
final org.kie.dmn.model.api.OutputClause dmnOutputClause1 = new TOutputClause();
final org.kie.dmn.model.api.OutputClause dmnOutputClause2 = new TOutputClause();
dmn.setId(UUID);
dmn.setDescription(DESCRIPTION);
dmn.setTypeRef(new QName(QNAME_LOCALPART));
dmnOutputClause1.setName(NAME + "-oc1");
dmnOutputClause2.setName(NAME + "-oc2");
dmnOutputClause1.setTypeRef(new QName(QNAME_LOCALPART + "-oc1"));
dmnOutputClause2.setTypeRef(new QName(QNAME_LOCALPART + "-oc2"));
dmn.getOutput().add(dmnOutputClause1);
dmn.getOutput().add(dmnOutputClause2);
final DecisionTable wb = DecisionTablePropertyConverter.wbFromDMN(dmn);
assertThat(wb).isNotNull();
assertThat(wb.getId()).isNotNull();
assertThat(wb.getId().getValue()).isEqualTo(UUID);
assertThat(wb.getDescription()).isNotNull();
assertThat(wb.getDescription().getValue()).isEqualTo(DESCRIPTION);
assertThat(wb.getTypeRef()).isNotNull();
assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART);
assertThat(wb.getOutput()).hasSize(2);
final OutputClause wbOutputClause1 = wb.getOutput().get(0);
final OutputClause wbOutputClause2 = wb.getOutput().get(1);
assertThat(wbOutputClause1.getName()).isEqualTo(NAME + "-oc1");
assertThat(wbOutputClause2.getName()).isEqualTo(NAME + "-oc2");
assertThat(wbOutputClause1.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART + "-oc1");
assertThat(wbOutputClause2.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART + "-oc2");
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTablePropertyConverterTest method testDMNFromWBSingleOutputClauseTypeRef.
@Test
public void testDMNFromWBSingleOutputClauseTypeRef() {
final DecisionTable wb = new DecisionTable();
final OutputClause outputClause1 = 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));
outputClause1.setName(NAME);
outputClause1.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(NULL_NS_URI, QNAME_LOCALPART + "-oc1"));
wb.getOutput().add(outputClause1);
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(1);
final org.kie.dmn.model.api.OutputClause dmnOutputClause1 = dmn.getOutput().get(0);
assertThat(dmnOutputClause1.getName()).isNull();
assertThat(dmnOutputClause1.getTypeRef()).isNull();
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricher method buildOutputClausesByDataType.
void buildOutputClausesByDataType(final HasExpression hasExpression, final DecisionTable dTable, final DecisionRule decisionRule) {
final HasTypeRef hasTypeRef = getHasTypeRef(hasExpression, dTable);
final QName typeRef = !Objects.isNull(hasTypeRef) ? hasTypeRef.getTypeRef() : BuiltInType.UNDEFINED.asQName();
final String name = DecisionTableDefaultValueUtilities.getNewOutputClauseName(dTable);
final List<ClauseRequirement> outputClausesRequirement = generateOutputClauseRequirements(dmnGraphUtils.getModelDefinitions(), typeRef, name);
if (outputClausesRequirement.isEmpty()) {
dTable.getOutput().add(buildOutputClause(dTable, typeRef, name));
populateOutputEntries(decisionRule);
} else {
outputClausesRequirement.stream().sorted(Comparator.comparing(outputClauseRequirement -> outputClauseRequirement.text)).map(outputClauseRequirement -> buildOutputClause(dTable, outputClauseRequirement.typeRef, outputClauseRequirement.text)).forEach(outputClause -> {
dTable.getOutput().add(outputClause);
populateOutputEntries(decisionRule);
});
}
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricher method buildOutputClause.
private OutputClause buildOutputClause(final DecisionTable dtable, final QName typeRef, final String text) {
final OutputClause outputClause = new OutputClause();
outputClause.setName(text);
outputClause.setTypeRef(typeRef);
outputClause.setParent(dtable);
return outputClause;
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricher method enrichOutputClauses.
void enrichOutputClauses(final DecisionTable dtable) {
if (dtable.getParent() instanceof ContextEntry && dtable.getOutput().isEmpty()) {
final ContextEntry contextEntry = (ContextEntry) dtable.getParent();
final OutputClause outputClause = new OutputClause();
outputClause.setName(getOutputClauseName(contextEntry).orElse(DecisionTableDefaultValueUtilities.getNewOutputClauseName(dtable)));
outputClause.setTypeRef(getOutputClauseTypeRef(contextEntry).orElse(BuiltInType.UNDEFINED.asQName()));
dtable.getOutput().add(outputClause);
dtable.getRule().stream().forEach(decisionRule -> {
final LiteralExpression decisionRuleLiteralExpression = new LiteralExpression();
decisionRuleLiteralExpression.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT);
decisionRule.getOutputEntry().add(decisionRuleLiteralExpression);
decisionRuleLiteralExpression.setParent(decisionRule);
});
outputClause.setParent(dtable);
}
}
Aggregations