hierarchy

package
v1.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package hierarchy provides the client for making API requests to Enlight Hierarchy Management Service.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements the HierarchyClient and holds the connection.

Example
package main

import (
	"log"

	"github.com/SKF/go-enlight-sdk/grpc"
	"github.com/SKF/go-enlight-sdk/services/hierarchy"
)

func main() {
	host, port := "<host>", "<port>"
	clientCert, clientKey := "<clientCertPath>", "<clientKey>"
	caCert := "<caCert>"

	// Create a Hierarchy Service client
	client := hierarchy.CreateClient()

	// Dial the Hierarchy Service
	dialOption, err := grpc.WithTransportCredentials(host, clientCert, clientKey, caCert)
	if err != nil {
		log.Fatalf("Couldn't connect due to error: %+v", err)
	}

	// Dial the Hierarchy Service
	err = client.Dial(host, port, dialOption)
	if err != nil {
		log.Fatalf("Couldn't dial due to error: %+v", err)
	}
	defer client.Close()

	// Ping the Hierarchy Service
	err = client.DeepPing()
	if err != nil {
		log.Fatalf("Couldn't ping the Hierarchy Service due to error: %+v", err)
	}
}
Output:

func (*Client) Close

func (c *Client) Close()

Close tears down the ClientConn and all underlying connections.

func (*Client) CopyNode added in v1.14.0

func (c *Client) CopyNode(userID, srcNodeID, dstParentNodeID string) (string, error)

CopyNode copies the given node, recursively, returning the copied root node's ID.

func (*Client) CopyNodeWithContext added in v1.14.0

func (c *Client) CopyNodeWithContext(ctx context.Context, userID, srcNodeID, dstParentNodeID string) (string, error)

CopyNodeWithContext copies the given node, recursively, returning the copied root node's ID.

func (*Client) DeepPing

func (c *Client) DeepPing() error

DeepPing pings the service to see if it is alive.

func (*Client) DeepPingWithContext

func (c *Client) DeepPingWithContext(ctx context.Context) error

DeepPingWithContext pings the service to see if it is alive.

func (*Client) DeleteNode

func (c *Client) DeleteNode(request hierarchy_grpcapi.DeleteNodeInput) error

DeleteNode will remove the node of the node id it takes as an argument.

func (*Client) DeleteNodeWithContext

func (c *Client) DeleteNodeWithContext(ctx context.Context, request hierarchy_grpcapi.DeleteNodeInput) error

DeleteNodeWithContext will remove the node of the node id it takes as an argument.

func (*Client) Dial

func (c *Client) Dial(host, port string, opts ...grpc.DialOption) error

Dial creates a client connection to the given host with background context and no timeout

func (*Client) DialWithContext

func (c *Client) DialWithContext(ctx context.Context, host, port string, opts ...grpc.DialOption) (err error)

DialWithContext creates a client connection to the given host with context (for timeout and transaction id)

func (*Client) GetAncestors

func (c *Client) GetAncestors(nodeID string) (nodes []hierarchy_grpcapi.AncestorNode, err error)

GetAncestors will return all ancestors to the top of the node id it takes as an argument.

func (*Client) GetAncestorsWithContext

func (c *Client) GetAncestorsWithContext(ctx context.Context, nodeID string) (nodes []hierarchy_grpcapi.AncestorNode, err error)

GetAncestorsWithContext will return all ancestors to the top of the node id it takes as an argument.

func (*Client) GetAssetTaxonomy added in v1.15.0

func (c *Client) GetAssetTaxonomy() (hierarchy_grpcapi.AssetTypes, error)

func (*Client) GetAssetTaxonomyWithContext added in v1.15.0

func (c *Client) GetAssetTaxonomyWithContext(ctx context.Context) (hierarchy_grpcapi.AssetTypes, error)

func (*Client) GetChildNodes

func (c *Client) GetChildNodes(parentID string) (nodes []hierarchy_grpcapi.Node, err error)

GetChildNodes will get all child nodes for the node id it takes as an argument.

func (*Client) GetChildNodesWithContext

func (c *Client) GetChildNodesWithContext(ctx context.Context, parentID string) (nodes []hierarchy_grpcapi.Node, err error)

GetChildNodesWithContext will get all child nodes for the node id it takes as an argument.

func (*Client) GetCompany added in v1.18.0

func (c *Client) GetCompany(nodeID string) (hierarchy_grpcapi.Node, error)

func (*Client) GetCompanyWithContext added in v1.18.0

func (c *Client) GetCompanyWithContext(ctx context.Context, nodeID string) (node hierarchy_grpcapi.Node, err error)

func (*Client) GetEvents

func (c *Client) GetEvents(since int, limit *int32) (events []eventsource.Record, err error)

GetEvents will return all events that has occurred in the Hierarchy Management Service.

func (*Client) GetEventsByCustomer added in v1.8.0

func (c *Client) GetEventsByCustomer(since int, limit *int32, customerID *string) (events []eventsource.Record, err error)

GetEventsByCustomer will return all events that has occurred in the Hierarchy under a specified company Management Service.

func (*Client) GetEventsByCustomerWithContext added in v1.8.0

func (c *Client) GetEventsByCustomerWithContext(ctx context.Context, since int, limit *int32, customerID *string) (events []eventsource.Record, err error)

GetEventsByCustomerWithContext will return all events that has occurred in the Hierarchy under a specified company Management Service.

func (*Client) GetEventsWithContext

func (c *Client) GetEventsWithContext(ctx context.Context, since int, limit *int32) (events []eventsource.Record, err error)

GetEventsWithContext will return all events that has occurred in the Hierarchy Management Service.

func (*Client) GetNode

func (c *Client) GetNode(uuid string) (node hierarchy_grpcapi.Node, err error)

GetNode takes an id of a node and returns the node.

func (*Client) GetNodeIDByOrigin

func (c *Client) GetNodeIDByOrigin(origin common.Origin) (string, error)

GetNodeIDByOrigin takes an origin and returns the Enlight ID.

func (*Client) GetNodeIDByOriginWithContext

func (c *Client) GetNodeIDByOriginWithContext(ctx context.Context, origin common.Origin) (string, error)

GetNodeIDByOriginWithContext takes an origin and returns the Enlight ID.

func (*Client) GetNodeWithContext

func (c *Client) GetNodeWithContext(ctx context.Context, uuid string) (node hierarchy_grpcapi.Node, err error)

GetNodeWithContext takes an id of a node and returns the node.

func (*Client) GetNodes

func (c *Client) GetNodes(parentID string) (nodes []hierarchy_grpcapi.Node, err error)

GetNodes will get all child nodes for the node id it takes as an argument.

func (*Client) GetNodesWithContext

func (c *Client) GetNodesWithContext(ctx context.Context, parentID string) (nodes []hierarchy_grpcapi.Node, err error)

GetNodesWithContext will get all child nodes for the node id it takes as an argument.

func (*Client) GetParentNode

func (c *Client) GetParentNode(nodeID string) (node hierarchy_grpcapi.Node, err error)

GetParentNode will return the parent of the node id it takes as an argument.

func (*Client) GetParentNodeWithContext

func (c *Client) GetParentNodeWithContext(ctx context.Context, nodeID string) (node hierarchy_grpcapi.Node, err error)

GetParentNodeWithContext will return the parent of the node id it takes as an argument.

func (*Client) GetSubTree added in v1.7.8

func (c *Client) GetSubTree(rootID string, depth int, nodeTypes ...string) (nodes []hierarchy_grpcapi.Node, err error)

GetSubTree will get a subtree rooted at the given node id. The resulting tree is cut off at the given depth. A depth of 0 means no depth limit. GetSubTree returned will be filtered on node types if specified. If node types are left out no filter is applied

func (*Client) GetSubTreeWithContext added in v1.7.8

func (c *Client) GetSubTreeWithContext(ctx context.Context, rootID string, depth int, nodeTypes ...string) (nodes []hierarchy_grpcapi.Node, err error)

GetSubTreeWithContext will get a subtree rooted at the given node id. The resulting tree is cut off at the given depth. A depth of 0 means no depth limit. GetSubTreeWithContext returned will be filtered on node types if specified. If node types are left out no filter is applied

func (*Client) SaveNode

func (c *Client) SaveNode(request hierarchy_grpcapi.SaveNodeInput) (string, error)

SaveNode will add the node if it this not exist and otherwise create it.

Example (Create)
package main

import (
	"log"

	hierarchy_grpcapi "github.com/SKF/proto/hierarchy"

	"github.com/SKF/go-enlight-sdk/services/hierarchy"
)

func main() {
	var client hierarchy.HierarchyClient
	saveNodeInput := hierarchy_grpcapi.SaveNodeInput{
		UserId:   "<user_id>",
		Node:     &hierarchy_grpcapi.Node{},
		ParentId: "<parent_id>",
	}
	nodeID, err := client.SaveNode(saveNodeInput)
	if err != nil {
		log.Printf("Couldn't save node due to error: %+v", err)
		return
	}
	log.Printf("nodeId: %q", nodeID)
}
Output:

Example (Update)
package main

import (
	"log"

	hierarchy_grpcapi "github.com/SKF/proto/hierarchy"

	"github.com/SKF/go-enlight-sdk/services/hierarchy"
)

func main() {
	var client hierarchy.HierarchyClient
	saveNodeInput := hierarchy_grpcapi.SaveNodeInput{
		UserId: "<user_id>",
		Node: &hierarchy_grpcapi.Node{
			Id: "<node_id>",
		},
		ParentId: "<parent_id>",
	}
	nodeID, err := client.SaveNode(saveNodeInput)
	if err != nil {
		log.Printf("Couldn't save node due to error: %+v", err)
		return
	}
	log.Printf("nodeId: %q", nodeID)
}
Output:

func (*Client) SaveNodeWithContext

func (c *Client) SaveNodeWithContext(ctx context.Context, request hierarchy_grpcapi.SaveNodeInput) (string, error)

SaveNodeWithContext will add the node if it this not exist and otherwise create it.

type HierarchyClient

type HierarchyClient interface {
	Dial(host, port string, opts ...grpc.DialOption) error
	DialWithContext(ctx context.Context, host, port string, opts ...grpc.DialOption) error
	Close()

	DeepPing() error
	DeepPingWithContext(ctx context.Context) error

	SaveNode(request hierarchy_grpcapi.SaveNodeInput) (string, error)
	SaveNodeWithContext(ctx context.Context, request hierarchy_grpcapi.SaveNodeInput) (string, error)

	CopyNode(userID, srcNodeID, dstParentNodeID string) (string, error)
	CopyNodeWithContext(ctx context.Context, userID, srcNodeID, dstParentNodeID string) (string, error)

	GetNode(nodeID string) (hierarchy_grpcapi.Node, error)
	GetNodeWithContext(ctx context.Context, nodeID string) (hierarchy_grpcapi.Node, error)

	GetNodes(parentID string) ([]hierarchy_grpcapi.Node, error)
	GetNodesWithContext(ctx context.Context, parentID string) ([]hierarchy_grpcapi.Node, error)

	GetChildNodes(parentID string) ([]hierarchy_grpcapi.Node, error)
	GetChildNodesWithContext(ctx context.Context, parentID string) ([]hierarchy_grpcapi.Node, error)

	GetSubTree(parentID string, depth int, nodeTypes ...string) ([]hierarchy_grpcapi.Node, error)
	GetSubTreeWithContext(ctx context.Context, parentID string, depth int, nodeTypes ...string) ([]hierarchy_grpcapi.Node, error)

	DeleteNode(request hierarchy_grpcapi.DeleteNodeInput) error
	DeleteNodeWithContext(ctx context.Context, request hierarchy_grpcapi.DeleteNodeInput) error

	GetAncestors(nodeID string) ([]hierarchy_grpcapi.AncestorNode, error)
	GetAncestorsWithContext(ctx context.Context, nodeID string) ([]hierarchy_grpcapi.AncestorNode, error)

	GetEventsByCustomer(since int, limit *int32, customerID *string) ([]eventsource.Record, error)
	GetEventsByCustomerWithContext(ctx context.Context, since int, limit *int32, customerID *string) ([]eventsource.Record, error)

	GetEvents(since int, limit *int32) ([]eventsource.Record, error)
	GetEventsWithContext(ctx context.Context, since int, limit *int32) ([]eventsource.Record, error)

	GetParentNode(nodeID string) (hierarchy_grpcapi.Node, error)
	GetParentNodeWithContext(ctx context.Context, nodeID string) (hierarchy_grpcapi.Node, error)

	GetNodeIDByOrigin(origin common.Origin) (string, error)
	GetNodeIDByOriginWithContext(ctx context.Context, origin common.Origin) (string, error)

	GetAssetTaxonomy() (hierarchy_grpcapi.AssetTypes, error)
	GetAssetTaxonomyWithContext(ctx context.Context) (hierarchy_grpcapi.AssetTypes, error)

	GetCompany(nodeID string) (hierarchy_grpcapi.Node, error)
	GetCompanyWithContext(ctx context.Context, nodeID string) (hierarchy_grpcapi.Node, error)
}

HierarchyClient provides the API operation methods for making requests to Enlight Hierarchy Management Service. See this package's package overview docs for details on the service.

func CreateClient

func CreateClient() HierarchyClient

CreateClient creates an instance of the HierarchyClient.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL