use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method testUnmarshallSequenceFlow.
@Test
public void testUnmarshallSequenceFlow() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_SEQUENCEFLOW);
SequenceFlow sequenceFlow1 = null;
SequenceFlow sequenceFlow2 = null;
Iterator<Element> it = nodesIterator(diagram);
while (it.hasNext()) {
Element element = it.next();
if (element.getContent() instanceof View) {
Object oDefinition = ((View) element.getContent()).getDefinition();
if (oDefinition instanceof ExclusiveGateway) {
List<Edge> outEdges = ((NodeImpl) element).getOutEdges();
for (Edge edge : outEdges) {
SequenceFlow flow = (SequenceFlow) ((ViewConnectorImpl) ((EdgeImpl) edge).getContent()).getDefinition();
if ("route1".equals(flow.getGeneral().getName().getValue())) {
sequenceFlow1 = flow;
}
if ("route2".equals(flow.getGeneral().getName().getValue())) {
sequenceFlow2 = flow;
}
}
}
}
}
assertNotNull(sequenceFlow1);
assertNotNull(sequenceFlow1.getExecutionSet());
assertNotNull(sequenceFlow1.getExecutionSet().getConditionExpression());
assertNotNull(sequenceFlow1.getExecutionSet().getPriority());
assertNotNull(sequenceFlow1.getGeneral());
assertNotNull(sequenceFlow1.getGeneral().getName());
assertEquals("route1", sequenceFlow1.getGeneral().getName().getValue());
assertEquals("age >= 10;", sequenceFlow1.getExecutionSet().getConditionExpression().getValue().getScript());
assertEquals("javascript", sequenceFlow1.getExecutionSet().getConditionExpression().getValue().getLanguage());
assertEquals("2", sequenceFlow1.getExecutionSet().getPriority().getValue());
assertNotNull(sequenceFlow2);
assertNotNull(sequenceFlow2.getExecutionSet());
assertNotNull(sequenceFlow2.getExecutionSet().getConditionExpression());
assertNotNull(sequenceFlow2.getExecutionSet().getPriority());
assertNotNull(sequenceFlow2.getGeneral());
assertNotNull(sequenceFlow2.getGeneral().getName());
assertEquals("route2", sequenceFlow2.getGeneral().getName().getValue());
assertEquals("age\n" + "<\n" + "10;", sequenceFlow2.getExecutionSet().getConditionExpression().getValue().getScript());
assertEquals("java", sequenceFlow2.getExecutionSet().getConditionExpression().getValue().getLanguage());
assertEquals("1", sequenceFlow2.getExecutionSet().getPriority().getValue());
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
// Work Items.
workItemDefinitionMockRegistry = new WorkItemDefinitionMockRegistry();
// Graph utils.
when(definitionManager.adapters()).thenReturn(adapterManager);
when(adapterManager.registry()).thenReturn(adapterRegistry);
definitionUtils = new DefinitionUtils(definitionManager, applicationFactoryManager);
testScopeModelFactory = new BPMNTestScopeModelFactory(new BPMNDefinitionSet.BPMNDefinitionSetBuilder().build(), workItemDefinitionMockRegistry);
// 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);
bpmnGraphFactory = 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 (BPMNDefinitionSet.class.getName().equals(id)) {
Graph graph = (Graph) bpmnGraphFactory.build(uuid, BPMN_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(), anyString());
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
Class type = (Class) invocationOnMock.getArguments()[1];
String id = BindableAdapterUtils.getGenericClassName(type);
if (BPMNDefinitionSet.class.equals(type)) {
Graph graph = (Graph) bpmnGraphFactory.build(uuid, BPMN_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));
// Bpmn 2 oryx stuff.
oryxIdMappings = new Bpmn2OryxIdMappings(definitionManager, () -> workItemDefinitionMockRegistry);
StringTypeSerializer stringTypeSerializer = new StringTypeSerializer();
BooleanTypeSerializer booleanTypeSerializer = new BooleanTypeSerializer();
ColorTypeSerializer colorTypeSerializer = new ColorTypeSerializer();
DoubleTypeSerializer doubleTypeSerializer = new DoubleTypeSerializer();
IntegerTypeSerializer integerTypeSerializer = new IntegerTypeSerializer();
EnumTypeSerializer enumTypeSerializer = new EnumTypeSerializer(definitionUtils);
AssignmentsTypeSerializer assignmentsTypeSerializer = new AssignmentsTypeSerializer();
VariablesTypeSerializer variablesTypeSerializer = new VariablesTypeSerializer();
TimerSettingsTypeSerializer timerSettingsTypeSerializer = new TimerSettingsTypeSerializer();
ScriptTypeTypeSerializer scriptTypeTypeSerializer = new ScriptTypeTypeSerializer();
ScriptTypeListTypeSerializer scriptTypeListTypeSerializer = new ScriptTypeListTypeSerializer();
TaskTypeSerializer taskTypeSerializer = new TaskTypeSerializer(definitionUtils, enumTypeSerializer);
List<Bpmn2OryxPropertySerializer<?>> propertySerializers = new LinkedList<>();
propertySerializers.add(stringTypeSerializer);
propertySerializers.add(booleanTypeSerializer);
propertySerializers.add(colorTypeSerializer);
propertySerializers.add(doubleTypeSerializer);
propertySerializers.add(integerTypeSerializer);
propertySerializers.add(enumTypeSerializer);
propertySerializers.add(assignmentsTypeSerializer);
propertySerializers.add(variablesTypeSerializer);
propertySerializers.add(timerSettingsTypeSerializer);
propertySerializers.add(scriptTypeTypeSerializer);
propertySerializers.add(scriptTypeListTypeSerializer);
propertySerializers.add(taskTypeSerializer);
oryxPropertyManager = new Bpmn2OryxPropertyManager(propertySerializers);
oryxManager = new Bpmn2OryxManager(oryxIdMappings, oryxPropertyManager);
oryxManager.init();
// Marshalling factories.
objectBuilderFactory = new BPMNGraphObjectBuilderFactory(definitionManager, oryxManager, () -> workItemDefinitionMockRegistry);
taskMorphDefinition = new TaskTypeMorphDefinition();
Collection<MorphDefinition> morphDefinitions = new ArrayList<MorphDefinition>() {
{
add(taskMorphDefinition);
}
};
BackendBindableMorphAdapter<Object> morphAdapter = new BackendBindableMorphAdapter(definitionUtils, applicationFactoryManager, cloneManager, morphDefinitions);
when(adapterRegistry.getMorphAdapter(eq(UserTask.class))).thenReturn(morphAdapter);
when(adapterRegistry.getMorphAdapter(eq(NoneTask.class))).thenReturn(morphAdapter);
when(adapterRegistry.getMorphAdapter(eq(ScriptTask.class))).thenReturn(morphAdapter);
when(adapterRegistry.getMorphAdapter(eq(BusinessRuleTask.class))).thenReturn(morphAdapter);
GraphIndexBuilder<?> indexBuilder = new MapIndexBuilder();
when(rulesManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(new DefaultRuleViolations());
// The work item definition registry.
WorkItemDefinitionBackendRegistry widRegistry = mock(WorkItemDefinitionBackendRegistry.class);
when(widRegistry.getRegistry()).thenReturn(workItemDefinitionMockRegistry);
when(widRegistry.items()).thenReturn(workItemDefinitionMockRegistry.items());
when(widRegistry.load(any(Metadata.class))).thenReturn(widRegistry);
doAnswer(invocationOnMock -> workItemDefinitionMockRegistry.get((String) invocationOnMock.getArguments()[0])).when(widRegistry).get(anyString());
// The tested BPMN marshaller.
tested = new BPMNDiagramMarshaller(new XMLEncoderDiagramMetadataMarshaller(), objectBuilderFactory, definitionManager, indexBuilder, oryxManager, applicationFactoryManager, rulesManager, commandManager, commandFactory, widRegistry);
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method testUnmarshallNotBoundaryEvents.
@Test
@SuppressWarnings("unchecked")
public void testUnmarshallNotBoundaryEvents() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_NOT_BOUNDARY_EVENTS);
assertEquals("Not Boundary Event", diagram.getMetadata().getTitle());
assertDiagram(diagram, 6);
// Assert than the intermediate event is connected using a view connector,
// so not boundary to the task ( not docked ).
Node event = diagram.getGraph().getNode("_CB178D55-8DC2-4CAA-8C42-4F5028D4A1F6");
List<Edge> inEdges = event.getInEdges();
boolean foundViewConnector = false;
for (Edge e : inEdges) {
if (e.getContent() instanceof ViewConnector) {
foundViewConnector = true;
}
}
assertTrue(foundViewConnector);
// Assert absolute position as the node is not docked.
Bounds bounds = ((View) event.getContent()).getBounds();
Bounds.Bound ul = bounds.getUpperLeft();
Bounds.Bound lr = bounds.getLowerRight();
assertEquals(305, ul.getX(), 0);
assertEquals(300, ul.getY(), 0);
assertEquals(335, lr.getX(), 0);
assertEquals(330, lr.getY(), 0);
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class AbstractNodeBuilder method afterNodeBuild.
@SuppressWarnings("unchecked")
protected void afterNodeBuild(final BuilderContext context, final T node) {
// Outgoing connections.
if (outgoingResourceIds != null && !outgoingResourceIds.isEmpty()) {
for (String outgoingNodeId : outgoingResourceIds) {
GraphObjectBuilder<?, ?> outgoingBuilder = getBuilder(context, outgoingNodeId);
if (outgoingBuilder == null) {
throw new RuntimeException("No outgoing edge builder for " + outgoingNodeId);
}
final List<Command<GraphCommandExecutionContext, RuleViolation>> commands = new LinkedList<>();
// If outgoing element it's a node means that it's docked.
if (outgoingBuilder instanceof AbstractNodeBuilder) {
// Command - Create the docked node.
Node docked = (Node) outgoingBuilder.build(context);
commands.add(context.getCommandFactory().addDockedNode(node, docked));
// Obtain docked position and use those for the docked node.
final List<Double[]> dockers = ((AbstractNodeBuilder) outgoingBuilder).dockers;
if (!dockers.isEmpty()) {
// TODO: Use not only first docker coordinates?
Double[] dCoords = dockers.get(0);
double x = dCoords[0];
double y = dCoords[1];
commands.add(context.getCommandFactory().updatePosition(docked, new Point2D(x, y)));
}
} else {
// Create the outgoing edge.
AbstractEdgeBuilder edgeBuilder = (AbstractEdgeBuilder) outgoingBuilder;
Edge edge = (Edge) edgeBuilder.build(context);
if (edge != null) {
// Command - Execute the graph command to set the node as the edge connection's source..
Double[] sourceDocker = null;
final List<Double[]> dockers = ((AbstractEdgeBuilder) outgoingBuilder).dockers;
if (dockers != null && dockers.size() > 1) {
sourceDocker = dockers.get(0);
}
Connection sourceConnection = null;
if (null != sourceDocker) {
sourceConnection = MagnetConnection.Builder.at(sourceDocker[0], sourceDocker[1]).setAuto(edgeBuilder.isSourceAutoConnection());
}
commands.add(context.getCommandFactory().setSourceNode(node, edge, sourceConnection));
}
}
if (!commands.isEmpty()) {
for (Command<GraphCommandExecutionContext, RuleViolation> command : commands) {
doExecuteCommand(context, command);
}
}
}
}
// Children connections.
if (childNodeIds != null && !childNodeIds.isEmpty()) {
for (String childNodeId : childNodeIds) {
GraphObjectBuilder<?, ?> childNodeBuilder = getBuilder(context, childNodeId);
if (childNodeBuilder == null) {
throw new RuntimeException("No child node builder for " + childNodeId);
}
Command<GraphCommandExecutionContext, RuleViolation> command = null;
if (childNodeBuilder instanceof NodeObjectBuilder) {
// Command - Create the child node and the parent-child relationship.
Node childNode = (Node) childNodeBuilder.build(context);
command = context.getCommandFactory().addChildNode(node, childNode);
}
if (null != command) {
doExecuteCommand(context, command);
}
}
}
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class BPMNGraphGenerator method createGraph.
public Graph<DefinitionSet, Node> createGraph() {
Graph<DefinitionSet, Node> graph = (Graph<DefinitionSet, Node>) factoryManager.newElement(UUID.uuid(), diagramDefinitionSetClass);
// TODO: Where are the BPMN diagram bounds in the Oryx json structure? Exist?
if (null == graph.getContent().getBounds()) {
graph.getContent().setBounds(new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(BPMNGraphFactory.GRAPH_DEFAULT_WIDTH, BPMNGraphFactory.GRAPH_DEFAULT_HEIGHT)));
}
builderContext.init(graph).execute(builderContext.getCommandFactory().clearGraph());
NodeObjectBuilder diagramBuilder = getDiagramBuilder(builderContext);
if (diagramBuilder == null) {
throw new RuntimeException("No diagrams found!");
}
Node<View<BPMNDefinition>, Edge> diagramNode = (Node<View<BPMNDefinition>, Edge>) diagramBuilder.build(builderContext);
graph.addNode(diagramNode);
logBuilders();
return graph;
}
Aggregations