# KKW00810SFLogic

## Purpose

`KKW00810SFLogic` is the web-page business logic controller for the **Fixed Global IP Address Information Registration** screen (KKW00810) in the K-Opticom customer contract system. It orchestrates a three-step registration wizard — **Input → Confirm → Complete** — that allows an operator to register a fixed global IP address for a service contract. The class fetches existing IP data via a backend service, presents it for review, and persists the registration by calling a second service with all supporting contract details.

## Design

`KKW00810SFLogic` follows the standard **Web Business Logic** pattern used throughout the Fujitsu Futurity X31 web framework. It extends `JCCWebBusinessLogic` and acts as a **screen controller / facade** for the three-page flow:

1. **KKW00810** — Initial input screen (displays fetched fixed IP address, netmask, subscription number, etc.)
2. **KKW00811** — Confirmation screen (shows a summary before final registration)
3. **KKW00812** — Completion screen (displays success and navigates away)

The class coordinates between two backend services:

- **KKSV0022 / KKSV0022OP** — Fetches existing fixed global IP address information from the database.
- **KKSV0023 / KKSV0023OP** — Registers the fixed global IP address along with all related contract details.

## Class Diagram

```mermaid
flowchart TD
    XML1["WEBGAMEN_KKW008100PJP"] --> CLS["KKW00810SFLogic"]
    XML2["WEBGAMEN_KKW008110PJP"] --> CLS
    XML3["WEBGAMEN_KKW008120PJP"] --> CLS
    XML4["x31business_logic_KKW00810SF"] --> CLS
    CLS --> PARENT["JCCWebBusinessLogic"]
    CLS --> SVC1["KKSV0022 Service
(IP lookup)"]
    CLS --> SVC2["KKSV0023 Service
(IP registration)"]
```

## Key Methods

### `action_Init()` → boolean

**The main entry point.** Dispatches to one of three initializers depending on the target screen ID stored in the common info bean:

- If the next screen is `KKW00810`, it calls `actionInitKKW00810()` (the full data-fetch flow).
- If the next screen is `KKW00811`, it calls `actionInitKKW00811()`.
- If the next screen is `KKW00812`, it calls `actionInitKKW00812()`.

This method is invoked by the framework at the start of every request to the three screens. It is the central switchboard for the wizard flow.

### `actionInitKKW00810()` → boolean

The core initialization method for the **input screen** (KKW00810). Performs the following sequence:

1. Retrieves the `X31SDataBeanAccess` service form bean.
2. Calls `JCCWebCommon.getScreenInfo(this)` to load screen-level metadata into the logic instance.
3. Calls `initServiceFormBean(svcFormBean)` to copy inheritance context (customer contract info, disconnection reasons, etc.) from incoming data into the service form.
4. Builds three `HashMap<String, Object>` containers: `paramMap` (service invocation parameters including `SVC_ID_KKSV0022` and `OP_ID_KKSV0022OP`), `inputMap`, and `outputMap`.
5. Creates a `KKSV0022_KKSV0022OPDBMapper` and populates `inputMap` by calling `mapper.setKKSV002201CC(paramBean, inputMap, JPCModelConstant.FUNC_CD_1)` to map the form bean into service parameters.
6. Calls `invokeService(paramMap, inputMap, outputMap)` to execute the backend KKSV0022 service, which looks up the fixed global IP address from the database.
7. Calls `mapper.getKKSV002201CC(paramBean, outputMap)` to copy the service response back into the form bean.
8. Checks for a search error flag from service `KKSV041307SC` — if an error exists, sets an informational message ("Fixed IP Address") with error code `EKB5470_KW`.
9. Calls `editServiceFormBean(svcFormBean)` to extract the fixed IP address and netmask from the nested data bean array and copy them into top-level form fields (year, month, day for the service start date).

Returns `true` to indicate successful initialization.

### `editServiceFormBean(X31SDataBeanAccess svcFormBean)` → void

A private helper that post-processes the data returned by the KKSV0022 service call. It:

1. Reads the fixed IP address from the first element of the `FIXIPAD_HRADSI_LIST` nested bean array.
2. Reads the netmask from `NETMASK_02` of the same bean.
3. Extracts the current operation date (`unyo_ymd`) and splits it into year, month, and day components.
4. Sets the IP address (`KOTEI_IP_AD`), netmask (`SUBNET_MASK`), service start date fields (`USE_STAYMD_YEAR`, `USE_STAYMD_MON`, `USE_STAYMD_DAY`), service subscription number (`SVC_KEI_KAISEN_UCWK_NO`), service subscription internal number (`SVC_KEI_UCWK_NO`), registration timestamp (`KK0161_GENE_ADD_DTM`), and service subscription status (`SVC_KEI_UCWK_STAT`) on the form bean.

This method is the bridge between the raw database result and the screen-display format.

### `initServiceFormBean(X31SDataBeanAccess svcFormBean)` → void

Called during input screen initialization, this method populates the service form bean with **inheritance context** data carried over from the previous screen (typically the service contract selection screen). It:

1. Sets the operation date (`UNYO_YMD`) from `JCCWebCommon.getOpeDate(this, null)`.
2. Extracts the customer contract inheritance list (`CUST_KEI_HKTGI_LIST`) from the form bean and reads the first element.
3. Copies key fields: `SYSID`, `IDO_DIV` (disconnection classification), and `SVC_KEI_NO` (service contract number).
4. Copies disconnection reason codes (`IDO_RSN_CD_01`) and the disconnection reason memo (`IDO_RSN_MEMO_01`) into the `EKK1091D010CBSMSG1LIST` data bean array (the progression registration S-IF disconnection detail structure).
5. The disconnection memo is applied to all reason entries (the same memo is duplicated across all disconnection reason rows).

This ensures the backend services receive the full context of the customer contract being modified.

### `doRegistFixedIPAddressOption(String func_code)` → void

The **central service invocation method**. Called by both `action_Cfm()` (registration button on input screen) and `action_Fix()` (confirmation button on confirmation screen). It:

1. Calls `configServiceFormBean(svcFormBean)` to prepare all fields needed for the KKSV0023 registration service (see below).
2. Sets up the service parameter map with `SVC_ID_KKSV0023` and `OP_ID_KKSV0023OP`.
3. Creates a `KKSV0023_KKSV0023OPDBMapper` and chains multiple mapper method calls to populate the `inputMap` with all contract-related data:
   - `setJKKGlobalIpAddCfmCC()` — the IP address confirmation registration unit (the only mapper call that is active; all others are commented out since the v7.00 modularization).
4. Calls `invokeService(paramMap, inputMap, outputMap)` to execute the KKSV0023 service.
5. Calls `mapper.getKKSV002304SC(paramBean, outputMap)` to retrieve the registration application number (`MSKM_NO`).
6. Calls `mapper.getKKSV002310SC(paramBean, outputMap)` to retrieve the progression registration number.
7. If the function code is `FUNC_CD_1` (confirmation mode), extracts any discount service auto-application messages (`WrisvcAutoAplyCC.msg_list`) and stores them in the session via `JKKSetSessionMessage.setSessionMessage(this, msgList)`.

The `func_code` parameter distinguishes between:
- `FUNC_CD_1` (1) — Confirmation (actual registration). Used by `action_Fix()`.
- `FUNC_CD_2` (2) — Input screen registration button (pre-registration display). Used by `action_Cfm()`.

### `configServiceFormBean(X31SDataBeanAccess svcFormBean)` → void

A private helper that populates the service form bean with **all fields required for the KKSV0023 registration service call**. This is the most comprehensive field-preparation method in the class. It:

1. Retrieves the fixed IP address consent detail bean (`FIXIPAD_HRADSI_LIST`) from the form bean.
2. Gets the operation date (`unyo_ymd`) and constructs the operation date-time (`unyo_dtm`) by appending the system timestamp (hhmmssSSS format) to the date.
3. Parses the service start date from the form bean (year/month/day strings → YYYYMMDD format) and sets:
   - `USE_STA_YMD` — service start date
   - `USE_STA_DTM` — service start date-time (appends `000000000`)
   - `CHRG_STA_YMD` — billing start date (same as service start date)
   - `UNYO_YMD` / `UNYO_DTM` — operation date and date-time
4. Copies fields from the fixed IP address bean:
   - `SHYAKK_CD` — contract office code
   - `KOTEI_IP_STKU_SBT_CD` — fixed IP acquisition type code
   - `USE_CNT` — usage count (incremented by 1 from the form bean value)
   - `ZM0101_UPD_DTM` — ZM0101 update date-time
5. Sets hardcoded/mapped constants:
   - `MSKM_SBT_CD` — application type code (value `00026`)
   - `OP_SVC_CD` — operation service code (value `0040`)
   - `PCRS_CD` — provider code (constant `PCRS_CD_B04`)
   - `PPLAN_CD` — price plan code (constant `PB0401` — Fixed Global IP Address)
   - `OYA_KEI_SKBT_CD` — parent contract identifier code (value `03` — Service Contract Internal Details, modified from `01` in OT-2013-0000223)
6. Adds a data bean to `EKK0011D020CBSMSG1LIST` with application form code (`""`) and detail codes.
7. Determines `PRG_STAT` (progression status):
   - If the operation date equals the service start date → `5102` (Option settings complete).
   - Otherwise → `5101` (Option information application in progress).
8. Sets `PRG_TKJK_1` (progression special item 1) to `"固定グローバルIPアドレス情報登録"` (Fixed Global IP Address Information Registration) — added in ANK-1223-00-00.

### `action_Cfm()` → boolean

Called when the user clicks the **Registration (登録)** button on the KKW00810 input screen. Performs:

1. Calls `doRegistFixedIPAddressOption(JPCModelConstant.FUNC_CD_2)` — pre-registration call (display mode).
2. Sets the next screen to `KKW00811` (confirmation screen) in the common info bean.
3. Displays an informational message: `"Fixed Global IP Addressの登録"` (Registration of Fixed Global IP Address) with message code `EKB0370__I`.
4. Dumps the DataBean state to the log for debugging.
5. Returns `true` to proceed to the next screen.

Note: Despite the method name "Cfm" (confirm), this is the button on the *input* screen that transitions to the *confirmation* screen. The actual data registration happens on `action_Fix()`.

### `action_Fix()` → boolean

Called when the user clicks the **Confirm (確定)** button on the KKW00811 confirmation screen. Performs:

1. Calls `doRegistFixedIPAddressOption(JPCModelConstant.FUNC_CD_1)` — actual registration call.
2. Sets the next screen to `KKW00812` (completion screen) in the common info bean.
3. Displays an informational message: `"Fixed Global IP Addressの登録"` with message code `EKB4390__I` (indicating successful registration).
4. Dumps the DataBean state to the log.
5. Returns `true` to proceed.

### `action_Syuse()` → boolean

Called when the user clicks the **Correction (修正)** button on the KKW00811 confirmation screen. Redirects back to the input screen `KKW00810` so the operator can modify the displayed data. No service calls are made — it simply resets the navigation target.

### `action_Fin()` → boolean

Called when the user clicks the **Finish (完了)** button on the KKW00812 completion screen. Redirects to the operation service contract list screen (`KKW02301` — "Operation Service Contract List") by setting the next screen ID and name in the common info bean.

### `action_Back()` → boolean

Called when the user clicks the **Back (戻る)** button on the input screen. Sets the next screen ID to the screen from which the user originally navigated here (`JCCWebCommon.getScreenId(this)`), effectively returning to the previous page.

### `actionInitKKW00811()` → boolean / `actionInitKKW00812()` → boolean

Stub initializers for the confirmation and completion screens. Both currently return `true` without any additional processing. The KKW00810 initialization flow already fetches all necessary data in `actionInitKKW00810()`, and the confirmation/completion screens are primarily display screens with navigation buttons.

## Relationships

### Inbound (who depends on this class)

Four configuration XML files reference `KKW00810SFLogic`:

| Consumer | Purpose |
|----------|---------|
| `WEBGAMEN_KKW008100PJP.xml` | Maps the input screen (KKW00810) to this logic class |
| `WEBGAMEN_KKW008110PJP.xml` | Maps the confirmation screen (KKW00811) to this logic class |
| `WEBGAMEN_KKW008120PJP.xml` | Maps the completion screen (KKW00812) to this logic class |
| `x31business_logic_KKW00810SF.xml` | X31 business logic configuration binding |

### Outbound (what this class depends on)

| Dependency | Purpose |
|------------|---------|
| `JCCWebBusinessLogic` (parent class) | Base class providing `getCommonInfoBean()`, `getServiceFormBean()`, `invokeService()`, and `dumpDatabean()` |
| `KKSV0022_KKSV0022OPDBMapper` | Maps form bean data to KKSV0022 service parameters (fixed IP lookup) |
| `KKSV0023_KKSV0023OPDBMapper` | Maps form bean data to KKSV0023 service parameters (fixed IP registration) |
| `JCCWebCommon` | Utilities for screen info, error flags, operation date/time |
| `KKW00810SFConst` | Screen-specific field key constants |
| `JKKCommonConst` / `JPCModelConstant` | System-wide constants (codes, function codes, message IDs) |

### Sequence Diagram

```mermaid
sequenceDiagram
    participant User
    participant Web as WEBGAMEN_KKW008100PJP
    participant CLS as KKW00810SFLogic
    participant Svc1 as KKSV0022 Service
    participant Svc2 as KKSV0023 Service
    participant Common as Common Info Bean

    User->>Web: Navigate to KKW00810
    Web->>CLS: action_Init()
    CLS->>CLS: actionInitKKW00810()
    CLS->>CLS: initServiceFormBean()
    CLS->>Svc1: invokeService (IP lookup)
    Svc1-->>CLS: Fixed IP data
    CLS->>CLS: editServiceFormBean()
    CLS-->>Web: true (show screen)

    User->>Web: Click Registration (登録)
    Web->>CLS: action_Cfm()
    CLS->>CLS: doRegistFixedIPAddressOption(FUNC_CD_2)
    CLS->>Svc2: invokeService (pre-reg)
    Svc2-->>CLS: result
    CLS->>Common: Set next screen = KKW00811
    CLS-->>Web: true (show confirm screen)

    User->>Web: Click Confirm (確定)
    Web->>CLS: action_Fix()
    CLS->>CLS: doRegistFixedIPAddressOption(FUNC_CD_1)
    CLS->>Svc2: invokeService (actual reg)
    Svc2-->>CLS: reg number
    CLS->>Common: Set next screen = KKW00812
    CLS-->>Web: true (show complete screen)

    User->>Web: Click Finish (完了)
    Web->>CLS: action_Fin()
    CLS->>Common: Set next screen = KKW02301
    CLS-->>Web: true
```

## Usage Example

The typical calling flow is driven by the X31 web framework:

```
1. User arrives at KKW00810 screen → Web framework instantiates
   KKW00810SFLogic and calls action_Init()
   
2. action_Init() reads NEXT_SCREEN_ID from CommonInfoBean,
   sees "KKW00810", and calls actionInitKKW00810() which:
   - Fetches inherited customer contract data
   - Calls KKSV0022 service to look up fixed IP address
   - Populates the form bean with IP, netmask, dates, etc.

3. Screen displays the fetched data to the operator.

4. Operator clicks "Registration" button → action_Cfm() is called.
   - Calls doRegistFixedIPAddressOption(FUNC_CD_2) — pre-registration
   - Navigates to KKW00811 (confirmation screen)

5. Operator clicks "Confirm" → action_Fix() is called.
   - Calls doRegistFixedIPAddressOption(FUNC_CD_1) — actual registration
   - Navigates to KKW00812 (completion screen)

6. Operator clicks "Finish" → action_Fin() is called.
   - Navigates to KKW02301 (service contract list)
```

The class is instantiated per request by the web framework (not reused as a singleton), since it maintains instance state in `unyo_ymd`, `unyo_dtm`, and `use_sta_ymd` — fields that were converted from `static` to instance fields in IT1-2013-0000289 to fix thread-safety concerns.

## Notes for Developers

- **Thread safety:** In version 4.01 (IT1-2013-0000289), the `static` fields `unyo_ymd`, `unyo_dtm`, and `use_sta_ymd` were changed to instance fields to prevent thread contention. The class is expected to be instantiated per HTTP request, not shared across threads.

- **Two-phase registration:** The class implements a pre-registration check (`FUNC_CD_2` in `action_Cfm()`) before the actual registration (`FUNC_CD_1` in `action_Fix()`). The pre-registration call validates the data without committing, allowing the operator to review. Both calls go through `doRegistFixedIPAddressOption()`.

- **Service modularization:** Since v7.00 (IT1-2014-0000037), the KKSV0023 service mapping was consolidated into a single modularized mapper method `setJKKGlobalIpAddCfmCC()`. The older granular mapper calls are commented out in the source. This means the IP address confirmation registration unit handles all the complex field mapping, and adding new fields requires changes to that mapper.

- **Progression status logic:** The `configServiceFormBean()` method determines the progression status (`PRG_STAT`) based on whether the operation date matches the service start date:
  - Same day → `5102` (Option settings complete) — immediate effect.
  - Different day → `5101` (Option information application in progress) — pending processing.

- **Parent contract code change:** In OT-2013-0000223, the parent contract identifier code was changed from `"01"` (Service Contract) to `"03"` (Service Contract Internal Details). This is a hardcoded constant in the class.

- **Fixed values:** Several fields are hardcoded rather than derived from input:
  - Price plan code: `PB0401` (Fixed Global IP Address)
  - Provider code: `PCRS_CD_B04`
  - Operation service code: `0040`
  - Application type code: `00026`
  - Progression special item 1: `"固定グローバルIPアドレス情報登録"`

- **Error handling:** The `actionInitKKW00810()` method checks for search errors from service `KKSV041307SC`. If an error is found, it sets message `EKB5470_KW` with the label "Fixed IP Address" — this alerts the operator that the IP address lookup failed.

- **Back navigation:** `action_Back()` uses `JCCWebCommon.getScreenId(this)` to determine the previous screen dynamically, rather than hardcoding a return destination. This allows the same logic class to handle back navigation from different entry points.
