🔍 Code Extractor

class RelTypes

Maturity: 36

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

File:
/tf/active/vicechatdev/CDocs/db/schema_manager.py
Lines:
42 - 68
Complexity:
simple

Purpose

RelTypes serves as a centralized registry of relationship type constants used throughout a document management system. These constants represent edges/relationships in a Neo4j graph database, defining connections between nodes such as documents, versions, users, approvals, comments, roles, and workflow steps. Using this class ensures consistency in relationship naming across the codebase and prevents typos when creating or querying graph relationships.

Source Code

class RelTypes:
    HAS_VERSION = "HAS_VERSION"
    CURRENT_VERSION = "CURRENT_VERSION"
    PREVIOUS_VERSION = "PREVIOUS_VERSION"
    FOR_REVIEW = "FOR_REVIEW"
    FOR_APPROVAL = "FOR_APPROVAL"
    COMMENTED_ON = "COMMENTED_ON"
    AUTHORED_BY = "AUTHORED_BY"
    BELONGS_TO = "BELONGS_TO"
    REVIEWED_BY = "REVIEWED_BY"
    APPROVED_BY = "APPROVED_BY"
    HAS_TYPE = "HAS_TYPE"
    DIRECTORY = "DIRECTORY"
    HAS_ROLE = "HAS_ROLE"
    ROLE_DEFINITION = "ROLE_DEFINITION"
    HAS_DOCUMENT = "HAS_DOCUMENT"
    HAS_EVENT = "HAS_EVENT"
    ASSIGNMENT = "ASSIGNMENT"
    HAS_STEP = "HAS_STEP"
    NEXT_STEP = "NEXT_STEP"
    APPROVES = "APPROVES"
    DELEGATED_TO = "DELEGATED_TO"
    SUBMITTED_BY = "SUBMITTED_BY"
    HAS_APPROVER = "HAS_APPROVER"
    # New approval cycle related relationship types
    APPROVAL_ASSIGNMENT = "APPROVAL_ASSIGNMENT"
    COMMENT_BY = "COMMENT_BY"

Parameters

Name Type Default Kind
bases - -

Parameter Details

bases: The base classes for RelTypes. 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 RelTypes returns a RelTypes object, though this class is designed to be used as a namespace for constants rather than being instantiated. The class attributes (relationship type strings) are accessed directly via the class name (e.g., RelTypes.HAS_VERSION) without creating instances.

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 a previous version in version history class
FOR_REVIEW str Relationship indicating a document is assigned for review class
FOR_APPROVAL str Relationship indicating a document is assigned for approval class
COMMENTED_ON str Relationship linking a user to a document they commented on class
AUTHORED_BY str Relationship linking a document to its author class
BELONGS_TO str Relationship indicating ownership or membership (e.g., document belongs to a project) class
REVIEWED_BY str Relationship linking a document to a user who reviewed it class
APPROVED_BY str Relationship linking a document to a user who approved it class
HAS_TYPE str Relationship linking an entity to its type classification class
DIRECTORY str Relationship indicating directory/folder structure class
HAS_ROLE str Relationship linking a user to their role class
ROLE_DEFINITION str Relationship linking to role definition or permissions class
HAS_DOCUMENT str Relationship indicating an entity contains or references a document class
HAS_EVENT str Relationship linking to an event or audit log entry class
ASSIGNMENT str Relationship indicating a task or document assignment class
HAS_STEP str Relationship linking a workflow to its steps class
NEXT_STEP str Relationship linking sequential workflow steps class
APPROVES str Relationship indicating approval action or permission class
DELEGATED_TO str Relationship indicating delegation of responsibility to another user class
SUBMITTED_BY str Relationship linking a document to the user who submitted it class
HAS_APPROVER str Relationship linking to a designated approver class
APPROVAL_ASSIGNMENT str Relationship for approval cycle assignment tracking class
COMMENT_BY str Relationship linking a comment to the user who made it class

Usage Example

# RelTypes is used as a constants namespace, not instantiated
# Access relationship types directly from the class

# Example 1: Creating a relationship in Neo4j
from neo4j import GraphDatabase

# Use RelTypes constants when creating relationships
relationship_type = RelTypes.HAS_VERSION
query = f"MATCH (d:Document), (v:Version) WHERE d.id = $doc_id AND v.id = $ver_id CREATE (d)-[:{relationship_type}]->(v)"

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

# Example 3: Using in workflow logic
if relationship_type == RelTypes.FOR_APPROVAL:
    # Handle approval workflow
    pass
elif relationship_type == RelTypes.FOR_REVIEW:
    # Handle review workflow
    pass

# Example 4: Building dynamic queries
rel_types = [RelTypes.REVIEWED_BY, RelTypes.APPROVED_BY, RelTypes.COMMENTED_ON]
for rel in rel_types:
    query = f"MATCH (doc)-[:{rel}]->(user) RETURN user"
    # Execute query

Best Practices

  • Do not instantiate this class - use it as a static namespace by accessing class attributes directly (e.g., RelTypes.HAS_VERSION)
  • Always use these constants instead of hardcoded strings when working with Neo4j relationships to ensure consistency
  • These relationship types should match the relationship types defined in your Neo4j database schema
  • Consider using these constants in both Cypher query construction and relationship validation logic
  • If adding new relationship types, follow the existing naming convention: uppercase with underscores
  • Document the semantic meaning of each relationship type in your system documentation, as the class itself has no docstrings
  • These constants are immutable by convention - do not reassign their values at runtime
  • When refactoring relationship names in the database, update these constants and search for all usages across the codebase

Similar Components

AI-powered semantic similarity - components with related functionality:

  • 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 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
  • function create_references_medicationtypes_relationship 53.9% similar

    Creates a REFERENCES_MEDICATIONTYPES relationship in a Neo4j graph database between a Parameter_MedicationTypeProperties node and a Parameter_MedicationTypes node, with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_references_sampletypes_relationship 53.3% similar

    Creates a directed REFERENCES_SAMPLETYPES relationship in a Neo4j graph database from a LIMS_SampleTypeTests node to a LIMS_SampleTypes node, with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • class ManualRelationshipManager 53.2% 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