# Business Logic — JKKCustMemberSbtChgCC.editResultRP() [60 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKCustMemberSbtChgCC` |
| Layer | Common Component (CC) — Shared business logic component |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKCustMemberSbtChgCC.editResultRP()

This method is a shared utility that maps Service Component (SC) execution results into the `IRequestParameterReadWrite` response object after a SIF (Service Interface) call completes. It is the result-mapping bridge in the common SIF execution pipeline implemented by `callScCmn()`. When a service component is invoked (e.g., EKK0081B519 for home routing service contract confirmation), the SC returns raw message data via a `Map` containing a return code, a template with a status code, and potentially error information. `editResultRP` extracts these values, resolves the appropriate business error message based on the template's status, and promotes the SC status to the control map if it indicates a more severe condition than any prior BP-level status. It also delegates error info collection to `TemplateErrorUtil.getErrorInfo()`, consolidating error details from the SC response into the control map for downstream screen processing. The method implements a **delegation pattern** (delegating error consolidation to a dedicated utility) and a **result-translation pattern** (converting SC-level CAANMsg response into a structured business response). Its role in the larger system is as a reusable post-SIF-call handler — any SIF invocation pipeline through `callScCmn()` funnels through this method to normalize results.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editResultRP msgList param"])
    START --> EXTRACT["Extract CAANMsg templates from msgList"]
    EXTRACT --> GET_RETURN_CODE["Extract Integer returnCode from msgList"]
    GET_RETURN_CODE --> GET_TEMPLATE_STATUS["Get templateStatus from template.getInt STATUS_INT_KEY"]
    GET_TEMPLATE_STATUS --> CHECK_RETURN{returnCode != 0}
    CHECK_RETURN -->|Yes| SET_STATUS_9000["Set templateStatus = 9000"]
    SET_STATUS_9000 --> CHECK_TEMPLATE_MSG{Message lookup returns null}
    CHECK_RETURN -->|No| CHECK_TEMPLATE_MSG
    CHECK_TEMPLATE_MSG -->|Yes| SET_STATUS_0["Set templateStatus = 0"]
    SET_STATUS_0 --> BP_STATUS["Get bpStatus from param controlMapData"]
    CHECK_TEMPLATE_MSG -->|No| BP_STATUS
    BP_STATUS --> BP_STATUS_NULL{obj == null}
    BP_STATUS --> BP_STATUS_NOT_NULL["bpStatus = Integer.parseInt returnCode string"]
    BP_STATUS_NULL -->|Yes| BP_STATUS_NEG1["Set bpStatus = -1"]
    BP_STATUS_NEG1 --> COMPARE_STATUS{templateStatus > bpStatus}
    BP_STATUS_NOT_NULL --> COMPARE_STATUS
    COMPARE_STATUS -->|Yes| FORMAT_STATUS["formatStatus = format templateStatus as 4-digit string"]
    COMPARE_STATUS -->|No| ERROR_MAP
    FORMAT_STATUS --> GET_MESSAGE["Get message from JCMAPLConstMgr"]
    GET_MESSAGE --> SET_RETURN_CODE["Set controlMapData RETURN_CODE to formatStatus"]
    SET_RETURN_CODE --> SET_RETURN_MESSAGE["Set controlMapData RETURN_MESSAGE to message"]
    SET_RETURN_MESSAGE --> ERROR_MAP["Extract errList from param controlMapData ERROR_INFO"]
    ERROR_MAP --> ERR_LIST_NULL{errList == null}
    ERR_LIST_NULL -->|Yes| NEW_ERR_LIST["errList = new ArrayList"]
    ERR_LIST_NULL -->|No| GET_TEMPLATE_ID["tName = template.getString templateID"]
    NEW_ERR_LIST --> GET_TEMPLATE_ID
    GET_TEMPLATE_ID --> ERROR_INFO_MAP["Set ERROR_INFO via TemplateErrorUtil.getErrorInfo"]
    ERROR_INFO_MAP --> RETURN["Return param"]
```

**Key processing steps:**

1. **Extract return values from SC response.** Pulls `CAANMsg[]` templates and return code from the `msgList` map using keys defined in `JCMConstants.TEMPLATE_LIST_KEY` and `JCMConstants.RET_CD_INT_KEY`.
2. **Determine effective status.** Gets the template's status code. If the SC return code is non-zero (indicating a system-level error), overrides the status to `9000`. Then checks if a message constant for the current status exists — if not, resets status to `0` (success/default).
3. **Compare and promote status.** Reads the current BP-level status from `param` control map. If the SC template status is higher (more severe) than the BP status, promotes the SC status and its associated message into the control map for screen display.
4. **Consolidate error information.** Extracts or creates an error list, then calls `TemplateErrorUtil.getErrorInfo()` to map error details from the SC response into the structured error list in the control map.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `msgList` | `Map<?, ?>` | The raw response map returned by the Service Component (SC) via the SIF runtime. Contains the SC return code (`JCMConstants.RET_CD_INT_KEY`), the template message array (`JCMConstants.TEMPLATE_LIST_KEY`) with status codes and error data, and template metadata used for error mapping. This is the unprocessed SC result that must be translated into business terms. |
| 2 | `param` | `IRequestParameterReadWrite` | The business data read/write interface carrying the response control map. It holds the current BP status code (`SCControlMapKeys.RETURN_CODE`), the current message (`SCControlMapKeys.RETURN_MESSAGE`), and an error info list (`SCControlMapKeys.ERROR_INFO`). This object is both read (to determine current status) and written (to set promoted status, messages, and error details). |

**External state / constants referenced:**

| Source | Constant / Key | Business Meaning |
|--------|---------------|------------------|
| `JCMConstants.TEMPLATE_LIST_KEY` | Key used in `msgList` to extract `CAANMsg[]` templates | Identifier for the template list in SC response |
| `JCMConstants.RET_CD_INT_KEY` | Key used in `msgList` to extract return code as `Integer` | Identifier for the SC return code in the response |
| `JCMConstants.STATUS_INT_KEY` | Key used in `template.getInt()` to get status code | Identifier for the template status in CAANMsg |
| `SCControlMapKeys.RETURN_CODE` | Control map key for BP status code | Business process status code stored in param |
| `SCControlMapKeys.RETURN_MESSAGE` | Control map key for status message text | Human-readable message corresponding to the status code |
| `SCControlMapKeys.ERROR_INFO` | Control map key for the error info list | Consolidated error details list for screen display |
| N/A | `9000` | Hardcoded override status when SC return code is non-zero (system error) |
| N/A | `0` | Default/reset status when no message constant exists for a given template status |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `TemplateErrorUtil.getErrorInfo` | — | — | Reads error details from `msgList` and merges them into the existing `errList`. This is a local utility method (not an SC), performing in-memory error data consolidation. |

**Note:** The pre-computed evidence from the code analysis graph (e.g., `JBSbatACECBuyIfTrkm.getErrorInfo`, `JESC0101B010TPMA.getString`, etc.) were **not directly called** within the `editResultRP` method body (lines 1285–1344). The pre-computed evidence appears to reference methods in other parts of the codebase or other methods of this class. The only actual method call within `editResultRP` is `TemplateErrorUtil.getErrorInfo()`. All other data access is done through `msgList` map operations and `param` control map access, which are in-memory operations with no direct database interaction.

The SCs (e.g., EKK0081B519) are called by `callScCmn()` which is the **caller** of `editResultRP`, not the other way around. `editResultRP` operates strictly on the post-execution results of those SC calls.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `callScCmn()` (JKKCustMemberSbtChgCC) | `JKKCustMemberSbtChgCC.callScCmn()` → `editResultRP` | `TemplateErrorUtil.getErrorInfo [R] —` |

**Notes on callers:**

- `editResultRP` is a **private method** of `JKKCustMemberSbtChgCC`. It is called exclusively by `callScCmn()` within the same class (at line 1261).
- `callScCmn()` is the common SIF invocation pipeline used throughout this CC to execute service interface calls (e.g., EKK0081B519 for home routing service confirmation, ECK0021C010, ECK0031C010, ECK0201D010, ECK0201C010, ECK0011C120, etc.).
- Other `editResultRP` methods with different prefixes (e.g., `editResultRPECK0021C010`, `editResultRPECK0031C010`, `editResultRPECK0201D010`, `editResultRPECK0201C010`, `editResultRPECK0011C120`) exist in this same class — these are **different methods** for specific SC types, each following a similar pattern but tailored to their specific SC response structure.
- No screen-level or batch entry points directly call this method — it is an internal pipeline step.
- No screen classes (KKSV*) directly invoke this method.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Extract SC response data (L1289–L1297)

> Extract the CAANMsg template array and the SC return code from the msgList map. Then read the template's status code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templates = (CAANMsg[])msgList.get(JCMConstants.TEMPLATE_LIST_KEY)` // Extract template list from SC response |
| 2 | SET | `template = templates[0]` // Get first (primary) template |
| 3 | SET | `returnCode = (Integer)msgList.get(JCMConstants.RET_CD_INT_KEY)` // Get SC return code — `0` indicates success, non-zero indicates system-level error |
| 4 | SET | `templateStatus = template.getInt(JCMConstants.STATUS_INT_KEY)` // Read template business status code |

**Block 2** — [IF] Override status on system error (L1299–L1301)

> If the SC return code is non-zero, the SC encountered a system-level error. Override the template status to 9000 (system error indicator).

| # | Type | Code |
|---|------|------|
| 1 | IF | `returnCode.intValue() != 0` [Non-zero SC return code → system error] |
| 1.1 | SET | `templateStatus = 9000` [Override to system error status] |

**Block 3** — [IF] Validate message constant existence (L1302–L1305)

> Check if a business message constant exists for the current template status. If `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + templateStatus)` returns null, no message is defined for this status — reset status to 0 (default/success).

| # | Type | Code |
|---|------|------|
| 1 | IF | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)) == null` [Message constant not found for this status] |
| 1.1 | SET | `templateStatus = 0` [Reset to default status — no message defined] |

**Block 4** — [SET/IF-ELSE] Determine BP-level status (L1307–L1316)

> Read the current business process status from the param control map. If the control map key has no value, the default BP status is -1 (indicating no prior status set).

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = 0` // Initialize default |
| 2 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read current BP status from control map |
| 3 | IF | `obj == null` [No prior BP status in control map] |
| 3.1 | SET | `bpStatus = -1` // Default — no prior status set |
| 4 | ELSE | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse existing status from control map |

**Block 5** — [IF] Promote SC status if more severe than BP status (L1318–L1325)

> Compare the SC template status against the BP-level status. If the SC status is higher (more severe), promote it to the control map so the screen displays the more serious status. This ensures error-level escalation: if the SC reports a failure worse than what the BP already knew about, the screen must show the SC's status and message.

| # | Type | Code |
|---|------|------|
| 1 | IF | `templateStatus > bpStatus` [SC status is more severe than BP status — promote] |
| 1.1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Format status as 4-digit zero-padded string |
| 1.2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Look up human-readable message for this status |
| 1.3 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Write promoted status code to control map |
| 1.4 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Write associated message to control map |

**Block 6** — [SET/IF-ELSE] Extract or initialize error list (L1328–L1334)

> Retrieve the existing error info list from the control map. If none exists (first SC call), create a new list. The `tName` variable captures the template ID for logging/error identification purposes.

| # | Type | Code |
|---|------|------|
| 1 | SET | `errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO)` // Extract existing error list from control map |
| 2 | IF | `errList == null` [No prior error list — first SIF call] |
| 2.1 | SET | `errList = new ArrayList<Object>()` // Initialize new error list |
| 3 | SET | `tName = template.getString("templateID")` // Store template ID for reference [S-IF name] |

**Block 7** — [EXEC] Consolidate error information (L1337)

> Delegate error detail mapping to the `TemplateErrorUtil` utility. Pass the raw SC response (`msgList`) and the error list to be populated. The utility reads error codes, descriptions, and field-level error data from the template and error list in `msgList`.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(msgList, errList))` // Map SC error details into the control map |

**Block 8** — [RETURN] Return processed result (L1339)

> Return the fully updated `param` object, now containing promoted status, messages, and error info.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return updated business data interface |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `msgList` | Parameter | SC response map — contains raw data returned from Service Component execution including templates, return codes, and error information |
| `param` | Parameter | `IRequestParameterReadWrite` — business data read/write interface carrying control map data including status codes, messages, and error lists |
| `CAANMsg` | Class | Fujitsu's message wrapper class used to exchange structured data between SCs and the application layer |
| `template` | Variable | The `CAANMsg` object representing the SC's response template, containing the business status code and template ID |
| `templateStatus` | Variable | Business status code from the SC response (e.g., 0=success, 9000=system error, or other domain-specific values) |
| `returnCode` | Variable | Low-level return code from the SC — 0 means no system error, non-zero indicates an exception during SC execution |
| `bpStatus` | Variable | Business Process status code currently set in the control map — tracks the worst status encountered during BP execution |
| `JCMConstants` | Constant class | Japanese: JCM定数 (JCM Constants) — defines message keys for template lists, return codes, and status codes |
| `SCControlMapKeys` | Constant class | Defines keys for control map data: RETURN_CODE, RETURN_MESSAGE, ERROR_INFO |
| `JCMAPLConstMgr` | Utility class | Message constant manager — looks up localized human-readable messages by key from a constants resource bundle |
| `TemplateErrorUtil` | Utility class | Error mapping utility — extracts error details from CAANMsg templates and populates error info lists |
| `RETURN_MESSAGE_XXXX` | Constant pattern | Message constant key format — `"RETURN_MESSAGE_" + 4-digit status code` maps a status code to its human-readable description |
| SIF | Acronym | Service Interface — the integration layer that invokes Service Components (SCs) with request/response message passing |
| SC | Acronym | Service Component — a business logic module that performs data operations (query, insert, update, delete) against the database |
| control map | Data structure | A key-value store within `IRequestParameterReadWrite` that carries status codes, messages, and error lists between processing stages |
| Error info | Business concept | Structured error details extracted from SC responses, including error codes, field-level errors, and error messages — displayed on screens to the user |
| templateID | Field | Identifier of the SC template used — indicates which service interface was invoked (the S-IF name) |
| `errList` | Variable | `ArrayList<Object>` holding consolidated error details from SC responses for screen display |
| `formatStatus` | Variable | Zero-padded 4-digit string representation of the status code (e.g., `"0000"`, `"9000"`) used as a message key |
