# Business Logic — KKW05601SFLogic.actionTokiAddCfmInit() [74 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW05601SF.KKW05601SFLogic` |
| Layer | Controller (extends `JCCWebBusinessLogic`; package: `eo.web.webview.KKW05601SF`) |
| Module | `KKW05601SF` (Package: `eo.web.webview.KKW05601SF`) |

## 1. Role

### KKW05601SFLogic.actionTokiAddCfmInit()

This method performs the **initial display processing for the Toki (transfer) registration confirmation screen** in the KKW05601SF web module. The business domain is **telephone number transfer registration** (トーキ登録) within a telecom contract management system operated by K-Opticom. Specifically, it prepares all display-ready values on the service form bean that the confirmation screen will render to the operator.

The method handles **three display value categories**: the transfer registration category (トーキ登録区分), the transfer type (トーキ種別), and the transfer preference (トーキ希望). For each category, it resolves a code-to-display-name mapping via the `getValueFromCd()` helper, which iterates over a code table stored in the data bean to find the human-readable label matching the incoming code value.

It also processes **two date fields** — the transfer manual start reservation date and the transfer end reservation date — by fetching their Year, Month, and Day components from the data bean, validating them (ensuring exactly 8 digits and a date earlier than 20991231), and formatting them into `YYYY/MM/DD` display strings or clearing them if invalid.

Additionally, the method sets the **reserved phone number** (予約電話番号) display value and checks whether the customer's transfer division field (異動区分) indicates a change of address / transfer registration type (code "00019"). If so, it sets an info message ("Transfer TOKI settings" / 移転トーキ設定) via `JCCWebCommon.setMessageInfo`, which appears to a message display area on the screen.

The method acts as the **entry-point initializer** for the confirmation screen — called by `actionCfmOtherIdoKbn()` and `setTokiInfoFromDB()` — and returns `true` to signal successful initialization. It implements a **builder/delegation pattern** by populating the `X31SDataBeanAccess` form bean, which the screen framework then uses to render form fields.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["actionTokiAddCfmInit(params)"])
    GET_BEAN["Get X31SDataBeanAccess from super.getServiceFormBean()"]
    CHECK_BEAN{"bean == null?"}
    THROW["Throw Exception"]
    DEBUG1["Debug: start logging"]

    SET_ADD_DIV["Set TOKI_ADD_DIV_DSP via getValueFromCd(tokiAddCd, TOKI_ADD_DIV)"]
    SET_SBT["Set TOKI_SBT_DSP via getValueFromCd(tokiSbtCd, TOKI_SBT)"]
    SET_KIBO["Set TOKI_KIBO_DSP via getValueFromCd(tokiKibo, TOKI_KIBO)"]

    GET_STA_YEAR["Get TOKI_STA_RSV_YEAR from bean"]
    GET_STA_MON["Get TOKI_STA_RSV_MON from bean"]
    GET_STA_DAY["Get TOKI_STA_RSV_DAY from bean"]
    KAKU_DATE1["Concat: tokiStaRsvYear.trim + tokiStaRsvMon.trim + tokiStaRsvDay.trim"]

    CHECK_DATE1{"kakuninDate.length() == 8 AND kakuninDate < 20991231?"}
    FORMAT_DATE1["Set TOKI_STA_RSV_DSP to Year/Month/Day format"]
    CLEAR_DATE1["Set TOKI_STA_RSV_DSP to empty string"]

    GET_END_YEAR["Get TOKI_END_RSV_YEAR from bean"]
    GET_END_MON["Get TOKI_END_RSV_MON from bean"]
    GET_END_DAY["Get TOKI_END_RSV_DAY from bean"]
    KAKU_DATE2["Concat: tokiEndRsvYear.trim + tokiEndRsvMon.trim + tokiEndRsvDay.trim"]

    CHECK_DATE2{"kakuninDate2.length() == 8 AND kakuninDate2 < 20991231?"}
    FORMAT_DATE2["Set TOKI_END_RSV_DSP to Year/Month/Day format"]
    CLEAR_DATE2["Set TOKI_END_RSV_DSP to empty string"]

    SET_RSV_TEL["Set RSV_TELNO_DSP via getValueFromCd(rsvTelNo, RSV_TELNO)"]

    GET_CUST_LIST["Get CUST_KEI_HKTGI_LIST from bean.getDataBeanArray()"]
    GET_HKTG_DB["Get first DataBean(0) from list"]
    GET_IDO_DIV["Get IDO_DIV_11 value from hktgKoumokuBean"]

    CHECK_IDO{"idoDiv != null AND !empty?"}
    SET_MSG["setMessageInfo: EKB0370--I with '移転トーキ設定'"]
    DEBUG2["Debug: end logging"]
    RETURN_TRUE["Return true"]

    START --> GET_BEAN --> CHECK_BEAN
    CHECK_BEAN -- Yes --> THROW --> END(["End"])
    CHECK_BEAN -- No --> DEBUG1
    DEBUG1 --> SET_ADD_DIV --> SET_SBT --> SET_KIBO
    SET_KIBO --> GET_STA_YEAR --> GET_STA_MON --> GET_STA_DAY
    GET_STA_DAY --> KAKU_DATE1 --> CHECK_DATE1
    CHECK_DATE1 -- Yes --> FORMAT_DATE1 --> GET_END_YEAR
    CHECK_DATE1 -- No --> CLEAR_DATE1 --> GET_END_YEAR
    GET_END_YEAR --> GET_END_MON --> GET_END_DAY
    GET_END_DAY --> KAKU_DATE2 --> CHECK_DATE2
    CHECK_DATE2 -- Yes --> FORMAT_DATE2 --> SET_RSV_TEL
    CHECK_DATE2 -- No --> CLEAR_DATE2 --> SET_RSV_TEL
    SET_RSV_TEL --> GET_CUST_LIST --> GET_HKTG_DB --> GET_IDO_DIV --> CHECK_IDO
    CHECK_IDO -- Yes --> SET_MSG --> DEBUG2
    CHECK_IDO -- No --> DEBUG2
    DEBUG2 --> RETURN_TRUE --> END
```

**Business processing flow:**

1. **Retrieve service form bean** — gets the data bean access object from the parent class. If null, throws an `Exception` immediately.
2. **Set transfer registration category display** — calls `getValueFromCd()` to resolve `tokiAddCd` (transfer registration category code) to its display name, and sets it to the screen field `TOKI_ADD_DIV_DSP`.
3. **Set transfer type display** — resolves `tokiSbtCd` (transfer type code) to display name via `getValueFromCd()`, sets to `TOKI_SBT_DSP`.
4. **Set transfer preference display** — resolves `tokiKibo` (transfer preference code) to display name via `getValueFromCd()`, sets to `TOKI_KIBO_DSP`.
5. **Process transfer start reservation date** — fetches Year, Month, Day from the data bean; concatenates trimmed values; validates that the result is exactly 8 characters and earlier than 20991231. If valid, formats as `YYYY/MM/DD` and sets to `TOKI_STA_RSV_DSP`; otherwise clears the field.
6. **Process transfer end reservation date** — same validation/formatting logic as step 5 for `TOKI_END_RSV_DSP`.
7. **Set reserved phone number** — resolves `rsvTelNo` to display name via `getValueFromCd()`, sets to `RSV_TELNO_DSP`.
8. **Check transfer division for message** — retrieves the customer history list, gets the first entry's transfer division field (`IDO_DIV_11`). If non-null and non-empty, displays an info message (EKB0370--I) with text "Transfer TOKI settings" (移転トーキ設定).
9. **Return `true`** — signaling successful screen initialization.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `tokiTgTelNo` | `String` | Transfer target phone number — the telephone number that is the target of the transfer operation (転覆対象電話番号). Not directly used in display setup; likely retained for downstream processing. |
| 2 | `tokiAddCd` | `String` | Transfer registration category code (転覆登録区分コード) — classifies the type of transfer registration (e.g., new registration, modification, cancellation). Used to look up display name for screen rendering. |
| 3 | `tokiSbtCd` | `String` | Transfer type code (転覆種別コード) — specifies the kind of transfer operation (e.g., number portability, same-provider transfer). Resolved to human-readable label via `getValueFromCd()`. |
| 4 | `tokiKibo` | `String` | Transfer preference (転覆希望) — indicates the customer's desired transfer timing or preference. Displayed on the confirmation screen. |
| 5 | `tokiStaRsvYmd` | `String` | Transfer manual start reservation date (転覆手動開始予定日) — the requested start date for the transfer operation. Year/Month/Day components are fetched from the bean separately and validated. |
| 6 | `tokiEndRsvYmd` | `String` | Transfer end reservation date (転覆終了予定日) — the requested end date for the transfer window. Same validation as start date. |
| 7 | `itenMotoTelNo` | `String` | Pre-transfer phone number (移転元電話番号) — the original phone number before the transfer. Used for reference during transfer processing. |
| 8 | `rrksTelNo` | `String` | Contact phone number (連絡先電話番号) — the phone number to reach the customer during the transfer process. Not set on screen directly; available for downstream use. |
| 9 | `rsvTelNo` | `String` | Reserved phone number (予約電話番号) — the new/assigned phone number that has been reserved for the transfer. Resolved to display format and set on the confirmation screen. |

**External state / instance fields read:**
- `DEBUG_LOG` — debug logger instance from `X31SWebLog`, used for start/end logging.
- `this` — instance reference passed to `JCCWebCommon.setMessageInfo()`.

**Data bean fields accessed (via `bean.sendMessageString` / `bean.getDataBeanArray`):**
- `KKW05601SFConst.TOKI_ADD_DIV_DSP` — transfer registration category display field.
- `KKW05601SFConst.TOKI_SBT_DSP` — transfer type display field.
- `KKW05601SFConst.TOKI_KIBO_DSP` — transfer preference display field.
- `KKW05601SFConst.TOKI_STA_RSV_YEAR`, `TOKI_STA_RSV_MON`, `TOKI_STA_RSV_DAY` — start reservation date components.
- `KKW05601SFConst.TOKI_STA_RSV_DSP` — formatted start reservation display field.
- `KKW05601SFConst.TOKI_END_RSV_YEAR`, `TOKI_END_RSV_MON`, `TOKI_END_RSV_DAY` — end reservation date components.
- `KKW05601SFConst.TOKI_END_RSV_DSP` — formatted end reservation display field.
- `KKW05601SFConst.RSV_TELNO_DSP` — reserved phone number display field.
- `KKW05601SFConst.CUST_KEI_HKTGI_LIST` — customer history item list.
- `KKW05601SFConst.IDO_DIV_11` — transfer division field (異動区分) from the first customer history entry.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `X31SDataBeanAccess.getServiceFormBean` | X31SWebBaseLogic | - | Retrieves the service form data bean for the current screen session |
| R | `X31SDataBeanAccess.sendMessageString` | X31SDataBeanAccess | - | Gets values from data bean fields (year, month, day components for dates) |
| SET | `X31SDataBeanAccess.sendMessageString` | X31SDataBeanAccess | - | Sets display values into data bean fields (category, type, preference, dates, phone number) |
| R | `X31SDataBeanAccess.getDataBeanArray` | X31SDataBeanAccess | - | Retrieves the customer history item list array from the data bean |
| R | `X31SDataBeanAccessArray.getDataBean` | X31SDataBeanAccessArray | - | Gets the first element of the customer history list |
| R | `X31SDataBeanAccess.sendMessageString` | X31SDataBeanAccess | - | Retrieves the transfer division code from the customer history item |
| R | `KKW05601SFLogic.getValueFromCd` | KKW05601SFLogic | - | Resolves a code value to its display name by iterating over a code table in the data bean |
| SET | `JCCWebCommon.setMessageInfo` | JCCWebCommon | - | Sets an info-level message (EKB0370--I) to display on screen when transfer division indicates change of address/transfer registration |

**Notes:**
- This method performs **no direct database CRUD operations**. It is a screen initialization method that works entirely within the data bean layer.
- The `getValueFromCd()` helper reads code/display pairs from the data bean (in-memory code table), so it is classified as an internal read operation, not a DB call.
- The only side effect beyond the data bean is setting a screen message via `JCCWebCommon.setMessageInfo()`.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Method: `KKW05601SFLogic.actionCfmOtherIdoKbn()` | `actionCfmOtherIdoKbn` -> `actionTokiAddCfmInit` | `setDataBean [SET] data bean fields`, `setMessageInfo [SET] EKB0370--I message`, `getValueFromCd [R] code table lookup` |
| 2 | Method: `KKW05601SFLogic.setTokiInfoFromDB()` | `setTokiInfoFromDB` -> `actionTokiAddCfmInit` | `setDataBean [SET] data bean fields`, `setMessageInfo [SET] EKB0370--I message`, `getValueFromCd [R] code table lookup` |

**Call chain notes:**
- Both callers are private/internal methods within `KKW05601SFLogic` itself.
- `actionCfmOtherIdoKbn()` handles other transfer category branching logic and delegates to `actionTokiAddCfmInit()` for the common confirmation screen display setup.
- `setTokiInfoFromDB()` is invoked during registration confirmation flows to populate the screen with data fetched from the database (via other SC/CBS calls), then calls `actionTokiAddCfmInit()` to finalize the display values.

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(bean == null)` (L1194)

> Retrieve and validate the service form bean. If the bean is null, the method cannot proceed.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `X31SDataBeanAccess bean = super.getServiceFormBean()` // Get service form bean |
| 2 | CHECK | `if (null == bean)` // Validate bean presence |
| 3 | EXEC | `throw new Exception()` // Abort if bean is null |

---

**Block 2** — [SET] (L1202)

> Set the transfer registration category display value.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getValueFromCd(tokiAddCd, KKW05601SFConst.TOKI_ADD_DIV, bean)` // Resolve registration category code to display name |
| 2 | EXEC | `bean.sendMessageString(KKW05601SFConst.TOKI_ADD_DIV_DSP, X31CWebConst.DATABEAN_SET_VALUE, ...)` // Set to screen field |

---

**Block 3** — [SET] (L1207)

> Set the transfer type display value.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getValueFromCd(tokiSbtCd, KKW05601SFConst.TOKI_SBT, bean)` // Resolve transfer type code to display name |
| 2 | EXEC | `bean.sendMessageString(KKW05601SFConst.TOKI_SBT_DSP, X31CWebConst.DATABEAN_SET_VALUE, ...)` // Set to screen field |

---

**Block 4** — [SET] (L1211)

> Set the transfer preference display value.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getValueFromCd(tokiKibo, KKW05601SFConst.TOKI_KIBO, bean)` // Resolve preference code to display name |
| 2 | EXEC | `bean.sendMessageString(KKW05601SFConst.TOKI_KIBO_DSP, X31CWebConst.DATABEAN_SET_VALUE, ...)` // Set to screen field |

---

**Block 5** — [PROCESS] (L1216–1223)

> Process the transfer manual start reservation date. Fetch Year/Month/Day, concatenate, validate, and format.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `String tokiStaRsvYear = bean.sendMessageString(KKW05601SFConst.TOKI_STA_RSV_YEAR, X31CWebConst.DATABEAN_GET_VALUE)` // Get year component |
| 2 | EXEC | `String tokiStaRsvMon = bean.sendMessageString(KKW05601SFConst.TOKI_STA_RSV_MON, X31CWebConst.DATABEAN_GET_VALUE)` // Get month component |
| 3 | EXEC | `String tokiStaRsvDay = bean.sendMessageString(KKW05601SFConst.TOKI_STA_RSV_DAY, X31CWebConst.DATABEAN_GET_VALUE)` // Get day component |
| 4 | SET | `String kakuninDate = tokiStaRsvYear.trim() + tokiStaRsvMon.trim() + tokiStaRsvDay.trim()` // Concat trimmed date parts |

**Block 5.1** — [IF] `(8 == kakuninDate.length() && "20991231".compareTo(kakuninDate) > 0)` (L1221) `[20991231 > kakuninDate]`

> Date validation passed: exactly 8 digits and earlier than 2099-12-31. Format as display string.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String tokiStaRsv = tokiStaRsvYear + "/" + tokiStaRsvMon + "/" + tokiStaRsvDay` // Format YYYY/MM/DD |
| 2 | EXEC | `bean.sendMessageString(KKW05601SFConst.TOKI_STA_RSV_DSP, X31CWebConst.DATABEAN_SET_VALUE, tokiStaRsv)` // Set formatted date |

**Block 5.2** — [ELSE] (L1223) `[date validation failed]`

> Date is invalid (not 8 digits or >= 20991231). Clear the display field.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `bean.sendMessageString(KKW05601SFConst.TOKI_STA_RSV_DSP, X31CWebConst.DATABEAN_SET_VALUE, "")` // Clear field |

---

**Block 6** — [PROCESS] (L1229–1236)

> Process the transfer end reservation date. Same validation/formatting as Block 5.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `String tokiEndRsvYear = bean.sendMessageString(KKW05601SFConst.TOKI_END_RSV_YEAR, X31CWebConst.DATABEAN_GET_VALUE)` // Get year |
| 2 | EXEC | `String tokiEndRsvMon = bean.sendMessageString(KKW05601SFConst.TOKI_END_RSV_MON, X31CWebConst.DATABEAN_GET_VALUE)` // Get month |
| 3 | EXEC | `String tokiEndRsvDay = bean.sendMessageString(KKW05601SFConst.TOKI_END_RSV_DAY, X31CWebConst.DATABEAN_GET_VALUE)` // Get day |
| 4 | SET | `String kakuninDate2 = tokiEndRsvYear.trim() + tokiEndRsvMon.trim() + tokiEndRsvDay.trim()` // Concat trimmed |

**Block 6.1** — [IF] `(8 == kakuninDate2.length() && "20991231".compareTo(kakuninDate2) > 0)` (L1233) `[20991231 > kakuninDate2]`

> Date validation passed for end date. Format and display.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String tokiEndRsv = tokiEndRsvYear + "/" + tokiEndRsvMon + "/" + tokiEndRsvDay` // Format YYYY/MM/DD |
| 2 | EXEC | `bean.sendMessageString(KKW05601SFConst.TOKI_END_RSV_DSP, X31CWebConst.DATABEAN_SET_VALUE, tokiEndRsv)` // Set display |

**Block 6.2** — [ELSE] (L1235) `[end date validation failed]`

> Invalid end date. Clear the display field.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `bean.sendMessageString(KKW05601SFConst.TOKI_END_RSV_DSP, X31CWebConst.DATABEAN_SET_VALUE, "")` // Clear field |

---

**Block 7** — [SET] (L1241)

> Set the reserved phone number display value.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getValueFromCd(rsvTelNo, KKW05601SFConst.RSV_TELNO, bean)` // Resolve reserved phone number to display |
| 2 | EXEC | `bean.sendMessageString(KKW05601SFConst.RSV_TELNO_DSP, X31CWebConst.DATABEAN_SET_VALUE, ...)` // Set to screen field |

---

**Block 8** — [PROCESS] (L1245–1249)

> Check the transfer division field from the customer history list to determine whether to display an info message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `X31SDataBeanAccessArray custKeiHktgiList = (X31SDataBeanAccessArray)bean.getDataBeanArray(KKW05601SFConst.CUST_KEI_HKTGI_LIST)` // Get customer history list |
| 2 | SET | `X31SDataBeanAccess hktgKoumokuBean = custKeiHktgiList.getDataBean(0)` // Get first entry |
| 3 | EXEC | `String idoDiv = hktgKoumokuBean.sendMessageString(KKW05601SFConst.IDO_DIV_11, X31CWebConst.DATABEAN_GET_VALUE)` // Get transfer division code |

**Block 8.1** — [IF] `(idoDiv != null && !"".equals(idoDiv))` (L1252) `[idoDiv is non-null and non-empty]`

> Transfer division is set (indicating a change-of-address/transfer registration type 00019). Display an info message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String[] msg = {UPD_MSG_CHG_STR}` // `UPD_MSG_CHG_STR = "移転トーキ設定"` (Transfer TOKI settings) |
| 2 | CALL | `JCCWebCommon.setMessageInfo(this, JPCOnlineMessageConstant.EKB0370__I, msg)` // Set info message EKB0370--I |

---

**Block 9** — [RETURN] (L1262–1264)

> Finalize processing and return success.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `DEBUG_LOG.debug("###actionTokiAddCfmInit: transfer registration confirmation screen initial display method end")` // End logging |
| 2 | RETURN | `return true` // Indicate successful initialization |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| トーキ (TOKI) | Business term | Short for 転覆 (tentoku) — Telephone Number Transfer/Conversion. The process of transferring a customer's telephone number during service migration. |
| トーキ登録区分 (TOKI Add Category) | Field | Transfer registration category — classifies the type of transfer registration action (e.g., new registration, modification, cancellation). |
| トーキ種別 (TOKI Type) | Field | Transfer type — specifies the kind of transfer operation (number portability, intra-provider transfer, etc.). |
| トーキ希望 (TOKI Preference) | Field | Transfer preference — the customer's preferred timing or conditions for the transfer. |
| 移転元電話番号 (iten Moto Tel No) | Field | Pre-transfer (original) phone number — the customer's phone number before the transfer operation. |
| 連絡先電話番号 (rrks Tel No) | Field | Contact phone number — the number at which the customer can be reached during the transfer process. |
| 予約電話番号 (rsv Tel No) | Field | Reserved phone number — the new/assigned phone number reserved for the transfer. |
| 異動区分 (ido Div) | Field | Transfer division / movement category — indicates the type of customer movement (e.g., change of address, transfer registration). Code "00019" refers to 住所変更・登録 (change of address / registration). |
| EKB0370--I | Message code | Info-level message code — displays a notice to the operator on the screen. |
| 移転トーキ設定 | Message text | "Transfer TOKI settings" — the info message displayed when the customer's transfer division indicates a change-of-address/transfer registration. |
| CUST_KEI_HKTGI_LIST | Field | Customer history item list — a data bean array containing the customer's history/movement records. |
| X31SDataBeanAccess | Technical | Service form data bean access class — the framework class used to store and retrieve screen display data. |
| X31SDataBeanAccessArray | Technical | Data bean array wrapper — allows indexed access to a list of data bean objects. |
| JCCWebCommon | Technical | Common web utility class — provides shared utilities like `setMessageInfo()` for displaying messages on screen. |
| JPCOnlineMessageConstant.EKB0370__I | Constant | Message constant for info-level notice EKB0370. |
| DATABEAN_SET_VALUE | Constant | Flag value indicating a "set" operation on a data bean field. |
| DATABEAN_GET_VALUE | Constant | Flag value indicating a "get" operation on a data bean field. |
| getValueFromCd | Method | Helper method that resolves a code value to its display name by iterating over a code table stored in the data bean. |
| JCCWebBusinessLogic | Class | Base class for web business logic — provides common methods like `getServiceFormBean()`. |
| 住所変更・登録 (00019) | Business term | Change of address / registration (code 00019) — a customer movement category indicating a transfer registration due to address change. |
