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

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

## 1. Role

### JKKCustMemberSbtChgCC.editResultRPECK0201D010()

This method acts as a **result post-processor** following a service component execution for contact registration operations. Its primary business purpose is to translate the raw execution result from a CBS (Central Business System) service into a standardized response that the calling business layer (BP — Business Process) can consume. Specifically, it extracts the service template status and return code from the execution result map (`msgList`), normalizes the status code by cross-referencing against registered return message definitions, and then decides whether to propagate the CBS-level status back to the BP control map or suppress it. It also aggregates any template-level errors into a consolidated error list and either returns it cleanly or throws an `SCallException` if errors were detected. This method implements a **delegation and transformation** pattern: it reads structured results from a shared message template system and re-writes a normalized control state back into the workflow parameter object. It serves as a shared utility called by multiple entry points (e.g., `execute()` and `runShosa()`), making it a reusable result-mapping utility across different contact registration and inquiry screens.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editResultRPECK0201D010 starts"])
    START --> STEP1["Extract templates array from msgList using TEMPLATE_LIST_KEY"]
    STEP1 --> STEP2["Get first template from CAANMsg array"]
    STEP2 --> STEP3["Get returnCode from msgList using RET_CD_INT_KEY"]
    STEP3 --> STEP4["Read status from template using ECK0201D010CBSMsg.STATUS"]
    STEP4 --> CHECK_RETURN{"returnCode != 0?"}
    CHECK_RETURN -->|Yes| SET_STATUS["Set templateStatus = 9000"]
    CHECK_RETURN -->|No| CHECK_MSG{"Return message exists for status?"}
    SET_STATUS --> CHECK_MSG
    CHECK_MSG -->|Yes| GET_BPCODE["Get BP return code from param using SCControlMapKeys.RETURN_CODE"]
    CHECK_MSG -->|No| RESET_STATUS["Set templateStatus = 0"]
    RESET_STATUS --> GET_BPCODE
    GET_BPCODE --> CHECK_BPCODE{"param.getControlMapData(RETURN_CODE) is null?"}
    CHECK_BPCODE -->|Yes| SET_BPNEG1["Set bpStatus = -1"]
    CHECK_BPCODE -->|No| PARSE_BP["Parse bpStatus from param control map"]
    SET_BPNEG1 --> CHECK_TEMPLATE
    PARSE_BP --> CHECK_TEMPLATE{"templateStatus > bpStatus?"}
    CHECK_TEMPLATE -->|Yes| SET_BP_CONTROL["Set BP control map with formatted status and return message"]
    CHECK_TEMPLATE -->|No| INIT_ERRORS["Create empty errorList"]
    SET_BP_CONTROL --> INIT_ERRORS
    INIT_ERRORS --> GET_ERRORS["Call TemplateErrorUtil.getErrorInfo(msgList, errorList)"]
    GET_ERRORS --> CHECK_ERRORS{"errorList not null and not empty?"}
    CHECK_ERRORS -->|Yes| THROW_ERR["Throw SCCallException with returnCode and status"]
    CHECK_ERRORS -->|No| RETURN_ERR["Return errorList"]
    THROW_ERR --> END(["Method ends with exception"])
    RETURN_ERR --> END
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `msgList` | `Map<?, ?>` | The execution result map returned from a CBS service call. It contains the service response template array (`TEMPLATE_LIST_KEY`), the integer return code (`RET_CD_INT_KEY`), and error information. This map is the raw output from the CBS communication layer, carrying status codes, operator metadata, and per-field error markers. |
| 2 | `param` | `IRequestParameterReadWrite` | The business data read/write interface that flows through the processing chain. It carries the BP-level control map state (including the BP's own `RETURN_CODE` and `RETURN_MESSAGE` keys) and is used to write back the normalized result. The control map acts as a shared context between screens, CBS calls, and business processes. |

**External State / Instance Fields:** None. This method is purely stateless — it reads only from its parameters and returns/throws.

## 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 information from the `msgList` execution result map and populates the `errorList` collection |
| R | `JCMAPLConstMgr.getString` | - | - | Looks up a return message string by key pattern `"RETURN_MESSAGE_" + <formatted_status_code>` |
| R | `param.getControlMapData(SCControlMapKeys.RETURN_CODE)` | - | - | Reads the BP-level return code from the control map for status comparison |
| R | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, ...)` | - | - | Writes the formatted status code into the control map |
| R | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, ...)` | - | - | Writes the return message text into the control map |
| R | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, ...)` | - | - | Writes aggregated error info into the control map |

**Analysis Notes:**
- This method performs **no direct database operations**. It is a pure result-transformation layer that reads from the CBS execution result map and writes normalized values back into the workflow control map.
- `TemplateErrorUtil.getErrorInfo()` is an internal utility that inspects the `msgList` for error indicators and extracts them into a structured `ArrayList<Object>`.
- `JCMAPLConstMgr.getString()` is a message resource lookup utility that resolves Japanese/i18n return messages from a properties-based configuration.
- The `SCControlMapKeys` constants (`RETURN_CODE`, `RETURN_MESSAGE`, `ERROR_INFO`) are internal keys used to pass state between business process layers.

## 5. Dependency Trace

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

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

**Terminal operations reached from this method:**
`getErrorInfo` [R] (TemplateErrorUtil), `getString` [R] (JCMAPLConstMgr) × 2 lookups (validation check + message fetch), `getControlMapData` [R] (param × 2 reads), `setControlMapData` [W] (param × 3 writes).

## 6. Per-Branch Detail Blocks

**Block 1** — SET (extract templates from msgList) (L1681)

The method begins by casting the generic map value at `TEMPLATE_LIST_KEY` to a `CAANMsg` array and selecting the first template element.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templates = (CAANMsg[])msgList.get(JCMConstants.TEMPLATE_LIST_KEY)` // Extract the CBS service response template array |
| 2 | SET | `template = templates[0]` // Take the first template element |

**Block 2** — SET (get return code) (L1685)

Retrieves the integer return code from the execution result map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `returnCode = (Integer)msgList.get(JCMConstants.RET_CD_INT_KEY)` // Get the raw return code from CBS execution result |

**Block 3** — SET (read template status) (L1687)

Reads the CBS service status from the template.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = template.getInt(ECK0201D010CBSMsg.STATUS)` // Read status code from CBS template |

**Block 4** — IF/ELSE (return code validation) (L1688)

If the CBS execution returned a non-zero return code, override the template status to 9000 (indicating a CBS-level error).

> If `returnCode != 0`, the CBS reported an error. Force templateStatus to 9000 to flag it.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` // Override status to error indicator when CBS return code is non-zero |

**Block 5** — IF/ELSE (return message existence check) (L1692)

Checks whether a return message is registered for the current `templateStatus`. If no message exists for this status code, reset the status to 0 (unknown/normal).

> If the i18n message resource `"RETURN_MESSAGE_" + <zero-padded_status>` returns `null`, the status is invalid or unrecognized. Set `templateStatus = 0`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Zero-pad to 4 digits for message key lookup |
| 2 | EXEC | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Check if message exists |
| 3 | SET | `templateStatus = 0` // Reset to 0 if no matching return message found |

**Block 6** — SET (read BP-level return code) (L1699-L1702)

Reads the BP's own return code from the control map. If the key is absent, default to -1 (meaning BP has no prior status).

> The BP may have set its own return code earlier in the chain. Compare it against the CBS status.

| # | Type | Code |
|---|------|------|
| 1 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read BP-level return code |
| 2 | SET | `bpStatus = -1` // Default to -1 if BP has no return code set |
| 3 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse existing BP return code |

**Block 7** — IF/ELSE (status comparison and propagation) (L1704)

If the CBS template status is higher (worse) than the BP's own status, propagate the CBS status and its human-readable message back into the BP control map. This ensures that CBS-level errors are surfaced to the calling screen.

> `templateStatus > bpStatus`: The CBS result is more severe than what the BP recorded. Propagate the CBS status code (zero-padded) and its i18n return message into the control map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Zero-pad to 4-digit format |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Resolve i18n message for status |
| 3 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Write formatted status to control map |
| 4 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Write human-readable message to control map |

**Block 8** — SET (initialize error list) (L1710)

Creates a fresh error list for aggregation.

| # | Type | Code |
|---|------|------|
| 1 | SET | `errorList = new ArrayList<Object>()` // Initialize empty error list for aggregation |

**Block 9** — CALL (extract template errors) (L1711)

Invokes the template error utility to scan the execution result and populate the error list with any error entries found in the template.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `TemplateErrorUtil.getErrorInfo(msgList, errorList)` // Scan msgList for errors and populate errorList |
| 2 | SET | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, result)` // Write aggregated errors to control map |

**Block 10** — IF/ELSE (error-driven exception throw) (L1714)

If the error list contains any errors after aggregation, throw an `SCallException` to abort processing. This signals to the caller that the CBS operation failed and the error details have been captured.

> If `errorList` is non-null and contains entries, an error occurred during CBS execution. Throw `SCallException` with empty message, the return code string, and the template status code as constructor arguments.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `new SCCallException("", ((Integer)returnCode).toString(), templates[0].getInt(ECK0201D010CBSMsg.STATUS))` // Throw exception with returnCode and template status |

**Block 11** — RETURN (return error list) (L1718)

If no errors were detected, return the (empty) error list as the result.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return errorList` // Return empty error list — processing succeeded |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `STATUS` | Field | CBS Template Status — numeric code indicating the result of a CBS service execution (0 = success, 9000 = error, other values = specific outcomes) |
| `returnCode` | Field | CBS Return Code — integer from the CBS execution result; 0 indicates success, non-zero indicates an error |
| `templateStatus` | Field | Normalized Template Status — the processed status value after validation against message definitions; may be overridden to 0 (unknown) or 9000 (error) |
| `bpStatus` | Field | BP (Business Process) Status — the status previously set by the business process layer; used as a baseline for comparison with CBS status |
| `SCControlMapKeys.RETURN_CODE` | Constant | Control Map Key — identifier for storing the return/status code in the shared control map between processing layers |
| `SCControlMapKeys.RETURN_MESSAGE` | Constant | Control Map Key — identifier for storing the human-readable return message text |
| `SCControlMapKeys.ERROR_INFO` | Constant | Control Map Key — identifier for storing aggregated error information |
| `JCMConstants.TEMPLATE_LIST_KEY` | Constant | Key used to extract the CAANMsg template array from the execution result map |
| `JCMConstants.RET_CD_INT_KEY` | Constant | Key used to extract the integer return code from the execution result map |
| `JCMAPLConstMgr.getString()` | Utility | i18n message resolution utility — looks up localized return messages by key (e.g., `"RETURN_MESSAGE_0001"`) |
| `TemplateErrorUtil.getErrorInfo()` | Utility | Template error extraction utility — scans a CBS execution result map for per-field error indicators and returns them as a structured list |
| `SCallException` | Class | Service Component Call Exception — thrown when a CBS service call results in errors, carrying error code and status information |
| `CAANMsg` | Class | Fujitsu CAAN message schema — structured message object holding CBS service request/response fields |
| `IRequestParameterReadWrite` | Interface | Business data interface — the shared parameter object that flows through screen/CBS/BP layers, carrying control data, business data, and results |
| `msgList` | Parameter | Execution Result Map — the raw output from a CBS service call, containing templates, return codes, and error data |
| `param` | Parameter | Business Data Interface — the read-write parameter object carrying state across the business process chain |
| CONTACT REGISTRATION | Business term | The contact registration business operation (Japanese: 連絡先登録) — the overall screen/transaction being handled, responsible for creating or modifying contact information for customers |
