# KKW02541SFLogic

## Purpose

`KKW02541SFLogic` is a screen logic (front-end controller) class for the **Domain Information Provision Agreement** screen in the K-Opticom contract management system. Its responsibility is to handle the initial display of a page that lists domain information tied to a specific service contract, allowing users to review and acknowledge the associated domains. It orchestrates screen initialization, fetches domain data from a backend service, and prepares the DataBean for rendering.

## Design

This class follows the **screen controller / action logic** pattern commonly used in the Futurity web framework. It extends `JCCWebBusinessLogic`, which provides base methods for screen information retrieval, service invocation, and common bean access. Each screen in this system typically has one such logic class that acts as a thin orchestration layer — it does not contain business logic itself but rather coordinates between the view (DataBeans), the backend service (`KKSV0573`), and the framework's common utilities.

The class is tightly coupled to a single screen (`KKW02541`), making it a focused, single-responsibility controller.

## Key Methods

### `actionInit() → boolean`

**Location:** Lines 50–76

This is the primary entry point, called by the framework when the screen is first requested. It orchestrates the entire initialization sequence:

1. **Retrieves screen information** via `JCCWebCommon.getScreenInfo(this)`, binding the current request's screen state to the logic instance.
2. **Obtains the service form bean** through `super.getServiceFormBean()`, wrapping it into an array (`paramBean`) for uniform passing to child methods.
3. **Sets up the DataBean** with `setHktgiBean(paramBean)`, which populates initial fields like the service contract number (`SVC_KEI_NO`).
4. **Calls the backend service** via `executeInitSvc(paramBean)`, which invokes the `KKSV0573` service to fetch the list of domain information for the contract.
5. **Generates authentication IDs** via `setNinshoID(paramBean)`, preparing display-ready identification values from the domain list.
6. **Sets the next screen name** (`SCREEN_NAME_KKW02541`) on the common info bean for navigation purposes.
7. **Dumps the DataBean state** to the log via `JSYwebLog.println(JSYwebLog.DataBean_Dump, ...)` for debugging purposes.
8. **Returns `true`** to indicate normal completion.

If any step throws an `Exception`, it propagates up to the framework's exception handler.

### `executeInitSvc(X31SDataBeanAccess[] paramBean) → void`

**Location:** Lines 83–106

This private method executes the **domain information provision** backend service call (`KKSV0573`). The flow is:

1. Creates three `HashMap<String, Object>` instances: `paramMap` (service parameters), `inputMap` (data to send to the service), and `outputMap` (results returned from the service).
2. Sets the use case ID (`KKSV0573`) in the parameter map.
3. Instantiates a `KKSV0573_KKSV0573OPDBMapper`, which handles mapping between DataBean fields and the service's input/output maps.
4. Calls `mapper.setKKSV057301SC(paramBean, inputMap, JPCModelConstant.FUNC_CD_1)` to populate the input map with the current form data (using function code `FUNC_CD_1`).
5. Invokes `invokeService(paramMap, inputMap, outputMap)` — a method inherited from `JCCWebBusinessLogic` that makes the actual remote service call.
6. Calls `mapper.getKKSV057301SC(paramBean, outputMap)` to map the service's output results back into the DataBean, populating the domain list that will be displayed on the screen.

This is the core data-fetching method. It bridges the web-layer DataBean with the backend service contract.

### `setHktgiBean(X31SDataBeanAccess[] paramBean) → void`

**Location:** Lines 115–134

This private method handles **initial DataBean setup** — specifically, setting fields that need to persist from the first page load. At present, it:

1. Reads the **service contract number** (`SVC_KEI_NO`) from the form bean via `paramBean[0].sendMessageString(KKW02541SFConst.SVC_KEI_NO, X31CWebConst.DATABEAN_GET_VALUE)`.
2. Sets it back onto the same bean, ensuring the value is available for subsequent processing.

There is commented-out legacy code (marked with "DEL" markers from v4.01) that previously read from a customer contract succession list (`HKTGI_LIST`) and extracted a `SYSID` field. This was removed in version 4.01 (ticket IT1-2012-0001210), suggesting a refactoring of how the system identifies which contract to display. The current implementation reads `SVC_KEI_NO` directly from the form bean rather than from a nested list.

### `setNinshoID(X31SDataBeanAccess[] paramBean) → void`

**Location:** Lines 143–195

This private method generates and sets **display-ready authentication IDs** for each domain in the domain information list. It iterates over the `TIK_LIST` (domain information list) in the DataBean and for each entry:

1. Retrieves the existing `TIK_LIST` array from the form bean, or creates a new entry if the index is out of bounds.
2. Extracts two authentication ID fields from each domain entry:
   - **ISP authentication ID** (`ISP_NINSHO_ID_01`) — the primary authentication identifier.
   - **Multi-selection authentication ID** (`MLTISE_NINSHO_ID_01`) — an additional identifier for multi-selection scenarios.
3. **Merges the IDs**: If the multi-selection ID is null or empty, it uses only the ISP ID. Otherwise, it concatenates them with a comma separator (`ispNinshoId + "," + mltiseNinshoId`).
4. Sets the merged result back into the entry's `NINSHO_ID_01` field.
5. **Alternates row styling**: Sets `ROW_STYLE_01` to `"odd"` or `"even"` based on the index (i % 2), enabling striped table rendering in the UI.

This method prepares the domain list for visual presentation, ensuring each row has a displayable authentication ID and proper alternating row styling.

## Relationships

```mermaid
flowchart LR
    subgraph Callers
        A["KKW025410PJP"]
        B["KKW02541SFLogic"]
    end
    subgraph Parent
        C["JCCWebBusinessLogic"]
    end
    subgraph Services
        D["KKSV0573 Service"]
    end
    A -->|"calls"| B
    B -->|"extends"| C
    B -->|"invokeService"| D
    B -->|"setHktgiBean"| C
    B -->|"setNinshoID"| C
    B -->|"executeInitSvc"| D
```

### Who Depends on This Class

| Dependent | Relationship |
|-----------|-------------|
| `WEBGAMEN_KKW025410PJP.xml` | The presentation-layer XML configuration that wires this logic to the screen. References `KKW02541SFLogic` as the screen's action handler. |
| `x31business_logic_KKW02541SF.xml` | Business logic configuration XML, likely defining the service mapping and DataBean structure for the screen. |

### Dependencies

| Dependency | Direction | Description |
|-----------|-----------|-------------|
| `JCCWebBusinessLogic` | Extends | Base class providing `invokeService()`, `getServiceFormBean()`, `getCommonInfoBean()`, and other framework utilities. |
| `X31SDataBeanAccess` / `X31SDataBeanAccessArray` | Uses | The framework's DataBean types for carrying screen state between the view and logic layers. |
| `KKSV0573_KKSV0573OPDBMapper` | Uses | A mapper class that handles field-by-field mapping between the `KKSV0573` service's input/output maps and the DataBean. |
| `KKW02541SFConst` | Uses | Constants for this screen's DataBean field names and IDs (e.g., `TIK_LIST`, `SVC_KEI_NO`, `NINSHO_ID_01`). |
| `JPCModelConstant` | Uses | Framework constants including `FUNC_CD_1` (function code for data retrieval). |
| `JCCWebCommon` / `CommonInfoCFConst` / `JKKScreenConst` | Uses | Common utilities for screen info retrieval, common info bean access, and screen name constants. |

## Usage Example

A typical invocation occurs when a user navigates to the Domain Information Provision Agreement screen. The framework's page lifecycle calls `actionInit()`:

```java
// The presentation layer (WEBGAMEN_KKW025410PJP) creates and calls this:
KKW02541SFLogic logic = new KKW02541SFLogic();
boolean result = logic.actionInit();
// result == true indicates the screen initialized successfully.
// At this point, paramBean[0] contains:
//   - SVC_KEI_NO: the service contract number
//   - TIK_LIST:   the list of domains, each with NINSHO_ID_01 and ROW_STYLE_01 set
```

The initialization flow inside `actionInit()`:

```
actionInit()
  ├─ JCCWebCommon.getScreenInfo(this)          // Bind screen state
  ├─ getServiceFormBean() → paramBean          // Get the form bean
  ├─ setHktgiBean(paramBean)                   // Set service contract number
  ├─ executeInitSvc(paramBean)                 // Fetch domain list from KKSV0573
  │   └─ invokeService(paramMap, inputMap, outputMap)
  ├─ setNinshoID(paramBean)                    // Prepare display IDs & row styles
  ├─ set NEXT_SCREEN_NAME on common info bean  // Navigation tracking
  └─ dumpDatabean()                            // Log for debugging
```

## Notes for Developers

- **Single-screen focus**: This class is dedicated to screen `KKW02541` only. It has no shared logic with other screens.
- **Initialization only**: The `actionInit()` method handles initial page load. There are no separate methods for post-back handling, form submission, or action buttons. If such behavior is needed, it would be added as additional methods in this class.
- **Thread safety**: The class is instantiated per-request by the framework, so there is no shared mutable state between requests. However, the class is not designed for concurrent reuse — treat each instance as request-scoped.
- **Exception handling**: `actionInit()` throws `Exception` generically. Any failure in the service call, bean access, or mapping will propagate up. The framework handles the exception, but no retry or fallback logic exists in this class.
- **Hardcoded use case ID**: The service call always uses `KKSV0573` as the use case ID, hardcoded in `executeInitSvc()`. This ties the class to a specific backend service contract.
- **Row style alternation**: The `setNinshoID()` method sets `"odd"`/`"even"` row styles, which the UI layer likely uses for CSS striping. This is a presentation concern baked into the logic layer, which is a minor architectural smell.
- **Commented-out legacy code**: The `setHktgiBean()` method contains commented-out code from the v4.00 era (customer contract succession list handling). This should be considered for deletion rather than left as dead code.
- **Authentication ID merging**: The comma-separated concatenation of `ISP_NINSHO_ID_01` and `MLTISE_NINSHO_ID_01` means the display ID may contain a comma. UI consumers should be aware that parsing by comma is not safe if both values are present.
- **v4.01 change (IT1-2012-0001210)**: A significant refactoring changed how the service contract number is obtained — from reading a nested customer contract succession list to reading it directly from the form bean. Ensure any new code follows this pattern.
