Backend API

public class Flow implements FlowInterface

The Flow is the main data structure of the project.

It contains the graph, that is the ensemble of elements that describe the process that the user wants to execute/simulate. This process is composed of nodes, connected with edges.

The flow also contains groups, that are some subgraph of the graph. They are used to let the user simulate some part of the graph instead of everything.

Beside that, the flow contains the library of components available.

We represent and store the flow as a JSON file. The web interface uses it, and only it, to create the view.

Created by antoine on 26/05/2017.

public Flow (JSONObject source, Workspace workspace)

Use case : after server restart, re-create workspaces’ flows from the saved JSON files.

public String serialize ()

Serialize the Flow as a JSON and return it

private void buildObject()

Build the Json object with the following structure

{ ‘id’: string, ‘name’: string, ‘library’: string, ‘description’: string, ‘edges’: Edge[], ‘nodes’: Node[], ‘groups’: Group[] }

public boolean addNode(String id, String component, JSONObject metadata, String graph, boolean executable)

Add a new node onto the graph

public boolean removeNode(String id, String graph)

Remove an existing node from the graph.

public boolean renameNode(String from, String to, String graph)

Change the id of a node

public boolean changeNode(String id, JSONObject metadata, String graph)

Update the metadata of a node.

public boolean addEdge (String id, JSONObject src, JSONObject tgt, JSONObject metadata, String graph)

Add an edge, connecting two nodes on the graph.

public boolean removeEdge(String id, String graph, JSONObject src, JSONObject tgt)

Remove an existing edge from the graph.

public boolean changeEdge(String id, String graph, JSONObject metadata, JSONObject src, JSONObject tgt)

Modify the src, tgt and metadata of an edge

public boolean addGroup(String name, JSONArray nodes, JSONObject metadata, String graph)

Create a new group that is a kind of subgraph user can run independently.

public boolean removeGroup(String name, String graph)

Remove an existing group

public boolean renameGroup(String from, String to, String graph)

Rename a group.

public boolean changeGroup(String name, JSONObject metadata, String graph)

Change the metadata of a group.

public ArrayList findFirstNodesOfFlow (ArrayList nodes)

Determine which nodes are the first one on the flow and give the list of them.

public String getComponentsLibrary()

The components library is the library that contains all the components the user will be able to use in order to build his flow.

public String getId()

The unique id of the Flow

public JSONObject getFlowObject ()

public Edge getEdge (JSONObject src, JSONObject tgt, String graph)

Get an edge from its source and target nodes

public Edge getEdge (String id)

Get an edge from its id

public ArrayList getNodes()

public ArrayList getNodes (Group g)

Get the list of nodes of a given group.

public Node getNode (String id, String graph)

Get a node

public Group getGroup (String name, String graph)

Get a group

public Object getGraph (String graph)

Get a graph

public void setDescription(String description)

Set the description of the flow/project.

public Status getStatus()

Get the status of the Flow

private boolean nodeExist (String id)

Test whether a node exists or not

private boolean edgeExist (JSONObject src, JSONObject tgt)

Test whether an edge exists or not

private boolean edgeExist(String id)

Test whether an edge exists or not

private boolean graphExist (String id)

Test whether a graph exists or not

private boolean groupExist (String name)

Test whether a group exists or not

private int indexOfEdge (JSONObject src, JSONObject tgt)

Get the index of an edge in the edges array

private int indexOfEdge (String id)

Get the index of an edge in the edges array

private int indexOfNode (String id)

Get the index of a node in the nodes array

private int indexOfGroup (String name)

Get the index of a group in the groups array