# KKW02404SFLogic

## Purpose

`KKW02404SFLogic` is the central business-logic class for managing **Fixed Global IP Address Information** (固定グローバルIPアドレス情報) updates within a K-Opticom web application. It handles three core operations — **deregistration** (解約), **restoration** (回復), and **scheduled cancellation** (予約取消) — of fixed global IP address assignments tied to an option service contract. The class orchestrates data preparation, service invocation, and navigation across a three-screen confirmation workflow.

## Design

This class follows the standard **webview action-logic pattern** used across the K-Opticom JCC framework. It extends `JCCWebBusinessLogic` and acts as a **mediator/facade** between the presentation layer (three JSP screens — KKW02404, KKW02405, KKW02406) and the backend business services.

Each public `actionXxx()` method corresponds to a user-triggered event on the UI:

| Action | Trigger | Flow |
|---|---|---|
| `actionInit()` | Screen load | Fetch screen info, call inquiry service, validate state |
| `actionUpd()` | Confirm button (update screen) | Set deregistration data, invoke dereg service, navigate to detail screen |
| `actionFix()` | Execute/Confirm button | Based on operation type: call the appropriate service (dereg, restore, cancel), navigate to result screen |
| `actionBack()` | Back button | Return to the calling screen |
| `actionShusei()` | Correction button | Return to the entry screen (KKW02404) for data correction |
| `actionFin()` | Finish button | Return to the original calling screen |
| `actionClear()` | Clear button | Re-fetch initial data and re-render the form |

The class uses **operation type dispatch** via the `TRAN_DIV` field in the DataBean. Three values determine the flow:

- `OP_TRAN_DIV_DSL` — Deregistration (解約)
- `OP_TRAN_DIV_KAIHK` — Restoration (回復)
- `OP_TRAN_DIV_RSV_CL` — Scheduled cancellation (予約取消)

## Class Diagram

```mermaid
flowchart TD
    KKW02404SFLogic["KKW02404SFLogic"] -->|"extends"| JCCWebBusinessLogic["JCCWebBusinessLogic"]
    WEBGAMEN_KKW02404["WEBGAMEN_KKW024040PJP<br>Confirmation Screen"] -->|"calls"| KKW02404SFLogic
    WEBGAMEN_KKW02405["WEBGAMEN_KKW024050PJP<br>Detail Screen"] -->|"calls"| KKW02404SFLogic
    WEBGAMEN_KKW02406["WEBGAMEN_KKW024060PJP<br>Result Screen"] -->|"calls"| KKW02404SFLogic
    x31business_logic["x31business_logic_KKW02404SF"] -->|"references"| KKW02404SFLogic
    KKW02404SFLogic -->|"uses"| KKSV0264Mapper["KKSV0264 Mapper<br>Initial Inquiry"]
    KKW02404SFLogic -->|"uses"| KKSV0265Mapper["KKSV0265 Mapper<br>Deregistration"]
    KKW02404SFLogic -->|"uses"| KKSV0266Mapper["KKSV0266 Mapper<br>Restoration"]
    KKW02404SFLogic -->|"uses"| KKSV0267Mapper["KKSV0267 Mapper<br>Cancellation"]
```

## Key Methods

### `actionInit() -> boolean`

**Entry point for screen initialization.** This is the primary method invoked when the user first loads the Fixed Global IP Address Information update screen (KKW02404). It performs the following:

1. **Fetches screen information** via `JCCWebCommon.getScreenInfo(this)`, which populates caller/screen context.
2. **Retrieves the service form DataBean** and wraps it in an array for downstream methods.
3. **Calls `setHktgiBean(paramBean)`** — copies customer contract data (SYSID, service contract number, migration type, migration reason codes, option service contract number, operation type division, application number, application detail number) from the customer contract inheritance list into the screen DataBean.
4. **Calls `executeInitSvc(paramBean)`** — invokes the **KKSV0264** service (Fixed Global IP Address information inquiry) using mappers `KKSV0264_KKSV0264OPDBMapper` for four fields. This populates the screen with the current state of the Fixed Global IP address.
5. **Calls `setDataInit(paramBean)`** — initializes the aging/entry info list, sets the aging type code to `"002"` (Fixed Global IP Address), sets the aging target value from `FIXIPAD`, and derives the usage end date from the operation date (`USE_YMD`). It also normalizes the maximum date `99991231` to an empty string for display.
6. **Validates state-dependent business rules:**
   - For **deregistration** (`TRAN_DIV = DSL`): The option service contract status must be one of `030` (contracted), `100` (in service), or `210` (suspended/discontinued). Otherwise, displays error `EKB1510_KW` ("Deregistration option service — cannot update") and disables the update flag (`CHG_KAHI_FLG = false`).
   - For **restoration** (`TRAN_DIV = KAIHK`): The status must be `910` (deregistered). Otherwise, shows the same "cannot update" error. Displays info message `EKB0370__I` with the string "Fixed Global IP Address information restoration".
   - For **scheduled cancellation** (`TRAN_DIV = RSV_CL`): The status must be `010`, `020`, `030`, or `100`. Otherwise, shows the "cannot update" error. Displays info message `EKB0370__I` with the string "Fixed Global IP Address information scheduled cancellation".
7. **Dumps the DataBean** to the log for debugging.

**Return value:** `true` on success (screen rendered normally). Throws `Exception` on errors.

**Side effects:** Populates `paramBean[0]` with screen data, sets message info for display, writes to the DataBean log.

---

### `actionBack() -> boolean`

**Back button handler.** Retrieves the common form DataBean, sets `NEXT_SCREEN_ID` to the current screen's ID (so the caller knows where to return), and logs the DataBean. Returns `true`.

---

### `setHktgiBean(X31SDataBeanAccess[] paramBean) -> void`

**Copies customer contract inheritance data into the screen DataBean.** This is a private setup method called during initialization. It:

- Sets the operation date (`USE_YMD`) from the system.
- Extracts data from the customer contract inheritance list (`hktgilist`), including:
  - `SYSID_01` → `SYSID`
  - `SVC_KEI_NO_01` → `SVC_KEI_NO`
  - `IDO_DIV_01` → `IDO_DIV` (migration type)
  - `IDO_RSN_CD_01` (repeated entries) → `IDO_RSN_CD_02` (migration reason codes)
  - `IDO_RSN_MEMO_01` → `IDO_RSN_MEMO_02` (migration reason memo)
  - `OP_SVC_KEI_NO_01` → `OP_SVC_KEI_NO`
  - `TRAN_DIV_01` → `TRAN_DIV`
  - `MSKM_NO_01` → `MSKM_NO` (application number)
  - `MSKM_DTL_NO_01` → `MSKM_DTL_NO` (application detail number)
- Hard-codes the reservation application date (`RSV_APLY_YMD`) to `"20991231"`.

**Parameters:** `paramBean` — a one-element array of `X31SDataBeanAccess` representing the screen form DataBean.

**Side effects:** Writes multiple fields into `paramBean[0]` and its associated nested DataBean arrays.

---

### `executeInitSvc(X31SDataBeanAccess[] paramBean) -> void`

**Invokes the KKSV0264 inquiry service** (Fixed Global IP Address information confirmation) for initial display. Uses `KKSV0264_KKSV0264OPDBMapper` to map four fields (`KKSV026401SC` through `KKSV026404SC`) from the DataBean into the service input map, calls `invokeService()`, then maps the results back.

**Parameters:** `paramBean` — the screen DataBean array.
**Side effects:** Populates the DataBean with inquiry results from the backend service.

---

### `setDataInit(X31SDataBeanAccess[] paramBean) -> void`

**Initializes the entry information list** on the screen. Sets:
- The aging info list with a single entry: type code `"002"` and target value from `FIXIPAD` (the IP address field).
- The usage end date components (year, month, day) extracted from the operation date `USE_YMD`.
- Normalizes `USE_ENDYMD` — if it equals `99991231` (max date), replaces it with empty string.
- Sets `CHG_KAHI_FLG` (update enable flag) to `true`.

**Parameters:** `paramBean` — the screen DataBean array.

---

### `actionClear() -> boolean`

**Clear button handler.** Re-invokes `executeInitSvc()` (re-fetches data from the inquiry service) and `setDataInit()` (re-initializes the DataBean), then logs and returns `true`. This effectively refreshes the screen with fresh server-side data.

---

### `actionUpd() -> boolean`

**Update confirmation button handler.** This is the core action that triggers the **deregistration** flow. It:

1. Gets the common form DataBean and the service form DataBean.
2. Retrieves `TRAN_DIV` from the DataBean.
3. **If `TRAN_DIV = DSL` (deregistration):**
   - Calls `setDataDsl(paramBean)` — sets the usage end date (concatenating year/month/day), service end date, service charge end date, and the progress-specific text ("Fixed Global IP Address information deregistration").
   - Calls `executeDslSvc(paramBean, FUNC_CD_2)` — invokes the **KKSV0265** deregistration confirmation service with `FUNC_CD_2` (confirmation mode).
   - Retrieves `RTN_MSG_ID` from the DataBean.
4. **Screen navigation:**
   - If `RTN_MSG_ID` is empty → no error from the service. Sets `NEXT_SCREEN_ID` to `KKW02405` (the confirmation detail screen) and shows info message `EKB0370__I` with "Fixed Global IP Address information deregistration".
   - If `RTN_MSG_ID` is non-empty → an error occurred. Calls `getMsgRep(trandiv, rtn_msg_id)` to get replacement text for the error message, then displays it. Does **not** navigate; stays on the current screen.
5. Logs the DataBean.

**Return value:** Always `true`.

**Key detail:** The confirmation call uses `FUNC_CD_2` (confirmation), while the actual execution in `actionFix()` uses `FUNC_CD_1` (execution).

---

### `setDataDsl(X31SDataBeanAccess[] paramBean) -> void`

**Sets deregistration-specific data** in the DataBean before calling the dereg service. Concatenates year/month/day components into `USE_ENDYMD`, sets `SVC_ENDYMD` and `SVC_CHRG_ENDYMD`, and sets the progress-specific display text to "Fixed Global IP Address information deregistration".

---

### `executeDslSvc(X31SDataBeanAccess[] paramBean, String func_code) -> void`

**Invokes the KKSV0265 deregistration confirmation service.** Maps the DataBean into the service input via `KKSV0265_KKSV0265OPDBMapper`, calling:
- `setOpSvcKeiDslCC` — option service contract deregistration CC (change control)
- `setJKKHakkoSODCC` — SOD (statement of discharge) CC
- `setKKSV0265WORK` — WORK mapping

Clears `RTN_MSG_ID` before invocation, then maps results back via `getOpSvcKeiDslCC`.

---

### `actionFix() -> boolean`

**Execute/Confirm button handler.** This is the action that performs the **actual state change**. It:

1. Gets the common form and service form DataBeans.
2. Retrieves `TRAN_DIV`.
3. **Dispatches by operation type:**

   - **Deregistration (DSL):** Calls `executeDslSvc(paramBean, FUNC_CD_1)` — executes the dereg service (with `FUNC_CD_1` meaning "execute" rather than "confirm"). Gets `RTN_MSG_ID`. Message: "Fixed Global IP Address information deregistration".

   - **Restoration (KAIHK):** Calls `setDataKaihk(paramBean)` — sets the restoration date to the operation date and progress text to "Fixed Global IP Address information restoration". Calls `executeKaihkSvc(paramBean, FUNC_CD_1)` — invokes **KKSV0266** service. Gets `RTN_MSG_ID`. Message: "Fixed Global IP Address information restoration".

   - **Scheduled cancellation (RSV_CL):** Calls `setDataRsvcl(paramBean)` — sets progress text to "Fixed Global IP Address information scheduled cancellation". Calls `executeRsvclSvc(paramBean, FUNC_CD_1)` — invokes **KKSV0267** service. Gets `RTN_MSG_ID`. Message: "Fixed Global IP Address information scheduled cancellation".

4. **Screen navigation:**
   - If `RTN_MSG_ID` is empty → success. Sets `NEXT_SCREEN_ID` to `KKW02406` (the result screen) and shows info message `EKB4390__I`.
   - If `RTN_MSG_ID` is non-empty → error. Calls `getMsgRep()` for replacement text, displays the error message, and stays on the current screen.
5. Logs the DataBean.

**Return value:** Always `true`.

---

### `executeKaihkSvc(X31SDataBeanAccess[] paramBean, String func_code) -> void`

**Invokes the KKSV0266 restoration service.** Maps:
- `setOpSvcKeiKaihkCC` — option service contract restoration CC
- `setJKKHakkoSODCC` — SOD CC
- `setKKSV0266WORK` — WORK mapping

Clears `RTN_MSG_ID`, calls `invokeService()`, and maps results back via `getOpSvcKeiKaihkCC`.

---

### `executeRsvclSvc(X31SDataBeanAccess[] paramBean, String func_code) -> void`

**Invokes the KKSV0267 scheduled cancellation service.** Maps:
- `setOpSvcKeiCnslCC` — option service contract cancellation CC
- `setJKKHakkoSODCC` — SOD CC (cancellable SOD emission)
- Calls `invokeService()` and maps results back via `getOpsvckeiCnslCC`.

Note: The SOD CC mapping includes a comment indicating it was added for cancellable SOD emission support ([IT1-2013-0000167]).

---

### `setDataKaihk(X31SDataBeanAccess[] paramBean) -> void`

**Sets restoration-specific data.** Sets `KAIHK_YMD` (restoration date) to the current operation date (`USE_YMD`) and the progress-specific text to "Fixed Global IP Address information restoration".

---

### `setDataRsvcl(X31SDataBeanAccess[] paramBean) -> void`

**Sets scheduled cancellation-specific data.** Sets the progress-specific text to "Fixed Global IP Address information scheduled cancellation".

---

### `getMsgRep(String trandiv, String rtn_msg_id) -> String[]`

**Gets replacement text for error messages.** Returns a `String[]` with replacement placeholders for specific error IDs, or `null` if no replacements are needed.

| `TRAN_DIV` | `RTN_MSG_ID` | Replacements returned |
|---|---|---|
| DSL | `EKB0690_NW` | `{"usage end date", "past"}` |
| KAIHK | `EKB5440_JW` | `{"outside restoration period", "restoration"}` |
| RSV_CL | `EKB5420_JW` | `{"option", "scheduled cancellation"}` |

**Parameters:**
- `trandiv` — the operation type division code (DSL/KAIHK/RSV_CL).
- `rtn_msg_id` — the return message ID from the service.

**Return value:** A `String[]` of two replacement strings, or `null` if no specific replacement text is defined.

---

### `actionShusei() -> boolean`

**Correction button handler.** Sets the next screen to `KKW02404` (the original entry screen) in the common form DataBean and returns `true`. This allows the user to go back and correct their input.

---

### `actionFin() -> boolean`

**Finish button handler.** Sets the next screen to the original calling screen (retrieved via `JCCWebCommon.getScreenId(this)`) in the common form DataBean and returns `true`.

---

## Relationships

### Inbound (who calls this class)

Four classes reference `KKW02404SFLogic`:

```mermaid
flowchart TD
    KKW02404SFLogic["KKW02404SFLogic<br>Fixed Global IP Update Logic"]
    WEBGAMEN_KKW02404["WEBGAMEN_KKW024040PJP<br>Confirmation Screen JSP"] --> KKW02404SFLogic
    WEBGAMEN_KKW02405["WEBGAMEN_KKW024050PJP<br>Detail Screen JSP"] --> KKW02404SFLogic
    WEBGAMEN_KKW02406["WEBGAMEN_KKW024060PJP<br>Result Screen JSP"] --> KKW02404SFLogic
    x31business["x31business_logic_KKW02404SF<br>Business Logic Config"] --> KKW02404SFLogic
```

1. **WEBGAMEN_KKW024040PJP.xml** — The confirmation screen (KKW02404). This is the entry point where users view current Fixed Global IP address data and select an operation (deregister, restore, or cancel). It instantiates `KKW02404SFLogic` and calls `actionInit()`, `actionUpd()`, `actionBack()`, `actionShusei()`, and `actionFin()`.

2. **WEBGAMEN_KKW024050PJP.xml** — The detail confirmation screen (KKW02405). Shown after the user clicks the update confirmation button. Displays the deregistration details. Calls the logic class for `actionBack()` and `actionShusei()`.

3. **WEBGAMEN_KKW024060PJP.xml** — The result screen (KKW02406). Shown after the user confirms execution (`actionFix()`). Displays the result of the operation. Calls the logic class for `actionBack()`, `actionShusei()`, and `actionFin()`.

4. **x31business_logic_KKW02404SF.xml** — The business logic configuration, which wires the screen IDs to the logic class name.

### Outbound (this class's dependencies)

`KKW02404SFLogic` extends `JCCWebBusinessLogic`, which provides:

- `getServiceFormBean()` — access to the screen DataBean
- `getCommonInfoBean()` — access to the shared form DataBean (for screen navigation)
- `invokeService()` — invocation of backend services (KKSV0264-0267)
- `dumpDatabean()` — DataBean serialization for logging

It also directly uses the following mapper classes:
- `KKSV0264_KKSV0264OPDBMapper` — Initial inquiry mapper
- `KKSV0265_KKSV0265OPDBMapper` — Deregistration mapper
- `KKSV0266_KKSV0266OPDBMapper` — Restoration mapper
- `KKSV0267_KKSV0267OPDBMapper` — Scheduled cancellation mapper

## Sequence Diagram: Initialization Flow

```mermaid
sequenceDiagram
    participant C as Client
    participant L as KKW02404SFLogic
    participant S as Init Service
    participant B as DataBean

    C->>L: actionInit()
    L->>B: getScreenInfo()
    L->>B: getServiceFormBean()
    L->>L: setHktgiBean(paramBean)
    L->>S: invokeService(KKSV0264)
    S-->>L: outputMap
    L->>B: setDataInit(paramBean)
    L->>L: validate state & display messages
    L-->>C: true
```

## Usage Example

The typical lifecycle for using `KKW02404SFLogic` is:

1. **User navigates to screen KKW02404** — The screen JSP (WEBGAMEN_KKW024040PJP) instantiates the logic class and calls `actionInit()`. This populates the screen with current Fixed Global IP address data, validates the service contract state, and checks whether the operation type is eligible.

2. **User reviews data and clicks "Update" (confirm)** — The JSP calls `actionUpd()`. For deregistration, this sets the usage end date, calls the KKSV0265 confirmation service, and navigates to screen KKW02405 for detail review. If the service returns an error, the user stays on the current screen with an error message.

3. **User reviews details and clicks "Execute"** — The JSP calls `actionFix()`. Based on the `TRAN_DIV` type, this dispatches to the appropriate service (KKSV0265, KKSV0266, or KKSV0267) and navigates to screen KKW02406 for the result.

4. **User clicks "Back", "Correction", or "Finish"** — Appropriate action method (`actionBack()`, `actionShusei()`, or `actionFin()`) sets the next screen and returns.

## Notes for Developers

1. **Thread safety:** The class has no instance fields (all state is passed via `paramBean` arrays), so it is thread-safe. However, it should not be shared as a singleton in the servlet container — a new instance should be created per request.

2. **Hard-coded constants:** The operation type division codes and service contract status codes are compared against constants from `JKKCommonConst`. Changing these values requires coordinated updates.

3. **Date handling:** The usage end date components (year/month/day) are extracted by substring from `USE_YMD` (a YYYYMMDD string). Any change to the date format would break this logic.

4. **Maximum date normalization:** The service end date `99991231` (represented as `MAX_YMD`) is normalized to an empty string for display. This indicates "no end date specified" and is a data display convention, not a business rule change.

5. **Service invocation pattern:** All backend services are invoked via `invokeService()`, passing `paramMap`, `inputMap`, and `outputMap` as `HashMap<String, Object>`. The mapper classes handle DataBean-to-Map and Map-to-DataBean conversion. This is a common pattern in the JCC framework.

6. **Confirmation vs. execution distinction:** The `func_code` parameter differentiates between confirmation (`FUNC_CD_2`) and execution (`FUNC_CD_1`). `actionUpd()` uses confirmation mode (KKSV0265), while `actionFix()` uses execution mode for all three operations. This two-step pattern prevents accidental state changes.

7. **Japanese comments and constants:** The source is entirely in Japanese (comments, constants, message strings). All strings in `MSGSTRING` array are: "Fixed Global IP Address information deregistration", "Fixed Global IP Address information restoration", and "Fixed Global IP Address information scheduled cancellation".

8. **Progress-specific text (PRG_TKJK_1):** Added in 2012 ([ANK-1223-00-00]), this field carries a display label for the current operation (e.g., "Fixed Global IP Address information deregistration") that is shown on progress screens. It is only set for `setDataDsl()`, `setDataKaihk()`, and `setDataRsvcl()`.

9. **SOD CC mapping:** The scheduled cancellation service (KKSV0267) explicitly includes a cancellable SOD (statement of discharge) CC mapping added in 2013 ([IT1-2013-0000167]). The deregistration (KKSV0265) and restoration (KKSV0266) services already include SOD CC mapping.

10. **Logging:** Every action method logs the full DataBean state using `JSYwebLog.println(JSYwebLog.DataBean_Dump, ...)`. This is useful for debugging but may produce large log outputs.