use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class DecisionTablePropertyConverter method wbFromDMN.
public static DecisionTable wbFromDMN(final org.kie.dmn.model.api.DecisionTable dmn) {
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
final DecisionTable result = new DecisionTable();
result.setId(id);
result.setDescription(description);
result.setTypeRef(typeRef);
if (!(dmn instanceof org.kie.dmn.model.v1_1.TDecisionTable)) {
if (dmn.getAnnotation().isEmpty()) {
final RuleAnnotationClause ruleAnnotationClause = new RuleAnnotationClause();
ruleAnnotationClause.setParent(result);
result.getAnnotations().add(ruleAnnotationClause);
} else {
for (final org.kie.dmn.model.api.RuleAnnotationClause ruleAnnotationClause : dmn.getAnnotation()) {
final RuleAnnotationClause converted = RuleAnnotationClauseConverter.wbFromDMN(ruleAnnotationClause);
if (converted != null) {
converted.setParent(result);
}
result.getAnnotations().add(converted);
}
}
}
for (org.kie.dmn.model.api.InputClause input : dmn.getInput()) {
final InputClause inputClauseConverted = InputClausePropertyConverter.wbFromDMN(input);
if (inputClauseConverted != null) {
inputClauseConverted.setParent(result);
}
result.getInput().add(inputClauseConverted);
}
for (org.kie.dmn.model.api.OutputClause output : dmn.getOutput()) {
final OutputClause outputClauseConverted = OutputClausePropertyConverter.wbFromDMN(output);
if (outputClauseConverted != null) {
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(null);
}
for (org.kie.dmn.model.api.DecisionRule dr : dmn.getRule()) {
final DecisionRule decisionRuleConverted = DecisionRulePropertyConverter.wbFromDMN(dr);
if (decisionRuleConverted != null) {
decisionRuleConverted.setParent(result);
}
result.getRule().add(decisionRuleConverted);
}
if (dmn.getHitPolicy() != null) {
result.setHitPolicy(HitPolicy.fromValue(dmn.getHitPolicy().value()));
}
if (dmn.getAggregation() != null) {
result.setAggregation(BuiltinAggregator.fromValue(dmn.getAggregation().value()));
}
if (dmn.getPreferredOrientation() != null) {
result.setPreferredOrientation(DecisionTableOrientation.fromValue(dmn.getPreferredOrientation().value()));
}
result.setOutputLabel(dmn.getOutputLabel());
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class DecisionRuleFactoryTest method setup.
@Before
public void setup() {
dtable = new DecisionTable();
dtable.getInput().add(new InputClause());
dtable.getInput().add(new InputClause());
dtable.getOutput().add(new OutputClause());
dtable.getOutput().add(new OutputClause());
dtable.getAnnotations().add(new RuleAnnotationClause());
dtable.getAnnotations().add(new RuleAnnotationClause());
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class DecisionTableDefaultValueUtilitiesTest method testGetNewInputClauseNameWithExistingInputClauses.
@Test
public void testGetNewInputClauseNameWithExistingInputClauses() {
final InputClause inputClause1 = new InputClause() {
{
setInputExpression(new InputClauseLiteralExpression());
}
};
dtable.getInput().add(inputClause1);
inputClause1.getInputExpression().getText().setValue("input");
final InputClause inputClause2 = new InputClause() {
{
setInputExpression(new InputClauseLiteralExpression());
}
};
dtable.getInput().add(inputClause2);
inputClause2.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
assertThat(inputClause2.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1");
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class DecisionTableDefaultValueUtilitiesTest method testGetNewInputClauseName.
@Test
public void testGetNewInputClauseName() {
final InputClause inputClause1 = new InputClause() {
{
setInputExpression(new InputClauseLiteralExpression());
}
};
dtable.getInput().add(inputClause1);
inputClause1.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
assertThat(inputClause1.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1");
final InputClause inputClause2 = new InputClause() {
{
setInputExpression(new InputClauseLiteralExpression());
}
};
dtable.getInput().add(inputClause2);
inputClause2.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
assertThat(inputClause2.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "2");
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType.
@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType() {
setupGraphWithDiagram();
setupGraphWithInputData();
final Definitions definitions = diagram.getDefinitions();
final String complexItemDefinitionName = "tSmurf";
final String complexItemDefinitionPart1Name = "tDateOfBirth";
final String complexItemDefinitionPart2Name = "tIsBlue";
final QName complexItemDefinitionPart1TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
final QName complexItemDefinitionPart2TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.BOOLEAN.getName());
final ItemDefinition complexItemDefinition = new ItemDefinition();
complexItemDefinition.setName(new Name(complexItemDefinitionName));
complexItemDefinition.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(complexItemDefinitionPart1Name));
setTypeRef(complexItemDefinitionPart1TypeRef);
}
});
complexItemDefinition.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(complexItemDefinitionPart2Name));
setTypeRef(complexItemDefinitionPart2TypeRef);
}
});
definitions.getItemDefinition().add(complexItemDefinition);
final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, complexItemDefinitionName);
inputData1.getVariable().setTypeRef(inputData1TypeRef);
final Optional<DecisionTable> oModel = definition.getModelClass();
definition.enrich(Optional.of(NODE_UUID), decision, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
final List<InputClause> input = model.getInput();
assertThat(input.size()).isEqualTo(3);
assertThat(input.get(0).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(0).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_2);
assertThat(input.get(0).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_2);
assertThat(input.get(1).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(1).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart1Name);
assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart1TypeRef);
assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart2Name);
assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart2TypeRef);
assertStandardOutputClauseEnrichment(model);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
Aggregations