# (DD41) Business Logic — JDKCommon08CC.updateSTB() [71 LOC]

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

## 1. Role

### JDKCommon08CC.updateSTB()

This method performs **STB (Set-Top Box) information update processing** as part of a device replacement (home appliance replacement) approval workflow. It acts as a **delegation/routing layer** that iterates over each device entry in the `unlinkMap` list and invokes the STB update service component (`EWCA0010003CBS`) to synchronize STB/device information with the home management system (homesystem).

The method implements a **repeating delegation pattern**: for every device (STB or C-CAS terminal) that needs to be unlinked or re-registered during a replacement approval, it constructs a service call parameter map containing SC input common data (transaction ID, use case ID, operation ID, call type, client hostname, client IP, screen ID, operator ID) and user data, prepares the STB update message payload, and dispatches it via `scCall.run()`. After each service call, it validates the result using `JDKBPCommon.hasError()` and throws an `SCCallException` if the update failed.

It is called from the `approve()` method when the device replacement status (`updateStat`) equals `HMPIN_KIKI_STAT_SHONIN` (approved) and is not a cancellation function code (`FUNC_CODE_2`). This method was added under change request **OM-2018-0000010** to ensure STB information is updated in the homesystem after a replacement device is approved.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["updateSTB param, unlinkMap, scCall, handle"])
    INIT["paramMap = new HashMap<String, Object>()"]

    LOOP_START{"unlinkMap has more entries?"}

    LOOP_BODY["paramMap = new HashMap<String, Object>()"]

    SC_DATA["Set SC Input Common Data:<br/>TRANZACTION_ID_KEY = telegramID<br/>USECASE_ID_KEY = usecaseID<br/>OPERATION_ID_KEY = operationID<br/>CALL_TYPE_KEY = callType"]

    CTRL_DATA["Set Control Map Data:<br/>CLIENT_HOST_NAME_KEY = REQ_HOSTNAME<br/>CLIENT_IP_ADDRESS_KEY = REQ_HOSTIP<br/>INVOKE_GAMEN_ID_KEY = REQ_VIEWID<br/>OPERATOR_ID_KEY = operatorID"]

    GET_USER["inMap = param.getData(DKSV008101CC)<br/>// User data from control map"]

    CREATE_TEMPLATE["template = new CAANMsg(EWCA0010003CBSMsg)<br/>template.set(TEMPLATEID, EWCA0010003)"]

    EDIT_MSG["editSTBUpdateMsg(paramMap, inMap, tmpParamMap)"]

    LOG["JSYejbLog.println DEBUG: STB information update processing"]

    SC_RUN["result = scCall.run(paramMap, handle)<br/>// SC EWCA0010003 CBS Execution"]

    EDIT_RR["editResultRrr(result, param)"]

    CHECK_ERROR{"JDKBPCommon.hasError(param)?"}

    THROW_ERROR["throw SCCallException:<br/>STB update failure"]

    LOOP_END["loop back to unlinkMap check"]

    RETURN["return"]

    END(["End"])

    START --> INIT
    INIT --> LOOP_START
    LOOP_START -->|Yes| LOOP_BODY
    LOOP_BODY --> SC_DATA
    SC_DATA --> CTRL_DATA
    CTRL_DATA --> GET_USER
    GET_USER --> CREATE_TEMPLATE
    CREATE_TEMPLATE --> EDIT_MSG
    EDIT_MSG --> LOG
    LOG --> SC_RUN
    SC_RUN --> EDIT_RR
    EDIT_RR --> CHECK_ERROR
    CHECK_ERROR -->|true| THROW_ERROR
    CHECK_ERROR -->|false| LOOP_END
    THROW_ERROR --> END
    LOOP_END --> LOOP_START
    LOOP_START -->|No| RETURN
    RETURN --> END
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying the full business context for the STB update operation. It contains system-level identifiers (telegramID, usecaseID, operationID, callType) and user data retrieved by key `DKSV008101CC`. It also holds error flags (via `controlMapData("returnCode")`) and control map data (REQ_HOSTNAME, REQ_HOSTIP, REQ_VIEWID, operatorID) used for SC invocation metadata. |
| 2 | `unlinkMap` | `List<HashMap<String, Object>>` | A list of per-device parameter maps to be updated. Each entry represents a single STB or C-CAS terminal that was previously processed by the `unlink()` method. The method iterates over this list, creating a fresh `paramMap` per device and invoking the STB update service component for each. This list is the core input that drives the loop. |
| 3 | `scCall` | `ServiceComponentRequestInvoker` | The service component invocation handler. It encapsulates the ability to dispatch synchronous service component calls (`scCall.run()`) to the home management system's STB update CBS (`EWCA0010003`). The instance is pre-constructed by the caller (`approve()` method) and injected here. |
| 4 | `handle` | `SessionHandle` | The session handle used for the SC invocation. It carries session context (authentication, transaction boundaries) required by the underlying service component. |

**External/Instance State:**
- No instance fields are read by this method. It is a stateless utility method.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| U | `editSTBUpdateMsg` | EWCA0010003CBS | - | Populates the CAANMsg template with STB update data from user input (`param`, `inMap`, `tmpParamMap`). Prepares message parameters for the STB update service call. |
| C | `scCall.run` | EWCA0010003CBS | - | Invokes the STB information update service component (CBS `EWCA0010003`). This service updates device information (STB/C-CAS terminal) in the home management system. Called once per device in `unlinkMap`. |
| U | `editResultRrr` | - | - | Processes the service response and maps return values back into the `param` object. Sets error flags and result data. |
| R | `JDKBPCommon.hasError` | - | - | Checks whether the `param` object contains error flags after the SC call. Returns true if processing failed. |

**How to classify:**
- **U** (Update/Prepare): `editSTBUpdateMsg` prepares and modifies the CAANMsg template with STB device data.
- **C** (Create/Invoke): `scCall.run()` with `EWCA0010003CBSMsg` performs the actual STB record creation/update in the home management system.
- **U** (Update/Process): `editResultRrr` updates the parameter object with SC results.
- **R** (Read/Check): `hasError()` reads error state from the parameter.

**SC Code Details:**
- `EWCA0010003CBS` — STB Information Update Service Component. The CAANMsg template is configured with template ID `EWCA0010003`. This CBS handles synchronization of STB device information with the home management system.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CC: `JDKCommon08CC.approve` | `approve(handle, param, fixedText)` -> (after approval processing loop, when `updateStat == HMPIN_KIKI_STAT_SHONIN` and `!funcCode.equals(FUNC_CODE_2)`) -> `updateSTB(param, unlinkMap, scCall, handle)` | `scCall.run [C] EWCA0010003CBS`, `editResultRrr [U] param`, `hasError [R] param` |

**Call Chain Details:**
- The `approve()` method in the same class (`JDKCommon08CC`) is the sole caller. It is called during device replacement approval processing and triggers `updateSTB()` when:
  1. The device replacement status (`updateStat`) equals `HMPIN_KIKI_STAT_SHONIN` (Approved)
  2. The function code is NOT `FUNC_CODE_2` (cancellation mode)
- The method was originally commented out under `ST-2017-0000015`, then added back under `ANK-3080-00-00 ADD` and `OM-2018-0000010 ADD` to enable STB update during approval.
- Terminal operations reached from this method: `hasError` (read/validate), `editResultRrr` (update/transform), `editSTBUpdateMsg` (update/prepare), `scCall.run` (create/update via EWCA0010003CBS).

## 6. Per-Branch Detail Blocks

**Block 1** — [INITIALIZATION] (L1912)

> Initialize the outer `paramMap` before entering the loop.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramMap = new HashMap<String, Object>()` |

**Block 2** — [FOR EACH] `(for each entry in unlinkMap)` (L1914)

> Iterate over each device entry prepared for STB update. Each entry represents one STB or C-CAS terminal.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramMap = new HashMap<String, Object>()` // Reset paramMap for each device |

**Block 2.1** — [SET] — SC Input Common Data (L1921–L1927)

> Populate the SC invocation common header with system-level identifiers from the request parameter.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramMap.put(JCMConstants.TRANZACTION_ID_KEY, param.getTelegramID())` // Telegram ID [-> TRANZACTION_ID_KEY="TRANZACTION_ID_KEY" (JCMConstants)] |
| 2 | SET | `paramMap.put(JCMConstants.USECASE_ID_KEY, param.getUsecaseID())` // Use case ID [-> USECASE_ID_KEY="USECASE_ID_KEY"] |
| 3 | SET | `paramMap.put(JCMConstants.OPERATION_ID_KEY, param.getOperationID())` // Operation ID [-> OPERATION_ID_KEY="OPERATION_ID_KEY"] |
| 4 | SET | `paramMap.put(JCMConstants.CALL_TYPE_KEY, param.getCallType())` // Service call division [-> CALL_TYPE_KEY="CALL_TYPE_KEY"] |

**Block 2.2** — [SET] — Control Map Data (L1931–L1939)

> Populate the SC invocation control header with client/request metadata.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramMap.put(JCMConstants.CLIENT_HOST_NAME_KEY, param.getControlMapData(SCControlMapKeys.REQ_HOSTNAME))` // Requester hostname [-> CLIENT_HOST_NAME_KEY="CLIENT_HOST_NAME_KEY"] |
| 2 | SET | `paramMap.put(JCMConstants.CLIENT_IP_ADDRESS_KEY, param.getControlMapData(SCControlMapKeys.REQ_HOSTIP))` // Requester IP address [-> CLIENT_IP_ADDRESS_KEY="CLIENT_IP_ADDRESS_KEY"] |
| 3 | SET | `paramMap.put(JCMConstants.INVOKE_GAMEN_ID_KEY, param.getControlMapData(SCControlMapKeys.REQ_VIEWID))` // Requester screen ID [-> INVOKE_GAMEN_ID_KEY="INVOKE_GAMEN_ID_KEY"] |
| 4 | SET | `paramMap.put(JCMConstants.OPERATOR_ID_KEY, param.getControlMapData(SCControlMapKeys.OPERATOR_ID))` // Operator ID [-> OPERATOR_ID_KEY="OPERATOR_ID_KEY"] |

**Block 2.3** — [SET] — User Data Retrieval (L1942–L1943)

> Retrieve user data from the control map using the key `DKSV008101CC`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = (HashMap)param.getData(DKSV008101CC)` // User data information [-> DKSV008101CC="DKSV008101CC"] |

**Block 2.4** — [SET] — Create CAANMsg Template (L1947–L1948)

> Create the message template for the STB update service component.

| # | Type | Code |
|---|------|------|
| 1 | SET | `template = new CAANMsg(EWCA0010003CBSMsg.class.getName())` // STB update service interface |
| 2 | SET | `template.set(EWCA0010003CBSMsg.TEMPLATEID, "EWCA0010003")` // Template ID [-> TEMPLATEID="TEMPLATEID"] |

**Block 2.5** — [CALL] — Build STB Update Message (L1950)

> Populate the template with STB device-specific data.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `editSTBUpdateMsg(paramMap, inMap, tmpParamMap)` // Build STB update message from user data |

**Block 2.6** — [EXEC] — Debug Log (L1954)

> Log the start of STB update processing.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JSYejbLog.println(JSYejbLog.DEBUG, this.getClass(), "STB情報更新処理の実行")` // Execute STB update processing |

**Block 2.7** — [CALL] — Execute Service Component (L1957)

> Dispatch the STB update request to the home management system.

| # | Type | Code |
|---|------|------|
| 1 | SET | `result = scCall.run(paramMap, handle)` // SC call execution |

**Block 2.8** — [CALL] — Process Result (L1958)

> Map the SC response back into the param object.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `editResultRrr(result, param)` // Edit result to RR |

**Block 3** — [IF] `(JDKBPCommon.hasError(param))` (L1959–L1964)

> If the service call returned an error, throw an exception. The error code is read from `param.getControlMapData("returnCode")`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `throw new SCCallException("STB情報更新失敗", "0", Integer.parseInt(param.getControlMapData("returnCode").toString()))` // STB update failure |

**Block 4** — [END LOOP] (L1968)

> After processing all entries in `unlinkMap`, return control to the caller.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| STB | Business term | Set-Top Box — a terminal device used in cable/satellite/FTTH systems to decode and display broadcast content. In this context, it refers to the home gateway device managed by the home management system. |
| C-CAS | Business term | Conditional Access System — a security system that controls access to pay-TV content. Here it refers to a C-CAS card/module installed in the STB. |
| HMPIN | Field | Home appliance (home device) — refers to the customer premises equipment being replaced. `key_hmpin_kiki_no` is the home device number. |
| HMPIN_KIKI_STAT_SHONIN | Field | Home device status: Approved — indicates the device replacement has been approved and STB information needs to be updated. |
| FUNC_CODE_2 | Field | Function code 2 — a cancellation mode flag. When set, STB update is skipped to avoid updating during cancellation processing. |
| DKSV008101CC | Field | Control map key for user data — the key used to retrieve STB device data from the request parameter's control map. |
| EWCA0010003CBS | SC Code | STB Information Update Service Component — the CBS responsible for updating STB device information in the home management system. |
| SC Call Exception | Technical term | `SCCallException` — a runtime exception thrown when a service component call fails. Contains an error message, error code ("0"), and a numeric return code. |
| CAANMsg | Technical term | An enterprise messaging class used to construct and pass structured data between service components. Here it carries STB update request parameters. |
| JCMConstants | Class | Japanese Constants Management — a constants class holding standardized keys for transaction ID, use case ID, operation ID, call type, client hostname, client IP, screen ID, and operator ID used in SC input parameters. |
| SCControlMapKeys | Class | Service Component Control Map Keys — a constants class holding keys for REQ_HOSTNAME, REQ_HOSTIP, REQ_VIEWID, and OPERATOR_ID in the control map. |
| HOMESYSTEM | Business term | Home Management System — the backend system that manages customer premises equipment (STB, C-CAS, etc.). STB updates are synchronized with this system. |
| OM-2018-0000010 | Change request | Change request that added STB update processing to the approval path of device replacement processing. |
| ANK-3080-00-00 | Change request | Change request that re-enabled STB update processing after it was previously commented out under ST-2017-0000015. |
| TRANZACTION_ID_KEY | Field | Transaction ID key — uniquely identifies a service transaction. Populated from `param.getTelegramID()`. |
| USECASE_ID_KEY | Field | Use case ID key — identifies the business use case context. Populated from `param.getUsecaseID()`. |
| OPERATION_ID_KEY | Field | Operation ID key — identifies the specific operation within a use case. Populated from `param.getOperationID()`. |
| CALL_TYPE_KEY | Field | Service call type key — identifies the calling service context (e.g., screen call, batch call). Populated from `param.getCallType()`. |
| CLIENT_HOST_NAME_KEY | Field | Client hostname key — the hostname of the requesting client. Populated from control map `REQ_HOSTNAME`. |
| CLIENT_IP_ADDRESS_KEY | Field | Client IP address key — the IP address of the requesting client. Populated from control map `REQ_HOSTIP`. |
| INVOKE_GAMEN_ID_KEY | Field | Invoked screen ID key — the screen ID of the originating request. Populated from control map `REQ_VIEWID`. |
| OPERATOR_ID_KEY | Field | Operator ID key — the ID of the operator who initiated the request. Populated from control map `OPERATOR_ID`. |
| `unlinkMap` | Parameter | List of device entries to unlink/re-register during replacement approval. Each entry contains device-specific data prepared by the `unlink()` method. |
| `tmpParamMap` | Local var | Temporary parameter map for each device entry being processed in the loop. |
