# Com / Optage / Kopt / Bp

## Overview

The `com.optage.kopt.bp` module is a subpackage of the broader `com.optage.kopt` batch processing system. It handles SOD (complaints/complaints processing) dispatch and coordination logic, including dispatching SOD records, validating them against batch rules, and formatting data. This module acts as a thin orchestration layer — the core business logic for validation and sending is delegated to classes in sibling packages (`com.optage.kopt.batch`, `com.optage.kopt.ekk`).

## Key Classes and Interfaces

### `JKKHakkoSODCC` — Main Orchestrator

This is the central entry point for SOD issuance ("hakko") operations. It coordinates the dispatch and validation steps needed to process complaints records.

**Key methods:**

- **`dispatch()`** — Initiates the SOD dispatch flow by instantiating [`JKKSodSendCC`](#jkksodsendcc--dispatch-logic) and invoking its `send()` method. This is the primary outbound action: it creates a fresh `JKKSodSendCC` instance on each call (no shared state), then delegates to it.

- **`validate()`** — Runs the validation step by instantiating [`KKPRC14901`](../batch.md#kkprc14901--batch-check) (a class in the `com.optage.kopt.batch` package) and calling its `check()` method. Like `dispatch()`, it creates a new instance per call rather than reusing state.

**Design note:** Both methods follow a "create-then-delegate" pattern, instantiating collaborators on each invocation. This means the class is stateless between calls and each invocation is self-contained.

```java
public void dispatch() { new JKKSodSendCC().send(); }
public void validate() { new KKPRC14901().check(); }
```

### `JKKSodSendCC` — Dispatch Logic

Responsible for the actual SOD dispatch/sending operations. The `send()` method encapsulates the logic for transmitting or processing SOD records to downstream systems.

**Key methods:**

- **`send()`** — Executes the SOD dispatch logic. The method body contains the core dispatch implementation. It is always called through a freshly instantiated `JKKSodSendCC` object (see `JKKHakkoSODCC.dispatch()`).

This class is instantiated and consumed inline — it has no constructor parameters and is not designed to be stored or reused.

### `JKKHakkoSODHelper` — String Formatting Utility

A small utility class providing helper methods for SOD-related data formatting. Currently exposes a single method:

- **`format(String input)`** — Trims whitespace from the input string and returns the result. This is used to normalize text fields (such as complaint descriptions or reference codes) before they are passed to dispatch or validation logic.

```java
public String format(String input) { return input.trim(); }
```

**Note:** The current implementation is minimal (`String.trim()`). This is an extension point — additional formatting logic (e.g., encoding, date formatting, field truncation) can be added here as SOD data requirements evolve.

### `JKKBpServiceBase` — Shared Initialization

A base class providing common initialization logic for SOD-related services.

**Key methods:**

- **`baseInit()`** — A `protected` method that performs shared initialization. Because it is `protected`, subclasses (in this or other packages) can override or extend it to inject common setup steps such as loading configuration, establishing database connections, or initializing logging. Currently the body contains a placeholder comment (`/* shared init */`).

The naming suggests this class is designed to be extended by other service classes within the `bp` namespace, promoting code reuse for initialization patterns shared across SOD complaint processing workflows.

### `JKKHakkoSODCCTest` — Unit Tests

The JUnit test class for this module. It resides in `src/test/java` and currently provides a basic test scaffold:

- **`testMain()`** — A placeholder test using `assertTrue(true)`. This method is intended to serve as a starting point for unit tests covering `JKKHakkoSODCC` behavior — specifically the `dispatch()` and `validate()` flows.

```java
@Test
public void testMain() {
    assertTrue(true);
}
```

## How It Works

### SOD Issuance Flow

A typical SOD issuance ("hakko") operation flows through `JKKHakkoSODCC` as follows:

```mermaid
flowchart LR
    HAKKO["JKKHakkoSODCC"] -->|dispatch()| SEND["JKKSodSendCC.send()"]
    HAKKO -->|validate()| CHECK["KKPRC14901.check()"]
    HAKKO -->|format()| HELPER["JKKHakkoSODHelper.format()"]
    HAKKO -.->|extends base of| BASE["JKKBpServiceBase"]
    HAKKO -->|tested by| TEST["JKKHakkoSODCCTest"]
```

1. **Initialization:** A consumer (e.g., a batch job or scheduled task) instantiates `JKKHakkoSODCC` — optionally after calling inherited `baseInit()` from `JKKBpServiceBase`.

2. **Validation:** `validate()` is called first, delegating to `KKPRC14901.check()` in the `com.optage.kopt.batch` package. This class performs the actual business rule validation against complaint records.

3. **Formatting (optional):** Before or during dispatch, `JKKHakkoSODHelper.format()` can be used to normalize any text fields — currently just trimming whitespace.

4. **Dispatch:** `dispatch()` delegates to `JKKSodSendCC.send()`, which handles the actual outbound transmission of the validated SOD record.

### Design Patterns Used

- **Create-on-Call:** `JKKHakkoSODCC` creates new instances of its collaborators (`JKKSodSendCC`, `KKPRC14901`) inline rather than injecting them. This makes the orchestrator simple and stateless, but means no state is shared between calls.

- **Delegation:** The `bp` package acts as a facade — the heavy lifting (validation, actual send logic) is done by classes in other packages (`batch`, and likely `ekk` for downstream processing).

- **Base-class inheritance:** `JKKBpServiceBase` provides a common initialization hook via `baseInit()`, enabling consistent setup across SOD service implementations.

## Data Model

This module does not define its own data classes. It operates on complaint/SOD records using the DTOs from the sibling `com.optage.kopt.dto` package:

- **[`JKKSodRequestDTO`](../dto.md)** — Carries inbound SOD data with fields like `tenantId` and `serviceId`.
- **[`JKKSodResponseDTO`](../dto.md)** — Carries outbound results with `status` and `message` fields.

The `bp` module transforms and dispatches these records through the validation and send pipeline.

## Dependencies and Integration

### Internal Dependencies

| Dependency | Package | Role |
|---|---|---|
| `KKPRC14901` | `com.optage.kopt.batch` | Validation — called by `JKKHakkoSODCC.validate()` |
| `JKKSodRequestDTO` / `JKKSodResponseDTO` | `com.optage.kopt.dto` | Data transfer objects used across the kopt system |
| `EKK0301A010` | `com.optage.kopt.ekk` | Downstream processing — called by `KKPRC14901.run()` |

### External Dependencies

- **JUnit** — Used in `JKKHakkoSODCCTest` for unit testing.

### Integration Points

- **Upstream:** The `bp` module is the leaf of the `com.optage.kopt` package hierarchy — it has no child subpackages. External callers (e.g., batch schedulers, REST controllers in other modules) interact with it through `JKKHakkoSODCC`.

- **Downstream:** Dispatched SOD records flow through `JKKSodSendCC.send()` to downstream systems (the actual transport mechanism is encapsulated within that method).

## Notes for Developers

- **This is a fixture/stub module.** The classes in this package are auto-generated fixture classes for `SPEC-SCOPED-WIKI` tests. The implementations are minimal placeholders. When integrating this documentation into a real codebase, replace the placeholder descriptions with actual business logic details.

- **Stateless orchestrator:** `JKKHakkoSODCC` does not hold state between calls. If you need to share configuration or context across `dispatch()` and `validate()`, consider adding instance fields or using dependency injection.

- **Extension point:** `JKKHakkoSODHelper.format()` is a clear place to add new formatting logic. As SOD data requirements grow (date formats, special characters, multi-line text), this helper is the natural home for normalization.

- **Base class purpose:** If you are adding new service classes that share initialization steps, extend `JKKBpServiceBase` and call or override `baseInit()` rather than duplicating setup code.

- **Test coverage:** `JKKHakkoSODCCTest.testMain()` is a stub. New tests should cover:
  - That `dispatch()` correctly delegates to `JKKSodSendCC.send()`
  - That `validate()` correctly delegates to `KKPRC14901.check()`
  - That `JKKHakkoSODHelper.format()` trims whitespace as expected
