use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method setup.
@Before
public void setup() throws Exception {
// Graph utils.
when(definitionManager.adapters()).thenReturn(adapterManager);
when(adapterManager.registry()).thenReturn(adapterRegistry);
definitionUtils = new DefinitionUtils(definitionManager, applicationFactoryManager);
testScopeModelFactory = new TestScopeModelFactory(new DMNDefinitionSet.DMNDefinitionSetBuilder().build());
// Definition manager.
final BackendDefinitionAdapter definitionAdapter = new BackendDefinitionAdapter(definitionUtils);
final BackendDefinitionSetAdapter definitionSetAdapter = new BackendDefinitionSetAdapter(definitionAdapter);
final BackendPropertySetAdapter propertySetAdapter = new BackendPropertySetAdapter();
final BackendPropertyAdapter propertyAdapter = new BackendPropertyAdapter();
when(adapterManager.forDefinitionSet()).thenReturn(definitionSetAdapter);
when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
when(adapterManager.forPropertySet()).thenReturn(propertySetAdapter);
when(adapterManager.forProperty()).thenReturn(propertyAdapter);
when(adapterRegistry.getDefinitionSetAdapter(any(Class.class))).thenReturn(definitionSetAdapter);
when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter);
when(adapterRegistry.getPropertySetAdapter(any(Class.class))).thenReturn(propertySetAdapter);
when(adapterRegistry.getPropertyAdapter(any(Class.class))).thenReturn(propertyAdapter);
commandManager = new GraphCommandManagerImpl(null, null, null);
commandFactory = new GraphCommandFactory();
connectionEdgeFactory = new EdgeFactoryImpl(definitionManager);
viewNodeFactory = new NodeFactoryImpl(definitionUtils);
dmnGraphFactory = new GraphFactoryImpl(definitionManager);
doAnswer(invocationOnMock -> {
String id = (String) invocationOnMock.getArguments()[0];
return testScopeModelFactory.build(id);
}).when(applicationFactoryManager).newDefinition(anyString());
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
String id = (String) invocationOnMock.getArguments()[1];
if (DMNDefinitionSet.class.getName().equals(id)) {
// Emulate DMNGraphFactoryImpl, that adds a DMNDiagram to new Graphs
// Please note this is different from the stunner jbpm test which this dmn test is based on
Graph graph = (Graph) dmnGraphFactory.build(uuid, DMN_DEF_SET_ID);
DMNDiagram model = new DMNDiagram.DMNDiagramBuilder().build();
Node node = viewNodeFactory.build(uuid, model);
graph.addNode(node);
return graph;
}
Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
if (null != model) {
Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
if (element.isAssignableFrom(NodeFactory.class)) {
Node node = viewNodeFactory.build(uuid, model);
return node;
} else if (element.isAssignableFrom(EdgeFactory.class)) {
Edge edge = connectionEdgeFactory.build(uuid, model);
return edge;
}
}
return null;
}).when(applicationFactoryManager).newElement(anyString(), anyString());
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
Class type = (Class) invocationOnMock.getArguments()[1];
String id = BindableAdapterUtils.getGenericClassName(type);
if (DMNDefinitionSet.class.equals(type)) {
Graph graph = (Graph) dmnGraphFactory.build(uuid, DMN_DEF_SET_ID);
return graph;
}
Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
if (null != model) {
Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
if (element.isAssignableFrom(NodeFactory.class)) {
Node node = viewNodeFactory.build(uuid, model);
return node;
} else if (element.isAssignableFrom(EdgeFactory.class)) {
Edge edge = connectionEdgeFactory.build(uuid, model);
return edge;
}
}
return null;
}).when(applicationFactoryManager).newElement(anyString(), any(Class.class));
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
String defSetId = (String) invocationOnMock.getArguments()[1];
final Graph graph = (Graph) applicationFactoryManager.newElement(uuid, defSetId);
final DiagramImpl result = new DiagramImpl(uuid, new MetadataImpl.MetadataImplBuilder(defSetId).build());
result.setGraph(graph);
return result;
}).when(applicationFactoryManager).newDiagram(anyString(), anyString(), any(Metadata.class));
MappingContextSingleton.loadDynamicMarshallers();
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method test_function_java_WB_model.
@Test
public void test_function_java_WB_model() throws IOException {
final DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
@SuppressWarnings("unchecked") final Graph<?, Node<?, ?>> g = m.unmarshall(null, this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final Stream<Node<?, ?>> stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(g.nodes().iterator(), Spliterator.ORDERED), false);
final Optional<Decision> wbDecision = stream.filter(n -> n.getContent() instanceof ViewImpl).map(n -> (ViewImpl) n.getContent()).filter(n -> n.getDefinition() instanceof Decision).map(n -> (Decision) n.getDefinition()).findFirst();
wbDecision.ifPresent(d -> {
assertTrue(d.getExpression() instanceof FunctionDefinition);
final FunctionDefinition wbFunction = (FunctionDefinition) d.getExpression();
// This is what the WB expects
assertTrue(wbFunction.getAdditionalAttributes().containsKey(FunctionDefinition.KIND_QNAME));
assertEquals("J", wbFunction.getAdditionalAttributes().get(FunctionDefinition.KIND_QNAME));
});
final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final DMNModel dmnModel = runtime.getModels().get(0);
final DecisionNode dmnDecision = dmnModel.getDecisions().iterator().next();
assertTrue(dmnDecision.getDecision().getExpression() instanceof org.kie.dmn.model.v1_1.FunctionDefinition);
final org.kie.dmn.model.v1_1.FunctionDefinition dmnFunction = (org.kie.dmn.model.v1_1.FunctionDefinition) dmnDecision.getDecision().getExpression();
assertTrue(dmnFunction.getAdditionalAttributes().containsKey(org.kie.dmn.model.v1_1.FunctionDefinition.KIND_QNAME));
assertEquals("J", dmnFunction.getAdditionalAttributes().get(org.kie.dmn.model.v1_1.FunctionDefinition.KIND_QNAME));
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class DMNEditBusinessKnowledgeModelToolboxAction method onMouseClick.
@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
// Notice the toolbox factory ensure this action is only being included
// for BusinessKnowledgeModel definitions, next cast is safe.
final Node<View<? extends BusinessKnowledgeModel>, Edge> bkmNode = (Node<View<? extends BusinessKnowledgeModel>, Edge>) AbstractToolboxAction.getElement(canvasHandler, uuid).asNode();
final BusinessKnowledgeModel bkm = bkmNode.getContent().getDefinition();
editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, bkm.getEncapsulatedLogic(), Optional.of(bkm)));
return this;
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class DMNEditDecisionToolboxAction method onMouseClick.
@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
// Notice the toolbox factory ensure this action is only being included
// for Decision definitions, next cast is safe.
final Node<View<? extends Decision>, Edge> decisionNode = (Node<View<? extends Decision>, Edge>) AbstractToolboxAction.getElement(canvasHandler, uuid).asNode();
final Decision decision = decisionNode.getContent().getDefinition();
editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, decision, Optional.of(decision)));
return this;
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class DMNFlowActionsToolboxFactory method getActions.
@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> element) {
final Set<ToolboxAction<AbstractCanvasHandler>> actions = new LinkedHashSet<>();
final Node<Definition<Object>, Edge> node = (Node<Definition<Object>, Edge>) element;
final Diagram diagram = canvasHandler.getDiagram();
final String defSetId = diagram.getMetadata().getDefinitionSetId();
// Look for the allowed connectors present in the Definition Set.
final Set<String> allowedConnectorIds = commonLookups.getAllowedConnectors(defSetId, node, 0, 10);
for (final String allowedConnectorId : allowedConnectorIds) {
// Append a new action for each connector.
actions.add(createConnectorActions.get().setEdgeId(allowedConnectorId));
// Append a new action for each candidate target node (as from the current connector).
commonLookups.getAllowedTargetDefinitions(defSetId, diagram.getGraph(), node, allowedConnectorId, 0, 10).forEach(def -> actions.add(createNodeActions.get().setEdgeId(allowedConnectorId).setNodeId(getDefinitionId(def))));
}
return actions;
}
Aggregations