# Business Logic — JKKStbUcwkEoTvKktkSvcKeiCC.editErrorInfoCom() [60 LOC]

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

## 1. Role

### JKKStbUcwkEoTvKktkSvcKeiCC.editErrorInfoCom()

The `editErrorInfoCom` method is a shared common-component utility responsible for **consolidating error and message information** from a service component (SC) template into the request parameter object before presenting it to the caller. It implements a **priority-based status resolution** design pattern: the SC-provided status takes precedence over any business process (BP) status only when the SC status is numerically higher, ensuring that deeper or more severe errors propagate upward without being silently masked. When a higher SC status is detected, the method resolves the corresponding localized return message from a constants manager (`JCMAPLConstMgr`) using a zero-padded status code key (`RETURN_MESSAGE_<NNNN>`), then writes both the formatted return code and human-readable message into the control map. Beyond status handling, the method also acts as a **message bridge**, iterating over the template's hashmap to extract any keys ending in `_err` (error field suffix) and copying their values into the business data map keyed by `dataMapKey`. This method is called by multiple screens and batch processes (e.g., `JKKStbUcwkEoTvKktkSvcKeiCC.callSC`, `JKKStbUcwkEoTvKktkSvcKeiCC.editErrorInfo`) and is duplicated across many other CC classes in the codebase (e.g., `JKKSokoListCC`, `JKKWribAutoAddBatchCC`, `JCHSeikyDtailPayKigenCC`), serving as the **standardized error-bridging step** in the request-processing pipeline after an SC call completes.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfoCom(param, templates, returnCode, dataMapKey)"])

    START --> S1["S1: Retrieve templates[0] and extract STATUS field"]
    S1 --> S2["S2: if (returnCode != 0) -> templateStatus = 9000"]
    S2 --> S3["S3: Check if RETURN_MESSAGE_<status> constant exists"]
    S3 --> S3_COND{"Constant returned null?"}
    S3_COND -->|Yes| S3_SET["S3a: templateStatus = 0 (fallback)")
    S3_COND -->|No| S4["S4: Constant exists - keep templateStatus as-is"]
    S3_SET --> S4
    S4 --> S5["S5: Read bpStatus from control map RETURN_CODE (default -1 if null)"]
    S5 --> S6_COND{"templateStatus > bpStatus?"}
    S6_COND -->|No (SC status not higher)| COPY["S7: Iterate template hashmap - copy _err keys into inMap"]
    S6_COND -->|Yes (SC status higher)| S6A["S6a: Format status as zero-padded string (e.g. \"2001\")"]
    S6A --> S6B["S6b: Look up RETURN_MESSAGE_<formattedStatus> from constants"]
    S6B --> S6C["S6c: Set RETURN_CODE and RETURN_MESSAGE in control map"]
    S6C --> COPY
    COPY --> RETURN(["Return param with updated error info"])
```

**Processing flow summary:**

1. **Extract SC status** — Read the first template (`templates[0]`) and extract its `STATUS` field value (defined in `ECK0011B002CBSMsg.STATUS = "status"`).
2. **Error override** — If `returnCode != 0` (i.e., an error occurred during the SC call), override the template status to `9000`, a generic error sentinel.
3. **Constant validation** — Check whether a localized message constant exists for `RETURN_MESSAGE_<status>`. If the constants manager returns `null` (no message defined for this status), reset `templateStatus` to `0` (success/informational default).
4. **BP status baseline** — Read the current business process status from the control map under `SCControlMapKeys.RETURN_CODE`. If absent, default to `-1`.
5. **Priority comparison** — If the SC status is strictly greater than the BP status, the SC error takes precedence: format the status as a zero-padded 4-digit string, look up its localized message, and write both into the control map.
6. **Error field bridge** — Iterate over all keys in the template's hashmap; for any key ending in `_err`, copy the value into the business data map (`inMap`) so error messages are available to the presentation layer.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying business data, control map entries, and error context throughout the service request pipeline. It holds the data map (keyed by `dataMapKey`) where error messages are written, and the control map where return code/message pairs are stored for screen-level display. |
| 2 | `templates` | `CAANMsg[]` | An array of service component message templates. `templates[0]` holds the SC response containing the status field and any `_err`-suffixed error message keys. The `CAANMsg` class provides access to typed fields (`getInt`, `getString`, `isNull`) and a hashmap representation of all message data. |
| 3 | `returnCode` | `int` | The raw return code from the service component call. `0` indicates success; any non-zero value signals an error and triggers the generic status override to `9000`. This is the primary indicator of whether the SC call succeeded or failed. |
| 4 | `dataMapKey` | `String` | The key used to retrieve the business data map (`HashMap<String, String>`) from the parameter object. Error message fields (`_err` keys) are copied into this data map for consumption by the calling business process or screen. |

**External state / instance fields:** None. This method is fully stateless — it operates exclusively on its parameters and does not read any instance fields.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `ECK0011B002CBSMsg.getInt` | ECK0011B002CBS | - | Reads the `status` integer field from the SC response template |
| - | `JCMAPLConstMgr.getString` | JCMAPLConstMgr | - | Looks up localized return message constants by key `RETURN_MESSAGE_<NNNN>`; returns `null` if the key is undefined |
| - | `param.getControlMapData` | param | - | Reads the BP's current return code from the control map; used as baseline for status priority comparison |
| - | `param.setControlMapData` | param | - | Writes the resolved return code (zero-padded) and localized message into the control map when SC status takes priority |
| - | `param.getData` | param | - | Retrieves the business data map (`HashMap<String, String>`) keyed by `dataMapKey` for error message merging |
| - | `template.getHashMap().keySet().iterator()` | template | - | Iterates over all keys in the SC message template hashmap to find `_err`-suffixed error fields |
| - | `template.isNull` | template | - | Checks whether a specific template key has a null value before copying |
| - | `template.getString` | template | - | Retrieves the string value of an error message field from the template |
| - | `inMap.put` | inMap | - | Writes the error message value into the business data map for the calling screen/BP to consume |

**Classification rationale:** This method performs no direct database or SC-level Create/Read/Update/Delete operations. It is a **message transformation and routing layer** that bridges raw SC response data into the structured request parameter object. All operations are reads from templates/parameters, local constant lookups, and writes to in-memory maps. The `JCMAPLConstMgr.getString` call is a constants lookup (not a DB operation), and `param.setControlMapData` is an in-memory control map write.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS:JKKStbUcwkEoTvKktkSvcKeiCC.callSC | `callSC` -> `editErrorInfoCom` | `isNull` [-], `getString` [R] |
| 2 | CBS:JKKStbUcwkEoTvKktkSvcKeiCC.editErrorInfo | `editErrorInfo` -> `editErrorInfoCom` | `isNull` [-], `getString` [R] |

**Notes:**
- Both direct callers (`callSC` and `editErrorInfo`) reside within the same class `JKKStbUcwkEoTvKktkSvcKeiCC`, which is a Business Component Service (CBS).
- `callSC` is the service component invocation entry point — `editErrorInfoCom` is called immediately after an SC call returns to process and merge any error information.
- `editErrorInfo` is a dedicated error-handling method that delegates to `editErrorInfoCom` for the actual error consolidation.
- This method is also duplicated with the same signature across many other CC classes in the codebase (e.g., `JKKSokoListCC`, `JKKWribAutoAddBatchCC`, `JCHSeikyDtailPayKigenCC`, `JFUWebMskmNyoListCC`, `JKKKojihiKapKeiOperateBfCC`), indicating it is a **code-smell pattern** — the same logic should be consolidated into a shared utility class.

## 6. Per-Branch Detail Blocks

**Block 1** — SET (SC status extraction) (L898)

> Extracts the service component's status field from the first template element.

| # | Type | Code |
|---|------|------|
| 1 | SET | `template = templates[0]` // Get the SC response template |
| 2 | SET | `templateStatus = template.getInt(ECK0011B002CBSMsg.STATUS)` // Extract status — `[-> ECK0011B002CBSMsg.STATUS = "status"]` |

**Block 2** — IF `returnCode != 0` (Error override) (L902)

> If the SC call returned a non-zero error code, override the template status to `9000` (generic error sentinel).

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` // Generic error status overrides SC status |

**Block 3** — IF `JCMAPLConstMgr.getString(...) == null` (Constant validation) (L906)

> Checks whether a localized message constant exists for the current status. If `null` (no message defined), resets status to `0` (success/default).
> Condition key: `RETURN_MESSAGE_` + zero-padded `templateStatus`

| # | Type | Code |
|---|------|------|
| 1 | SET | `msgKey = "RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)` // e.g., "RETURN_MESSAGE_2001" |
| 2 | SET | `JCMAPLConstMgr.getString(msgKey)` // Constants manager lookup |
| 3 | IF | `result == null` // No constant defined for this status |

**Block 3.1** — ELSE-IF (constant exists) — no action, fall through

**Block 3.1.1** — SET (fallback) (L908)

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

**Block 4** — SET (BP status baseline) (L912)

> Reads the business process's current return code from the control map. Defaults to `-1` if the key is absent.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = 0` // Initialize to zero |
| 2 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read BP's return code from control map |

**Block 5** — IF `obj == null` (BP status default) (L913)

> If no return code exists in the control map, default to `-1` (lower than any real status, ensuring SC status always wins).

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = -1` // Default: BP has no status, SC status takes precedence |

**Block 5.1** — ELSE (L916)

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

**Block 6** — IF `templateStatus > bpStatus` (Priority comparison) (L920)

> The core business rule: the SC status only overrides the BP status if it is numerically higher. This ensures deeper errors propagate while allowing the BP to override with its own status in lower-priority scenarios.
> Condition: `templateStatus` (SC status, possibly overridden to `9000`) is **strictly greater than** `bpStatus` (BP's current status).

**Block 6.1** — ELSE-IF (SC status <= BP status) — no action, skip to error field copying

> When the BP status is equal to or higher than the SC status, the BP's status is preserved and no control map update occurs. The method proceeds to copy `_err` fields from the template.

**Block 6.2** — IF body (SC status wins) (L923)

> Format the SC status as a zero-padded 4-digit string, look up the localized message, and write both into the control map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Zero-padded, e.g., "2001" |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Localized message lookup |
| 3 | CALL | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // `[-> SCControlMapKeys.RETURN_CODE = "returnCode"]` |
| 4 | CALL | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // `[-> SCControlMapKeys.RETURN_MESSAGE = "returnMessage"]` |

**Block 7** — SET (Error field bridge initialization) (L930)

> Retrieves the business data map from the parameter object for error message merging.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = null` // Initialize error data map reference |
| 2 | EXEC | `inMap = (HashMap<String, String>) param.getData(dataMapKey)` // Cast and retrieve data map — comment: "ユーザデータ情報" (User data information) |

**Block 8** — WHILE (Error field iteration) (L933)

> Iterates over all keys in the template's hashmap. For each key ending in `_err` (the error field naming convention), copies the error message value into the business data map if the template value is not null.

| # | Type | Code |
|---|------|------|
| 1 | SET | `it = template.getHashMap().keySet().iterator()` // Iterator over template hashmap keys |
| 2 | WHILE | `it.hasNext()` // Iterate over all template keys |
| 3 | SET | `key = it.next()` // Current hashmap key |
| 4 | IF | `key.endsWith("_err")` // Error field naming convention check |

**Block 8.1** — IF `!template.isNull(key)` (Not null guard) (L937)

> Only copy the error message if the template field contains a non-null value. Prevents null propagation into the business data map.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `inMap.put(key, template.getString(key))` // Copy error message from template to business data map |

**Block 9** — RETURN (L941)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return the modified parameter with updated error info |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `templates` | Parameter | SC response message array — contains the status field and any error messages returned by the called service component |
| `STATUS` | Field | Status code field name (`"status"`) — defined in `ECK0011B002CBSMsg` as an integer representing the SC execution outcome |
| `returnCode` | Parameter | SC call return code — `0` means success, non-zero indicates an error occurred during the service component invocation |
| `templateStatus` | Variable | Extracted or derived status from the template — the primary status value used for comparison and message lookup |
| `bpStatus` | Variable | Business Process status — the status already recorded by the calling business process layer, used as a baseline for priority comparison |
| `9000` | Constant | Generic error sentinel status — assigned when `returnCode != 0`, indicating an unspecified error occurred |
| `RETURN_MESSAGE_<NNNN>` | Constant pattern | Localized message key pattern — each status code maps to a human-readable message via `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + zeroPaddedStatus)` |
| `_err` | Naming convention | Error field suffix — template keys ending in `_err` contain error messages that need to be bridged to the business data map |
| `dataMapKey` | Parameter | Data map key — identifies which business data map within the parameter object should receive the error messages |
| `SCControlMapKeys.RETURN_CODE` | Constant | Control map key for return code — `[-> "returnCode"]` used to store and retrieve the formatted status code |
| `SCControlMapKeys.RETURN_MESSAGE` | Constant | Control map key for return message — `[-> "returnMessage"]` used to store the localized error message |
| `JCMAPLConstMgr` | Class | Constants manager utility — provides localized message lookups via `getString()` for configurable message keys |
| `CAANMsg` | Class | Message container class — holds typed fields (int, String) and a hashmap representation of message data from the service component |
| `IRequestParameterReadWrite` | Interface | Request parameter interface — the central data carrier for service requests, holding business data maps, control maps, and error context |
| `inMap` | Variable | Business data map — a `HashMap<String, String>` that holds user/business data including error messages for presentation |
| 本来はインターフェース分の処理が必要 (Original comment) | Comment | "Processing for the interface layer is originally required" — indicates this method is intended to bridge SC response data to the presentation/interface layer |