# Business Logic — FUW05401SFLogic.checkInitError() [110 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.FUW05401SF.FUW05401SFLogic` |
| Layer | Service (Webview Service Layer — Front-end business logic handler) |
| Module | `FUW05401SF` (Package: `eo.web.webview.FUW05401SF`) |

## 1. Role

### FUW05401SFLogic.checkInitError()

This method performs **pre-display error validation** (業務エラー判定(初期表示)) during the initial screen load of the "eo Optical Electric Phone Option Service Contract Cancellation" (eo光電話オプションサービス契約解約) screen. It acts as a **gatekeeper** that verifies the business state of service contracts before the user is allowed to view or interact with the cancellation screen. The method executes a series of **contract existence checks**, **contract status validity checks**, **sub-option contract status checks**, **pending-transaction guards**, and **mandatory data presence checks** — each designed to catch data integrity problems early and present the user with an appropriate error message.

Specifically, the method branches across five validation categories: (a) verifying that both the general service contract list and the device-provisioning service contract list contain at least one record, (b) validating that the service contract internal status is in one of three permissible states (Confirmed "020", Completed "030", or Service Provision "100"), (c) for sub-option processing scenarios (when `SBOP_TRAN_FLG = "1"`), retrieving and validating the first sub-option contract's status against the same permissible set, (d) scanning all option/sub-option records for pending change reservation detail codes (異動予約詳細コード) that would indicate a concurrent contract modification in progress, and (e) confirming that the fee-course option-service list is not empty. This follows a **fail-fast defensive validation pattern**, throwing a `JCCBusinessException` immediately upon the first violation.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["checkInitError Start"])

    START --> S1["SVC_KEI_INFO_LIST.getCount()"]
    S1 --> S2{SVC_KEI_INFO_LIST.count == 0<br/>or KKTK_SVC_KEI_LIST.count == 0}
    S2 -->|Yes| S3["Throw JCCBusinessException
ERROR_CODE_0102
Contract status error"]
    S2 -->|No| S4["getDataBeanItemByPath
commonInfoBean
SVC_KEI_UCWK_STAT_24"]

    S4 --> S5{"status == 020 Confirmed
or 030 Completed
or 100 Service provision"}
    S5 -->|No| S6["Throw JCCBusinessException
ERROR_CODE_0102
Contract status error"]
    S5 -->|Yes| S7{"SBOP_TRAN_FLG == 1
Required"}

    S7 -->|No| S12{"OP_TRAN_FLG == 1
Required"}

    S7 -->|Yes| S8{"tranTrgtRecOpArray == null
or length == 0"}
    S8 -->|Yes| S9["Throw JCCBusinessException
ERROR_CODE_0102
Contract status error"]
    S8 -->|No| S10["getDataBeanItemByPath
tranTrgtRecOpArray[0]
OP_SVC_KEI_STAT_01"]
    S10 --> S11{"sub_status == 020 Confirmed
or 030 Completed
or 100 Service provision"}
    S11 -->|No| S13["Throw JCCBusinessException
ERROR_CODE_0102
Contract status error"]
    S11 -->|Yes| S12

    S12 -->|Yes| S14{"tranTrgtRecOpArray != null"}
    S12 -->|No| S20

    S14 -->|Yes| S15["For each record
in tranTrgtRecOpArray"]
    S14 -->|No| S20
    S15 --> S16{"KK0351_IDO_RSV_DTL_CD_01
!= null
or KK0401_IDO_RSV_DTL_CD_01
!= null"}
    S16 -->|Yes| S17["Throw JCCBusinessException
ERROR_CODE_0203
Contract change
processing error"]
    S16 -->|No| S18["i++"]
    S18 --> S19{i < tranTrgtRecOpArray.length}
    S19 -->|Yes| S15
    S19 -->|No| S20

    S20{"PCRS_OP_SVC_LIST
.getCount == 0"}
    S20 -->|Yes| S21["Throw JCCBusinessException
ERROR_CODE_0002
System error"]
    S20 -->|No| S22["checkInitError End"]

    S3 --> S22
    S6 --> S22
    S13 --> S22
    S17 --> S22
    S21 --> S22
    S22 --> END(["Return / Next"])
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `bean` | `X31SDataBeanAccess` | The main service-form data bean carrying the current screen's business state. Contains service contract information lists (`SVC_KEI_INFO_LIST`), device-provisioning service contract lists (`KKTK_SVC_KEI_LIST`), fee-course option-service lists (`PCRS_OP_SVC_LIST`), and processing flags (`OP_TRAN_FLG`, `SBOP_TRAN_FLG`). This is the primary data context for the "eo Optical Electric Phone Option Service Contract Cancellation" screen. |
| 2 | `commonInfoBean` | `X31SDataBeanAccess` | A shared form bean used to carry common business data across the service layer. Specifically holds the service contract internal status (`SVC_KEI_UCWK_STAT_24`) which determines whether the contract is in a valid state (Confirmed, Completed, or Service Provision) to proceed with cancellation. |
| 3 | `tranTrgtRecOpArray` | `X31SDataBeanAccess[]` | An optional array of record-operation beans representing the target records for processing. Each element contains per-record data including sub-option service contract status (`OP_SVC_KEI_STAT_01`) and change reservation detail codes (`KK0351_IDO_RSV_DTL_CD_01`, `KK0401_IDO_RSV_DTL_CD_01`). May be `null` or empty, which itself triggers errors in certain processing flag scenarios. |

**External state read:**
- `DEBUG_LOG` — Logger instance for debug tracing
- `JFUWebCommon` — Static utility class for data bean path access
- `FUW05401SFConst` — Class-level constant definitions for field paths
- `CommonInfoCFConst` — Shared constant for service contract status field path
- `JFUStrConst` — Standard string constants for error codes and status codes
- `JCCBusinessException` — Business exception class for error signaling

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `OneStopDataBeanAccessArray.getCount` | - | - | Reads record count of service contract info list (`SVC_KEI_INFO_LIST`) |
| R | `OneStopDataBeanAccessArray.getCount` | - | - | Reads record count of device-provisioning service contract list (`KKTK_SVC_KEI_LIST`) |
| R | `JFUWebCommon.getDataBeanItemByPath` | - | - | Retrieves service contract internal status (`SVC_KEI_UCWK_STAT_24`) from `commonInfoBean` |
| R | `JFUWebCommon.getDataBeanItemByPath` | - | - | Retrieves sub-option processing flag (`SBOP_TRAN_FLG`) from `bean` |
| R | `JFUWebCommon.getDataBeanItemByPath` | - | - | Retrieves option processing flag (`OP_TRAN_FLG`) from `bean` |
| R | `JFUWebCommon.getDataBeanItemByPath` | - | - | Retrieves sub-option service contract status (`OP_SVC_KEI_STAT_01`) from `tranTrgtRecOpArray[0]` |
| R | `JFUWebCommon.getDataBeanItemByPath` | - | - | Retrieves change reservation detail code for option service (`KK0351_IDO_RSV_DTL_CD_01`) per record |
| R | `JFUWebCommon.getDataBeanItemByPath` | - | - | Retrieves change reservation detail code for sub-option service (`KK0401_IDO_RSV_DTL_CD_01`) per record |
| R | `OneStopDataBeanAccessArray.getCount` | - | - | Reads record count of fee-course option-service list (`PCRS_OP_SVC_LIST`) |
| - | `JACBatCommon.isNull` | - | - | Static utility call for null-checking string values |
| - | `JCCBusinessException` | - | - | Throws business exception for contract status, pending-change, or system errors |

**Note:** This method is a **read-only validation** method — it performs no Create, Update, or Delete operations. It exclusively reads data from data bean objects to validate the preconditions for the option service cancellation screen. The `isNull` calls are null-safety utilities, and `JCCBusinessException` is the error-signaling mechanism.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | FUW05401SFLogic.init() | `FUW05401SFLogic.init()` -> `FUW05401SFLogic.checkInitError(bean, commonInfoBean, tranTrgtRecOpArray)` | `getCount [R] SVC_KEI_INFO_LIST`, `getCount [R] KKTK_SVC_KEI_LIST`, `getDataBeanItemByPath [R] SVC_KEI_UCWK_STAT_24`, `getDataBeanItemByPath [R] SBOP_TRAN_FLG`, `getDataBeanItemByPath [R] OP_TRAN_FLG`, `getDataBeanItemByPath [R] OP_SVC_KEI_STAT_01`, `getDataBeanItemByPath [R] KK0351_IDO_RSV_DTL_CD_01`, `getDataBeanItemByPath [R] KK0401_IDO_RSV_DTL_CD_01`, `getCount [R] PCRS_OP_SVC_LIST` |

## 6. Per-Branch Detail Blocks

### (a) Service Contract Existence Check (L1632–L1641)

> Verify that both the service contract information list and the device-provisioning service contract list contain at least one record. If either is empty, throw a contract status error.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `bean.getDataBeanArray(FUW05401SFConst.SVC_KEI_INFO_LIST).getCount()` // Read: "サービス契約情報リスト" (Service Contract Information List) |
| 2 | CALL | `bean.getDataBeanArray(FUW05401SFConst.KKTK_SVC_KEI_LIST).getCount()` // Read: "機器提供サービス契約リスト" (Device Provisioning Service Contract List) |
| 3 | IF | `count == 0 OR count == 0` [L1635] — **Condition:** Either list is empty |
| 4 | EXEC | `DEBUG_LOG.info("...サービス契約、機器提供レコード：0件エラー...")` // Log: "Service Contract, Device Provision Record: 0 records error" |
| 5 | CALL | `throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0102)` // "0102": Contract Status Error |

### (b) Service Contract Status Check (L1643–L1659)

> Retrieve the service contract internal status and validate it is one of the three permissible states.

| # | Type | Code |
|---|------|------|
| 1 | SET | `status = JFUWebCommon.getDataBeanItemByPath(commonInfoBean, "サービス契約内況" + "." + "サービス契約内況ステータス")` [-> `JFUWebCommon.SVC_KEI_UCWK_INFO + JFUWebCommon.SEP_0 + CommonInfoCFConst.SVC_KEI_UCWK_STAT_24`] |
| 2 | IF | `!(status == "020" OR "030" OR "100")` [L1653] — **Condition:** Status NOT in {Confirmed, Completed, Service Provision} |
| 3 | EXEC | `DEBUG_LOG.info("...サービス契約内況ステータスエラー...")` // Log: "Service Contract Internal Status Error" |
| 4 | CALL | `throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0102)` // "0102": Contract Status Error |

**Constant Resolution:**
- `JFUStrConst.CD00037_020 = "020"` — Confirmed (照会済)
- `JFUStrConst.CD00037_030 = "030"` — Completed (結了済)
- `JFUStrConst.CD00037_100 = "100"` — Service Provision (サービス提供中)
- `CommonInfoCFConst.SVC_KEI_UCWK_STAT_24 = "サービス契約内況ステータス"` — Service Contract Internal Status

### (c) Sub-option Processing Status Check (L1661–L1677)

> If sub-option processing is required (`SBOP_TRAN_FLG = "1"`), validate that the sub-option target records exist and that the first sub-option contract status is valid.

| # | Type | Code |
|---|------|------|
| 1 | IF | `JFUStrConst.CD00001_1.equals(getDataBeanItemByPath(bean, "サブオプション処理フラグ"))` [L1661] — **Condition:** Sub-option processing flag == "1" (Required) |
| 2 | IF | `tranTrgtRecOpArray == null OR length == 0` [L1665] — **Condition:** No sub-option target records provided |
| 3 | EXEC | `DEBUG_LOG.info("...サブオプションサービス契約ステータスエラー...")` // Log: "Sub-option Service Contract Status Error" |
| 4 | CALL | `throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0102)` // "0102": Contract Status Error |
| 5 | SET | `status = getDataBeanItemByPath(tranTrgtRecOpArray[0], "オプションサービス契約ステータス")` [-> `FUW05401SFConst.OP_SVC_KEI_STAT_01`] |
| 6 | IF | `!(status == "020" OR "030" OR "100")` [L1673] — Same status check as (b) |
| 7 | EXEC | `DEBUG_LOG.info("...サブオプションサービス契約ステータスエラー...")` // Log: "Sub-option Service Contract Status Error" |
| 8 | CALL | `throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0102)` // "0102": Contract Status Error |

**Constant Resolution:**
- `FUW05401SFConst.SBOP_TRAN_FLG = "サブオプション処理フラグ"` — Sub-option Processing Flag
- `FUW05401SFConst.OP_SVC_KEI_STAT_01 = "オプションサービス契約ステータス"` — Option Service Contract Status
- `JFUStrConst.CD00001_1 = "1"` — Required

### (d) Pending Change Reservation Check — Option Service (L1682–L1701)

> If option processing is required (`OP_TRAN_FLG = "1"`), iterate over all target records and check for pending change reservation detail codes that would indicate a concurrent modification.

| # | Type | Code |
|---|------|------|
| 1 | IF | `JFUStrConst.CD00001_1.equals(getDataBeanItemByPath(bean, "オプション処理フラグ"))` [L1682] — **Condition:** Option processing flag == "1" (Required) |
| 2 | IF | `tranTrgtRecOpArray != null` [L1685] |
| 3 | FOR | `int i = 0; i < tranTrgtRecOpArray.length; i++` [L1688] |
| 4 | IF | `!isNull(getDataBeanItemByPath(record, "異動予約詳細コード（オプションサービス契約）")) OR !isNull(getDataBeanItemByPath(record, "異動予約詳細コード（サブオプションサービス契約）"))` [L1691–1693] — **Condition:** Pending change code present on either option or sub-option contract |
| 5 | EXEC | `DEBUG_LOG.info("...異動予約手続中エラー...")` // Log: "Pending Change Reservation Processing Error" |
| 6 | CALL | `throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0203)` // "0203": Contract Change Processing Error |

**Constant Resolution:**
- `FUW05401SFConst.OP_TRAN_FLG = "オプション処理フラグ"` — Option Processing Flag
- `FUW05401SFConst.KK0351_IDO_RSV_DTL_CD_01 = "異動予約詳細コード（オプションサービス契約）"` — Change Reservation Detail Code (Option Service Contract)
- `FUW05401SFConst.KK0401_IDO_RSV_DTL_CD_01 = "異動予約詳細コード（サブオプションサービス契約）"` — Change Reservation Detail Code (Sub-option Service Contract)
- `JFUStrConst.ERROR_CODE_0203 = "0203"` — Contract Change Processing Error

### (e) Pending Change Reservation Check — Sub-option Service (L1703–L1722)

> If sub-option processing is required (`SBOP_TRAN_FLG = "1"`) (else branch of the OP_TRAN_FLG check), iterate over all target records and check for pending change reservation detail codes on sub-option contracts.

| # | Type | Code |
|---|------|------|
| 1 | IF | `JFUStrConst.CD00001_1.equals(getDataBeanItemByPath(bean, "サブオプション処理フラグ"))` [L1703] — **Condition:** Sub-option processing flag == "1" (Required) — **Else branch of OP_TRAN_FLG** |
| 2 | IF | `tranTrgtRecOpArray != null` [L1705] |
| 3 | FOR | `int i = 0; i < tranTrgtRecOpArray.length; i++` [L1707] |
| 4 | IF | `!isNull(getDataBeanItemByPath(record, "異動予約詳細コード（オプションサービス契約）")) OR !isNull(getDataBeanItemByPath(record, "異動予約詳細コード（サブオプションサービス契約）"))` [L1710–1712] — Same condition as (d) |
| 5 | EXEC | `DEBUG_LOG.info("...異動予約手続中エラー...")` // Log: "Pending Change Reservation Processing Error" |
| 6 | CALL | `throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0203)` // "0203": Contract Change Processing Error |

### (f) Fee Course Option Service List Presence Check (L1727–L1734)

> Verify that the fee-course option-service list contains at least one record. If empty, throw a system error.

| # | Type | Code |
|---|------|------|
| 1 | IF | `bean.getDataBeanArray("料金コース_オプションサービスリスト").getCount() == 0` [L1729] — **Condition:** Fee Course Option Service List is empty |
| 2 | EXEC | `DEBUG_LOG.info("...料金コース_オプションサービス：0件エラー...")` // Log: "Fee Course Option Service: 0 records error" |
| 3 | CALL | `throw new JCCBusinessException(JFUStrConst.ERROR_CODE_0002)` // "0002": System Error |

**Constant Resolution:**
- `FUW05401SFConst.PCRS_OP_SVC_LIST = "料金コース_オプションサービスリスト"` — Fee Course _ Option Service List
- `JFUStrConst.ERROR_CODE_0002 = "0002"` — System Error

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `SVC_KEI_INFO_LIST` | Field | Service Contract Information List — top-level list of service contract records associated with the customer |
| `KKTK_SVC_KEI_LIST` | Field | Device Provisioning Service Contract List — service contracts related to hardware/device provisioning |
| `PCRS_OP_SVC_LIST` | Field | Fee Course _ Option Service List — list of fee courses (pricing plans) associated with option services |
| `SVC_KEI_UCWK_STAT_24` | Field | Service Contract Internal Status — the internal state code of a service contract (020/030/100 are valid) |
| `SBOP_TRAN_FLG` | Field | Sub-option Processing Flag — indicates whether sub-option service processing is required ("1" = required) |
| `OP_TRAN_FLG` | Field | Option Processing Flag — indicates whether option service processing is required ("1" = required) |
| `OP_SVC_KEI_STAT_01` | Field | Option Service Contract Status — the status of an option service contract |
| `KK0351_IDO_RSV_DTL_CD_01` | Field | Change Reservation Detail Code (Option Service Contract) — code indicating a pending change/modification on an option service contract |
| `KK0401_IDO_RSV_DTL_CD_01` | Field | Change Reservation Detail Code (Sub-option Service Contract) — code indicating a pending change/modification on a sub-option service contract |
| `ERROR_CODE_0102` | Constant | Contract Status Error — thrown when service contract data is missing, or status is not in a permissible state |
| `ERROR_CODE_0203` | Constant | Contract Change Processing Error — thrown when a pending contract change reservation is detected (concurrent modification conflict) |
| `ERROR_CODE_0002` | Constant | System Error — thrown when mandatory option service data (fee course list) is missing |
| `CD00037_020` | Constant | "020" — Confirmed (照会済) — contract status indicating the contract has been confirmed/inquired |
| `CD00037_030` | Constant | "030" — Completed (結了済) — contract status indicating the contract processing is completed |
| `CD00037_100` | Constant | "100" — Service Provision (サービス提供中) — contract status indicating the service is actively being provided |
| `CD00001_1` | Constant | "1" — Required flag value — indicates a processing flag is set to required/on |
| `JCCBusinessException` | Exception | Business exception class — used to signal business-level validation failures with error parameter IDs |
| `X31SDataBeanAccess` | Type | Service-form data bean access object — a structured data container carrying screen-level business data |
| `tranTrgtRecOpArray` | Parameter | Target record operation array — array of per-record operation data for option/sub-option service records |
| eo光電話オプションサービス契約解約 | Business term | eo Optical Electric Phone Option Service Contract Cancellation — the business process/screen this method belongs to |
| 異動予約 | Business term | Change Reservation — a pending modification or migration record for a service contract |
| サブオプション | Business term | Sub-option — an optional add-on service layered beneath a primary option service |
