🔍 Code Extractor

class RelTypes_v1

Maturity: 34

A constants class that defines string constants for relationship types used in a graph database (Neo4j) for a document management system.

File:
/tf/active/vicechatdev/CDocs single class/db/schema_manager.py
Lines:
41 - 84
Complexity:
simple

Purpose

RelTypes serves as a centralized registry of relationship type constants used throughout a document management system built on Neo4j. It organizes relationship types into logical categories (document versioning, workflow management, user relationships, organizational structure, audit trails, approvals, reviews, and comments) to ensure consistency when creating and querying graph database relationships. This class follows the constants pattern and is not meant to be instantiated.

Source Code

class RelTypes:
    # Document relationships
    HAS_VERSION = "HAS_VERSION"
    CURRENT_VERSION = "CURRENT_VERSION"
    PREVIOUS_VERSION = "PREVIOUS_VERSION"
    
    # Workflow relationships
    FOR_REVIEW = "FOR_REVIEW"
    FOR_APPROVAL = "FOR_APPROVAL"
    COMMENTED_ON = "COMMENTED_ON"
    REVIEWED_BY = "REVIEWED_BY"
    APPROVED_BY = "APPROVED_BY"
    
    # User relationships
    AUTHORED_BY = "AUTHORED_BY"
    BELONGS_TO = "BELONGS_TO"
    HAS_ROLE = "HAS_ROLE"
    ROLE_DEFINITION = "ROLE_DEFINITION"
    
    # Organizational relationships
    HAS_TYPE = "HAS_TYPE"
    HAS_DOCUMENT = "HAS_DOCUMENT"
    DIRECTORY = "DIRECTORY"
    
    # Audit relationships
    HAS_EVENT = "HAS_EVENT"
    
    # Assignment relationships
    ASSIGNMENT = "ASSIGNMENT"
    
    # Approval relationships
    HAS_STEP = "HAS_STEP"
    NEXT_STEP = "NEXT_STEP"
    APPROVES = "APPROVES"
    HAS_APPROVER = "HAS_APPROVER"
    DELEGATED_TO = "DELEGATED_TO"
    SUBMITTED_BY = "SUBMITTED_BY"
    
    # Review relationships
    HAS_REVIEWER = "HAS_REVIEWER"
    
    # Comment relationships
    PARENT_COMMENT = "PARENT_COMMENT"
    HAS_REPLY = "HAS_REPLY"

Parameters

Name Type Default Kind
bases - -

Parameter Details

bases: The base classes for RelTypes. Since this is a simple constants class with no explicit inheritance, it implicitly inherits from object. No parameters are needed for instantiation as this class is designed to be used statically.

Return Value

This class is not meant to be instantiated. It serves as a namespace for string constants. Accessing any attribute (e.g., RelTypes.HAS_VERSION) returns a string value representing a relationship type in the graph database.

Class Interface

Attributes

Name Type Description Scope
HAS_VERSION str Relationship indicating a document has a specific version class
CURRENT_VERSION str Relationship pointing to the current active version of a document class
PREVIOUS_VERSION str Relationship linking to the previous version in the version history chain class
FOR_REVIEW str Workflow relationship indicating a document is submitted for review class
FOR_APPROVAL str Workflow relationship indicating a document is submitted for approval class
COMMENTED_ON str Relationship linking a comment to the entity it comments on class
REVIEWED_BY str Relationship indicating which user reviewed a document class
APPROVED_BY str Relationship indicating which user approved a document class
AUTHORED_BY str Relationship linking a document to its author class
BELONGS_TO str Relationship indicating ownership or membership (e.g., user belongs to organization) class
HAS_ROLE str Relationship linking a user to their role class
ROLE_DEFINITION str Relationship defining role properties or permissions class
HAS_TYPE str Relationship indicating the type classification of an entity class
HAS_DOCUMENT str Relationship linking a container (folder, project) to a document class
DIRECTORY str Relationship representing directory/folder structure class
HAS_EVENT str Audit relationship linking an entity to an audit event class
ASSIGNMENT str Relationship indicating task or document assignment class
HAS_STEP str Relationship linking an approval workflow to its steps class
NEXT_STEP str Relationship linking sequential steps in an approval workflow class
APPROVES str Relationship indicating an approval action class
HAS_APPROVER str Relationship linking an approval step to designated approvers class
DELEGATED_TO str Relationship indicating approval or review delegation to another user class
SUBMITTED_BY str Relationship indicating which user submitted a document for approval/review class
HAS_REVIEWER str Relationship linking a review process to designated reviewers class
PARENT_COMMENT str Relationship linking a reply comment to its parent comment class
HAS_REPLY str Relationship linking a comment to its reply comments class

Usage Example

# Import the RelTypes class
from your_module import RelTypes

# Use relationship type constants when creating Neo4j relationships
# Example 1: Creating a document version relationship
relationship_type = RelTypes.HAS_VERSION
query = f"MATCH (d:Document), (v:Version) CREATE (d)-[:{relationship_type}]->(v)"

# Example 2: Using in workflow operations
if relationship == RelTypes.FOR_REVIEW:
    # Handle review workflow
    pass
elif relationship == RelTypes.FOR_APPROVAL:
    # Handle approval workflow
    pass

# Example 3: Querying relationships by type
approval_rel = RelTypes.APPROVED_BY
query = f"MATCH (doc)-[:{approval_rel}]->(user) RETURN user"

# Example 4: Using in relationship creation
from neo4j import GraphDatabase
driver = GraphDatabase.driver("bolt://localhost:7687")
with driver.session() as session:
    session.run(
        f"MATCH (u:User {{id: $user_id}}), (d:Document {{id: $doc_id}}) "
        f"CREATE (u)-[:{RelTypes.AUTHORED_BY}]->(d)",
        user_id="user123",
        doc_id="doc456"
    )

Best Practices

  • Do not instantiate this class - use it as a static constants container by accessing class attributes directly (e.g., RelTypes.HAS_VERSION)
  • Use these constants instead of hardcoded strings when creating or querying Neo4j relationships to ensure consistency across the codebase
  • When adding new relationship types, follow the existing naming convention: use uppercase with underscores and group related relationships together with comments
  • These constants should match exactly with the relationship types defined in your Neo4j database schema
  • Consider using these constants in conjunction with type hints or validation to catch typos at development time
  • Document any new relationship types added to this class with appropriate category comments
  • These relationship types form the core of the graph database schema - changes should be coordinated with database migrations

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class RelTypes 97.3% 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 get_relationship_types 76.9% similar

    Retrieves a dictionary of relationship type constants from the RelTypes class, filtering out private attributes that start with underscore.

    From: /tf/active/vicechatdev/CDocs/db/schema_manager.py
  • class NodeLabels_v1 67.3% similar

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

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

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

    From: /tf/active/vicechatdev/CDocs/db/schema_manager.py
  • class ManualRelationshipManager 54.8% similar

    A class that manages manually defined database relationships with persistent JSON storage, allowing users to add, retrieve, update, and remove relationship definitions between database tables.

    From: /tf/active/vicechatdev/full_smartstat/manual_relationships.py
← Back to Browse