# Business Logic — JKKCustMemberSbtChgCC.editResultRPECK0021C010() [55 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKCustMemberSbtChgCC` |
| Layer | CC / Common Component (Customer Business Component — shared utility layer) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKCustMemberSbtChgCC.editResultRPECK0021C010()

This method is a **result-mapping utility** for the **Individual Customer Information Change** (お客様情報＜個人＞変更) business process. It runs after a service component (CBS — Customer Business Service) has been executed, and its role is to transform the raw CBS execution response into the data structures expected by the calling screen/business layer.

Specifically, it performs three distinct business operations:

1. **Status Normalization**: It reads the CBS return status from the first template in the CAANMsg[] array, adjusts it to a fallback value of 9000 if the business return code is non-zero, and validates that the status maps to a known return message. If the status is unrecognized, it resets to 0 (success). This implements a defensive fallback pattern to ensure the UI always displays a valid status message.

2. **BP-Level Status Override**: It compares the CBS status against the business-process-level return code stored in `param`. If the CBS status is higher (worse) than the BP status, it overwrites the BP's return code and message with the CBS-level values. This ensures that service-component failures propagate upward and override any misleading success indicators from the business process layer.

3. **Error Aggregation and Exception Handling**: It delegates error detail extraction to `TemplateErrorUtil.getErrorInfo()`, which populates an error list from the CBS message array. If any errors exist, it throws an `SCallException` carrying the return code and status from the CBS response. This enforces the convention that business errors must be surfaced to the caller rather than silently swallowed.

The method acts as a **bridge transformer** between the CBS execution layer and the business process response contract. It is called by `execute()` (the main entry point for the individual customer change screen) and `runShosa()` (the review/inspection flow), making it a shared result-postprocessor used across multiple customer-facing workflows.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editResultRPECK0021C010"])
    START --> EXTRACT["Extract CAANMsg[] templates and returnCode from msgList"]
    EXTRACT --> GET_STATUS["template.getInt(ECK0021C010CBSMsg.STATUS)"]
    GET_STATUS --> CHECK_RC{returnCode == 0?}
    CHECK_RC -->|No| SET_STATUS["templateStatus = 9000"]
    CHECK_RC -->|Yes| GET_BP_STATUS["Get bpStatus from param.getControlMapData(RETURN_CODE)"]
    SET_STATUS --> CHECK_MSG{RETURN_MESSAGE_<status> == null?}
    GET_BP_STATUS --> CHECK_MSG
    CHECK_MSG -->|Yes| RESET_STATUS["templateStatus = 0"]
    CHECK_MSG -->|No| CHECK_BP{obj == null?}
    RESET_STATUS --> CHECK_BP
    CHECK_BP -->|Yes| BP_STATUS_NEG1["bpStatus = -1"]
    CHECK_BP -->|No| BP_STATUS_PARSE["bpStatus = Integer.parseInt(returnCode)"]
    BP_STATUS_NEG1 --> CMP_STATUS{templateStatus > bpStatus?}
    BP_STATUS_PARSE --> CMP_STATUS
    CMP_STATUS -->|Yes| SET_BP_DATA["Set RETURN_CODE and RETURN_MESSAGE on param"]
    CMP_STATUS -->|No| BUILD_ERROR["Create empty errorList"]
    SET_BP_DATA --> BUILD_ERROR
    BUILD_ERROR --> SET_ERROR_INFO["param.setControlMapData(ERROR_INFO, getErrorInfo)"]
    SET_ERROR_INFO --> CHECK_ERR{errorList not null AND not empty?}
    CHECK_ERR -->|Yes| THROW_ERR["throw new SCCallException"]
    CHECK_ERR -->|No| RETURN_OK["return errorList"]
    THROW_ERR --> RETURN_OK
    RETURN_OK --> END_NODE(["end"])
```

**Processing Flow:**

1. **Extract CBS Response**: Retrieves the `CAANMsg[]` template array and integer return code from `msgList` using `TEMPLATE_LIST_KEY` and `RET_CD_INT_KEY`. The first template in the array is selected as the active response container.

2. **Read CBS Status**: Reads the `STATUS` field from the CBS message, which holds the raw service-component status code.

3. **Fallback on Non-Zero Return**: If the business return code is non-zero (indicating an error from the CBS call), forces `templateStatus` to 9000. This ensures error responses always map to a known error message category rather than displaying an undefined status.

4. **Message Validation**: Checks whether a return message exists for the current status via `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)`. If no message is found (unrecognized status), resets `templateStatus` to 0 (success). This prevents the system from displaying blank or garbled status messages.

5. **BP-Level Status Retrieval**: Reads the business-process-level return code from `param` via `SCControlMapKeys.RETURN_CODE`. If the key is absent, sets `bpStatus` to -1 (indicating no prior BP-level status was set).

6. **CBS-Overrides-BP Comparison**: If the CBS status is numerically greater than the BP status, overwrites the BP's return code and message with the CBS-level values. This ensures service-component-level errors take precedence over business-process-level outcomes.

7. **Error Aggregation**: Calls `TemplateErrorUtil.getErrorInfo(msgList, errorList)` to extract structured error details from the CBS response, storing them in `param` under `ERROR_INFO`.

8. **Exception on Error**: If the aggregated error list is non-empty, throws `SCallException` with the return code and status, forcing the calling screen to display the error. Otherwise, returns the (empty) error list for a successful flow.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `msgList` | `Map<?, ?>` | The raw CBS execution result container. It holds a `CAANMsg[]` array of template responses under `TEMPLATE_LIST_KEY` and an integer return code under `RET_CD_INT_KEY`. Each `CAANMsg` in the array corresponds to one CBS invocation and contains fields like `status` (service status code), `cust_nm` (customer name), and all individual customer change data. The first element (`templates[0]`) is used as the primary response template. |
| 2 | `param` | `IRequestParameterReadWrite` | The business data read/write interface — a request parameter object that carries data between the business component and the calling screen. It stores control-level mapping data such as `RETURN_CODE`, `RETURN_MESSAGE`, and `ERROR_INFO` via `setControlMapData`/`getControlMapData`. The method writes the normalized status and error info into this object so the calling screen can render appropriate UI responses. |

**External State / Instance Fields Read:**
- None. This method is stateless and does not reference any instance fields. It operates entirely on its parameters and calls to utility classes.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatACECBuyIfTrkm.getErrorInfo` | JBSbatACECBuyIfTrkm | - | Calls `getErrorInfo` to extract error details from the message |
| R | `JBSbatACKojiChrgInfoTrkm.getErrorInfo` | JBSbatACKojiChrgInfoTrkm | - | Calls `getErrorInfo` to extract error details from the message |
| R | `JBSbatFUCaseFileRnkData.getString` | JBSbatFUCaseFileRnkData | - | Calls `getString` to retrieve a string field from the message |
| R | `JBSbatFUMoveNaviData.getString` | JBSbatFUMoveNaviData | - | Calls `getString` to retrieve navigation data from the message |
| R | `JBSbatZMAdDataSet.getString` | JBSbatZMAdDataSet | - | Calls `getString` to retrieve address data from the message |
| R | `JESC0101B010TPMA.getString` | JESC0101B010TPMA | - | Calls `getString` to retrieve template message field |
| R | `JESC0101B020TPMA.getString` | JESC0101B020TPMA | - | Calls `getString` to retrieve template message field |
| R | `ApiBpInterface.getErrorInfo` | ApiBpInterface | - | Calls `getErrorInfo` to extract error details from API response |

**Note**: This method itself performs **no direct database or entity CRUD operations**. It is a pure result-mapping utility that reads from the CBS response (`msgList`), reads and writes control data via `param`, and delegates error extraction to `TemplateErrorUtil.getErrorInfo()`. The "R" entries above represent the downstream read operations that `getErrorInfo()` and `getString()` internally perform on the CBS message structures. The actual database reads/writes are executed by the CBS component (`ECK0021C010CBS`) that was called *before* this method, not by this method itself.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `JKKCustMemberSbtChgCC` (Business Component) | `execute()` -> `editResultRPECK0021C010` | `getErrorInfo` [R], `getString` [R] |
| 2 | `JKKSvkeiShosaCC` (Business Component) | `runShosa()` -> `editResultRPECK0021C010` | `getErrorInfo` [R], `getString` [R] |

**Terminal operations from this method**: `getErrorInfo` [R], `getString` [R] — these are all read operations performed through the error extraction utility and CBS message field access.

## 6. Per-Branch Detail Blocks

### Block 1 — INIT (Data Extraction) (L1462)

Extract the CBS response templates and return code from the `msgList` map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templates = (CAANMsg[])msgList.get(JCMConstants.TEMPLATE_LIST_KEY)` |
| 2 | SET | `template = templates[0]` |
| 3 | SET | `returnCode = (Integer)msgList.get(JCMConstants.RET_CD_INT_KEY)` |

### Block 2 — IF (Status Override on Non-Zero Return Code) (L1467)

If the CBS return code is non-zero, force the template status to 9000 as a fallback error indicator.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = template.getInt(ECK0021C010CBSMsg.STATUS)` |
| 2 | IF | `returnCode.intValue() != 0` |

### Block 2.1 — ELSE (of returnCode check) (L1468)

Sets `templateStatus` to 9000 when CBS returns a non-zero error code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` |

### Block 3 — IF (Return Message Validation) (L1471)

Validates that a return message exists for the current status. If no message template is found for `"RETURN_MESSAGE_" + formattedStatus`, resets status to 0 (success fallback).

| # | Type | Code |
|---|------|------|
| 1 | IF | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)) == null` |

### Block 3.1 — ELSE (of return message validation) (L1473)

If the status message is found, `templateStatus` remains unchanged. Otherwise, reset to 0.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 0` |

### Block 4 — INIT (BP Status Initialization) (L1477)

Reads the business-process-level return code from `param` for comparison.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = 0` (default initialization) |
| 2 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` |

### Block 5 — IF (BP Status Parsing) (L1479)

Parses the BP-level return code. If absent, uses -1 to indicate no prior status.

| # | Type | Code |
|---|------|------|
| 1 | IF | `obj == null` |

### Block 5.1 — ELSE (of obj check) (L1480)

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` |

### Block 5.2 — ELSE (of obj == null) (L1484)

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = -1` |

### Block 6 — IF (CBS-Overrides-BP Comparison) (L1488)

If the CBS status is numerically greater than the BP status, the CBS result takes precedence. Updates `param` with the CBS-level return code and message.

| # | Type | Code |
|---|------|------|
| 1 | IF | `templateStatus > bpStatus` |

### Block 6.1 — ELSE (CBS does not override) (L1489)

When CBS status is not higher than BP status, no action is taken on `param`. Processing continues to error aggregation.

### Block 6.2 — ELSE (of templateStatus > bpStatus) (L1490)

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` |
| 3 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` |
| 4 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` |

### Block 7 — INIT (Error Aggregation) (L1495)

Creates a new error list and delegates error extraction to `TemplateErrorUtil`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `errorList = new ArrayList<Object>()` |
| 2 | EXEC | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(msgList, errorList))` |

### Block 8 — IF (Error Exception Throwing) (L1498)

If errors were detected during aggregation, throws `SCallException` to force the calling screen to display an error.

| # | Type | Code |
|---|------|------|
| 1 | IF | `errorList != null && !errorList.isEmpty()` |

### Block 8.1 — ELSE (of error check) (L1499)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `throw new SCCallException("", ((Integer)returnCode).toString(), templates[0].getInt(ECK0021C010CBSMsg.STATUS))` |

### Block 9 — RETURN (Success Path) (L1502)

Returns the (empty) error list to the caller when no errors occurred.

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `templateStatus` | Field | CBS response status code — an integer representing the outcome of the service component execution (e.g., 0 = success, 9000 = generic error) |
| `returnCode` | Field | Business return code from CBS — integer 0 indicates success; non-zero indicates an error condition |
| `bpStatus` | Field | Business-process-level return code — the status previously set by the calling business process, used as a baseline for comparison against CBS-level status |
| `formatStatus` | Field | Zero-padded 4-digit string representation of `templateStatus` (e.g., "0001", "9000"), used as a key for message lookups |
| CAANMsg | Technical | Fujitsu's CAAN messaging schema class — a typed container for CBS request/response data with strongly-typed getters for each field (e.g., `getInt()`, `getString()`) |
| CBS | Acronym | Customer Business Service — the service component layer that executes the actual business logic and database operations for customer information changes |
| CAAN | Acronym | Fujitsu's application framework for service-based architecture (CAAN = Component Architecture Application Network) |
| SCCallException | Technical | Custom exception class thrown when a service component call results in a business error, carrying return code and status for error display |
| TEMPLATE_LIST_KEY | Constant | Map key used to retrieve the `CAANMsg[]` template array from `msgList` |
| RET_CD_INT_KEY | Constant | Map key used to retrieve the integer return code from `msgList` |
| RETURN_CODE | Constant | Control map key (`SCControlMapKeys.RETURN_CODE`) — the key used to store and retrieve the numeric return code in the business parameter object |
| RETURN_MESSAGE | Constant | Control map key (`SCControlMapKeys.RETURN_MESSAGE`) — the key used to store the human-readable return message for UI display |
| ERROR_INFO | Constant | Control map key (`SCControlMapKeys.ERROR_INFO`) — the key under which structured error details are stored for the calling screen |
| STATUS | Constant | CBS message field (`ECK0021C010CBSMsg.STATUS`) — the field within the CBS response that holds the status code |
| IRequestParameterReadWrite | Technical | Interface for bidirectional data exchange between the business component and the calling screen — supports `getControlMapData()` and `setControlMapData()` |
| ECK0021C010CBS | CBS | Customer <Individual> Content Change CBS — the service component that executes the individual customer information change operation |
| TemplateErrorUtil | Technical | Utility class that extracts structured error information from CBS message arrays (`getErrorInfo()`) |
| JCMAPLConstMgr | Technical | Constant/message manager for JCM (Japan Customer Management) application-level strings — used to look up localized return messages by key |
| `RETURN_MESSAGE_XXXX` | Constant | Pattern for return message keys — `"RETURN_MESSAGE_" + zero-padded status code` (e.g., `"RETURN_MESSAGE_0000"`, `"RETURN_MESSAGE_9000"`) |
| Individual Customer Change | Business term | Customer <Individual> Change (お客様情報＜個人＞変更) — the business process for updating personal customer information such as name, address, contact details |
