# Business Logic — JKKTvSvcKeiCancelCC.editErrorInfoCom() [60 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKTvSvcKeiCancelCC` |
| Layer | CC / Common Component (Custom Business Component shared across screens) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKTvSvcKeiCancelCC.editErrorInfoCom()

This method is a **shared error-information reconciliation utility** within the eo Hikari TV Contract Cancellation common component (`JKKTvSvcKeiCancelCC`). It consolidates error state from a service component (SC) response template into the screen's control map, ensuring that the most severe error status and its associated message are surfaced to the UI layer. Specifically, it compares the **service-level status** (extracted from the first template's `status` field) against the **business-parameter (BP) return code** already stored in the control map, and overwrites the BP return code and message with the service's status and message when the service status indicates a more severe condition (`templateStatus > bpStatus`). It then **merges error keys** from the template's hashmap into the caller's data map — any key ending with `_err` (error field suffix) is copied from the template into the inMap, allowing per-field error messages (e.g., `customer_name_err`) to propagate from the SC response back to the presentation layer. This method implements a **delegate pattern** — it is called by `callSC()` (which wraps service invocations and error extraction) and `editErrorInfo()` (which iterates over multiple templates), making it a **centralized error-routing node** for the cancellation screen's post-SC error handling path.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfoCom(params)"])

    START --> GET_TEMPLATE["Get templates[0] from templates array"]
    GET_TEMPLATE --> GET_STATUS["Get template.getInt(ECK0011B002CBSMsg.STATUS = 'status')"]
    GET_STATUS --> CHECK_RETURN_CODE{"returnCode != 0?"}
    CHECK_RETURN_CODE -->|Yes| SET_TEMPLATE_STATUS["templateStatus = 9000"]
    CHECK_RETURN_CODE -->|No| CHECK_MESSAGE{"RETURN_MESSAGE_'%04d'{templateStatus} exists?"}
    SET_TEMPLATE_STATUS --> CHECK_MESSAGE

    CHECK_MESSAGE -->|No| SET_ZERO_STATUS["templateStatus = 0"]
    CHECK_MESSAGE -->|Yes| INIT_BP_STATUS["bpStatus = 0"]
    SET_ZERO_STATUS --> INIT_BP_STATUS

    INIT_BP_STATUS --> GET_BP_RETURN["param.getControlMapData(SCControlMapKeys.RETURN_CODE)"]
    GET_BP_RETURN --> BP_STATUS_NULL{"obj == null?"}
    BP_STATUS_NULL -->|Yes| SET_BP_NEG1["bpStatus = -1"]
    BP_STATUS_NULL -->|No| SET_BP_PARSE["bpStatus = Integer.parseInt(getControlMapData)"]

    SET_BP_NEG1 --> COMPARE_STATUS{"templateStatus > bpStatus?"}
    SET_BP_PARSE --> COMPARE_STATUS

    COMPARE_STATUS -->|No| PREPARE_INMAP["inMap = (HashMap)param.getData(dataMapKey)"]
    COMPARE_STATUS -->|Yes| FORMAT_STATUS["formatStatus = String.format('%04d', templateStatus)"]

    FORMAT_STATUS --> GET_MESSAGE["message = JCMAPLConstMgr.getString('RETURN_MESSAGE_' + formatStatus)"]
    GET_MESSAGE --> SET_CONTROL_RETURN["param.setControlMapData(RETURN_CODE, formatStatus)"]
    SET_CONTROL_RETURN --> SET_CONTROL_MESSAGE["param.setControlMapData(RETURN_MESSAGE, message)"]
    SET_CONTROL_MESSAGE --> PREPARE_INMAP

    PREPARE_INMAP --> GET_TEMPLATE_HASHMAP["Iterator over template.getHashMap().keySet()"]
    GET_TEMPLATE_HASHMAP --> HAS_NEXT{"it.hasNext()?"}

    HAS_NEXT -->|Yes| GET_KEY["key = it.next()"]
    GET_KEY --> ENDS_ERR{"key.endsWith('_err')?"}

    ENDS_ERR -->|No| HAS_NEXT
    ENDS_ERR -->|Yes| NOT_NULL{"template.isNull(key)?"}

    NOT_NULL -->|True| HAS_NEXT
    NOT_NULL -->|False| PUT_INMAP["inMap.put(key, template.getString(key))"]
    PUT_INMAP --> HAS_NEXT

    HAS_NEXT -->|No| RETURN_PARAM["Return param"]
    RETURN_PARAM --> END(["Next"])
```

**Processing summary:**

1. **Extract template and status**: Takes the first element from the `templates` array and retrieves its `status` field (CBS message key: `"status"` from `ECK0011B002CBSMsg.STATUS`).
2. **Override on non-zero return code**: If `returnCode` is non-zero (indicating an error at the caller level), forces `templateStatus` to `9000` — a generic error status that ensures the error message is surfaced.
3. **Validate return message exists**: Checks whether a localized message constant `RETURN_MESSAGE_'%04d'{templateStatus}` exists. If not, resets `templateStatus` to `0` (success) to suppress a non-existent message.
4. **Read BP return code**: Reads the current BP return code from the control map (`SCControlMapKeys.RETURN_CODE`). If absent, sets `bpStatus = -1` as a sentinel.
5. **Compare and escalate**: If `templateStatus > bpStatus`, the service status is more severe. It formats the status as a 4-digit zero-padded string (e.g., `"1000"`), looks up the corresponding message constant (`RETURN_MESSAGE_` + formatStatus), and writes both the formatted status code and message back into the control map. This ensures the screen displays the higher-severity error.
6. **Merge error keys**: Iterates over all keys in the template's hashmap. For any key ending with `_err` (the error field naming convention), copies the value from the template into the caller's data map (retrieved by `dataMapKey`). This propagates per-field validation errors back to the screen.
7. **Return**: Returns the modified `param` object for chaining.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The screen's request parameter object carrying both control map data (return codes, error lists, operator info) and business data maps. It is both read and written — the method reads the current BP return code from its control map and writes back the escalated return code, error message, and merged per-field error strings. |
| 2 | `templates` | `CAANMsg[]` | An array of CBS message objects returned from the service component call. Each `CAANMsg` contains business data fields plus a `status` field (integer) indicating success/failure. The method reads only `templates[0]` — the first template holds the primary response status and error messages. |
| 3 | `returnCode` | `int` | The integer return code from the service call (from `JCMConstants.RET_CD_INT_KEY`). If non-zero, it signals a general SC-level failure, triggering an override of `templateStatus` to `9000`. If zero, the original service status from the template is preserved. |
| 4 | `dataMapKey` | `String` | The key used to retrieve the business-data `HashMap<String, String>` from `param`. Per-field error messages (keys ending in `_err`) are merged into this map so the screen can display inline validation errors for specific input fields. |

**External state / instance fields read:** None. This method is fully stateless and depends only on its parameters.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JCMAPLConstMgr.getString` | - | - | Reads a localized constant string from the application constant manager. Used to resolve return message labels for status codes. |
| R | `JACBatCommon.isNull` | - | - | Calls `isNull` in `JACBatCommon` — null-check utility (called by template from within loop) |
| - | `JACbatRknBusinessUtil.isNull` | JACbatRknBusiness | - | Calls `isNull` in `JACbatRknBusinessUtil` — null-check utility |
| - | `JCHbatSeikyKaknoBusinessUtil.isNull` | JCHbatSeikyKaknoBusiness | - | Calls `isNull` in `JCHbatSeikyKaknoBusinessUtil` — null-check utility |
| - | `JBSbatACInsentetivePrcInfoSaksei.isNull` | JBSbatACInsentetivePrcInfoSaksei | - | Calls `isNull` in `JBSbatACInsentetivePrcInfoSaksei` — null-check utility |
| - | `JBSbatAKCHSeikyYsoInfMake.isNull` | JBSbatAKCHSeikyYsoInfMake | - | Calls `isNull` in `JBSbatAKCHSeikyYsoInfMake` — null-check utility |
| R | `JBSbatDKNyukaFinAdd.getData` | JBSbatDKNyukaFinAdd | - | Calls `getData` in `JBSbatDKNyukaFinAdd` |
| R | `JBSbatFUCaseFileRnkData.getString` | JBSbatFUCaseFileRnkData | - | Calls `getString` in `JBSbatFUCaseFileRnkData` |
| R | `JBSbatFUMoveNaviData.getString` | JBSbatFUMoveNaviData | - | Calls `getString` in `JBSbatFUMoveNaviData` |
| - | `JBSbatKKCashPostAddMail.keySet` | JBSbatKKCashPostAddMail | - | Calls `keySet` in `JBSbatKKCashPostAddMail` |
| - | `JBSbatKKCashPostChsht.keySet` | JBSbatKKCashPostChsht | - | Calls `keySet` in `JBSbatKKCashPostChsht` |
| R | `JBSbatZMAdDataSet.getString` | JBSbatZMAdDataSet | - | Calls `getString` in `JBSbatZMAdDataSet` |
| R | `JFUeoTelOpTransferCC.getData` | JFUeoTelOpTransferCC | - | Calls `getData` in `JFUeoTelOpTransferCC` |
| R | `JFUTransferCC.getData` | JFUTransferCC | - | Calls `getData` in `JFUTransferCC` |
| R | `JFUTransferListToListCC.getData` | JFUTransferListToListCC | - | Calls `getData` in `JFUTransferListToListCC` |
| R | `JESC0101B010TPMA.getString` | JESC0101B010TPMA | - | Calls `getString` in `JESC0101B010TPMA` |
| R | `JESC0101B020TPMA.getString` | JESC0101B020TPMA | - | Calls `getString` in `JESC0101B020TPMA` |
| R | `KKW12701SFLogic.getData` | KKW12701SFLogic | - | Calls `getData` in `KKW12701SFLogic` |

### Direct analysis of this method:

The method itself does **not** directly invoke any SC or database service. It operates exclusively on in-memory objects:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `template.getInt("status")` | `ECK0011B002CBSMsg` | - | Reads the integer `status` field from the first CBS response template — indicates service-level success/failure. |
| R | `JCMAPLConstMgr.getString(...)` | `JCMAPLConstMgr` | - | Reads application constant by key to determine if a return message label exists for a given status code. |
| R | `param.getControlMapData(RETURN_CODE)` | ControlMap | - | Reads the current BP return code stored in the control map. |
| W | `param.setControlMapData(RETURN_CODE, ...)` | ControlMap | - | Writes the escalated (or original) return code as a 4-digit zero-padded string. |
| W | `param.setControlMapData(RETURN_MESSAGE, ...)` | ControlMap | - | Writes the localized error message text corresponding to the return status. |
| R | `param.getData(dataMapKey)` | Data Map | - | Retrieves the business-data HashMap where per-field errors will be merged. |
| R | `template.getHashMap().keySet()` | Template | - | Iterates all field keys in the template's hashmap to find error-suffixed keys. |
| R | `template.isNull(key)` | Template | - | Checks if a specific error field value is null (empty) in the template. |
| R | `template.getString(key)` | Template | - | Retrieves the error message string for a given error key (e.g., `customer_name_err`). |
| W | `inMap.put(key, value)` | Data Map | - | Merges the per-field error string into the caller's data map for UI display. |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 6 methods.
Terminal operations from this method: `getString` [R], `getString` [R], `getString` [R], `getString` [R], `getString` [R], `isNull` [-], `isNull` [-], `isNull` [-], `isNull` [-], `isNull` [-], `keySet` [-], `keySet` [-], `getData` [R], `getData` [R], `getData` [R], `getData` [R], `getData` [R], `getString` [R], `getString` [R], `getString` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Caller: `JKKTvSvcKeiCancelCC.callSC()` | `callSC(param, handle, inCAANMsg)` → retrieves `result.get(RET_CD_INT_KEY)` and `templates` → `editErrorInfoCom(param, templates, return_code, dataMapKey)` | `template.getInt("status")` [R], `JCMAPLConstMgr.getString` [R], `param.setControlMapData(RETURN_CODE)` [W], `param.setControlMapData(RETURN_MESSAGE)` [W], `inMap.put()` [W] |
| 2 | Caller: `JKKTvSvcKeiCancelCC.editErrorInfo()` | `editErrorInfo(param, templates, returnCode, fixedText)` → loops `for (int i = 0; i < templates.length; i++)` → `editErrorInfoCom(param, templates, returnCode, fixedText)` | Same terminals as above — called in a loop, each iteration re-processes the same param with the same templates and dataMapKey. |

**Notes:**
- `callSC()` is the primary integration point. It wraps a service component invocation via `ServiceComponentRequestInvoker`, extracts the response, and delegates to `editErrorInfoCom()` for error reconciliation.
- `editErrorInfo()` is a public wrapper that iterates over the entire template array, calling `editErrorInfoCom()` for each. This allows multi-template scenarios (e.g., multiple service responses) to all propagate their errors.
- No screen (KKSV) or batch (KKBT) entry points are directly found within 8 hops, indicating this is a **deep utility** buried in the common component layer.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(template extraction)` (L980)

Extracts the first CBS template and its status field from the response.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `CAANMsg template = templates[0];` | Retrieves the first CBS response template from the array. The first template always holds the primary response status. // 「本来はサービスインターフェース分の処理が必要」 — "Originally, processing is required per service interface, but only the first template is used here." |
| 2 | SET | `int templateStatus = template.getInt(ECK0011B002CBSMsg.STATUS);` | Reads the `status` integer field (CBS message key: `"status"`) from the template. This indicates the SC-level outcome. |

---

**Block 2** — [IF] `(returnCode != 0)` (L982)

If the caller passed a non-zero return code (indicating SC-level failure), override the template status to a forced error status.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `templateStatus = 9000;` | Forces template status to `9000` — a generic service error code that ensures the error message path is triggered. // This takes precedence over the template's own status. |

---

**Block 3** — [IF] `(JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)) == null)` (L987)

Validates that a localized message constant exists for the current template status. If no message constant exists, resets status to `0` (success) to suppress a stale or invalid status code.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `String.format("%1$04d", templateStatus)` | Formats the status as a 4-digit zero-padded string (e.g., `9000` → `"9000"`, `0` → `"0000"`). |
| 2 | SET | `String constantKey = "RETURN_MESSAGE_" + formatStatus;` | Constructs the constant key, e.g., `RETURN_MESSAGE_9000`. |
| 3 | SET | `templateStatus = 0;` | Resets status to `0` (success) when no message constant is found, preventing display of an undefined error message. // Silently demotes unknown status to success. |

---

**Block 4** — [IF-ELSE] `(bpStatus initialization)` (L991–L998)

Reads the current BP return code from the control map. If the key is absent, uses `-1` as a sentinel to ensure any valid status will override it.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `int bpStatus = 0;` | Initializes comparison status. |
| 2 | SET | `Object obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE);` | Reads the current return code from the control map. `SCControlMapKeys.RETURN_CODE` is the control-map key for the BP-level return code. |
| 3 | IF-ELSE | `if (obj == null)` | Checks if the return code key is absent from the control map. |
| 4 | SET (ELSE-YES) | `bpStatus = -1;` | Sentinel value: `-1` ensures that any non-negative `templateStatus` (0, 1000, 9000, etc.) will be considered higher and will trigger an override. |
| 5 | SET (ELSE-NO) | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE));` | Parses the return code string to int for numeric comparison. |

---

**Block 5** — [IF] `(templateStatus > bpStatus)` (L1000)

Core escalation logic: if the service-level status is more severe than the current BP return code, overwrite the control map with the service status and its message. This is a **priority escalation pattern** — the SC always wins when it reports a worse condition.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `String formatStatus = String.format("%1$04d", templateStatus);` | Formats status as 4-digit zero-padded (e.g., `1000` → `"1000"`, `9000` → `"9000"`). |
| 2 | SET | `String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus);` | Looks up the localized error message text for this status code from the application constants. |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus);` | Writes the escaped status code back to the control map. This replaces the BP's return code with the service-level status. |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message);` | Writes the localized error message text to the control map for UI display. |

// 「BPにサービスコンポーネントのステータスを設定する。」 — "Set the service component's status in the BP."

---

**Block 6** — [SET] `(inMap preparation)` (L1006–L1007)

Prepares the data map for error key merging.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `HashMap<String, String> inMap = null;` | Declares the error data map variable. |
| 2 | SET | `inMap = (HashMap<String, String>)param.getData(dataMapKey);` | Retrieves the business data map identified by `dataMapKey`. Per-field errors will be merged into this map. // ユーザーデータ情報 — "User data information." |

---

**Block 7** — [WHILE] `(iterator over template.getHashMap().keySet())` (L1009–L1021)

Iterates over all keys in the template's hashmap. For each key ending with `_err` (the per-field error naming convention), copies the error message from the template into the caller's data map. This propagates field-level validation errors (e.g., `name_err`, `address_err`) from the SC response back to the screen.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `Iterator<String> it = template.getHashMap().keySet().iterator();` | Creates an iterator over all keys in the template's internal hashmap. |
| 2 | IF | `it.hasNext()` — loop condition | Checks for remaining keys. |
| 3 | SET | `String key = it.next();` | Retrieves the next key from the iterator. |
| 4 | IF | `key.endsWith("_err")` | Filters to only error-suffixed keys. This is the naming convention for per-field error messages (e.g., `customer_name_err` holds the validation error for the customer name field). |
| 5 | IF | `template.isNull(key)` | Checks whether the error field actually has a value (not null/empty). If the template field is null, there is no error message to propagate — skip it. |
| 6 | EXEC | `inMap.put(key, template.getString(key));` | Copies the error message string from the template into the data map. The screen will display this as a per-field inline error. |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `status` (CBSMsg) | Field | Service-level status code (integer) returned by the SC — `0` typically means success; non-zero indicates failure with a specific error code. |
| `RETURN_CODE` (ControlMapKey) | Field | Control map key for the business parameter return code — stores the current error/success status as a string. |
| `RETURN_MESSAGE` (ControlMapKey) | Field | Control map key for the localized error message text corresponding to the return code. |
| `ERROR_INFO` (ControlMapKey) | Field | Control map key for a list of error information objects, aggregated from multiple SC calls. |
| `_err` (suffix) | Naming convention | Error field naming suffix — any hashmap key ending with `_err` holds a per-field validation error message (e.g., `name_err` = name field error). |
| `RETURN_MESSAGE_XXXX` | Constant prefix | Application constant prefix for localized error messages — e.g., `RETURN_MESSAGE_9000` is the error message displayed when status is `9000`. |
| `template` | Object | A `CAANMsg` object representing the CBS (Service Component) response message — contains field values plus a `status` integer. |
| `param` | Object | The request parameter object (`IRequestParameterReadWrite`) — the primary data carrier between the screen and the business layer, holding both control-map metadata and business data maps. |
| `bpStatus` | Variable | The current business-parameter return code — represents the worst error state detected so far at the business parameter level. |
| `templateStatus` | Variable | The service-level status extracted from the CBS response — represents the SC's assessment of success or failure. |
| `JCMConstants` | Class | Fujiru/Futurity framework constants class — provides standard keys like `TEMPLATE_LIST_KEY`, `RET_CD_INT_KEY`, `TRANZACTION_ID_KEY`. |
| `SCControlMapKeys` | Class | Shared control map key constants — defines standard keys for return codes, error info, operator ID, etc., across all screens. |
| `JCMAPLConstMgr` | Class | Application constant manager — reads localized string constants from the application's configuration/resource store. |
| `CAANMsg` | Class | Futurity's base message class — an extensible key-value message container used for CBS request/response data transfer. |
| `JKKTvSvcKeiCancelCC` | Class | TV Service Contract Cancellation Common Component — a shared custom component providing common logic for the eo Hikari TV contract cancellation screens. |
| `callSC` | Method | Service Component call wrapper — wraps the `ServiceComponentRequestInvoker`, extracts the response, and delegates error processing. |
| `editErrorInfo` | Method | Public entry point that iterates over all templates and calls `editErrorInfoCom` for each — allows multi-template error merging. |
| `dataMapKey` | Parameter | Key identifying which business data HashMap within `param` should receive the per-field error messages. |
