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

## Overview

The `kksv0908` module handles **Individual Discount Applicability Inquiry and Change Request Acceptance** (個別割引適用可否照会・変更依頼受付). It is part of the eo Customer Base System (eo顧客基幹システム) and belongs to the custom BPM (Business Process Management) layer of the Fujitsu Futurity framework.

This module was introduced in version 38.00.00 (2018-06-13) as part of the "eo Light x eo Electric Power x mineo Set Discount"対応 (ANK-3436-00-00), enabling the system to check whether individual discounts apply to a given customer/service and to accept change requests for those discount configurations.

The module follows a standard BPM flow pattern: a stateless session bean orchestrates the business process, delegating the core operation logic to a dedicated operation class, which in turn invokes a common component (CC) that contains the actual business rules.

## Key Classes and Interfaces

### [KKSV0908Flow](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0908/KKSV0908Flow.java)

A `@Stateless` EJB that acts as the **service flow controller** for the discount applicability inquiry and change request process. It extends `AbstractService` and implements both `IBPM` and `IOperation`.

#### Role in the system

`KKSV0908Flow` is the entry point for this business process. It does not contain business logic itself — instead, it orchestrates three phases:

1. **Common pre-processing** (pre-hook) — runs shared initialization/mapping logic.
2. **Core operation** — delegates to `KKSV0908OPOperation` for the actual discount applicability logic.
3. **Common post-processing** (post-hook) — runs shared cleanup/teardown logic.

This three-phase pattern is standard across the BPM framework and ensures that shared concerns (logging, transaction setup, common mappings) are handled consistently.

#### Key methods

- **`KKSV0908Flow()`** (constructor) — No-arg constructor. The flow instance is managed by the EJB container as a `@Stateless` bean.

- **`run(RequestParameter param)`** — The main entry method. This is where the orchestrator does its work:
  1. Logs service start and template/BPMXML version numbers.
  2. Configures the BPM operator with a `DefaultDBL` (database lookup handler) and a `RandomDBSSelector` (database selection strategy).
  3. Extracts the `operationId` from the request's control header.
  4. Validates that `operationId` equals `"KKSV0908OP"`. If not, sets a `StatusInfo` error (EL988, UNKNOWN area) and throws `BPMFlowException`.
  5. Runs the **pre-processing** phase via `targetMappingInit` (a `CCRequestBroker` pointing to `MappingInitializer.mappingInit`).
  6. Runs the **core operation** via `target1` — an `OperationBroker` that delegates to `KKSV0908OPOperation`. It resolves the database code via `getDBCode(param, "FUDB")` and `getDBSystem()`.
  7. Runs the **post-processing** phase via `targetMappingDispose` (a `CCRequestBroker` pointing to `MappingInitializer.mappingDispose`).
  8. Always logs the service end in a `finally` block, ensuring cleanup logging even on failure.
  9. Returns the (potentially modified) `RequestParameter`.

- **`getID()`** — Returns `"KKSV0908Flow"`. Used for identification in logs and BPM framework routing.

#### Exception handling

Exception judgment for both pre-processing and post-processing phases uses the `DefaultCCExceptionJudge` class, meaning exceptions are handled in a standard, non-custom way through the common component layer.

### [KKSV0908OPOperation](source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0908/KKSV0908OPOperation.java)

A BPM operation class that extends `AbstractOperation` and implements `IOperation`. This is the **operation-level delegate** that performs the actual work of the discount applicability inquiry and change request.

#### Role in the system

`KKSV0908OPOperation` sits between the flow controller and the common component. It is the second level of the delegation chain:

```
KKSV0908Flow → KKSV0908OPOperation → JKKKbtWrbaplKhShokaiChgReqCC
```

Its `run()` method configures and executes a single `CCRequestBroker` (`target1`) that invokes:

- **Common Component**: `com.fujitsu.futurity.bp.custom.common.JKKKbtWrbaplKhShokaiChgReqCC`
- **CC Method**: `khShokaiChgReq`
- **CC Target Name**: `KKSV090801CC`

This common component name (`JKKKbtWrbaplKhShokaiChgReqCC`) translates roughly to "Individual Discount Applicability Inquiry/Change Request Common Component," confirming that the actual business logic for evaluating discount eligibility resides outside this package in the shared `bp.custom.common` layer.

#### Key methods

- **`KKSV0908OPOperation()`** (constructor) — No-arg constructor, operation instances are managed by the BPM framework.

- **`run(RequestParameter param)`** — The operation entry point:
  1. Logs operation start with DEBUG level.
  2. Configures the `CCRequestBroker` (`target1`) with the bean factory and BPM operator.
  3. Creates a `DBConnectionInfo` with the `FUDB` database code (from context) — note that the `isCreate` flag is `false`, meaning the operation expects an existing database connection rather than creating a new one.
  4. Executes `target1.run()`, which invokes `JKKKbtWrbaplKhShokaiChgReqCC.khShokaiChgReq()`.
  5. Logs operation end.
  6. Returns the modified `RequestParameter`.

## How It Works

### Request Flow

Here is the step-by-step flow for a single request through this module:

```mermaid
flowchart TD
    subgraph F ["KKSV0908Flow (Service Flow)"]
        START(["Request Arrives"])
        CHECK{"operationId ==
KKSV0908OP?"}
        PREPROC["Pre-processing
MappingInitializer
mappingInit"]
        OP["KKSV0908OPOperation.run"]
        POSTPROC["Post-processing
MappingInitializer
mappingDispose"]
        END(["Return
RequestParameter"])

        START --> PREPROC
        PREPROC --> CHECK
        CHECK -- Yes --> OP
        OP --> POSTPROC
        POSTPROC --> END
        CHECK -- No --> ERROR["Set EL988 error
Throw BPMFlowException"]
        ERROR --> END
    end

    subgraph OP["KKSV0908OPOperation (Operation)"]
        SUB1["CCRequestBroker
→ JKKKbtWrbaplKhShokaiChgReqCC
→ khShokaiChgReq"]
    end

    OP --> SUB1
```

1. **Service start**: The flow logs execution start and version info.
2. **Pre-processing**: The `MappingInitializer.mappingInit` common component runs shared pre-processing (mapping setup, initialization).
3. **Operation dispatch**: The `OperationBroker` delegates to `KKSV0908OPOperation.run()`.
4. **Common component invocation**: `KKSV0908OPOperation` calls `JKKKbtWrbaplKhShokaiChgReqCC.khShokaiChgReq()` — this is where the actual discount applicability check logic resides.
5. **Post-processing**: The `MappingInitializer.mappingDispose` common component runs shared post-processing (cleanup, response mapping).
6. **Service end**: The flow logs completion.

### Error Handling

- If the `operationId` in the request header is anything other than `"KKSV0908OP"`, the flow immediately sets a `StatusInfo` with error level `EL988` in the `UNKNOWN` outbreak area and throws a `BPMFlowException` with a descriptive message.
- Database and validation exceptions (`DBLookupException`, `DBSystemException`, `ReqChkException`) propagate through the flow and are caught by the BPM framework's exception handling infrastructure.

## Data Model

This module does not define its own data model classes. Instead, it works exclusively with the BPM framework's `RequestParameter` object, which carries:

- **Control header**: Contains metadata such as `operationId`.
- **Status area**: Holds `StatusInfo` objects for error reporting (e.g., error level `EL988`, outbreak area).
- **Business data**: The actual customer/discount data passed to and from the common component.

The `DBConnectionInfo` object is used to manage database connectivity, specifying the database code (`"FUDB"`) and connection parameters.

## Dependencies and Integration

### Internal dependencies

- `eo.business.service` and `eo.business.common` — the broader service and common packages that provide the BPM framework infrastructure.
- `com.fujitsu.futurity.bp.x21.bpm.*` — the Futurity BPM framework (v3.2.0.a, BPMXML v2.6), including:
  - `AbstractService` / `AbstractOperation` — base classes for flow and operation beans.
  - `RequestParameter` — the request/response envelope.
  - `CCRequestBroker` / `OperationBroker` — delegation mechanisms.
  - `DBConnectionInfo`, `DBLookupException`, `DBSystemException` — database connectivity and error handling.
  - `ReqChkException` — request validation errors.
  - `StatusInfo`, `ErrorLevel`, `OUTBREAK_AREA` — error reporting structures.
- `com.fujitsu.futurity.bp.custom.common.JKKKbtWrbaplKhShokaiChgReqCC` — the shared common component that contains the actual business logic (outside this package).
- `com.fujitsu.futurity.bp.custom.mapping.BpOperationMapping` — the operation mapping configuration used by the `OperationBroker`.

### External-facing contract

The module exposes itself as a stateless EJB mapped as `"KKSV0908"`, making it available for invocation through the EJB container. The entry point is the `run(RequestParameter)` method, which follows the standard BPM framework interface.

## Notes for Developers

- **Template-generated code**: Both classes are generated from BPM XML (template version 3.2.0.a, BPMXML version 2.6). If you need to regenerate them, the source BPM XML definition drives the code generation — direct edits to these files will be overwritten.
- **Business logic location**: The actual discount applicability logic lives in the common component `JKKKbtWrbaplKhShokaiChgReqCC.khShokaiChgReq` (package `com.fujitsu.futurity.bp.custom.common`). To understand the business rules, look at that common component class.
- **Database routing**: The flow uses `RandomDBSSelector` for load-balanced database selection and `DefaultDBL` for database lookups. The specific database code is `"FUDB"`.
- **Error codes**: Error level `EL988` in the `UNKNOWN` outbreak area indicates an invalid operation ID — this is a flow-level routing error.
- **Transaction management**: The flow bean uses `@TransactionManagement(TransactionManagementType.BEAN)`, meaning transactions are explicitly managed rather than container-managed.
