use of org.kie.dmn.model.v1_3.TDecision in project drools by kiegroup.
the class XLS2DMNParser method appendDecisionDT.
private void appendDecisionDT(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
for (DTHeaderInfo hi : headerInfos.values()) {
Decision decision = new TDecision();
decision.setName(hi.getSheetName());
decision.setId("d_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
InformationItem variable = new TInformationItem();
variable.setName(hi.getSheetName());
variable.setId("dvar_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
variable.setTypeRef(new QName("Any"));
decision.setVariable(variable);
for (String ri : hi.getRequiredInput()) {
InformationRequirement ir = new TInformationRequirement();
DMNElementReference er = new TDMNElementReference();
er.setHref("#id_" + CodegenStringUtil.escapeIdentifier(ri));
ir.setRequiredInput(er);
decision.getInformationRequirement().add(ir);
}
for (String ri : hi.getRequiredDecision()) {
InformationRequirement ir = new TInformationRequirement();
DMNElementReference er = new TDMNElementReference();
er.setHref("#d_" + CodegenStringUtil.escapeIdentifier(ri));
ir.setRequiredDecision(er);
decision.getInformationRequirement().add(ir);
}
DecisionTable dt = new TDecisionTable();
dt.setOutputLabel(hi.getSheetName());
dt.setId("ddt_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
dt.setHitPolicy(HitPolicy.ANY);
for (String ri : hi.getRequiredInput()) {
InputClause ic = new TInputClause();
ic.setLabel(ri);
LiteralExpression le = new TLiteralExpression();
le.setText(ri);
ic.setInputExpression(le);
dt.getInput().add(ic);
}
for (String rd : hi.getRequiredDecision()) {
InputClause ic = new TInputClause();
ic.setLabel(rd);
LiteralExpression le = new TLiteralExpression();
le.setText(rd);
ic.setInputExpression(le);
dt.getInput().add(ic);
}
OutputClause oc = new TOutputClause();
dt.getOutput().add(oc);
decision.setExpression(dt);
definitions.getDrgElement().add(decision);
}
}
use of org.kie.dmn.model.v1_3.TDecision in project kie-wb-common by kiegroup.
the class DecisionConverterTest method testWBFromDMN.
@Test
@SuppressWarnings("unchecked")
public void testWBFromDMN() {
final Node<View<Decision>, ?> factoryNode = new NodeImpl<>(UUID.uuid());
final View<Decision> view = new ViewImpl<>(new Decision(), Bounds.create());
factoryNode.setContent(view);
when(factoryManager.newElement(Mockito.<String>any(), eq(getDefinitionId(Decision.class)))).thenReturn(element);
when(element.asNode()).thenReturn(factoryNode);
final org.kie.dmn.model.api.Decision dmn = new TDecision();
final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
literalExpression.setId(EXPRESSION_UUID);
dmn.setId(DECISION_UUID);
dmn.setName(DECISION_NAME);
dmn.setDescription(DECISION_DESCRIPTION);
dmn.setVariable(informationItem);
dmn.setExpression(literalExpression);
final Node<View<Decision>, ?> node = converter.nodeFromDMN(dmn, hasComponentWidthsConsumer);
final Decision wb = (Decision) DefinitionUtils.getElementDefinition(node);
assertThat(wb).isNotNull();
assertThat(wb.getId()).isNotNull();
assertThat(wb.getId().getValue()).isEqualTo(DECISION_UUID);
assertThat(wb.getName()).isNotNull();
assertThat(wb.getName().getValue()).isEqualTo(DECISION_NAME);
assertThat(wb.getDescription()).isNotNull();
assertThat(wb.getDescription().getValue()).isEqualTo(DECISION_DESCRIPTION);
assertThat(wb.getVariable()).isNotNull();
assertThat(wb.getVariable().getName().getValue()).isEqualTo(DECISION_NAME);
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.dmn.model.v1_3.TDecision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testStunnerConstellationButtonCausingPoint2DbeingNull.
/**
* DROOLS-3184: If the "connection source/target location is null" assume it's the centre of the shape.
* [source/target location is null] If the connection was created from the Toolbox (i.e. add a InputData and then the Decision from it using the Decision toolbox icon).
* <p>
* This test re-create by hard-code the behavior of the Stunner framework "Toolbox" by instrumenting API calls to achieve the same behavior.
*/
@SuppressWarnings("unchecked")
@Test
public void testStunnerConstellationButtonCausingPoint2DbeingNull() throws IOException {
final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> {
/*NOP*/
};
Diagram diagram = createDiagram();
Graph g = diagram.getGraph();
Node diagramRoot = DMNMarshallerStandalone.findDMNDiagramRoot(g);
testAugmentWithNSPrefixes(((DMNDiagram) ((View<?>) diagramRoot.getContent()).getDefinition()).getDefinitions());
org.kie.dmn.model.api.InputData dmnInputData = new TInputData();
dmnInputData.setId("inputDataID");
dmnInputData.setName(dmnInputData.getId());
Node inputDataNode = new InputDataConverter(api.getFactoryManager()).nodeFromDMN(dmnInputData, hasComponentWidthsConsumer);
org.kie.dmn.model.api.Decision dmnDecision = new TDecision();
dmnDecision.setId("decisionID");
dmnDecision.setName(dmnDecision.getId());
Node decisionNode = new DecisionConverter(api.getFactoryManager()).nodeFromDMN(dmnDecision, hasComponentWidthsConsumer);
g.addNode(inputDataNode);
g.addNode(decisionNode);
View content = (View) decisionNode.getContent();
content.setBounds(org.kie.workbench.common.stunner.core.graph.content.Bounds.create(200, 200, 300, 250));
final String irID = "irID";
Edge myEdge = api.getFactoryManager().newElement(irID, DMNMarshallerStandalone.INFO_REQ_ID).asEdge();
myEdge.setSourceNode(inputDataNode);
myEdge.setTargetNode(decisionNode);
inputDataNode.getOutEdges().add(myEdge);
decisionNode.getInEdges().add(myEdge);
ViewConnector connectionContent = (ViewConnector) myEdge.getContent();
// DROOLS-3184: If the "connection source/target location is null" assume it's the centre of the shape.
// keep Stunner behavior of constellation button
connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(inputDataNode).setLocation(null).setAuto(true));
connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(decisionNode).setLocation(null).setAuto(true));
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, inputDataNode);
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, decisionNode);
DMNMarshallerStandalone m = getDMNMarshaller();
String output = m.marshall(diagram);
LOG.debug(output);
Definitions dmnDefinitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(output);
DMNEdge dmndiEdge = findEdgeByDMNI(dmnDefinitions.getDMNDI().getDMNDiagram().get(0), irID);
assertThat(dmndiEdge.getWaypoint()).hasSize(2);
Point wpSource = dmndiEdge.getWaypoint().get(0);
assertThat(wpSource.getX()).isEqualByComparingTo(50d);
assertThat(wpSource.getY()).isEqualByComparingTo(25d);
Point wpTarget = dmndiEdge.getWaypoint().get(1);
assertThat(wpTarget.getX()).isEqualByComparingTo(250d);
assertThat(wpTarget.getY()).isEqualByComparingTo(225d);
}
use of org.kie.dmn.model.v1_3.TDecision in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsHelperStandaloneImplTest method testGetDrgElementsWithNamespace.
@Test
public void testGetDrgElementsWithNamespace() {
final Definitions definitions = mock(Definitions.class);
final Import anImport = mock(Import.class);
final TDecision drgElement1 = new TDecision();
final TInputData drgElement2 = new TInputData();
final TDecisionService drgElement3 = new TDecisionService();
final InformationItem informationItem1 = new TInformationItem();
final InformationItem informationItem2 = new TInformationItem();
final InformationItem informationItem3 = new TInformationItem();
final List<DRGElement> drgElements = asList(drgElement1, drgElement2, drgElement3);
final String namespace = "http://github.com/kiegroup/_something";
final String builtInTypeNumber = BuiltInType.NUMBER.getName();
when(anImport.getName()).thenReturn("model");
when(anImport.getNamespace()).thenReturn(namespace);
informationItem1.setTypeRef(new QName(XMLConstants.NULL_NS_URI, "tUUID", XMLConstants.DEFAULT_NS_PREFIX));
informationItem2.setTypeRef(new QName(XMLConstants.NULL_NS_URI, "tAge", XMLConstants.DEFAULT_NS_PREFIX));
informationItem3.setTypeRef(new QName(XMLConstants.NULL_NS_URI, builtInTypeNumber, XMLConstants.DEFAULT_NS_PREFIX));
drgElement1.setId("0000-1111");
drgElement2.setId("2222-3333");
drgElement3.setId("4444-5555");
drgElement1.setName("Decision");
drgElement2.setName("Input Data");
drgElement3.setName("Decision Service");
drgElement1.setVariable(informationItem1);
drgElement2.setVariable(informationItem2);
drgElement3.setVariable(informationItem3);
when(definitions.getDrgElement()).thenReturn(drgElements);
final List<DRGElement> elements = helper.getDrgElementsWithNamespace(definitions, anImport);
assertEquals(3, elements.size());
final TDecision element1 = (TDecision) elements.get(0);
assertEquals("0000-1111", element1.getId());
assertEquals("model.Decision", element1.getName());
assertEquals("model.tUUID", element1.getVariable().getTypeRef().getLocalPart());
assertEquals(namespace, getNamespace(element1));
final TInputData element2 = (TInputData) elements.get(1);
assertEquals("2222-3333", element2.getId());
assertEquals("model.Input Data", element2.getName());
assertEquals("model.tAge", element2.getVariable().getTypeRef().getLocalPart());
assertEquals(namespace, getNamespace(element2));
final TDecisionService element3 = (TDecisionService) elements.get(2);
assertEquals("4444-5555", element3.getId());
assertEquals("model.Decision Service", element3.getName());
assertEquals(builtInTypeNumber, element3.getVariable().getTypeRef().getLocalPart());
assertEquals(namespace, getNamespace(element3));
}
use of org.kie.dmn.model.v1_3.TDecision in project drools-wb by kiegroup.
the class AbstractDMNTest method getDecisionNode.
protected DecisionNode getDecisionNode(DMNType dmnType, String name) {
TDecision decision = new TDecision();
decision.setName(name);
DecisionNode toReturn = new DecisionNodeImpl(decision, dmnType);
return toReturn;
}
Aggregations