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

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

## 1. Role

### JKKSvkeiShosaBaseCC.editResultRP()

This method serves as the **service component result mapping** bridge between the Service IF (S-IF) execution layer and the business process (BP) parameter layer. After a Service Component Request is dispatched via `callScCmn()`, this method extracts the response metadata from the returned `msgList` and normalizes it into the `IRequestParameterReadWrite` interface that drives subsequent screen processing. Specifically, it resolves the template execution status (including overriding to status 9000 when the return code indicates an SC-level failure), validates the status against the application's return message catalog, compares the SC status against the BP's own status to propagate the higher/severity status upward, and finally aggregates error information via `TemplateErrorUtil.getErrorInfo()`. This is a **shared utility** — every S-IF invocation in the `callScCmn()` delegation pattern chains through this method, making it the single normalization point for all service contract verification screen results.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editResultRP start"])
    
    START --> EXTRACT["Extract CAANMsg[] and Integer returnCode from msgList"]
    EXTRACT --> GETSTATUS["Get templateStatus from template"]
    GETSTATUS --> CHECKRC{"returnCode != 0?"}
    CHECKRC -- Yes --> SETERR["Set templateStatus = 9000"]
    SETERR --> CHECKMSG{"Return message for templateStatus exists?"}
    CHECKRC -- No --> CHECKMSG
    CHECKMSG -- Yes --> COMPARE{"templateStatus > bpStatus?"}
    CHECKMSG -- No --> SETZERO["Set templateStatus = 0"]
    SETZERO --> COMPARE
    COMPARE -- Yes --> SETRESULT["Set RETURN_CODE, RETURN_MESSAGE in param"]
    SETRESULT --> GETERRINFO["Get existing errList from param"]
    COMPARE -- No --> GETERRINFO
    GETERRINFO --> INITERR["If errList is null, create new ArrayList"]
    INITERR --> GETTPLID["Get templateID (S-IF name)"]
    GETTPLID --> UPDATEERRINFO["Set ERROR_INFO = TemplateErrorUtil.getErrorInfo(msgList, errList)"]
    UPDATEERRINFO --> END(["Return param"])
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `msgList` | `Map<?, ?>` | The response map returned from the S-IF (Service IF) call via `ServiceComponentRequestInvoker.run()`. Contains the `CAANMsg[]` template array under `TEMPLATE_LIST_KEY`, the return code under `RET_CD_INT_KEY`, and the `STATUS_INT_KEY` status field. Represents the raw results of the service component invocation. |
| 2 | `param` | `IRequestParameterReadWrite` | The business data read/write interface (`IRequestParameterReadWrite`) that carries control map data such as return code, return message, and error info between BP processing steps. Used both as source (reading current bpStatus, existing error list) and destination (writing normalized status and error aggregation). |

**Instance/External state referenced:**
- No instance fields are directly read within this method.
- External constants accessed: `JCMConstants.TEMPLATE_LIST_KEY`, `JCMConstants.RET_CD_INT_KEY`, `JCMConstants.STATUS_INT_KEY` — standard keys for extracting S-IF response data from the message map.
- `JCMAPLConstMgr.getString()` — global constant manager used to validate status codes against the application's return message catalog.
- `SCControlMapKeys.RETURN_CODE`, `SCControlMapKeys.RETURN_MESSAGE`, `SCControlMapKeys.ERROR_INFO` — control map key constants for param data read/write.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `TemplateErrorUtil.getErrorInfo(Map<?, ?>, ArrayList<Object>)` | - | - | Aggregates error information from the SC response `msgList` into the error list. Performs a read of error messages from the template and builds the consolidated error info for display. |
| R | `JCMAPLConstMgr.getString(String)` | - | - | Reads a return message string from the application constant catalog using the key `RETURN_MESSAGE_{status}`. Validates that the template status maps to a known message; if not found, the status is reset to 0. |
| R | `IRequestParameterReadWrite.getControlMapData(String)` | - | - | Reads control map data (bpStatus, existing error list) from the param object. Used to retrieve the BP's current return code and any previously accumulated error entries. |
| W | `IRequestParameterReadWrite.setControlMapData(String, Object)` | - | - | Writes control map data (return code, return message) back to the param object to propagate the highest-severity status and its message. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `callScCmn()` (CommonComponent) | `callScCmn(param, handle, template, mapper)` -> `editResultRP(sIFResult, param)` | `getErrorInfo [R] TemplateErrorUtil`, `getString [R] JCMAPLConstMgr`, `getControlMapData [R] param`, `setControlMapData [W] param` |

## 6. Per-Branch Detail Blocks

**Block 1** — [EXTRACTION] (L669)

> Extracts the CAANMsg template array and return code from the SC response map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `CAANMsg[] templates = (CAANMsg[])msgList.get(JCMConstants.TEMPLATE_LIST_KEY)` // Extract CAANMsg[] from SC response (SCからの戻り値からCAANMsgを取得) |
| 2 | SET | `CAANMsg template = templates[0]` // Take the first (and typically only) template from the array |
| 3 | SET | `Integer returnCode = (Integer)msgList.get(JCMConstants.RET_CD_INT_KEY)` // Extract return code from SC response (リターンコード取得) |
| 4 | SET | `int templateStatus = template.getInt(JCMConstants.STATUS_INT_KEY)` // Extract template status (テンプレートID、ステータス取得) |

**Block 2** — [IF] `(returnCode.intValue() != 0)` (L677)

> If the SC returned a non-zero return code (indicating an error), override the template status to 9000 (generic SC error status).

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` // Override to generic error status when SC returns non-zero (SCからの戻り値からCAANMsgを取得) |

**Block 3** — [IF] `(JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formattedStatus) == null)` (L681)

> If there is no predefined return message for the current templateStatus in the application's constant catalog, reset templateStatus to 0 (normal/unknown). This acts as a validation step to ensure only recognized status codes are propagated.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String.format("%1$04d", templateStatus)` // Format status as 4-digit zero-padded string |
| 2 | SET | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formattedStatus)` // Look up return message in catalog |
| 3 | SET | `templateStatus = 0` // Reset to 0 if no message found for this status |

**Block 4** — [VARIABLE INIT] (L687)

> Determines the BP's own status from the param's control map data, defaulting to -1 if not set.

| # | Type | Code |
|---|------|------|
| 1 | SET | `int bpStatus = 0` // Initialize BP status |
| 2 | SET | `Object obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read BP's return code |
| 3 | IF | `obj == null` |
| 3.1 | SET | `bpStatus = -1` // BP has no return code set yet |
| 3.2 | ELSE | |
| 3.2.1 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse existing BP status |

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

> If the SC status is higher (more severe) than the BP's current status, propagate the SC status and its message to the param. This ensures the most severe status from the service component is always surfaced to the BP layer.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String formatStatus = String.format("%1$04d", templateStatus)` // Format as 4-digit status |
| 2 | SET | `String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Look up message for this status |
| 3 | CALL | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Set SC status as the BP return code (BPにサービスコンポーネントのステータスを設定する) |
| 4 | CALL | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Set the associated return message |

**Block 6** — [EXTRACTION] (L699)

> Retrieves or initializes the error info list from the param for subsequent error aggregation.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ArrayList<Object> errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO)` // Get existing error list (エラー情報のマップを取得) |
| 2 | IF | `errList == null` |
| 2.1 | SET | `errList = new ArrayList<Object>()` // Create new empty list if none exists |

**Block 7** — [EXTRACTION] (L706)

> Reads the template ID, which serves as the S-IF name, from the template object.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String tName = template.getString("templateID")` // S-IF name (S-IF名) |

**Block 8** — [EXEC/CALL] (L709)

> Aggregates error information from the SC response and writes it back to the param, replacing any previous error info.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `TemplateErrorUtil.getErrorInfo(msgList, errList)` // Consolidate error info from SC response and error list |
| 2 | CALL | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, result)` // Set consolidated error info in param |

**Block 9** — [RETURN] (L711)

> Returns the updated param with normalized status, message, and error information.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return the modified business data read/write interface |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `templateStatus` | Field | Template execution status — numeric code from the service component indicating success (0) or various error conditions |
| `RETURN_CODE` | Key | Control map key for return code — stores the normalized status code in the param |
| `RETURN_MESSAGE` | Key | Control map key for return message — stores the human-readable message corresponding to the status code |
| `ERROR_INFO` | Key | Control map key for error info — stores an aggregated list of error objects for screen display |
| S-IF | Acronym | Service Interface — the interface used to invoke service components in this platform |
| SC | Acronym | Service Component — the business logic component invoked via S-IF |
| BP | Acronym | Business Process — the higher-level workflow that orchestrates screen-level operations |
| CAANMsg | Class | Message class used for passing data between service components and the BP layer |
| `TEMPLATE_LIST_KEY` | Constant | Map key for retrieving the CAANMsg[] template array from the SC response |
| `RET_CD_INT_KEY` | Constant | Map key for retrieving the Integer return code from the SC response |
| `STATUS_INT_KEY` | Constant | Map key for retrieving the template status integer from the CAANMsg object |
| TemplateErrorUtil | Class | Utility class that aggregates error information from SC responses into a structured error list |
| `IRequestParameterReadWrite` | Interface | Business data read/write interface — the central data carrier between BP processing steps |
| `JCMAPLConstMgr` | Class | Global constant manager — retrieves application-level string constants such as return messages |
| SCControlMapKeys | Class | Constants class defining keys for control map data in the param |
