# Business Logic — JKKSmtvlYoSanshoFukaInfCC.editErrorInfo() [59 LOC]

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

## 1. Role

### JKKSmtvlYoSanshoFukaInfCC.editErrorInfo()

This method serves as the **error information mapping bridge** between Service Component (SC) responses and the Business Process (BP) request parameter context. After a cascade of SCs is invoked (via `callSC`), each SC populates its `CAANMsg` template with status codes and error fields. `editErrorInfo` walks through every template returned by the SC cascade, normalizes the status code, and promotes the most severe error status into the BP's control map so that the presenting screen can display appropriate error messages. Specifically, it suppresses invalid status codes by falling them back to `0`, compares the validated SC status against the BP's current status, and — if the SC's status is numerically higher (i.e., more severe) — overwrites the BP's `RETURN_CODE` and `RETURN_MESSAGE`. It also iterates the error-keyed fields (those ending with `_err`) from each SC template's hash map, selectively copying only those whose corresponding non-err field already exists in the BP's service data map. This ensures the UI receives error messages only for fields that are actually rendered on the screen. The method acts as a shared utility invoked at the end of any SC cascade where error propagation to the screen layer is required.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfo start"])
    LOOP["for each template in templates array"]
    GET_STATUS["Get templateStatus from template.getInt(STATUS_INT_KEY)"]
    CHECK_RETURN["returnCode != 0 ?"]
    OVERRIDE_STATUS["Set templateStatus = 9000"]
    CHECK_MSG["JCMAPLConstMgr.getString(RETURN_MESSAGE_TEMPLATESTATUS) == null ?"]
    RESET_STATUS["Set templateStatus = 0"]
    GET_BP_STATUS["Get bpStatus from param.getControlMapData(RETURN_CODE)"]
    SET_BP_NEG1["Set bpStatus = -1 (null control map)"]
    PARSE_BP_STATUS["Parse bpStatus = Integer.parseInt(returnCode string)"]
    COMPARE["templateStatus > bpStatus ?"]
    SET_CONTROL["Set RETURN_CODE and RETURN_MESSAGE on param.controlMap"]
    GET_DATA["Get inMap = param.getData(SERVICE_ID)"]
    GET_TEMPLATE_MAP["Get mp = template.getHashMap()"]
    ITERATE["Iterate over mp.keySet()"]
    CHECK_ERR["key ends with '_err' ?"]
    SUBSTR["Extract field name: key.substring(0, key.lastIndexOf('_err'))"]
    CHECK_EXISTS["inMap.containsKey(fieldName) ?"]
    PUT_ERR["inMap.put(key, mp.get(key))"]
    NEXT_TEMPLATE["End of loop - continue"]
    RETURN(["Return param"])

    START --> LOOP
    LOOP --> GET_STATUS
    GET_STATUS --> CHECK_RETURN
    CHECK_RETURN -->|true| OVERRIDE_STATUS
    CHECK_RETURN -->|false| CHECK_MSG
    OVERRIDE_STATUS --> CHECK_MSG
    CHECK_MSG -->|null| RESET_STATUS
    CHECK_MSG -->|not null| GET_BP_STATUS
    RESET_STATUS --> GET_BP_STATUS
    GET_BP_STATUS --> SET_BP_NEG1
    SET_BP_NEG1 --> COMPARE
    GET_BP_STATUS --> PARSE_BP_STATUS
    PARSE_BP_STATUS --> COMPARE
    COMPARE -->|true| SET_CONTROL
    COMPARE -->|false| GET_DATA
    SET_CONTROL --> GET_DATA
    GET_DATA --> GET_TEMPLATE_MAP
    GET_TEMPLATE_MAP --> ITERATE
    ITERATE --> CHECK_ERR
    CHECK_ERR -->|true| SUBSTR
    CHECK_ERR -->|false| NEXT_TEMPLATE
    SUBSTR --> CHECK_EXISTS
    CHECK_EXISTS -->|true| PUT_ERR
    CHECK_EXISTS -->|false| NEXT_TEMPLATE
    PUT_ERR --> NEXT_TEMPLATE
    NEXT_TEMPLATE --> LOOP
    LOOP --> RETURN
```

**Processing Summary:**

1. **Loop over SC templates** — Iterates through every `CAANMsg` template returned by the SC cascade.
2. **Read status code** — Extracts the status code from the template via `template.getInt(JCMConstants.STATUS_INT_KEY)`.
3. **Global override** — If the overall `returnCode` parameter is non-zero, override the per-template status to `9000` (a catch-all error indicator), ensuring the most severe error surface at the screen.
4. **Status validation** — Check if a valid message key exists (`RETURN_MESSAGE_<status>`). If the message key is null (unknown status code), reset status to `0` (success), effectively silencing unrecognized status codes.
5. **BP status comparison** — Read the BP's current return code from the control map. If not yet set, default to `-1` (so any valid error status wins). If set, parse it as an integer. Compare: only update if the template's status is strictly greater (more severe).
6. **Error field mapping** — Extract the service data map for this CC's `SERVICE_ID` (`"KKSV065102CC"`). Iterate over the template's hash map, find keys ending with `_err`, and if the corresponding base field (without `_err` suffix) exists in the BP data map, copy the error value over.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying the BP's data context. It holds the control map (with `RETURN_CODE` and `RETURN_MESSAGE` keys) and the service data map under `SERVICE_ID` (`"KKSV065102CC"`). This is the shared data carrier between the BP and the screen layer. |
| 2 | `templates` | `CAANMsg[]` | An array of `CAANMsg` objects, each representing the response from a single Service Component (SC) in the cascade. Each template carries a status code (`STATUS_INT_KEY`) and a key-value hash map of field results, including error messages keyed by `<field>_err`. |
| 3 | `returnCode` | `int` | A global override return code. If non-zero, forces all template statuses to `9000` (override mode), meaning the most severe error is determined at the SC cascade level rather than per-template. If zero, each template's individual status is evaluated independently. |

**External state read by this method:**
- `SERVICE_ID` (constant = `"KKSV065102CC"`) — The service ID used to identify the BP's data map within the request parameter.
- `JCMConstants.STATUS_INT_KEY` — The key used to retrieve the status integer from each `CAANMsg` template.
- `SCControlMapKeys.RETURN_CODE` / `SCControlMapKeys.RETURN_MESSAGE` — Keys for the control map that stores the return code and message at the BP level.
- `JCMAPLConstMgr.getString(...)` — A lookup utility that resolves message keys like `RETURN_MESSAGE_0000`, `RETURN_MESSAGE_9000`, etc., into displayable Japanese error messages.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `param.getControlMapData` | - | - | Reads the BP control map to retrieve the current `RETURN_CODE` value for status comparison |
| R | `template.getInt` | - | - | Reads the status code from the SC response template |
| R | `JCMAPLConstMgr.getString` | - | - | Reads a static message resource to validate whether a status code has a corresponding error message |
| R | `param.getControlMapData` | - | - | Reads the BP's current return code from the control map |
| R | `param.getData` | - | - | Reads the service data map for the CC's `SERVICE_ID` (`KKSV065102CC`) |
| R | `template.getHashMap` | - | - | Reads the SC response key-value pairs (field results and error messages) |
| R | `mp.keySet` | - | - | Reads the set of keys from the SC template's hash map for iteration |
| R | `inMap.containsKey` | - | - | Checks whether the BP data map already contains a given field |
| W | `inMap.put` | - | - | Writes error field values (`<field>_err`) from the SC template into the BP data map |
| W | `param.setControlMapData` | - | - | Writes the new `RETURN_CODE` and `RETURN_MESSAGE` back into the BP control map |

**Notes:**
- This method is a **data mapper** — it does not call any database-level SC or CBS directly. All operations are reads/writes against in-memory data structures (`IRequestParameterReadWrite` and `CAANMsg`).
- The SC cascade (which does actual DB access) was invoked by the caller (`callSC`) prior to this method.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Class: JKKSmtvlYoSanshoFukaInfCC | `callSC()` -> `editErrorInfo(param, templates, returnCode)` | `param.getControlMapData [R]`, `template.getInt [R]`, `JCMAPLConstMgr.getString [R]`, `param.getData [R]`, `template.getHashMap [R]`, `inMap.put [W]`, `param.setControlMapData [W]` |

**Call Chain Description:**
- The caller `callSC()` within the same class (`JKKSmtvlYoSanshoFukaInfCC`) is responsible for invoking the SC cascade and then calling `editErrorInfo()` to map error information from SC responses back into the request parameter for the screen layer.

**Terminal operations reached from this method:**
- `getControlMapData` [R] — reads the BP return code
- `getInt` [R] — reads the template status code
- `getString` [R] — looks up error message strings from static constants
- `getData` [R] — reads the service data map
- `getHashMap` [R] — reads the SC response field map
- `keySet` [R] — iterates over error field keys
- `containsKey` [R] — checks field existence in BP data map
- `put` [W] — writes error field values into BP data map
- `setControlMapData` [W] — writes the effective return code and message

## 6. Per-Branch Detail Blocks

**Block 1** — [FOR-LOOP] `(int i = 0; i < templates.length; i++)` (L533)

> Iterates over each `CAANMsg` template returned from the SC cascade. For each template, the method normalizes its status, compares it against the BP's current status, and copies error fields.

| # | Type | Code |
|---|------|------|
| 1 | SET | `CAANMsg template = templates[i]` // Current SC response template |
| 2 | SET | `int templateStatus = template.getInt(JCMConstants.STATUS_INT_KEY)` // Read SC status code [-> `STATUS_INT_KEY` from JCMConstants] |
| 3 | IF | `[returnCode != 0]` (L537) — Global override: if a non-zero returnCode was passed, force this template's status to 9000 |
| 4 | IF | `[returnCode == 0 && message key is null]` (L541) — Unknown status code: reset to 0 to suppress it |
| 5 | SET | `int bpStatus = -1` or `int bpStatus = Integer.parseInt(...)` (L546–551) — Read BP's current status from control map |
| 6 | IF | `[templateStatus > bpStatus]` (L553) — Only propagate if SC status is more severe |
| 7 | SET | `String formatStatus = String.format("%1$04d", templateStatus)` (L556) // Format status as 4-digit zero-padded string, e.g. "0000", "9000" |
| 8 | SET | `String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` (L557) // Resolve the Japanese error message |
| 9 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` (L558) |
| 10 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` (L559) |
| 11 | SET | `HashMap<String, Object> inMap = param.getData(SERVICE_ID)` (L562) // [-> `SERVICE_ID = "KKSV065102CC"`] |
| 12 | SET | `HashMap<?, ?> mp = template.getHashMap()` (L564) // Get SC response key-value pairs |
| 13 | WHILE | `[it.hasNext()]` (L566) — Iterate over all keys in the SC response map |
| 14 | IF | `[key.endsWith("_err")]` (L567) — Check if this is an error field |
| 15 | IF | `[inMap.containsKey(fieldName)]` (L570) — Only copy if the base field exists in the BP data |
| 16 | SET | `inMap.put(key, mp.get(key))` (L571) // Copy error value from SC template to BP data map |

**Block 1.3** — [IF] `(returnCode != 0)` (L537)

> If a global override return code is provided, the per-template status is replaced with `9000`. This ensures that when the overall SC cascade failed, every template's status becomes `9000` (the override error), making the error surface consistently at the screen level regardless of individual SC statuses.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` // Override all statuses to 9000 |

**Block 1.4** — [IF] `[JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus) == null]` (L541)

> The message lookup function checks whether the formatted status code has a corresponding error message. If the key `RETURN_MESSAGE_XXXX` does not exist (unknown status), the status is reset to `0`, effectively treating the SC response as successful and preventing an unrecognized error from surfacing at the UI.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 0` // Unknown status suppressed to success |

**Block 1.5** — [IF-ELSE] `(obj == null)` (L547)

> Determines how to initialize the BP's current status code from the control map. If the return code hasn't been set yet (`null`), defaults to `-1` so any valid template status (which is >= 0) will be strictly greater and win the comparison.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = -1` // No prior status set, any valid status wins |
| 2 | ELSE-SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` (L551) // Parse existing BP status |

**Block 1.6** — [IF] `(templateStatus > bpStatus)` (L553)

> Core business logic: propagate the SC's error to the BP if the SC's status is numerically higher (more severe). The BP maintains the single most severe status it has seen across all SCs in the cascade. If the SC's status is more severe, both the formatted status code and the human-readable message are written into the BP control map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String formatStatus = String.format("%1$04d", templateStatus)` (L556) // Format as 4-digit string, e.g. "0000", "1000" |
| 2 | SET | `String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` (L557) // Resolve the display message [日本語のエラーメッセージ] |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Set return code [リターンコードの設定] |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Set return message [リターンメッセージの設定] |

**Block 1.7** — [WHILE] `(it.hasNext())` — Iterating SC template keys (L566)

> Walks through every key in the SC template's hash map. For keys that represent error fields (ending with `_err`), checks if the corresponding base field (without the `_err` suffix) exists in the BP's data map. If so, copies the error value from the SC template to the BP data map. This selective copying ensures error messages are only placed in the BP data for fields that the screen actually renders.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String key = (String)it.next()` // Next key from SC template |
| 2 | IF | `[key.endsWith("_err")]` (L567) — Check if key is an error field |
| 3 | SET | `int keyIdx = key.lastIndexOf("_err")` (L568) // Find the position before the _err suffix |
| 4 | SET | `String fieldName = key.substring(0, keyIdx)` (L569) // Extract the base field name [フィールド名の抽出] |
| 5 | IF | `[inMap.containsKey(fieldName)]` (L570) — Only copy if the base field exists in BP data [BPのデータマップにフィールドが存在する場合のみコピー] |
| 6 | SET | `inMap.put(key, mp.get(key))` (L571) // Copy error value [エラー値の設定] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `editErrorInfo` | Method | Error information mapping — copies SC error data into the BP request parameter for screen display |
| `IRequestParameterReadWrite` | Interface | Request parameter data carrier — shared object between the Business Process (BP) layer and the screen layer, holding both control map metadata and service data |
| `CAANMsg` | Class | Service Component response message — wraps the result of an SC call, containing status code and a key-value hash map of fields |
| `templates` | Parameter | SC response array — one `CAANMsg` per Service Component invoked in the cascade |
| `returnCode` | Parameter | Global override return code — when non-zero, forces all template statuses to 9000 (override all individual SC statuses) |
| `templateStatus` | Local variable | Status code extracted from an individual SC template response |
| `bpStatus` | Local variable | Current status stored in the BP's control map, used as the comparison baseline |
| `inMap` | Local variable | The BP's service data map (under `SERVICE_ID`), used to selectively copy SC error fields |
| `mp` | Local variable | The SC template's hash map of field name-value pairs, including error fields |
| `SERVICE_ID` | Constant | `"KKSV065102CC"` — Identifies the data map for this specific CC within the request parameter |
| `STATUS_INT_KEY` | Constant | The key used to retrieve the integer status code from a `CAANMsg` template |
| `SCControlMapKeys.RETURN_CODE` | Constant | Key for the return code in the BP's control map |
| `SCControlMapKeys.RETURN_MESSAGE` | Constant | Key for the return message in the BP's control map |
| `JCMAPLConstMgr.getString` | Method | Static message lookup — resolves keys like `RETURN_MESSAGE_0000` into Japanese display strings |
| `RETURN_MESSAGE_XXXX` | Message Key | Pattern for error message constants — maps a 4-digit status code to a Japanese user-facing error message |
| `_err` suffix | Field naming convention | Indicates an error message field — e.g., `field_err` holds the error message for `field` |
| `KKSV065102CC` | Service ID | The service component identifier for this custom BP — maps to screen `KKSV0651` |
| `callSC` | Method | The caller method in this same class that invokes the Service Component cascade and then calls `editErrorInfo` |
| BP (Business Process) | Architecture concept | The Java business logic layer that orchestrates SC calls and maps results to the screen layer |
| SC (Service Component) | Architecture concept | A reusable service component that performs domain logic (often DB operations) and returns a `CAANMsg` response |
| Control Map | Data structure | A string-to-object map within `IRequestParameterReadWrite` storing metadata like `RETURN_CODE` and `RETURN_MESSAGE` |
| Service Data Map | Data structure | A map within `IRequestParameterReadWrite` storing field-level data, keyed by `SERVICE_ID` |
| 9000 | Status code | Override error status — when the global `returnCode` is non-zero, all SC template statuses are set to this value |
