# Business Logic — JKKOpsvkeiTelIktAddCC.isEnabledStartOption() [97 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKOpsvkeiTelIktAddCC` |
| Layer | CC / Common Component (Custom business logic bridge) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKOpsvkeiTelIktAddCC.isEnabledStartOption()

This method determines whether a customer's optional service ("option start") can be enabled for a contracted communication device (kiki-tekyo) in the context of a telecom service order. It acts as a gatekeeper for the "Anshin Hachakushin Service" (安心発着信サービス — a protective/assurance inbound call service with optional code B135). The method implements a **multi-source fallback** pattern: first it probes the CBS message list (`ekk0341b002Cbs1MsgList`) for device service status, then falls back to a pre-populated map (`kk0341b504`) if no device info is available in the message list. When device information is available but the device is not in an error/stopped state, it queries the delivery status via the `callEDK0011B090SC` service component to verify that delivery is complete and no work-contractor delivery is pending. The method's return value dictates whether the start option is permitted: `true` allows continuation of the optional service activation, while `false` blocks it.

The method handles two device types — multi-function routers (TAKINORT, code "C024") and home gateways (HGW, code "C025") — as identified by the device type code from CBS messages. It also implements a stat-priority resolution introduced in ANK-4315-00-00, where if multiple device records exist and one has a higher status number, the method keeps the newer status rather than overwriting it. This is critical for correctly tracking device state changes over time.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["isEnabledStartOption"])

    C1{opSvcCd equals B135?}
    C2{MsgList valid?}
    C3{SVC_CD TAKINORT or HGW?}
    C4{stat higher?}
    C5{Fallback map?}
    C6{stat in error states?}
    C7{SvcKeiNo present?}
    C8{call fails?}
    C9{delivery done and no work order?}

    P1["Init kktkSvcKeiNo and kktkStat to null"]
    P2["Loop msgList: get KKTK_SVC_CD and KKTK_SVC_KEI_STAT"]
    P3["Continue - higher stat exists"]
    P4["Fallback: get from kk0341b504 map"]
    P5["callEDK0011B090SC get delivery list"]
    P6["throw CCException"]
    P7["Check delivery list items"]
    P8["return true - delivery done no work contractor delivery"]
    P9["throw CCException Not Found R0"]
    P10["return false - option disabled"]
    P11["return true - default allow"]

    START --> C1
    C1 -- Yes --> P1
    P1 --> C2
    C2 -- Yes --> P2
    P2 --> C3
    C3 -- Yes --> C4
    C4 -- Yes --> P3
    P3 --> P2
    C4 -- No --> P2
    C3 -- No --> P2
    C2 -- No --> C5
    C1 -- No --> P11
    P2 --> C5
    C5 -- Yes --> P4
    P4 --> C6
    C5 -- No --> C6
    C6 -- Yes --> P11
    C6 -- No --> C7
    C7 -- Yes --> P5
    P5 --> C8
    C8 -- Yes --> P6
    C8 -- No --> P7
    P7 --> C9
    C9 -- Yes --> P8
    C9 -- No --> P10
    P8 --> P10
    C7 -- No --> P9
    P9 --> P10
```

**Step-by-step flow:**

1. **Service type guard** — The method first checks if `opSvcCd` equals `"B135"` (OP_SVC_CD_ANSN_HCS_SVC — Anshin Hachakushin Service). If not, it returns `true` immediately, meaning the start option is unconditionally allowed for non-protected optional services.

2. **Initialization** — For the Anshin Hachakushin Service, `kktkSvcKeiNo` and `kktkStat` are initialized to `null`.

3. **Device message list scan** — If `ekk0341b002Cbs1MsgList` is non-empty, the method iterates through each message entry. For entries matching device type "C024" (multi-function router) or "C025" (home gateway), it checks if an existing stat is higher than the current one (stat priority). If so, it skips the lower-priority entry. Otherwise, it updates `kktkSvcKeiNo` and `kktkStat` with the current device's service key number and status.

4. **Fallback map check** — If the device status is still `null` after scanning the message list, the method falls back to the `kk0341b504` map, extracting `KKTK_SVC_KEI_NO` and `KKTK_SVC_KEI_STAT` from it.

5. **Error-state gate** — If the device status is one of the active states (`"100"` = Service In Progress, `"210"` = Contract Acceptance In Progress, `"220"` = Contract Suspension In Progress), the method returns `true`, allowing start even though the device is still active. This is because the work completion/delivery is already done.

6. **Delivery verification** — If the device has a valid service key number, the method calls `callEDK0011B090SC` to fetch the contracted device delivery list. On failure, it throws a `CCException`.

7. **Delivery status check** — The method iterates the delivery list checking if any item has delivery status `"004"` (Delivery Completed) AND no work contractor delivery (`kojiak_no` is null). If so, it returns `true` — no device change number is needed and the start option is allowed.

8. **Default deny** — If none of the above conditions are met, the method returns `false`, blocking the start option.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database/session handle providing the connection context for SC (Service Component) calls. Used to execute `callEDK0011B090SC` when querying contracted device delivery status. |
| 2 | `param` | `IRequestParameterReadWrite` | Request parameter object carrying screen input data and SC call parameters. Passed to `callEDK0011B090SC` to retrieve the contracted device delivery target product list. |
| 3 | `requestParam` | `HashMap<String, Object>` | Request parameters map containing template data and fixed text definitions. Passed alongside `param` and `handle` to `callEDK0011B090SC` for the SC invocation. |
| 4 | `opSvcCd` | `String` | Optional service code — identifies which optional service is being processed. The critical value is `"B135"` (OP_SVC_CD_ANSN_HCS_SVC — Anshin Hachakushin Service). If it differs from "B135", the method returns `true` unconditionally, meaning non-Anshin services bypass this device validation entirely. |
| 5 | `ekk0341b002Cbs1MsgList` | `CAANMsg[]` | Array of CBS (Component-Based Service) message objects carrying device (kiki-tekyo) information. Each message contains `KKTK_SVC_CD` (device type code, typically "C024" for multi-function router or "C025" for home gateway) and `KKTK_SVC_KEI_STAT` (device service key status). This is the primary source for device status data. |
| 6 | `kk0341b504` | `Map<String, Object>` | Fallback map of device information populated when the CBS message list is absent or does not contain valid device status. Used as a secondary source to extract `KKTK_SVC_KEI_NO` and `KKTK_SVC_KEI_STAT`. |

**External state / instance fields read:**
| Field | Type | Business Meaning |
|-------|------|-------------------|
| `TEMPLATE_ID_EDK0011B090` | `String` | Template identifier constant `"EDK0011B090"` used as the result lookup key for the delivery list data returned by `callEDK0011B090SC`. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `callEDK0011B090SC` | EDK0011B090SC | Contracted device delivery data | Calls `callEDK0011B090SC(param, handle, requestParam, wkResultHash, kktkSvcKeiNo)` to retrieve the list of contracted device delivery target products (契約機器配送対象物品一覧). Returns a status code and populates `wkResultHash` with the delivery list. Used to verify delivery completion status. |
| R | `EKK0341B002CBSMsg1List.getString()` | EKK0341B002CBS | - | Reads `KKTK_SVC_CD` (device type code) and `KKTK_SVC_KEI_STAT` (device service key status) from each CBS message entry in `ekk0341b002Cbs1MsgList`. |
| R | `EKK0341B504CBSMsg1List.get()` | EKK0341B504CBS | - | Reads `KKTK_SVC_KEI_NO` and `KKTK_SVC_KEI_STAT` from the fallback `kk0341b504` map when the message list does not provide device status. |
| R | `EDK0011B090CBSMsg1List.get()` | EDK0011B090CBS | - | Reads `HAISO_STAT` (delivery status code) and `KOJIAK_NO` (work order number) from each delivery list item to determine if delivery is complete without pending work contractor delivery. |

**Notes:**
- **SC Code inference**: The SC method `callEDK0011B090SC` has SC Code `EDK0011B090SC`, named by the SC call pattern convention (`callEddXXXXXYYYSC` → SC Code `EDK0011B090SC`).
- **Entity/DB tables**: The actual underlying database tables for `EDK0011B090SC` are not directly referenced in this method. The SC layer handles the entity-to-table mapping. This SC is documented as the "Contracted Device Delivery Target Product List Inquiry" (契約機器配送対象物品一覧照会SIF).

## 5. Dependency Trace

### Direct callers of this method:

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | JKKOpsvkeiTelIktAddCC | `JKKOpsvkeiTelIktAddCC.mainProc()` → `JKKOpsvkeiTelIktAddCC.isEnabledStartOption` | `callEDK0011B090SC [R] Contracted Device Delivery Data` |

**Call chain explanation:**
- The `mainProc()` method of `JKKOpsvkeiTelIktAddCC` invokes `isEnabledStartOption()` during the processing of optional service additions for telecom product orders.
- When the device status is not in an error state and delivery information is available, the method calls `callEDK0011B090SC`, which performs a read (R) operation against contracted device delivery data to verify delivery completion.
- The CBS messages (`EKK0341B002CBS`, `EKK0341B504CBS`) and delivery list (`EDK0011B090CBS`) are read (R) operations on in-memory data structures derived from prior SC calls upstream in the call chain.

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(opSvcCd equals "B135" — ANSHIN_HCS_SVC)` (L4238)

> Guard clause: Only processes device validation for the Anshin Hachakushin Service (B135). All other optional services bypass validation and return `true`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiNo = null` // Initialize device service key number |
| 2 | SET | `kktkStat = null` // Initialize device status |
| 3 | RETURN (elsewhere, L4325) | `return true` // Non-Anshin services: allow start option unconditionally |

**Block 1.1** — [IF] `(ekk0341b002Cbs1MsgList != null && length > 0 — MsgList has entries)` (L4242)

> Primary source: Scan CBS message list for device information.

| # | Type | Code |
|---|------|------|
| 1 | SET | `// For each CAANMsg entry in the message list` |
| 2 | CALL | `kkSvcCd = ekk0341b002.getString(EKK0341B002CBSMsg1List.KKTK_SVC_CD)` // Get device type code |
| 3 | SET | `[-> KKTK_SVC_CD_TAKINORT = "C024" (Multi-Function Router)]` |
| 4 | SET | `[-> KKTK_SVC_CD_HGW = "C025" (Home Gateway)]` |

**Block 1.1.1** — [IF] `(kkSvcCd == "C024" || kkSvcCd == "C025" — Multi-Function Router OR Home Gateway)` (L4247)

> Device type filter: Only multi-function routers and home gateways are processed.

| # | Type | Code |
|---|------|------|
| 1 | SET | `[ANK-4315-00-00 MOD: Added OR check for KKTK_SVC_CD_HGW="C025"]` |

**Block 1.1.1.1** — [IF] `(kktkStat != null && kktkStat.compareTo(currentStat) > 0 — Higher stat already exists)` (L4252)

> Stat-priority check: If we already found a device with a higher status number, skip this lower-priority entry. Introduced in #84334 ADD.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `continue` // Skip to next message — higher stat wins |

**Block 1.1.1.2** — [ELSE-IF / fallback assignment in same IF body] (L4260)

> Update device info with current (highest stat) entry.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiNo = ekk0341b002.getString(EKK0341B002CBSMsg1List.KKTK_SVC_KEI_NO)` // Store device service key number |
| 2 | SET | `kktkStat = ekk0341b002.getString(EKK0341B002CBSMsg1List.KKTK_SVC_KEI_STAT)` // Store device status |

**Block 1.2** — [IF] `(kktkStat == null && kk0341b504 != null — Fallback map available)` (L4266)

> Fallback source: If the CBS message list did not provide device status, try the fallback map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiNo = (String)kk0341b504.get(EKK0341B504CBSMsg1List.KKTK_SVC_KEI_NO)` // Extract from fallback map |
| 2 | SET | `kktkStat = (String)kk0341b504.get(EKK0341B504CBSMsg1List.KKTK_SVC_KEI_STAT)` // Extract status from fallback map |

**Block 1.3** — [IF-ELSE] `(kktkStat equals "100" || "210" || "220" — In error/service state)` (L4272)

> Active status gate: If the device status is one of the active error/service states, the start option is allowed because the work has already been completed or delivered.

| # | Type | Code |
|---|------|------|
| 1 | SET | `[-> CD00056_STAT_TEIKYO_CHU = "100" (Service in progress)]` |
| 2 | SET | `[-> CD00056_STAT_KEI_KYUSHI_CHU = "210" (Contract acceptance in progress)]` |
| 3 | SET | `[-> CD00056_STAT_KEI_TEISHI_CHU = "220" (Contract suspension in progress)]` |

**Block 1.3.1** — [IF — True branch: stat in active states]

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true` // Device is in service/acceptance/suspension state — work is complete, allow start option |

**Block 1.3.2** — [ELSE — stat is NOT in active states, need to verify delivery]

> Device status is not in a terminal active state. Must verify delivery was completed without pending work contractor delivery.

**Block 1.3.2.1** — [IF] `(kktkSvcKeiNo != null && kktkSvcKeiNo.length() > 0 — Device service key number exists)` (L4293)

> Valid device key number check: Proceed to delivery verification if we have a device service key number.

| # | Type | Code |
|---|------|------|
| 1 | SET | `wkResultHash = new HashMap<String, Object>()` // Prepare result container for SC call |
| 2 | CALL | `statusCode = callEDK0011B090SC(param, handle, requestParam, wkResultHash, kktkSvcKeiNo)` // Query contracted device delivery target product list |

**Block 1.3.2.1.1** — [IF] `(statusCode != 0 — SC call failed)` (L4302)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `throw new CCException("", new SCCallException("", String.valueOf(statusCode), statusCode))` // Propagate SC error |

**Block 1.3.2.1.2** — [Post-SC-call processing] (L4305)

> Retrieve the delivery list from the SC result.

| # | Type | Code |
|---|------|------|
| 1 | SET | `[-> TEMPLATE_ID_EDK0011B090 = "EDK0011B090"]` |
| 2 | SET | `edk0011B090List = (ArrayList<HashMap<String, Object>>)wkResultHash.get(TEMPLATE_ID_EDK0011B090)` // Get delivery list |

**Block 1.3.2.1.3** — [FOR] `(each item in edk0011B090List)` (L4307)

> Iterate through delivery items to check if any has delivery completed and no work contractor delivery pending.

| # | Type | Code |
|---|------|------|
| 1 | SET | `[-> EDK0011B090CBSMsg1List.HAISO_STAT = "haiso_stat"]` |
| 2 | SET | `[-> EDK0011B090CBSMsg1List.KOJIAK_NO = "kojiak_no" (IT2-2020-0000014: replaced HISOS_KOCOMP_CD)]` |

**Block 1.3.2.1.3.1** — [IF] `(haiso_stat == "004" && kojiak_no is null — Delivery done and no work order)` (L4311)

> Delivery verification: The item's delivery status is "004" (delivery completed) and there is no work order number (kojiak_no is null), meaning no work-contractor delivery is pending.

| # | Type | Code |
|---|------|------|
| 1 | SET | `[-> HAISO_STAT_KANRYOU_ZM = "004" (Delivery Completed)]` |
| 2 | SET | `[IT2-2020-0000014 MOD: Changed from HISOS_KOCOMP_CD check to KOJIAK_NO check]` |
| 3 | RETURN | `return true` // Device change number not needed — allow start option |

**Block 1.3.2.2** — [ELSE — kktkSvcKeiNo is null/empty] (L4319)

> This path should normally not be reached (device should exist at application time), but is treated as a CC error for safety.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `throw new CCException("", new IllegalArgumentException("Not Found R0."))` // CC Error: device service key number not found |

**Block 1.3.3** — [Post all checks] (L4323)

> None of the allow conditions matched — block the start option.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return false` // Option not enabled — device status does not allow start |

**Block 2** — [ELSE — opSvcCd != "B135"] (L4325)

> Non-Anshin Hachakushin services are allowed to start without device validation.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true` // Default: allow start option for non-protected services |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `opSvcCd` | Field | Optional service code — identifies the optional service being processed. "B135" specifically refers to the Anshin Hachakushin Service. |
| `op_svc_cd_ansn_hcs_svc` | Constant | "B135" — Optional Service Code for Anshin Hachakushin Service (安心発着信サービス) |
| `ekk0341b002Cbs1MsgList` | Parameter | CBS message array containing device (kiki-tekyo) information extracted from upstream CBS processing |
| `kk0341b504` | Parameter | Fallback map containing device information when CBS messages are unavailable |
| `kk0341b504` key: `kktk_svc_kei_no` | Field | Device supply service contract number — internal identifier for the contracted device's service contract line item |
| `kk0341b504` key: `kktk_svc_kei_stat` | Field | Device supply service contract status — current lifecycle status of the device service contract |
| `KKTK_SVC_CD` | Field | Device supply service code — classifies the device type (e.g., "C024" = multi-function router, "C025" = home gateway) |
| `KKTK_SVC_KEI_STAT` | Field | Device supply service key status — the status code indicating the current state of the device service |
| `KKTK_SVC_KEI_NO` | Field | Device supply service key number — unique identifier for the device service key |
| `KKTK_SVC_CD_TAKINORT` | Constant | "C024" — Multi-Function Router device service code (多機能ルータ) |
| `KKTK_SVC_CD_HGW` | Constant | "C025" — Home Gateway device service code (ホームゲートウェイ) |
| `CD00056_STAT_TEIKYO_CHU` | Constant | "100" — Service in progress status (提供中). Device is actively being provided to the customer. |
| `CD00056_STAT_KEI_KYUSHI_CHU` | Constant | "210" — Contract acceptance in progress status (契約要求中). Contract approval is pending. |
| `CD00056_STAT_KEI_TEISHI_CHU` | Constant | "220" — Contract suspension in progress status (契約停止中). Contract is under suspension processing. |
| `HAISO_STAT_KANRYOU_ZM` | Constant | "004" — Delivery completed status (配送完了済). The delivery process for the device is fully done. |
| `HAISO_STAT` | Field | Delivery status code — indicates the current state of the delivery process (e.g., "004" = completed) |
| `KOJIAK_NO` | Field | Work order number (工事案件番号) — identifier for work-contractor delivery. If null, no work-contractor delivery is pending. |
| `HISOS_KOCOMP_CD` | Field | Subcontractor company code (配送下請会社コード) — replaced by `KOJIAK_NO` in IT2-2020-0000014 modification |
| `callEDK0011B090SC` | Method | Contracted Device Delivery Target Product List Inquiry SC (契約機器配送対象物品一覧照会SIF) — retrieves the list of contracted devices and their delivery status |
| `EDK0011B090SC` | SC Code | Service Component for contracted device delivery data retrieval |
| `TEMPLATE_ID_EDK0011B090` | Constant | "EDK0011B090" — Template identifier used as the result lookup key for the delivery list in the SC result hash |
| Anshin Hachakushin Service | Business term | 安心発着信サービス — A protective/assurance inbound call optional service (optional code "B135"). Requires device validation before start. |
| kiki-tekyo | Field | 機器特定 — Device identification. Refers to contracted communication equipment (devices supplied with telecom services). |
| CC | Abbreviation | Common Component — the shared business logic component layer (CC class). |
| SC | Abbreviation | Service Component — a service tier class that handles data access and business logic for specific operations. |
| CBS | Abbreviation | Component-Based Service — message/response objects exchanged between CBS layers. |
| CAANMsg | Type | Message container class — holds structured data returned from CBS calls, accessed via `getString()` with field key constants. |
| CCException | Type | Custom component exception — wraps business logic errors and SCCallException for propagation to the caller. |
| SCCallException | Type | Service Component call exception — wraps SC call failures with status codes for error reporting. |
| ANK-4315-00-00 | Change ticket | Modification adding HGW (Home Gateway, "C025") support to the device type check alongside multi-function router. |
| #84334 | Change ticket | Modification adding stat-priority resolution to keep higher status when multiple device entries exist. |
| IT2-2020-0000014 | Change ticket | Modification replacing `HISOS_KOCOMP_CD` (subcontractor code) check with `KOJIAK_NO` (work order number) for delivery verification logic. |
