# Com / Fujitsu / Futurity / Bp / Custom / Bpm / Kksv0464

## Overview

This module implements the **Service Contract Cancellation (TV)** business process within the K-Opticom customer billing system. It handles the full lifecycle of cancelling a TV-related service contract, including pre-check validation, DSL configuration updates, abnormal reservation queries, and cancellation notice registration. The module is auto-generated from BPMXML (version 2.6) using template version 3.2.0.a and is deployed as a Stateless EJB.

## Key Classes and Interfaces

### [KKSV0464Flow](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0464/KKSV0464Flow.java:58)

**Type:** Stateless EJB (Java class)

The primary entry point and orchestrator for the service contract cancellation process. Annotated with `@Stateless(mappedName="KKSV0464")` and `@TransactionManagement(TransactionManagementType.BEAN)`, this class extends `AbstractService` and implements both `IBPM` and `IOperation`.

The class is a generated dispatcher that wires together:

- **Common pre-processing** (`targetMappingInit`) — delegates to `MappingInitializer.mappingInit` for request validation and setup.
- **Core operation** (`target3`) — delegates to `KKSV0464OPOperation` for the actual cancellation logic.
- **Common post-processing** (`targetMappingDispose`) — delegates to `MappingInitializer.mappingDispose` for cleanup.

The class maintains two static exception-judge-configuration arrays (`exceptionJudgeClassNameMappingInit` and `exceptionJudgeClassNameMappingDispose`), both pointing to `DefaultCCExceptionJudge` as the fallback error handler.

#### Key methods

- **[KKSV0464Flow()](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0464/KKSV0464Flow.java:115)** — No-arg constructor.
- **[run(RequestParameter param)](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0464/KKSV0464Flow.java:129)** — The main process dispatcher. Returns `RequestParameter`.
  - Logs service start and template/BPMXML versions for traceability.
  - Configures the BPM operator with `DefaultDBL` for database lookups and `RandomDBSSelector` for DB system selection.
  - Reads the `operationId` from the request's control header and validates it against `"KKSV0464OP"`. If the ID does not match, it throws a `BPMFlowException` with error code `EL988` and an invalid operation-ID message.
  - Executes the pre-processing stage via `targetMappingInit`, passing DB connection info `"1"`.
  - Executes the core operation (`target3`, i.e. `KKSV0464OPOperation`) with DB code `"FUDB"` resolved via `getDBCode`/`getDBSystem` and connection info `"3"`.
  - Executes the post-processing stage via `targetMappingDispose` with DB connection info `"1"`.
  - Always logs service end in the `finally` block.
- **[getID()](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0464/KKSV0464Flow.java:204)** — Returns the flow identifier string `"KKSV0464Flow"`.

### [KKSV0464OPOperation](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0464/KKSV0464OPOperation.java:60)

**Type:** Java class

The business-logic implementation class that performs the actual steps of the cancellation. Extends `AbstractOperation` and implements `IOperation`. The class uses a series of `ExeCondition` arrays (lazily initialized via singleton pattern) to decide which sub-steps to execute, and `CCRequestBroker` / `ServiceComponentBroker` targets to invoke the downstream components.

The operation is controlled by four execution conditions:

| Condition variable | Condition class | Condition value | Purpose |
|---|---|---|---|
| `execondition1` | `JKKSomeSjishoDataReqChk` | `""` (empty) | Execute the **Notice Registration (TV)** step — registers cancellation notices. |
| `execondition2` | `JKKSV046405ReqChk` | — | Execute the **Pre-Check** step — added by ANK-2079-00-00 to allow immediate cancellation even when a rescheduled cancellation exists. |
| `execondition3` | `JKKDataMapSonzaiReqChk` | `"KKSV046401CC"` | Execute the **Main Cancellation CC** step — added by ANK-2141-00-00 for the STB handover method change. |
| `execondition4` | `JKKDataMapSonzaiReqChk` | `"KKSV046401SC"` | Execute the **Abnormal Reservation List Inquiry SC** step — added by ANK-2141-00-00. |

#### Key methods

- **[KKSV0464OPOperation()](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0464/KKSV0464OPOperation.java:155)** — No-arg constructor.
- **[run(RequestParameter param)](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0464/KKSV0464OPOperation.java:172)** — Executes the cancellation business logic. Returns `RequestParameter`.

  The method follows this execution order:

  1. Logs operation start and template/BPMXML versions.
  2. Resolves all four `ExeCondition` arrays on first access (lazy initialization with null guard).
  3. **Abnormal reservation inquiry** (`execondition4`) — If the condition evaluates to true, runs `target6` (the `異動予約一覧照会SC` ServiceComponent) with DB connection info `"6"`. This step was added in ANK-2141-00-00.
  4. **Pre-check** (`execondition2`) — If true, the method first reads `KKSV046405CC` data from the request to check whether `rsv_cancel_chk_only_flg` is set to `"1"` (a check-only mode). It calls `editRunDslPreChkMap(param)` to prepare the pre-check data map, then runs `target5` (`JKKDslRunCC.runDslPreChk` with `KKSV046405CC`). If `rsv_cancel_chk_only_flg` is `"1"`, it returns early — skipping the main cancellation logic. This early-exit behavior was introduced by ANK-2079-00-00.
  5. **Main cancellation** (`execondition3`) — If true, runs `target3` (`JKKDslRunCC.runDsl` with `KKSV046401CC`) which performs the core DSL cancellation logic.
  6. **Notice registration** (`execondition1`) — If true, runs `target4` (`JKKAddSjishoCC.addSjisho` with `KKSV019502CC`) which registers cancellation notices.
  7. Logs operation end and returns the parameter.

- **[editRunDslPreChkMap(RequestParameter param)](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0464/KKSV0464OPOperation.java:338)** — Prepares the data map for the `KKSV046405CC` pre-check. Extracts the service contract number, calling line code, movement type, service end date, and DSL charge end date from the `KKSV046401CC` data map and copies them into a new `KKSV046405CC` map in the request.

## How It Works

### Cancellation Flow

The following sequence diagram traces a typical cancellation request through the module:

```mermaid
sequenceDiagram
    participant Client
    participant F as FKKSV0464Flow
    participant OP as KKSV0464OPOperation
    participant SC as 異動予約一覧照会SC
    participant CC5 as KKSV046405CC
    participant CC1 as KKSV046401CC
    participant CCNotice as KKSV019502CC
    participant Pre as Pre-processing CC
    participant Post as Post-processing CC

    Client->>F: run(RequestParameter)
    F->>F: Validate operationId == KKSV0464OP
    F->>Pre: MappingInitializer.mappingInit
    Pre-->>F: params
    F->>OP: run(RequestParameter)

    OP->>SC: target6 (Abnormal reservation inquiry)
    SC-->>OP: result
    OP->>OP: check rsv_cancel_chk_only_flg

    alt check-only mode
        OP->>OP: editRunDslPreChkMap
        OP->>CC5: target5 runDslPreChk
        CC5-->>OP: result
        OP-->>F: return early
    else normal cancellation
        OP->>OP: editRunDslPreChkMap
        OP->>CC5: target5 runDslPreChk
        CC5-->>OP: result
        OP->>CC1: target3 runDsl
        CC1-->>OP: result
        OP->>CCNotice: target4 addSjisho
        CCNotice-->>OP: result
        OP-->>F: params
    end

    F->>Post: MappingInitializer.mappingDispose
    Post-->>F: params
    F-->>Client: params
```

### Conditional Execution Model

Rather than executing all steps unconditionally, the operation uses the `ExeConditionReqChk` (`ecrc`) injected via `@Inject` to evaluate each step's pre-condition. Each `ExeCondition` array wraps a single condition class and value pair. This design enables:

- **Feature flags** — Steps can be enabled or disabled by changing which condition classes exist and return true.
- **Check-only mode** — The `rsv_cancel_chk_only_flg` flag (set by `KKSV046405CC`) allows the pre-check to run without performing the actual cancellation, which is useful for validation before committing.
- **Separate DB connections** — Each target uses a distinct DB connection info key (1–6), allowing routing to different databases per step.

### Request-Parameter Data Map

The operation passes data between steps through the `RequestParameter`'s internal data map (accessed via `getData()`/`setData()`). Key keys used in this module:

| Key | Type | Purpose |
|---|---|---|
| `KKSV0464_KKSV0464OP.KKSV046401CC` | `HashMap<String, Object>` | Main cancellation CC data — contains `SVC_KEI_NO`, `KIDO_CD`, `IDO_DIV`, `SVC_ENDYMD`, `SVC_CHRG_ENDYMD`. |
| `KKSV0464_KKSV0464OP.KKSV046405CC` | `HashMap<String, Object>` | Pre-check CC data — populated by `editRunDslPreChkMap`, contains `rsv_cancel_chk_only_flg`. |

## Dependencies and Integration

### Downstream components called

| Target variable | Class | Method / Mapping key | Purpose |
|---|---|---|---|
| `target3` | `JKKDslRunCC` | `runDsl("KKSV046401CC")` | Core DSL cancellation logic |
| `target4` | `JKKAddSjishoCC` | `addSjisho("KKSV019502CC")` | Cancellation notice registration (TV) |
| `target5` | `JKKDslRunCC` | `runDslPreChk("KKSV046405CC")` | Pre-check before cancellation (ANK-2079) |
| `target6` | ServiceComponent | `異動予約一覧照会SC` | Abnormal reservation list inquiry (ANK-2141) |

### Framework dependencies

- **BPM X21 framework** — `AbstractService`, `AbstractOperation`, `IBPM`, `IOperation`, `CCRequestBroker`, `ServiceComponentBroker`, `RequestParameter`, `ExeCondition`, `ExeConditionReqChk`, `DBConnectionInfo`.
- **EJB** — `@Stateless` session bean with bean-managed transactions.
- **DI** — `@Inject` via `com.fujitsu.futurity.bp.x29.di.BeanFactory`.
- **Constants** — `JKKDslRunConstCC`, `KKSV0464_KKSV0464OP`, `KKSV0464_KKSV0464OP_KKSV046401CC` from the `constant` package.

### Package-level dependencies

- `com.fujitsu.futurity.bp.custom.constant` — Constant definitions used by condition checks and data maps.
- `eo.business.service` — Business service layer components.
- `eo.web.webview.KKW12701SF` — Web view / screen flow.
- `com.fujitsu.futurity.bp.custom.common` — Shared CC components (`JKKDslRunCC`, `JKKAddSjishoCC`).
- `eo.business.common` — Common business utilities.

## Class Relationship Diagram

```mermaid
flowchart TD
    subgraph F["KKSV0464Flow"]
        F_RUN["run()"]
        F_PRE["targetMappingInit<br/>Pre-processing"]
        F_OP["target3 → KKSV0464OPOperation"]
        F_POST["targetMappingDispose<br/>Post-processing"]
    end

    subgraph OP["KKSV0464OPOperation"]
        OP_SC["target6 → 異動予約一覧照会SC"]
        OP_PRECHK["target5 → JKKDslRunCC.runDslPreChk<br/>KKSV046405CC"]
        OP_MAIN["target3 → JKKDslRunCC.runDsl<br/>KKSV046401CC"]
        OP_NOTICE["target4 → JKKAddSjishoCC.addSjisho<br/>KKSV019502CC"]
        OP_EDIT["editRunDslPreChkMap()"]
    end

    F_PRE --> F_OP
    F_OP --> OP_SC
    OP_SC --> OP_PRECHK
    OP_PRECHK --> OP_EDIT
    OP_EDIT --> OP_MAIN
    OP_MAIN --> OP_NOTICE
```

## Notes for Developers

### Ticket history and changes

- **ANK-2079-00-00** (2014/06/16, Fujita): Allowed immediate cancellation requests to be submitted even when a rescheduled cancellation already exists. Added `execondition2`, `target5` (`runDslPreChk`/`KKSV046405CC`), the `rsv_cancel_chk_only_flg` check-only mode, and the `editRunDslPreChkMap` helper method.
- **ANK-2141-00-00** (2014/07/31, Ito): Changed the STB handover method. Added `execondition3` for the main cancellation CC and `execondition4` for the abnormal reservation list inquiry ServiceComponent (`target6`).

### Design patterns and conventions

1. **Lazy initialization of conditions** — All `ExeCondition[]` arrays are null-checked and initialized on first access within `run()`. This is a thread-safe singleton pattern (the initialization is cheap and the JVM guarantees the class initializer runs once). In production, consider using explicit synchronization or enum-based initialization if the class is accessed concurrently.

2. **Generated code** — Both classes are marked as `GENERATED BY TEMPLATE VERSION 3.2.0.a`. Modifications are preserved via ticket-marked sections (e.g. `ANK-2079-00-00 ... ADD START/END`). When regenerating from BPMXML, custom code blocks must be preserved or re-applied.

3. **Early-exit for check-only mode** — When `rsv_cancel_chk_only_flg` is `"1"`, the operation skips the main cancellation CC and notice registration entirely. Any downstream code consuming the cancellation result should account for this possibility.

4. **Logging granularity** — The code uses `JSYbpmLog` with multiple log levels (`EXECUTION`, `DEBUG`). Start/end markers include the flow/operation ID and a type string, making it straightforward to trace a request through log files.

5. **DB connection routing** — Each target uses a distinct DB connection info key. The pre/post-processing steps use `"1"`, the main operation uses `"3"` (resolved from `FUDB`), and individual sub-steps use `"4"`, `"5"`, `"6"`. Verify that the DB mapping configuration matches the expected targets.

6. **Exception handling** — The flow wraps errors in `BPMFlowException` and sets `StatusInfo` with `ErrorLevel.EL988` for invalid operation IDs. Each target's `CCRequestBroker` is configured with a default exception judge class. Custom exception handling would require changing the exception judge class arrays.
