julee.domain.use_cases

Use cases for julee domain.

This package contains use case classes that orchestrate business logic for the Capture, Extract, Assemble, Publish workflow while remaining framework-agnostic following Clean Architecture principles.

Submodules

Classes

ExtractAssembleDataUseCase

Use case for extracting and assembling documents according to

InitializeSystemDataUseCase

Use case for initializing required system data on application startup.

ValidateDocumentUseCase

Use case for validating documents against policies.

Package Contents

class julee.domain.use_cases.ExtractAssembleDataUseCase(document_repo, assembly_repo, assembly_specification_repo, knowledge_service_query_repo, knowledge_service_config_repo, knowledge_service, now_fn=lambda : ...)[source]

Use case for extracting and assembling documents according to specifications.

This class orchestrates the business logic for the “Extract, Assemble” phases of the Capture, Extract, Assemble, Publish workflow while remaining framework-agnostic. It depends only on repository protocols, not concrete implementations.

In workflow contexts, this use case is called from workflow code with repository stubs that delegate to Temporal activities for durability. The use case remains completely unaware of whether it’s running in a workflow context or a simple async context - it just calls repository methods and expects them to work correctly.

Architectural Notes:

  • This class contains pure business logic with no framework dependencies

  • Repository dependencies are injected via constructor (dependency inversion)

  • All error handling and compensation logic is contained here

  • The use case works with domain objects exclusively

  • Deterministic execution is guaranteed by avoiding non-deterministic operations

async assemble_data(document_id, assembly_specification_id, workflow_id)[source]

Assemble a document according to its specification and create a new assembly.

This method orchestrates the core assembly workflow:

  1. Generates a unique assembly ID

  2. Retrieves the assembly specification

  3. Stores the initial assembly in the repository

  4. Retrieves all knowledge service queries needed for the assembly

  5. Retrieves all knowledge service instances needed for the assembly

  6. Retrieves the input document and registers it with knowledge services

  7. Performs the assembly iteration to create the assembled document

  8. Adds the iteration to the assembly and returns it

Parameters:
  • document_id (str) – ID of the document to assemble

  • assembly_specification_id (str) – ID of the specification to use

  • workflow_id (str) – Temporal workflow ID that creates this assembly

Returns:

New Assembly with the assembled document iteration

Raises:
  • ValueError – If required entities are not found or invalid

  • RuntimeError – If assembly processing fails

Return type:

julee.domain.models.Assembly

assembly_repo
assembly_specification_repo
document_repo
knowledge_service
knowledge_service_config_repo
knowledge_service_query_repo
now_fn
class julee.domain.use_cases.InitializeSystemDataUseCase(knowledge_service_config_repository, document_repository, knowledge_service_query_repository, assembly_specification_repository)[source]

Use case for initializing required system data on application startup.

This use case ensures that essential configuration data exists in the system, such as knowledge service configurations that are required for the application to function properly.

All operations are idempotent - running this multiple times will not create duplicate data or cause errors.

async execute()[source]

Execute system data initialization.

This method orchestrates the creation of all required system data. It’s idempotent and can be safely called multiple times.

Raises:

Exception – If any critical system data cannot be initialized

assembly_spec_repo
config_repo
document_repo
logger
query_repo
class julee.domain.use_cases.ValidateDocumentUseCase(document_repo, knowledge_service_query_repo, knowledge_service_config_repo, policy_repo, document_policy_validation_repo, knowledge_service, now_fn)[source]

Use case for validating documents against policies.

This class orchestrates the business logic for document validation within the Capture, Extract, Assemble, Publish workflow while remaining framework-agnostic. It depends only on repository protocols, not concrete implementations.

In workflow contexts, this use case is called from workflow code with repository stubs that delegate to Temporal activities for durability. The use case remains completely unaware of whether it’s running in a workflow context or a simple async context - it just calls repository methods and expects them to work correctly.

Architectural Notes:

  • This class contains pure business logic with no framework dependencies

  • Repository dependencies are injected via constructor (dependency inversion)

  • All error handling and compensation logic is contained here

  • The use case works with domain objects exclusively

  • Deterministic execution is guaranteed by avoiding non-deterministic operations

async validate_document(document_id, policy_id)[source]

Validate a document against a policy and return the validation result.

This method orchestrates the core validation workflow:

  1. Generates a unique validation ID

  2. Retrieves the document and policy

  3. Creates and stores the initial validation record

  4. Retrieves all validation queries needed for the policy

  5. Retrieves all knowledge services needed for validation

  6. Registers the document with knowledge services

  7. Executes validation queries and calculates scores

  8. Determines pass/fail and updates validation record

Parameters:
  • document_id (str) – ID of the document to validate

  • policy_id (str) – ID of the policy to validate against

Returns:

DocumentPolicyValidation with validation results

Raises:
  • ValueError – If required entities are not found or invalid

  • RuntimeError – If validation processing fails

Return type:

julee.domain.models.DocumentPolicyValidation

document_policy_validation_repo
document_repo
knowledge_service
knowledge_service_config_repo
knowledge_service_query_repo
now_fn
policy_repo