use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class PMMLFunctionEditorDefinition method enrich.
@Override
public void enrich(final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<Context> expression) {
expression.ifPresent(context -> {
final List<String> variableNames = getVariableNames();
final ContextEntry contextEntryDocument = new ContextEntry();
contextEntryDocument.setVariable(createVariable(variableNames.get(0)));
contextEntryDocument.setExpression(new LiteralExpressionPMMLDocument());
context.getContextEntry().add(contextEntryDocument);
contextEntryDocument.setParent(context);
final ContextEntry contextEntryDocumentModel = new ContextEntry();
contextEntryDocumentModel.setVariable(createVariable(variableNames.get(1)));
contextEntryDocumentModel.setExpression(new LiteralExpressionPMMLDocumentModel());
context.getContextEntry().add(contextEntryDocumentModel);
contextEntryDocumentModel.setParent(context);
});
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testContextEntryDataType.
@Test
@SuppressWarnings("unchecked")
public void testContextEntryDataType() throws Exception {
final DMNMarshallerStandalone marshaller = getDMNMarshaller();
final Context context = new Context();
context.setTypeRef(BuiltInType.DATE_TIME.asQName());
final ContextEntry contextEntry = new ContextEntry();
final LiteralExpression literalExpression = new LiteralExpression();
literalExpression.setTypeRef(BuiltInType.BOOLEAN.asQName());
literalExpression.getText().setValue("feel");
contextEntry.setExpression(literalExpression);
context.getContextEntry().add(contextEntry);
final Diagram<Graph, Metadata> mockedDiagram = newDiagramDecisionWithExpression(context);
final String marshalledSource = marshaller.marshall(mockedDiagram);
final Graph<?, Node<View, ?>> unmarshalledGraph = marshaller.unmarshall(createMetadata(), new StringInputStream(marshalledSource));
assertThat(unmarshalledGraph.nodes()).hasSize(2);
checkDecisionExpression(unmarshalledGraph, context);
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextEntryPropertyConverterTest method testWBFromDMN.
@Test
public void testWBFromDMN() {
final org.kie.dmn.model.api.ContextEntry dmn = new TContextEntry();
final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
dmn.setVariable(informationItem);
final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
literalExpression.setId(EXPRESSION_UUID);
dmn.setExpression(literalExpression);
final ContextEntry wb = ContextEntryPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
assertThat(wb).isNotNull();
assertThat(wb.getVariable()).isNotNull();
assertThat(wb.getExpression()).isNotNull();
assertThat(wb.getExpression().getId().getValue()).isEqualTo(EXPRESSION_UUID);
verify(hasComponentWidthsConsumer).accept(eq(EXPRESSION_UUID), hasComponentWidthsCaptor.capture());
final HasComponentWidths hasComponentWidths = hasComponentWidthsCaptor.getValue();
assertThat(hasComponentWidths).isNotNull();
assertThat(hasComponentWidths).isEqualTo(wb.getExpression());
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextEntryPropertyConverterTest method testDMNFromWBWithNullWBExpression.
@Test
public void testDMNFromWBWithNullWBExpression() {
final ContextEntry wb = new ContextEntry();
final InformationItem informationItem = new InformationItem();
wb.setVariable(informationItem);
wb.setExpression(null);
final org.kie.dmn.model.api.ContextEntry dmn = ContextEntryPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
assertThat(dmn).isNotNull();
assertThat(dmn.getVariable()).isNotNull();
assertThat(dmn.getExpression()).isNotNull();
assertThat(dmn.getExpression()).isInstanceOf(org.kie.dmn.model.api.LiteralExpression.class);
final org.kie.dmn.model.api.LiteralExpression literalExpression = (org.kie.dmn.model.api.LiteralExpression) dmn.getExpression();
assertThat(literalExpression.getText()).isEqualTo(ContextEntry.DEFAULT_EXPRESSION_VALUE);
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry 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