# Business Logic — JKKEmgRrksNmUpdCC.editErrorInfo() [55 LOC]

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

## 1. Role

### JKKEmgRrksNmUpdCC.editErrorInfo()

The `editErrorInfo` method is a private utility responsible for **configuring error information into a request parameter object** after a service call has executed. It acts as a **post-processing error handler** that normalizes and promotes error status codes and messages into the request parameter's control map, ensuring the calling screen receives accurate error feedback.

The method implements a **severity-ranking pattern**: it compares the business process's current return code (`bpStatus`) against the template-derived error status (`templateStatus`). Only if the template's status is **more severe** (numerically higher) than the existing BP return code does it overwrite the control map. This ensures that critical error codes from downstream service components always take precedence over less severe status codes.

Additionally, the method **populates per-field error codes** from a template message array into an in-map container. It scans all content entries whose names end with the `_err` suffix, retrieves corresponding error codes from the template, and deposits non-blank error codes into the input map — enabling per-field error highlighting on the presentation layer.

The method follows the **delegation pattern**, using framework-provided utilities (`JCMAPLConstMgr`, `JKKStringUtil`, `CAANMsg`, `IRequestParameterReadWrite`) to access localized message strings and manage request parameter data. It is called by `callSC()` within the same class, serving as a centralized error reporting bridge between service component execution and screen-level error display.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfo params"])
    GET_TEMPLATE["Get first template from templates array"]
    GET_TEMPLATE_STATUS["Get templateStatus from template.getInt STATUS_INT_KEY"]

    CHECK_RETURN_CODE{returnCode != 0?}
    SET_STATUS_9000["Set templateStatus = 9000"]
    FIND_STATUS["Find RETURN_MESSAGE for templateStatus"]

    GET_BP_STATUS["Get bpStatus from param.controlMap RETURN_CODE"]
    CHECK_BP_STATUS{bpStatus null?}
    SET_BP_STATUS_NEG1["Set bpStatus = -1"]
    PARSE_BP_STATUS["Parse bpStatus from param.controlMap RETURN_CODE"]

    CHECK_BP_TEMPLATE{bpStatus < templateStatus?}
    FORMAT_STATUS["Format templateStatus as 4-digit string"]
    GET_MESSAGE["Get RETURN_MESSAGE for formatStatus"]
    SET_RETURN_CODE["Set param.controlMap RETURN_CODE = formatStatus"]
    SET_RETURN_MESSAGE["Set param.controlMap RETURN_MESSAGE = message"]

    GET_IN_MAP["Get inMap from param.getData fixedText"]
    INIT_I["Initialize i = 0"]
    CHECK_LOOP{null != contents && i < contents.length?}
    GET_ITEM_NM["Get itemNm from contents[i][0]"]
    CHECK_ENDS_ERR{itemNm ends with _err?}
    GET_ERR_CD["Get errCd from template.getString itemNm"]
    CHECK_ERR_CD{errCd is null/blank?}
    PUT_ERR_CD["Put itemNm -> errCd into inMap"]
    INCREMENT_I["Increment i"]

    RETURN_PARAM["Return param"]

    START --> GET_TEMPLATE --> GET_TEMPLATE_STATUS --> CHECK_RETURN_CODE
    CHECK_RETURN_CODE -->|true| SET_STATUS_9000 --> FIND_STATUS
    CHECK_RETURN_CODE -->|false| FIND_STATUS
    FIND_STATUS --> GET_BP_STATUS --> CHECK_BP_STATUS
    CHECK_BP_STATUS -->|true| SET_BP_STATUS_NEG1 --> CHECK_BP_TEMPLATE
    CHECK_BP_STATUS -->|false| PARSE_BP_STATUS --> CHECK_BP_TEMPLATE
    CHECK_BP_TEMPLATE -->|true| FORMAT_STATUS --> GET_MESSAGE --> SET_RETURN_CODE --> SET_RETURN_MESSAGE --> GET_IN_MAP
    CHECK_BP_TEMPLATE -->|false| GET_IN_MAP
    GET_IN_MAP --> INIT_I --> CHECK_LOOP
    CHECK_LOOP -->|true| GET_ITEM_NM --> CHECK_ENDS_ERR
    CHECK_LOOP -->|false| RETURN_PARAM
    CHECK_ENDS_ERR -->|true| GET_ERR_CD --> CHECK_ERR_CD
    CHECK_ENDS_ERR -->|false| INCREMENT_I --> CHECK_LOOP
    CHECK_ERR_CD -->|true| PUT_ERR_CD --> INCREMENT_I
    CHECK_ERR_CD -->|false| INCREMENT_I
```

**Processing Flow Summary:**

1. Extract the first template message from the `templates` array.
2. Read the template's status integer via `JCMConstants.STATUS_INT_KEY`.
3. If the caller passed a non-zero `returnCode`, override the status to **9000** (indicating a general service error).
4. Validate that a localized message exists for this status (keyed as `RETURN_MESSAGE_XXXX`). If not, reset the status to **0** (no error).
5. Retrieve the existing BP return code from the request parameter's control map. If absent, treat as **-1**.
6. **Compare severity**: if the template status is numerically higher than the BP status, overwrite the control map with the formatted 4-digit status and its localized message.
7. Extract an in-map (`HashMap`) from the request parameter using `fixedText` as the key.
8. Iterate over `contents` array. For each entry whose name ends with `_err`, extract the error code from the template and store it in the in-map if non-blank.
9. Return the enriched `param` object.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying the current request scope's control map and data containers. Used to read the existing BP return code and write back error status, localized message, and per-field error codes. |
| 2 | `templates` | `CAANMsg[]` | An array of localized template messages. The first element is used to extract the error status code and per-field error codes. Each entry contains key-value pairs where keys correspond to field names (including `_err` suffixed error code keys). |
| 3 | `returnCode` | `int` | The return code from the service component call. If non-zero, indicates an error condition and forces the error status to 9000 (general error). Zero indicates successful execution. |
| 4 | `fixedText` | `String` | A key string used to retrieve or create an in-map (`HashMap<String, String>`) from the request parameter. This map accumulates per-field error codes for display on the screen. |
| 5 | `contents` | `Object[][]` | A 2D array of content metadata. Each row contains field metadata: `contents[i][0]` is the field name. Fields whose names end with `_err` are error-code fields, and their values are extracted from the template. May be null (iteration is safely skipped). |

**External dependencies (framework-level, from external libraries):**
| Name | Type | Business Description |
|------|------|---------------------|
| `JCMConstants.STATUS_INT_KEY` | Constant | Key used to read the status integer from a `CAANMsg` template. |
| `SCControlMapKeys.RETURN_CODE` | Constant | Key for the return code entry in the request parameter's control map. |
| `SCControlMapKeys.RETURN_MESSAGE` | Constant | Key for the localized error message entry in the control map. |
| `JCMAPLConstMgr.getString(...)` | Framework utility | Retrieves a localized message string from the application's constant/message resource bundle. |
| `JKKStringUtil.isNullBlank(...)` | Framework utility | Checks if a string is null or blank (empty/whitespace-only). |

## 4. CRUD Operations / Called Services

The `editErrorInfo` method does not perform direct database operations. It acts as a **data transformer and error propagator**, reading from and writing to in-memory objects and framework message resources.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `template.getInt` | - | - | Reads the error status integer from the first CAANMsg template. |
| R | `JCMAPLConstMgr.getString` | - | - | Looks up a localized error message from the resource bundle using key `RETURN_MESSAGE_XXXX`. |
| R | `param.getControlMapData` | - | - | Reads the existing BP return code from the request parameter's control map. |
| W | `param.setControlMapData` | - | - | Writes the formatted status code and localized message into the control map (only if template status is more severe). |
| R | `param.getData` | - | - | Retrieves the per-field error map (`HashMap<String, String>`) keyed by `fixedText`. |
| R | `template.getString` | - | - | Reads per-field error codes from the template for entries suffixed with `_err`. |
| W | `inMap.put` | - | - | Stores a per-field error code into the in-map for screen-level error display. |

**Note:** The pre-computed evidence table in the pre-computed section reflects method calls found across the class. For this specific method, the operations above represent all actual invocations within `editErrorInfo`.

## 5. Dependency Trace

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

Direct caller: 1 method — `JKKEmgRrksNmUpdCC.callSC()`

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Component:JKKEmgRrksNmUpdCC | `callSC` -> `editErrorInfo` | `isNullBlank` [R - framework], `getString` [R - framework] |

The `callSC` method is the sole caller of `editErrorInfo`. It is invoked after a service component call (`callSC` — "call Service Component") returns, using the method to propagate any error information back to the request parameter so that the calling screen can display appropriate error messages.

## 6. Per-Branch Detail Blocks

**Block 1** — [ASSIGNMENT] (L875)

> Extract the first template message and read its status code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `template = templates[0]` // Extract first template message |
| 2 | SET | `templateStatus = template.getInt(JCMConstants.STATUS_INT_KEY)` // Read error status from template |

**Block 2** — [IF] `(returnCode != 0)` `(L878)`

> If the service component returned a non-zero error code, force the status to 9000 (general error).

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` // Override status to general error [-> 9000] |

**Block 3** — [IF] `(JCMAPLConstMgr.getString(...) == null)` `(L883)`

> Validate that a localized message exists for this status. If no message key exists, reset status to 0 (no error). This prevents screens from displaying undefined error states.

| # | Type | Code |
|---|------|------|
| 1 | SET | `messageKey = "RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)` // Build message lookup key, e.g., "RETURN_MESSAGE_9000" |
| 2 | SET | `templateStatus = 0` // Reset status if message not found [-> 0] |

**Block 4** — [ASSIGNMENT] `(L888)`

> Retrieve the existing BP return code from the control map to enable severity comparison.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = 0` // Initialize |
| 2 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read existing BP return code |

**Block 5** — [IF-ELSE] `(obj == null)` `(L890)`

> Handle the case where no BP return code is set yet.

| # | Type | Code |
|---|------|------|
| 1 | SET (IF-true) | `bpStatus = -1` // No existing return code — treat as no error [-> -1] |
| 2 | SET (IF-false) | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse existing return code |

**Block 6** — [IF] `(bpStatus < templateStatus)` `(L897)`

> **Severity comparison block.** If the template's error status is more severe (higher number) than the current BP status, promote the error to the control map. This ensures the most critical error always surfaces to the user.

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Format as 4-digit string, e.g., "9000" |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Fetch localized error message |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Write return code to control map |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Write localized message to control map |

**Block 7** — [ASSIGNMENT] `(L903)`

> Extract the per-field error map for accumulating field-level error codes.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = (HashMap<String, String>)param.getData(fixedText)` // Retrieve/create the error map |

**Block 8** — [FOR LOOP] `(null != contents && i < contents.length)` `(L905)`

> Iterate over content entries to collect per-field error codes. For each field whose name ends with `_err`, extract the error code from the template and store it in the in-map if non-blank.

| # | Type | Code |
|---|------|------|
| 1 | SET | `i = 0` // Loop initialization |
| 2 | SET | `itemNm = (String)contents[i][0]` // Extract field name |

**Block 8.1** — [IF] `(itemNm.endsWith("_err"))` `(L907)`

> Only process entries explicitly marked as error fields. The `_err` suffix convention distinguishes error code fields from regular field entries.

| # | Type | Code |
|---|------|------|
| 1 | SET | `errCd = (String)template.getString(itemNm)` // Read error code from template |

**Block 8.1.1** — [IF] `(!JKKStringUtil.isNullBlank(errCd))` `(L909)`

> Only store non-blank error codes. Blank error codes indicate no error for that field, so they are skipped.

| # | Type | Code |
|---|------|------|
| 1 | SET | `[-> "_err" suffix convention]` // Fields ending with _err are error code fields |
| 2 | EXEC | `inMap.put(itemNm, errCd)` // Store error code in the in-map for screen rendering |

**Block 9** — [RETURN] `(L917)`

> Return the enriched request parameter object, now containing updated return code, localized error message, and per-field error codes.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return enriched parameter |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `bpStatus` | Variable | BP return code status — the existing error status stored in the request parameter's control map. Lower values indicate less severe conditions; -1 means no prior error is set. |
| `templateStatus` | Variable | Template-derived error status integer extracted from the first CAANMsg template. Used as the authoritative error severity after validation. |
| `formatStatus` | Variable | 4-digit formatted error status string (e.g., "0000", "9000"). Used as the lookup key for localized messages and as the control map value. |
| `inMap` | Variable | Per-field error map (`HashMap<String, String>`) that accumulates field-level error codes for screen rendering. Keyed by field name (e.g., `fieldName_err`), valued by error code. |
| `fixedText` | Parameter | Key used to retrieve the per-field error map from the request parameter. Typically set to a fixed string identifying the error collection scope. |
| `_err` suffix | Convention | Field name suffix convention indicating that the entry's value is an error code rather than a display value. Used to filter content entries during error map population. |
| `CAANMsg` | Class | Framework message class for localized message templates. Provides `getInt()` and `getString()` methods to read message values by key. |
| `IRequestParameterReadWrite` | Interface | Request parameter interface providing control map read/write and data map access methods. Carries all request-scoped data including error info. |
| `SCControlMapKeys` | Constants | Framework constants defining keys for the request parameter control map (e.g., `RETURN_CODE`, `RETURN_MESSAGE`). |
| `JCMConstants` | Constants | Framework constants for message template access (e.g., `STATUS_INT_KEY` for reading the status field from a CAANMsg). |
| `JCMAPLConstMgr` | Utility | Framework utility for retrieving localized strings from the application's resource bundle, keyed by a string identifier. |
| `JKKStringUtil.isNullBlank` | Utility | Framework utility that returns true if a string is null, empty, or contains only whitespace. |
| 9000 | Status Code | General error status — indicates a non-specific service component failure. Forced when `returnCode != 0`. |
| 0 | Status Code | No error — indicates successful execution or no matching error message. Used when the status is reset due to missing localized message. |
| RETURN_MESSAGE_XXXX | Key Pattern | Resource bundle key pattern for localized error messages. `XXXX` is the 4-digit error status code. |
