Skip navigation links

Package com.orchestranetworks.addon.gram.graph

Classes and interfaces for computing nodes and their relationships in a data value graph.

See: Description

Package com.orchestranetworks.addon.gram.graph Description

Classes and interfaces for computing nodes and their relationships in a data value graph.

You can implement the GraphDataValueGenerator interface to define your own rules to get a list of nodes and their relationships that are encapsulated in the GraphNodes class.

public class GramGraphDataValue implements GraphDataValueGenerator
{
        public static final String DEFAULT_NODE_LAYOUT = "[ON] DefaultNodeLayout";
        public static final String DEFAULT_TRANSITION_LAYOUT = "[ON] Default";
        public static final String GRAM_API = "GramAPI";
        public GraphNodes generateGraph(GraphDataValueContext context) throws GramException
        {
                GraphNodes result = GraphValueNodesBridge.createGraphGraphValueNodes();
                AdaptationTable selectedTable = context.getSelection().getSelectedTable();
                if (selectedTable == null)
                {
                        throw new GramException(UserMessage.createError("Cannot get the corresponding table"));
                }
                Set<GraphNode> allNodes = new HashSet<GraphNode>();

                RequestResult requestResult = selectedTable.createRequest().execute();
                Adaptation adaptation;
                try
                {
                        while ((adaptation = requestResult.nextAdaptation()) != null)
                        {
                                allNodes.add(new GraphNode(adaptation));
                        }
                }
                finally
                {
                        requestResult.close();
                }

                GraphNode firstRecord = allNodes.iterator().next();
                if (firstRecord == null)
                {
                        throw new GramException(UserMessage.createError("The selected table is empty"));
                }
                GraphNode graphNode = result.get(firstRecord);
                if (graphNode == null)
                {
                        graphNode = firstRecord;
                        result.addNode(
                                graphNode,
                                new NodeSpec(UserMessage.createInfo(GramGraphDataValue.GRAM_API
                                        + firstRecord.getPrimaryKey().format()), GramGraphDataValue.DEFAULT_NODE_LAYOUT));
                }
                //Starting from the current table’s first record

                for (GraphNode aNode : allNodes)
                {
                        if (firstRecord.equals(aNode))
                        {
                                continue;
                        }
                        //links to all other records.
                        graphNode.addNodesTo(
                                aNode,
                                new RelationSpec(
                                        UserMessage.createInfo(firstRecord.getPrimaryKey().format() + " - "
                                                + aNode.getPrimaryKey().format()),
                                        GramGraphDataValue.DEFAULT_TRANSITION_LAYOUT));
                        GraphNode toNode = result.get(aNode);
                        if (toNode == null)
                        {
                                //Link the current record from firstRecord as linksFrom
                                toNode = aNode;
                                result.addNode(
                                        toNode,
                                        new NodeSpec(UserMessage.createInfo(GramGraphDataValue.GRAM_API
                                                + toNode.getPrimaryKey().format()), GramGraphDataValue.DEFAULT_NODE_LAYOUT));
                        }
                        toNode.addNodesFrom(firstRecord);
                }
                return result;
        }
}
Skip navigation links

Add-ons Version 4.5.22.

Copyright 2001-2025. Cloud Software Group, Inc. All rights reserved.
All third party product and company names and third party marks mentioned in this document are the property of their respective owners and are mentioned for identification.