# Business Logic — JKKSodSendCC.editResultRP() [112 LOC]

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

## 1. Role

### JKKSodSendCC.editResultRP()

This method is a **post-service result mapping utility** that transforms raw service component execution outcomes into a structured `IRequestParameterReadWrite` object ready for downstream screen processing. It is invoked by `callSvcInter()` after one or more Service Component (SC) calls have completed, acting as a central dispatcher for result handling across multiple service templates.

The method performs three core business operations: (1) **Service result status resolution** — it interprets return codes from the SC call and determines the effective status, prioritizing the SC's own status over any prior BP-level status; (2) **CBS message template routing** — based on the template ID returned by the service, it selects the correct CBS message class (EKK1041B001, EKK1041C010, EKK1041D010, EKK1081C010, ESC0041D010, ESC0051D010, or ESC0031D010) to extract error field metadata; (3) **Error mapping** — it iterates through CBS-defined error fields and maps any available error text from the service response template into the user data map, then aggregates the full error info list via `TemplateErrorUtil`.

The method implements a **routing/dispatch design pattern**, branching on template ID to select the appropriate CBS message handler. It serves as a shared utility consumed by multiple screens and processes that invoke SCs through `callSvcInter()`.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editResultRP msgList param fixedText"])

    START --> T1["Get templates from msgList TEMPLATE_LIST_KEY"]
    T1 --> T2["Get template from templates[0]"]
    T2 --> T3["Get returnCode from msgList RET_CD_INT_KEY"]
    T3 --> COND1{returnCode != 0?}
    COND1 -- true --> T4["Set templateStatus = 9000"]
    COND1 -- false --> T5["templateStatus from template.getInt STATUS_INT_KEY"]
    T4 --> COND2{RETURN_MESSAGE key exists?}
    T5 --> COND2
    COND2 -- false --> T6["Set templateStatus = 0"]
    COND2 -- true --> T7["Keep templateStatus"]
    T6 --> COND3
    T7 --> COND3

    T7 --> T8["Get bpStatus from RETURN_CODE"]
    T8 --> COND4{templateStatus > bpStatus?}
    T3 --> COND3{"bpStatus obj null?"}
    COND3 -- true --> C3_A["bpStatus = -1"]
    COND3 -- false --> C3_B["bpStatus = parseInt RETURN_CODE"]
    C3_A --> COND4
    C3_B --> COND4

    COND4 -- true --> UPDATE["Set RETURN_CODE formatStatus"]
    UPDATE --> UPDATE_MSG["Set RETURN_MESSAGE message"]
    UPDATE_MSG --> DATA
    COND4 -- false --> DATA["Get inMap from param.getData fixedText"]

    DATA --> T9["contents = null"]
    T9 --> COND_EKK{templateId check}
    COND_EKK -- EKK1041B001 --> GET_EKK1["contents = EKK1041B001CBSMsg.getContents"]
    COND_EKK -- EKK1041C010 --> GET_EKK2["contents = EKK1041C010CBSMsg.getContents"]
    COND_EKK -- EKK1041D010 --> GET_EKK3["contents = EKK1041D010CBSMsg.getContents"]
    COND_EKK -- EKK1081C010 --> GET_EKK4["contents = EKK1081C010CBSMsg.getContents"]
    COND_EKK -- ESC0041D010 --> GET_ESC1["contents = ESC0041D010CBSMsg.getContents"]
    COND_EKK -- ESC0051D010 --> GET_ESC2["contents = ESC0051D010CBSMsg.getContents"]
    COND_EKK -- ESC0031D010 --> GET_ESC3["contents = ESC0031D010CBSMsg.getContents"]
    COND_EKK -- no match --> NO_CB["contents = null"]

    GET_EKK1 --> LOOP{"contents != null and i < length?"}
    GET_EKK2 --> LOOP
    GET_EKK3 --> LOOP
    GET_EKK4 --> LOOP
    GET_ESC1 --> LOOP
    GET_ESC2 --> LOOP
    GET_ESC3 --> LOOP
    NO_CB --> LOOP

    LOOP -- yes --> GET_ELE["element = contents[i][0]"]
    GET_ELE --> IS_ERR{element contains _err?}
    IS_ERR -- true --> NOT_NULL{template not null for element?}
    IS_ERR -- false --> NEXT
    NOT_NULL -- true --> NOT_CONTAINS{inMap does not contain element?}
    NOT_NULL -- false --> NEXT
    NOT_CONTAINS -- true --> PUT["inMap.put element template value"]
    NOT_CONTAINS -- false --> NEXT
    PUT --> NEXT["i++"]
    NEXT --> LOOP
    LOOP -- no --> ERR_LIST["Get errList from ERROR_INFO"]
    ERR_LIST --> ERR_NEW{"errList null?"}
    ERR_NEW -- yes --> ERR_MAKE["errList = new ArrayList"]
    ERR_NEW -- no --> ERR_SET
    ERR_MAKE --> ERR_SET["Set ERROR_INFO via TemplateErrorUtil.getErrorInfo"]
    ERR_SET --> RET(["Return param"])
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `msgList` | `Map<?, ?>` | Service component return values — a map containing the `CAANMsg[]` template array (`TEMPLATE_LIST_KEY`), the return code integer (`RET_CD_INT_KEY`), and template-specific fields including `TEMPLATE_ID_KEY` and `STATUS_INT_KEY`. This map carries all results from the SC execution (status, return codes, template ID, field values). |
| 2 | `param` | `IRequestParameterReadWrite` | The business data I/F object used for data acquisition and writing — it holds control map data (return code, return message, error info) and user data maps keyed by `fixedText`. This is the primary output carrier for mapped results. |
| 3 | `fixedText` | `String` | A user-defined arbitrary string used as a key to retrieve the user data HashMap from `param`. It acts as the data section identifier — typically corresponds to a screen section or processing context. |

**External/Instance fields read:** None. This method is stateless and does not read any instance fields.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `EKK1041B001CBSMsg.getContents` | EKK1041B001CBS | - | Reads CBS message field definitions for template EKK1041B001 (error field metadata) |
| R | `EKK1041C010CBSMsg.getContents` | EKK1041C010CBS | - | Reads CBS message field definitions for template EKK1041C010 |
| R | `EKK1041D010CBSMsg.getContents` | EKK1041D010CBS | - | Reads CBS message field definitions for template EKK1041D010 |
| R | `EKK1081C010CBSMsg.getContents` | EKK1081C010CBS | - | Reads CBS message field definitions for template EKK1081C010 |
| R | `ESC0041D010CBSMsg.getContents` | ESC0041D010CBS | - | Reads CBS message field definitions for template ESC0041D010 |
| R | `ESC0051D010CBSMsg.getContents` | ESC0051D010CBS | - | Reads CBS message field definitions for template ESC0051D010 |
| R | `ESC0031D010CBSMsg.getContents` | ESC0031D010CBS | - | Reads CBS message field definitions for template ESC0031D010 |
| R | `TemplateErrorUtil.getErrorInfo` | TemplateErrorUtil | - | Extracts error information from msgList and returns error info list |
| R | `CAANMsg.getString` | CAANMsg | - | Reads string fields from CAANMsg template (e.g., templateId, error field values) |
| R | `CAANMsg.getInt` | CAANMsg | - | Reads integer fields from CAANMsg template (status) |
| R | `CAANMsg.isNull` | CAANMsg | - | Checks whether a field in CAANMsg is null |
| - | `JKKSodSendCC.editResultRP` | - | - | This method itself |

**CRUD Classification Summary:**

All operations are **Read (R)** — this method performs no database writes. It reads CBS message field definitions (via `getContents()` on CBS message classes), reads template field values (via `getString`, `getInt`, `isNull` on `CAANMsg`), and reads error info (via `TemplateErrorUtil.getErrorInfo`). The method itself performs only **SET** operations on the `param` object (writing control map data and mapping errors into user data).

## 5. Dependency Trace

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

Direct callers found: 1 method.
Terminal operations from this method: `getContents` [R], `getContents` [R], `getContents` [R], `getContents` [R], `getContents` [R], `getContents` [R], `getContents` [R], `getErrorInfo` [R], `getString` [R], `getInt` [R], `isNull` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS:JKKSodSendCC.callSvcInter | `callSvcInter` → `editResultRP` | `getContents [R]` (7 CBS templates), `getErrorInfo [R]` (TemplateErrorUtil), `getString [R]` (CAANMsg), `isNull [R]` (CAANMsg) |

**Instructions:**
- Caller identified from the code graph: `JKKSodSendCC.callSvcInter()` is the direct caller.
- This is a CBS-level method within the same component class, not a screen entry point.
- The method is a utility helper — no screen/batch entry points were found within 8 hops.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(template extraction and return code retrieval) (L2442-2450)`

Retrieves CAANMsg templates and return code from msgList, then extracts template ID and status.

| # | Type | Code |
|---|------|------|
| 1 | SET | `CAANMsg[] templates = (CAANMsg[])msgList.get(JCMConstants.TEMPLATE_LIST_KEY)` // Extract template array from service return |
| 2 | SET | `CAANMsg template = templates[0]` // Take first template (primary result) |
| 3 | SET | `Integer returnCode = (Integer)msgList.get(JCMConstants.RET_CD_INT_KEY)` [-> JCMConstants.TEMPLATE_LIST_KEY, RET_CD_INT_KEY] // Extract return code from msgList |
| 4 | SET | `String templateId = template.getString(JCMConstants.TEMPLATE_ID_KEY)` [-> JCMConstants.TEMPLATE_ID_KEY] // Get template ID to determine CBS message class |
| 5 | SET | `int templateStatus = template.getInt(JCMConstants.STATUS_INT_KEY)` [-> JCMConstants.STATUS_INT_KEY] // Get initial status from template |

**Block 2** — [IF] `(returnCode != 0 → override status to error) (L2451-2454)`

If the service returned a non-zero return code, override the status to 9000 (indicating a service error occurred). This is a blanket error status that takes precedence over any specific service status.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` [-> override to generic error status] |

**Block 3** — [IF] `(RETURN_MESSAGE key validation) (L2455-2459)`

Validates whether a localized return message exists for the current templateStatus. If the message key (`RETURN_MESSAGE_` + zero-padded status code) does not resolve to a string, reset templateStatus to 0 (success). This ensures only recognized status codes are displayed.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus))` // Check if message exists for this status |
| 2 | SET | `templateStatus = 0` [-> reset to success if no message key found] |

**Block 4** — [IF/ELSE] `(bpStatus extraction) (L2461-2468)`

Retrieves the current business process status from the param's control map. If no prior return code is set, defaults to -1 (uninitialized).

| # | Type | Code |
|---|------|------|
| 1 | SET | `Object obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` |
| 2 | IF | `obj == null` |
| 3 | SET | `bpStatus = -1` [-> uninitialized BP status] |
| 4 | ELSE | |
| 5 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` |

**Block 5** — [IF] `(templateStatus > bpStatus → promote service status) (L2470-2477)`

If the service component returned a higher (worse) status than the BP-level status, override the BP status with the service status and set the corresponding return message. This ensures errors from downstream services are not silently ignored.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String formatStatus = String.format("%1$04d", templateStatus)` |
| 2 | SET | `String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` |
| 3 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` [-> overwrite with service status] |
| 4 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` [-> set localized error message] |

**Block 6** — [SET] `(user data map retrieval) (L2480)`

Retrieves the user data HashMap keyed by `fixedText` — this is the data section that will receive mapped error information.

| # | Type | Code |
|---|------|------|
| 1 | SET | `HashMap inMap = (HashMap)param.getData(fixedText)` // User data section for error mapping |

**Block 7** — [IF/ELSE-IF chain] `(templateId-based CBS message routing) (L2484-2506)`

Routes to the appropriate CBS message class based on the template ID. Each branch calls `getContents()` on the corresponding CBS message class to obtain the array of error field metadata.

| # | Type | Code |
|---|------|------|
| 1 | IF | `templateId.equals("EKK1041B001")` |
| 2 | SET | `contents = new EKK1041B001CBSMsg().getContents()` [-> CBS template for error field metadata] |
| 3 | ELSE-IF | `templateId.equals("EKK1041C010")` |
| 4 | SET | `contents = new EKK1041C010CBSMsg().getContents()` |
| 5 | ELSE-IF | `templateId.equals("EKK1041D010")` |
| 6 | SET | `contents = new EKK1041D010CBSMsg().getContents()` |
| 7 | ELSE-IF | `templateId.equals("EKK1081C010")` |
| 8 | SET | `contents = new EKK1081C010CBSMsg().getContents()` |
| 9 | ELSE-IF | `templateId.equals("ESC0041D010")` |
| 10 | SET | `contents = new ESC0041D010CBSMsg().getContents()` |
| 11 | ELSE-IF | `templateId.equals("ESC0051D010")` |
| 12 | SET | `contents = new ESC0051D010CBSMsg().getContents()` |
| 13 | ELSE-IF | `templateId.equals("ESC0031D010")` |
| 14 | SET | `contents = new ESC0031D010CBSMsg().getContents()` |
| 15 | ELSE | `contents` remains `null` |

**Block 8** — [FOR] `(error field iteration and mapping) (L2508-2521)`

Iterates through the CBS-defined error fields array. For each field, if it contains "_err" (indicating an error field), and the template has a non-null value for that field, and the user data map does not already contain the field, copy the error text from the template to the user data map. This implements a one-way mapping of error messages from SC results into the screen data model.

| # | Type | Code |
|---|------|------|
| 1 | FOR | `i = 0; contents != null && i < contents.length; i++` |
| 2 | SET | `String element = (String)contents[i][0]` // Field name (e.g., "some_field_err") |
| 3 | IF | `element.indexOf("_err") > 0` // Only process error-typed fields |
| 4 | IF | `!template.isNull(element)` // Template has a value for this field |
| 5 | IF | `!inMap.containsKey(element)` // Not already set |
| 6 | SET | `inMap.put(element, template.getString(element))` // Copy error text from template |
| 7 | SET | `i++` |

**Block 9** — [IF/ELSE] `(error list initialization) (L2524-2528)`

Retrieves the error info list from the control map. If not initialized, creates a new empty list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ArrayList<Object> errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO)` |
| 2 | IF | `errList == null` |
| 3 | SET | `errList = new ArrayList<Object>()` |

**Block 10** — [SET] `(error info aggregation) (L2531)`

Calls `TemplateErrorUtil.getErrorInfo()` to build the complete error info list from the msgList and appends/sets it into the param's control map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(msgList, errList))` |

**Block 11** — [RETURN] `(return mapped param) (L2533)`

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return the fully mapped IRequestParameterReadWrite |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `editResultRP` | Method | Edit Result Response Processing — post-service result mapping method that transforms SC return data into screen-ready format |
| `msgList` | Parameter | Service Component return map — carries all data returned from executed service components including templates, return codes, and field values |
| `template` | Field | CAANMsg template — a structured message object returned by service components containing field values, status codes, and template IDs |
| `templateId` | Field | Template ID — a string identifier (e.g., "EKK1041B001") that determines which CBS message class to use for error field resolution |
| `templateStatus` | Field | Template status code — numeric status from the service component (0=success, 9000=error) used for display-level error handling |
| `returnCode` | Field | Return code integer — raw numeric return code from the service component (0=success, non-zero=error) |
| `bpStatus` | Field | Business Process status — the current status stored in the param's control map before service result processing |
| `fixedText` | Parameter | User-defined arbitrary string — serves as a key to identify and retrieve the user data HashMap section for error mapping |
| `inMap` | Field | User data HashMap — the data section where error messages are mapped for display on the screen |
| `contents` | Field | CBS message field definitions — a 2D object array where each row contains field metadata from the CBS message class (element name at index [i][0]) |
| `element` | Field | CBS field name — a string like "some_field_err" representing a field name, where "_err" suffix indicates an error field |
| `errList` | Field | Error list — an ArrayList containing structured error information extracted from the service component response |
| `CAANMsg` | Class | CAAN Message — a message/container class used by service components to pass field values and metadata |
| `IRequestParameterReadWrite` | Interface | Business Data I/F — the interface for reading and writing business data between screens and service components |
| `JCMConstants` | Class | JCM Constants — constant definitions class holding keys like `TEMPLATE_LIST_KEY`, `RET_CD_INT_KEY`, `TEMPLATE_ID_KEY`, `STATUS_INT_KEY` |
| `JCMAPLConstMgr` | Class | JCM Application Constants Manager — a manager class for retrieving localized/externalized message strings |
| `SCControlMapKeys` | Class | SC Control Map Keys — constant definitions for control map keys like `RETURN_CODE`, `RETURN_MESSAGE`, `ERROR_INFO` |
| `TemplateErrorUtil` | Class | Template Error Utility — utility class that extracts error information from service component responses |
| `CBS` | Acronym | Central Business System — external business system providing CBS message templates with field definitions |
| `SC` | Acronym | Service Component — a service-layer class that performs business operations and returns results via CAANMsg |
| `BP` | Acronym | Business Process — the application-layer process that orchestrates service calls and manages state |
| `_err` | Field Suffix | Error field marker — a string suffix in CBS field names indicating the field carries error message text |
| `RETURN_MESSAGE_*` | Constant Pattern | Localized message key pattern — message keys formed by appending the zero-padded status code to "RETURN_MESSAGE_" |
