@Test public void testModelEnrichmentWhenDecisionTypeRefIsStructureAndOneSubfieldIsStructure() { 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 tCompany = mockTCompanyStructure(); when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions); when(definitions.getItemDefinition()).thenReturn(Collections.singletonList(tCompany)); when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(decision); when(decision.getVariable()).thenReturn(informationItemPrimary); when(informationItemPrimary.getTypeRef()).thenReturn(new QName("", TYPE_COMPANY)); 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("address", outputClause1.getName()); assertEquals(ANY.asQName(), outputClause1.getTypeRef()); assertEquals("name", outputClause2.getName()); assertEquals(STRING.asQName(), outputClause2.getTypeRef()); }
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); }); } }
DecisionTableEditorDefinitionEnricher implements ExpressionEditorModelEnricher<DecisionTable> { 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); }); } } }
DecisionTableEditorDefinitionEnricher implements ExpressionEditorModelEnricher<DecisionTable> { 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); }); } } DecisionTableEditorDefinitionEnricher(); @Inject  DecisionTableEditorDefinitionEnricher(final SessionManager sessionManager,
                                                 final DMNGraphUtils dmnGraphUtils,
                                                 final ItemDefinitionUtils itemDefinitionUtils); }
DecisionTableEditorDefinitionEnricher implements ExpressionEditorModelEnricher<DecisionTable> { 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); }); } } DecisionTableEditorDefinitionEnricher(); @Inject  DecisionTableEditorDefinitionEnricher(final SessionManager sessionManager,
                                                 final DMNGraphUtils dmnGraphUtils,
                                                 final ItemDefinitionUtils itemDefinitionUtils); @Override void enrich(final Optional<String> nodeUUID,
                       final HasExpression hasExpression,
                       final Optional<DecisionTable> expression); }
DecisionTableEditorDefinitionEnricher implements ExpressionEditorModelEnricher<DecisionTable> { 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); }); } } DecisionTableEditorDefinitionEnricher(); @Inject  DecisionTableEditorDefinitionEnricher(final SessionManager sessionManager,
                                                 final DMNGraphUtils dmnGraphUtils,
                                                 final ItemDefinitionUtils itemDefinitionUtils); @Override void enrich(final Optional<String> nodeUUID,
                       final HasExpression hasExpression,
                       final Optional<DecisionTable> expression);  }