🔍 Code Extractor

class NodeLabels

Maturity: 34

A constants class that defines string labels for different node types in a Neo4j graph database schema for a document management system (CDocs).

File:
/tf/active/vicechatdev/CDocs/db/schema_manager.py
Lines:
19 - 39
Complexity:
simple

Purpose

NodeLabels serves as a centralized registry of node type labels used throughout the CDocs document management system. It provides consistent string constants for identifying different entities in the Neo4j graph database, including documents, users, reviews, approvals, and audit trails. This class follows the constants pattern to prevent typos and ensure consistency when creating or querying nodes in the database.

Source Code

class NodeLabels:
    CDOCS = "CDocs"
    CONTROLLED_DOCUMENT = "ControlledDocument"
    DOCUMENT_VERSION = "DocumentVersion"
    REVIEW_CYCLE = "ReviewCycle"
    APPROVAL = "Approval"
    REVIEW_COMMENT = "ReviewComment"
    USER = "User"
    PEOPLE = "People"
    CDOCS_ROLE = "CDocs_Role"
    REVIEWER_ASSIGNMENT = "ReviewerAssignment"
    AUDIT_TRAIL = "AuditTrail"
    AUDIT_EVENT = "AuditEvent"
    APPROVAL_STEP = "ApprovalStep"
    APPROVER = "Approver"
    APPROVAL_WORKFLOW = "ApprovalWorkflow"
    DOCUMENT_COUNTER = "DocumentCounter"
    # New approval cycle related node labels
    APPROVAL_CYCLE = "ApprovalCycle"
    APPROVER_ASSIGNMENT = "ApproverAssignment"
    APPROVAL_COMMENT = "ApprovalComment"

Parameters

Name Type Default Kind
bases - -

Parameter Details

bases: The base classes for NodeLabels. Since no explicit base class is defined, this defaults to 'object'. This parameter is automatically provided by Python's class mechanism and is not user-specified.

Return Value

Instantiating NodeLabels returns a NodeLabels object, though this class is typically used without instantiation by accessing its class-level string constants directly (e.g., NodeLabels.CDOCS). Each attribute returns a string value representing a node label in the Neo4j database.

Class Interface

Attributes

Name Type Description Scope
CDOCS str Label for the root CDocs system node class
CONTROLLED_DOCUMENT str Label for controlled document nodes representing master documents in the system class
DOCUMENT_VERSION str Label for document version nodes representing specific versions of controlled documents class
REVIEW_CYCLE str Label for review cycle nodes representing document review processes class
APPROVAL str Label for approval nodes representing individual approval actions class
REVIEW_COMMENT str Label for review comment nodes containing feedback during document reviews class
USER str Label for user nodes representing system users class
PEOPLE str Label for people nodes representing individuals in the system class
CDOCS_ROLE str Label for role nodes defining user roles and permissions in CDocs class
REVIEWER_ASSIGNMENT str Label for reviewer assignment nodes linking reviewers to review cycles class
AUDIT_TRAIL str Label for audit trail nodes representing audit log containers class
AUDIT_EVENT str Label for audit event nodes representing individual auditable actions class
APPROVAL_STEP str Label for approval step nodes representing stages in an approval workflow class
APPROVER str Label for approver nodes representing users with approval authority class
APPROVAL_WORKFLOW str Label for approval workflow nodes defining approval process templates class
DOCUMENT_COUNTER str Label for document counter nodes used for generating sequential document IDs class
APPROVAL_CYCLE str Label for approval cycle nodes representing document approval processes (newer approval system) class
APPROVER_ASSIGNMENT str Label for approver assignment nodes linking approvers to approval cycles class
APPROVAL_COMMENT str Label for approval comment nodes containing feedback during approval processes class

Usage Example

# NodeLabels is used as a constants class, typically without instantiation
# Access node labels directly from the class

# Example 1: Using in Neo4j query
from CDocs.db import NodeLabels

# Create a node with a specific label
query = f"CREATE (d:{NodeLabels.CONTROLLED_DOCUMENT} {{id: $id, title: $title}})"

# Example 2: Matching nodes by label
query = f"MATCH (u:{NodeLabels.USER}) WHERE u.email = $email RETURN u"

# Example 3: Using multiple labels
query = f"MATCH (d:{NodeLabels.DOCUMENT_VERSION})-[:BELONGS_TO]->(cd:{NodeLabels.CONTROLLED_DOCUMENT}) RETURN d, cd"

# Example 4: Accessing all available labels
all_labels = [
    NodeLabels.CDOCS,
    NodeLabels.CONTROLLED_DOCUMENT,
    NodeLabels.DOCUMENT_VERSION,
    NodeLabels.USER,
    NodeLabels.APPROVAL_CYCLE
]

# Example 5: Using in conditional logic
def get_node_type(label):
    if label == NodeLabels.USER:
        return "User node"
    elif label == NodeLabels.CONTROLLED_DOCUMENT:
        return "Document node"
    return "Unknown node type"

Best Practices

  • Do not instantiate this class - use it as a static constants container by accessing class attributes directly
  • Always use NodeLabels constants instead of hardcoded strings when working with Neo4j node labels to prevent typos
  • Import NodeLabels at the module level for consistent access throughout your code
  • Do not modify these constants at runtime as they represent the database schema
  • When adding new node types to the system, add corresponding constants to this class
  • Use these labels consistently across all database queries, node creation, and relationship definitions
  • Consider this class as the single source of truth for node type naming in the CDocs system

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_node_labels 71.3% similar

    Retrieves all non-private attributes from the NodeLabels class as a dictionary, filtering out attributes that start with underscore.

    From: /tf/active/vicechatdev/CDocs/db/schema_manager.py
  • class RelTypes 65.4% similar

    A constants class that defines string literals representing relationship types used in a graph database (Neo4j) for document management and approval workflows.

    From: /tf/active/vicechatdev/CDocs/db/schema_manager.py
  • function create_node 58.7% similar

    Creates a node in a Neo4j graph database with a specified label and properties, automatically generating a unique ID and timestamp if not provided.

    From: /tf/active/vicechatdev/CDocs/db/db_operations.py
  • class Permission 48.8% similar

    A constants class that defines permission type strings for a document management and review system.

    From: /tf/active/vicechatdev/CDocs/config/permission_types.py
  • function get_database_statistics 48.7% similar

    Retrieves statistical information about a Neo4j graph database, including counts of nodes grouped by label and counts of relationships grouped by type.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
← Back to Browse