---
# Business Logic — JKKCourseRkRtrNsIdChgCC.editErrorInfoCom() [61 LOC]

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

## 1. Role

### JKKCourseRkRtrNsIdChgCC.editErrorInfoCom()

This method serves as a **standardized error-message aggregation and status-resolution utility** used during course-change operations (specifically, service contract line-item number change processing, as indicated by the class name `JKKCourseRkRtrNsIdChg` — "RkRtrNsIdChg" meaning "Renkoku Sūji Henk" / Serial Number Change). It resolves the final HTTP/business status code and corresponding error message that will be returned to the caller, by comparing the service-template status against the business-process status and keeping whichever is more severe.

It performs **two distinct responsibilities** in sequence:

1. **Status resolution and message propagation**: If the parent caller supplied a non-zero `returnCode`, the template status is overridden to `9000` (indicating a generic error). The method then validates whether a localized message constant exists for the resolved status (`RETURN_MESSAGE_XXXX`). If not, the status resets to `0` (success). If the resolved template status is more severe (higher numeric value) than the business-process return code stored in `param`, the template's status and localized message overwrite the `param` control map data.

2. **Error message field population**: It iterates through the `mappingData` array and, for every entry whose first column starts with the prefix `key_`, copies any associated error message field (the corresponding `_err` suffix key) from the message template into the in-map business data. This is a **non-destructive merge** — it only populates `_err` fields that are missing from the in-map, preserving any previously-set values.

Design pattern: **Delegated status-resolution with conditional overlay** (acts as a shared utility called by the course-change business flow to normalize error handling). It implements the **Template Method** pattern by using `CAANMsg[] templates` as a message template source.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfoCom(params)"])
    T0["Get templates[0]"]
    T1["Read templateStatus from template"]
    RC["returnCode != 0"]
    RC_YES["Set templateStatus = 9000"]
    RC_NO["No change to templateStatus"]
    VM["Validate RETURN_MESSAGE constant exists"]
    VM_NO["Set templateStatus = 0"]
    VM_YES["templateStatus unchanged"]
    BP["Read bpStatus from param control map"]
    COMP["templateStatus > bpStatus"]
    COMP_YES["Copy template status to param"]
    COMP_NO["Keep existing bpStatus"]
    IN["Read inMap from param.getData(dataMapKey)"]
    LOOP["for i = 0 to mappingData.length"]
    CHECK["starts with 'key_'"]
    ISE["template has _err message"]
    ICK["inMap contains _err key"]
    PUT["inMap.put(key_err, template.getString)"]
    NEXT["i++"]
    LOOP_END["End loop"]
    RETURN(["return param"])

    START --> T0 --> T1 --> RC
    RC -->|Yes| RC_YES
    RC -->|No| RC_NO
    RC_YES --> VM
    RC_NO --> VM
    VM -->|Not found| VM_NO
    VM -->|Found| VM_YES
    VM_NO --> BP
    VM_YES --> BP
    BP --> COMP
    COMP -->|Yes| COMP_YES
    COMP -->|No| COMP_NO
    COMP_YES --> IN
    COMP_NO --> IN
    IN --> LOOP --> CHECK
    CHECK -->|Yes| ISE
    CHECK -->|No| NEXT
    ISE -->|Yes| ICK
    ICK -->|No| PUT
    ICK -->|Yes| NEXT
    PUT --> NEXT
    NEXT --> LOOP
    LOOP_END --> RETURN
```

**Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `JCMConstants.STATUS_INT_KEY` | `"STATUS"` (standard CAAN framework key) | Key to extract the numeric status code from the template message |
| `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` | Runtime-lookup of localized error message string | Maps status code like `"9000"` → error message via externalized resource bundle |
| `SCControlMapKeys.RETURN_CODE` | `"RETURN_CODE"` (standard control map key) | Key under which the business-process return code is stored in param's control data |
| `SCControlMapKeys.RETURN_MESSAGE` | `"RETURN_MESSAGE"` (standard control map key) | Key under which the localized error message is stored in param's control data |
| `mappingData[i][0].startsWith("key_")` | Prefix `"key_"` | Identifies mapping entries whose error message fields use the `<key>_err` naming convention |

**Conditional branch meanings:**
- `returnCode != 0`: A non-zero `returnCode` from the parent caller signals that the service component returned an error, forcing the status to `9000` (generic error).
- `RETURN_MESSAGE_XXXX == null`: If no localized message constant exists for the resolved status, the method defaults `templateStatus` back to `0` (success), effectively suppressing invalid status codes.
- `templateStatus > bpStatus`: The template's status is more severe than what the business process previously set — the template overrides the param's status and message.
- `mappingData[i][0].startsWith("key_")`: Only mapping entries with the `key_` prefix carry error message fields; others (e.g., data column mappings) are skipped.
- `!template.isNull(..._err)`: The template has an error message for this field.
- `!inMap.containsKey(..._err)`: The in-map does not already contain this error message — a non-destructive merge.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The business-process request parameter object that carries control data (return code, return message) and business data (in-map). It is both read and written — the method reads the current business-process status and error messages, then overwrites them with the resolved template values. |
| 2 | `templates` | `CAANMsg[]` | Array of message templates populated by the service component layer. `templates[0]` is used as the primary template containing the status code (`STATUS_INT_KEY`) and per-field error message strings (e.g., `key_fieldname_err`). |
| 3 | `returnCode` | `int` | The raw return code from the service component invocation. `0` means success; any non-zero value signals an error, triggering status override to `9000`. |
| 4 | `dataMapKey` | `String` | The key used to retrieve the business-data HashMap from `param`. This HashMap (`inMap`) holds field-level data and error messages for the current screen/business-process context. |
| 5 | `mappingData` | `Object[][]` | A 2D array defining field mappings between the template and the in-map. Each row is `[fieldName, ...]` where `fieldName` may be a regular data key or an error field (prefixed with `key_`). Used to propagate per-field error messages from the template into the in-map. |

**External / Instance state used:** None. This method is fully stateless — all data flows through parameters and return value.

## 4. CRUD Operations / Called Services

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

No direct service-component or database calls are made by this method. It operates entirely in-memory on `param`, `templates`, and `mappingData` objects.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCMConstants.STATUS_INT_KEY` | - | - | Static constant lookup for the status key name |
| R | `JCMAPLConstMgr.getString` | - | - | Read localized message string from resource bundle (externalized constants) |
| R | `param.getControlMapData(SCControlMapKeys.RETURN_CODE)` | - | - | Read the business-process return code from param's control data |
| R | `param.getData(dataMapKey)` | - | - | Read the in-map HashMap from param's business data |
| W | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, ...)` | - | - | Write the resolved status code to param's control data |
| W | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, ...)` | - | - | Write the resolved localized message to param's control data |
| R | `template.isNull(..._err)` | - | - | Check whether the template message has a non-null value for the error key |
| R | `template.getString(..._err)` | - | - | Read the localized error message string from the template |
| R/W | `inMap.put(key_err, value)` | - | - | Write the error message into the in-map (non-destructive merge) |
| R | `inMap.containsKey(key_err)` | - | - | Check whether the in-map already contains the error key |

**Classification summary:** This method performs **zero database or SC-level CRUD operations**. All operations are in-memory reads and writes to parameter objects (`IRequestParameterReadWrite`, `CAANMsg`, `HashMap`). The only external interaction is a read to the localized message resource bundle via `JCMAPLConstMgr.getString()`.

## 5. Dependency Trace

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

**Direct callers:** 1 method

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CC: `JKKCourseRkRtrNsIdChgCC` | `callSC()` -> `editErrorInfoCom(param, templates, returnCode, dataMapKey, mappingData)` | No database/SC endpoint — in-memory only |

**Call chain detail:** The `callSC()` method (also in `JKKCourseRkRtrNsIdChgCC`) invokes `editErrorInfoCom()` after performing a service-component call. It passes the request parameter, message templates returned by the SC, the SC's return code, a data map key, and field mapping metadata. This method then normalizes the error status and populates field-level error messages before `callSC()` returns to its own caller.

**Terminal operations from this method:** `getString` [R], `isNull` [R], `getControlMapData` [R], `getData` [R], `setControlMapData` [W], `put` [W], `containsKey` [R]

## 6. Per-Branch Detail Blocks

**Block 1** — [ASSIGNMENT] (L667-668)

> Extract the primary template and its status code from the template array.

| # | Type | Code |
|---|------|------|
| 1 | SET | `template = templates[0]` |
| 2 | SET | `templateStatus = template.getInt(JCMConstants.STATUS_INT_KEY)` |

**Block 2** — [IF] `returnCode != 0` (L670-672)

> If the service component returned a non-zero error code, override the template status to `9000` (generic error status).
> Japanese comment: 「本来はサービスインターフェース分の処理が必要」(Originally, processing per service interface would be necessary — indicating this is a simplified override).

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` [Generic error status] |

**Block 3** — [IF] `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus) == null` (L674-676)

> Validate that a localized message constant exists for the current status. If the constant is null (message not defined), reset `templateStatus` to `0` (success), effectively suppressing an invalid status code.
> Japanese comment: 「本来はサービスインターフェース分の処理が必要」(Originally, per-service-interface processing would be necessary).

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` → `"9000"` or `"0000"` |
| 2 | EXEC | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` |
| 3 | SET | `templateStatus = 0` [If constant is null] |

**Block 4** — [ASSIGNMENT] (L678-685)

> Read the business-process return code (`bpStatus`) from `param`'s control map data. If no return code is set (null), default `bpStatus` to `-1`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = 0` [Initial value] |
| 2 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` |
| 3 | IF | `obj == null` |
| 3.1 | SET | `bpStatus = -1` [No return code set — treat as lowest severity] |
| 3.2 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(...))` [Parse the stored return code] |

**Block 5** — [IF] `templateStatus > bpStatus` (L687-693)

> Compare the resolved template status against the business-process status. If the template's status is more severe (higher numeric value), overwrite `param`'s control map data with the template's status code and localized error message. This implements a "most-severe-wins" strategy.
> Japanese comment: 「BPにサービスコンポネントのステータスを設定する」(Set the service-component status on the business process).

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` → e.g., `"9000"` |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` |
| 3 | CALL | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` |
| 4 | CALL | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` |

**Block 6** — [ASSIGNMENT] (L695-697)

> Initialize the in-map HashMap by retrieving business data from `param` using the `dataMapKey`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = null` |
| 2 | SET | `inMap = (HashMap<String, String>)param.getData(dataMapKey)` [Cast to HashMap] |

**Block 7** — [FOR LOOP] `i = 0; i < mappingData.length` (L699-713)

> Iterate through the mapping data array to propagate per-field error messages from the template into the in-map. Only entries whose field name starts with `key_` are processed — these represent error-message field mappings. For each such entry, if the template has an error message (`_err` suffix) and the in-map does not already contain it, copy the message from the template into the in-map. This is a non-destructive merge that preserves any pre-existing error messages.
> Japanese comment: 「ユーザーデータ情報」(User data information).

| # | Type | Code |
|---|------|------|
| 1 | SET | `i = 0` [Loop initializer] |
| 2 | IF | `((String)mappingData[i][0]).startsWith("key_")` [Field is an error-mapping entry] |
| 2.1 | IF | `!template.isNull(mappingData[i][0] + "_err")` [Template has error message for this field] |
| 2.1.1 | IF | `!inMap.containsKey(mappingData[i][0] + "_err")` [In-map does not already have this error key] |
| 2.1.1.1 | CALL | `inMap.put(mappingData[i][0] + "_err", template.getString(mappingData[i][0] + "_err"))` [Copy error message from template to in-map] |
| 3 | SET | `i++` [Loop increment] |

**Block 8** — [RETURN] (L715)

> Return the modified `param` object with updated control map data and in-map error messages.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `editErrorInfoCom` | Method | Edit Error Information Common — shared utility for standardizing error message propagation and status resolution |
| `JKKCourseRkRtrNsIdChg` | Class | Course Serial Number Change — business process for changing service contract line-item serial numbers |
| `RkRtrNsIdChg` | Abbreviation | Renkoku Sūji Henk (連番数字変更) — Serial Number Change; the core business operation for renumbering service items |
| `param` | Parameter | IRequestParameterReadWrite — the request/response parameter object that flows through the entire business-process pipeline |
| `templates` | Parameter | CAANMsg[] — message templates returned by the service component, containing status codes and localized field-level error messages |
| `returnCode` | Parameter | int — raw return code from the service component invocation; 0 = success, non-zero = error |
| `dataMapKey` | Parameter | String — the key to retrieve the business-data HashMap from param |
| `mappingData` | Parameter | Object[][] — field-mapping metadata defining which template fields map to in-map entries and their error message suffixes |
| `templateStatus` | Variable | Resolved status code from the template; `9000` = generic error, `0` = success |
| `bpStatus` | Variable | Business-process status code retrieved from param's control map; tracks the severity level of the business process |
| `inMap` | Variable | HashMap<String, String> — in-memory business data map holding field-level values and error messages |
| `FORMAT_STATUS` | Constant pattern | `"RETURN_MESSAGE_" + "XXXX"` — externalized resource key for localized error messages |
| `9000` | Status code | Generic error status — used when the service component returns a non-zero error code |
| `STATUS_INT_KEY` | Constant | `"STATUS"` — key to extract the numeric status code from CAANMsg templates |
| `RETURN_CODE` | Constant | `"RETURN_CODE"` — control map key for the business-process return code |
| `RETURN_MESSAGE` | Constant | `"RETURN_MESSAGE"` — control map key for the localized error message text |
| `key_` | Prefix | Field name prefix in mappingData indicating error-message mapping entries; corresponding error field uses `key_..._err` format |
| `_err` | Suffix | Error message field suffix appended to the base field name in template keys (e.g., `key_fieldname_err`) |
| `JCMConstants` | Class | Fujitsu Common Message Constants — framework class providing standard constant keys for message handling |
| `JCMAPLConstMgr` | Class | Fujitsu Common Message Application Constants Manager — framework class for accessing externalized localized strings |
| `SCControlMapKeys` | Class | Service Component Control Map Keys — framework class defining standard control data keys for param |
| `CAANMsg` | Class | CAAN Message — Fujitsu CAAN framework message object containing typed getters for string, int, and other data types |
| `IRequestParameterReadWrite` | Interface | Request parameter read-write interface — the standard request/response parameter contract in the Fujitsu framework |
| `RequestParameterException` | Exception | Exception thrown when parameter operations fail (e.g., casting errors, missing keys) |
