# Business Logic — JKKKikiIchiranKkKaifukuCC.editErrorInfoCom() [58 LOC]

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

## 1. Role

### JKKKikiIchiranKkKaifukuCC.editErrorInfoCom()

This method is a **shared error-information assembly utility** used across the KKKiki (Equipment Specification / Equipment Details) screen component cluster. Its core business purpose is to determine the appropriate HTTP-like status code and error message to surface to the end user when a service order or equipment detail inquiry encounters an error, by **comparing the status from a called service component (SC) template against the status already set by the business process (BP)**, and retaining the more severe (higher-numbered) status.

The method implements a **priority-fallback pattern**: if the raw `returnCode` parameter is non-zero (indicating an error occurred upstream), it overrides the template status to `9000` (a generic error indicator). It then validates that a user-facing message exists for that status code by querying `JCMAPLConstMgr` with the key `RETURN_MESSAGE_<status>`; if no message is registered, it falls back to status `0` (normal/ok). The method then reads the BP's own return code from the control map, and if the template's computed status is strictly higher (more severe), it overwrites the control map with the template status code and its associated message.

Finally, it iterates over a `mappingData` array that describes which fields carry error messages. For each mapping entry, if the template contains a non-null error message for the field (named `<field>_err`), and the data map does not already contain that error key, the method populates the error message from the template into the data map. This enables per-field error reporting on the screen.

Its role in the larger system is as a **cross-screen utility**: similar `editErrorInfoCom` overloads exist in dozens of CC classes (e.g., `JKKSokoListCC`, `JKKWribAutoAddBatchCC`, `JCHSeikyDtailPayKigenCC`, `JKKGetAcasidCC`, `JKKSeiKeiKapListCC`, `JFUWebMskmNyoListCC`, `JCNKotekmbnsInfoAddCC`, `JCHShunoKknInfoStkuCC`, `JKKKojihiKapKeiOperateBfCC`), all following the same priority-fallback pattern for error message assembly. The JKKKikiIchiranKkKaifukuCC variant is specifically invoked from `callSC()` (within the same class) and from `JKKSokoListCC.callSC()` when processing equipment list inquiry screen responses.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfoCom(params)"])
    START --> EXTRACT["Extract templates[0] and
get templateStatus via getInt(STATUS_INT_KEY)"]
    EXTRACT --> CHECK_RC{"returnCode != 0?"}
    CHECK_RC --> YES["Yes — error in upstream call"]
    YES --> SET_9000["Set templateStatus = 9000
(override with generic error status)"]
    CHECK_RC --> NO["No — returnCode is 0
(no upstream error)"]
    NO --> CHECK_MSG
    SET_9000 --> CHECK_MSG{"RETURN_MESSAGE_<status>
exists in constants?"}
    CHECK_MSG --> EXISTS["Yes — valid message registered"]
    EXISTS --> READ_BP
    CHECK_MSG --> NOT_EXISTS["No — message key not found"]
    NOT_EXISTS --> RESET_0["Set templateStatus = 0
(fallback to normal/ok status)"]
    RESET_0 --> READ_BP
    READ_BP["Read bpStatus from control map
using SCControlMapKeys.RETURN_CODE"]
    READ_BP --> CHECK_BP_OBJ{"Is control map value null?"}
    CHECK_BP_OBJ --> NULL["Yes — no BP status set"]
    NULL --> SET_BP_MINUS1["Set bpStatus = -1"]
    CHECK_BP_OBJ --> NOT_NULL["No — BP status exists"]
    NOT_NULL --> PARSE_BP["Parse bpStatus from String
via Integer.parseInt()"]
    SET_BP_MINUS1 --> COMPARE
    PARSE_BP --> COMPARE{"templateStatus > bpStatus?"}
    COMPARE --> YES_SEVERE["Yes — template status is more severe"]
    YES_SEVERE --> FORMAT_STATUS["Format status as 4-digit string
String.format('%1$04d', templateStatus)"]
    FORMAT_STATUS --> LOOKUP_MSG["Lookup message via
JCMAPLConstMgr.getString('RETURN_MESSAGE_' + formatStatus)"]
    LOOKUP_MSG --> SET_CTRL1["Set control map RETURN_CODE
to formatStatus"]
    SET_CTRL1 --> SET_CTRL2["Set control map RETURN_MESSAGE
to resolved message"]
    SET_CTRL2 --> GET_DATA
    COMPARE --> NO_SAME["No — BP status is equal or more severe"]
    NO_SAME --> GET_DATA
    GET_DATA["Retrieve inMap from
param.getData(dataMapKey)"]
    GET_DATA --> LOOP_INIT["Initialize loop: i = 0"]
    LOOP_INIT --> LOOP_CHECK{"i < mappingData.length?"}
    LOOP_CHECK --> YES_ITER["Yes"]
    YES_ITER --> CHECK_ERR1{"Is template.get(mappingData[i][0] + '_err')
not null?"}
    CHECK_ERR1 --> HAS_ERR["Yes — error msg exists in template"]
    HAS_ERR --> CHECK_MAP1{"Does inMap contain
mappingData[i][0] + '_err'?"}
    CHECK_MAP1 --> EXISTS_MAP["Yes — already set"]
    EXISTS_MAP --> INCREMENT
    CHECK_MAP1 --> NOT_EXISTS_MAP["No — not yet set"]
    NOT_EXISTS_MAP --> PUT_ERR["Put template.getString(mappingData[i][0] + '_err')
into inMap.put(key, value)"]
    PUT_ERR --> INCREMENT
    CHECK_ERR1 --> NO_ERR["No error msg in template"]
    NO_ERR --> INCREMENT
    INCREMENT["Increment i"]
    INCREMENT --> LOOP_CHECK
    LOOP_CHECK --> NO_ITER["No — loop finished"]
    NO_ITER --> RETURN["Return param"]
    RETURN --> END(["End"])
```

**Processing Summary (in Japanese comment context):**

The Japanese comment `本来はサービスインターフェース分の処理が必要` translates to "Originally, processing for the service interface portion is required." This indicates that the method is a **simplified/stub variant** — the full implementation would handle per-service-interface logic, but this version provides a generic fallback for the equipment detail inquiry screen.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying the entire screen state: control map data (status code, return message) and application data map. This object is both read (to retrieve current BP status and the error data map) and written (to update the control map and populate error fields). |
| 2 | `templates` | `CAANMsg[]` | An array of message templates received from a called service component (SC). `templates[0]` always holds the primary response message including the status code (`JCMConstants.STATUS_INT_KEY`) and any per-field error messages (`<field>_err` patterns). In Japanese business terms, this carries the service interface response messages (サービスインターフェースからの応答メッセージ). |
| 3 | `returnCode` | `int` | An explicit error code returned by the upstream caller (e.g., `callSC()`). When non-zero, it signals that an error occurred during the service call, triggering an override of the template status to `9000` (a generic error status). A value of `0` indicates a successful/normal call. |
| 4 | `dataMapKey` | `String` | The key used to retrieve the application data map from `param` via `param.getData(dataMapKey)`. This map holds field-level data for the screen, and this method populates error messages into it. The actual value varies by caller — commonly a fixed text key like `"fixedText"` or a dynamic data map key. |
| 5 | `mappingData` | `Object[][]` | A 2D array describing which screen fields should carry error messages. Each row is `[fieldName, ...]` where `mappingData[i][0]` is the field name prefix. The method appends `"_err"` to each field name to construct error message keys (e.g., `addr1_err`, `phone_err`). This mapping defines the error-reporting schema for the screen. |

**External state / constants used:**

| Name | Type | Business Description |
|------|------|---------------------|
| `JCMConstants.STATUS_INT_KEY` | Framework constant | The key used to retrieve the status code as an integer from a `CAANMsg` template. Represents the service response status. |
| `SCControlMapKeys.RETURN_CODE` | Framework constant | The control map key storing the business process return code. Used to read/write the BP's own status code. |
| `SCControlMapKeys.RETURN_MESSAGE` | Framework constant | The control map key storing the human-readable return/error message corresponding to the return code. |
| `JCMAPLConstMgr.getString(key)` | Framework method | A constant/message lookup manager. Returns `null` if the message key does not exist. Used here to validate whether a `RETURN_MESSAGE_<status>` message is registered. |

## 4. CRUD Operations / Called Services

This method performs **no direct database or service component calls**. It operates purely on in-memory objects (`param`, `templates`, `inMap`, `mappingData`). All operations are reads/writes to local data structures and framework-level constant lookups.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCMConstants.STATUS_INT_KEY` | (Framework) | - | Reads the status key constant from the `CAANMsg` template object |
| R | `template.getInt(...)` | (Framework) | - | Reads the integer status value from the CAANMsg template |
| R | `JCMAPLConstMgr.getString(...)` | (Framework) | - | Constant/message lookup to check if `RETURN_MESSAGE_<status>` is registered |
| R | `param.getControlMapData(...)` | (Framework) | - | Reads the BP's current return code from the control map |
| W | `param.setControlMapData(...)` | (Framework) | - | Writes the resolved status code and message to the control map |
| R | `param.getData(dataMapKey)` | (Framework) | - | Retrieves the application data map from param |
| R/W | `inMap.put(...)` | (In-memory) | - | Populates per-field error messages into the data map |

**Note:** This method delegates **no calls to SC (Service Component) classes** or CBS (CBS Service) entities. The actual service calls that populate the `templates` array and set the initial `returnCode` are made by the caller (`callSC()` in the same class, or equivalent callers in other CC classes). The method's terminal operations are all framework-level reads and in-memory writes.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 25 methods.
Terminal operations from this method: `getInt` [R], `getString` [R (framework constant)], `getControlMapData` [R], `setControlMapData` [W], `getData` [R], `inMap.put` [W], `template.getString` [R].

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CC:JKKKikiIchiranKkKaifukuCC | `callSC()` -> `editErrorInfoCom(param, templates, returnCode, fixedText)` | Framework constant lookups [R], in-memory put [W] |
| 2 | CC:JKKKikiIchiranKkKaifukuCC | `callSC()` -> `editErrorInfoCom(param, templates, (Integer)return_code, dataMapKey, mappingData)` | Framework constant lookups [R], in-memory put [W] |
| 3 | CC:JKKSokoListCC | `callSC()` -> `editErrorInfoCom(param, templates, returnCode, fixedText)` | Framework constant lookups [R], in-memory put [W] |
| 4 | CC:JKKSokoListCC | `callSC()` -> `editErrorInfoCom(param, templates, (Integer)return_code, dataMapKey, mappingData)` | Framework constant lookups [R], in-memory put [W] |

**Summary:** This method is called exclusively from internal CC (Common Component) methods, primarily from `callSC()` methods that execute service component calls and then assemble error information from the returned templates. It is **not** directly invoked by any screen (KKSV*) or batch entry point — callers always go through an intermediate CC method first.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(Extract template and status)` (L539–L541)

Extracts the primary message template from the SC response and reads the initial status code.

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

---

**Block 2** — [IF] `(returnCode != 0)` (L543–L545)

If the upstream caller passed a non-zero return code, override the template status to `9000` (a generic error status code). This ensures that any detected error takes precedence.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `returnCode != 0` — An error was reported by the upstream caller |
| 2 | SET | `templateStatus = 9000` [-> Error override: generic error status when upstream reports error] |

---

**Block 3** — [IF] `(JCMAPLConstMgr.getString(...) == null)` (L547–L549)

Validates that a user-facing message is registered for the computed status code. The message key format is `RETURN_MESSAGE_<0-padded-4-digit-status>`. If no message exists for this status, fall back to status `0` (normal/ok), effectively suppressing the error display.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)) == null` — Check if a message is registered for this status |
| 2 | SET | `templateStatus = 0` [-> Status reset to 0: fallback to normal/ok when message key is not registered] |

---

**Block 4** — [SET] `(Initialize bpStatus)` (L551–L560)

Reads the business process's own return code from the control map. If the control map does not yet have a value for `RETURN_CODE`, defaults `bpStatus` to `-1` (meaning no BP status is set, so the template status will always win the comparison). Otherwise, parses the stored string value as an integer.

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

**Block 4.1** — [IF] `(obj == null)` (L553–L555)

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `obj == null` — Control map has no RETURN_CODE set by BP |
| 2 | SET | `bpStatus = -1` [-> No BP status: template status will always take precedence] |

**Block 4.2** — [ELSE] (L557–L559)

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

---

**Block 5** — [IF] `(templateStatus > bpStatus)` (L562–L569)

Compares the computed template status against the BP's own status. If the template's status is strictly higher (more severe), overwrite the control map with the template's status and message. This implements the priority-fallback: when the service component detects an error worse than what the BP already recorded, the service component's message wins.

> `BPにサービスコンポーネントのステータスを設定する。` — "Set the service component's status on the BP." (L563)

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `templateStatus > bpStatus` — Template status is more severe than BP's status |
| 2 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Format as 4-digit zero-padded string (e.g., "9000") |
| 3 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Lookup user-facing message |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Write resolved status to control map |
| 5 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Write resolved message to control map |

---

**Block 6** — [SET] `(Initialize inMap)` (L571–L573)

Retrieves the application data map from the param object. The Japanese comment `ユーザーデータ情報` translates to "User data information." This map holds the field-level data for the screen.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = null` // Initialize |
| 2 | SET | `inMap = (HashMap<String, String>)param.getData(dataMapKey)` // Retrieve user data map by key |

---

**Block 7** — [FOR] `(loop over mappingData)` (L575–L585)

Iterates over the `mappingData` array. For each mapping row, checks if the template has a non-null error message for the field. If so, and the data map doesn't already contain an error message for that field, writes the error message from the template into the data map. This implements per-field error message propagation.

| # | Type | Code |
|---|------|------|
| 1 | SET | `i = 0` // Loop initialization |
| 2 | CONDITION | `i < mappingData.length` — Continue while there are mapping entries |
| 3 | INCREMENT | `i++` — Advance to next mapping row |

**Block 7.1** — [IF] `(!template.isNull(mappingData[i][0] + "_err"))` (L577–L584)

Checks whether the template contains a non-null error message for the current field. The error message key is constructed by appending `"_err"` to the field name.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `!template.isNull(mappingData[i][0] + "_err")` — Template has an error message for this field |

**Block 7.1.1** — [IF] `(!inMap.containsKey(mappingData[i][0] + "_err"))` (L579–L582)

If the data map does not already contain an error entry for this field, populate it from the template. This is a **copy-on-miss** pattern: the method only writes the error if it hasn't been set before, preserving any previously-set error message.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `!inMap.containsKey(mappingData[i][0] + "_err")` — Data map does not yet have error for this field |
| 2 | EXEC | `inMap.put(mappingData[i][0] + "_err", template.getString(mappingData[i][0] + "_err"))` // Copy error message from template to data map |

---

**Block 8** — [RETURN] `(Return param)` (L586)

Returns the modified `param` object. The control map and data map have been updated with the resolved status and error messages.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` — Return the enriched param object with updated control map and data map |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `editErrorInfoCom` | Method | Error Information Assembly — a shared utility method that resolves and populates error status codes and messages for display on inquiry screens |
| `CAANMsg` | Class | Fujitsu message wrapper class used in the JCA (Java Component Architecture) framework for passing typed data between components. Contains `getInt()`, `getString()`, `isNull()` methods for typed data access. |
| `IRequestParameterReadWrite` | Interface | The request parameter object interface supporting both read and write operations on screen state data (control map and application data map). |
| `SCControlMapKeys` | Class | Framework constant class defining keys for the control map, including `RETURN_CODE` and `RETURN_MESSAGE`. The control map holds screen-level metadata (status, messages). |
| `JCMConstants` | Class | Fujitsu Common Framework constant class defining standard keys like `STATUS_INT_KEY` for accessing status codes in `CAANMsg` objects. |
| `JCMAPLConstMgr` | Class | Fujitsu Common Framework constant/message lookup manager. `getString(key)` returns the registered message for a key, or `null` if the key is not registered. |
| `templateStatus` | Field | The status code extracted from the SC response template, representing the service component's assessment of the operation outcome. |
| `bpStatus` | Field | The business process's own return code, stored in the control map. Represents the BP's self-assessed status, potentially set by prior processing logic. |
| `RETURN_MESSAGE_<N>` | Constant key pattern | A message registration key format where `<N>` is a 4-digit zero-padded status code (e.g., `RETURN_MESSAGE_0000`, `RETURN_MESSAGE_9000`). Maps status codes to user-facing message strings. |
| `mappingData` | Parameter | A 2D array (`Object[][]`) mapping field names to metadata. Each row's first element (`mappingData[i][0]`) is a field name prefix. Used to define which fields should carry error messages. |
| `_err` | Naming convention | Suffix appended to field names to create error message keys (e.g., `field1_err`, `address_err`). Indicates a validation or service error message for that field. |
| `9000` | Status code | Generic error status code used as a fallback when an upstream return code is non-zero but the specific status message is not registered. |
| `0` | Status code | Normal/ok status code used as fallback when no message is registered for the computed status. |
| `-1` | Status sentinel | Sentinel value for `bpStatus` indicating the control map has no RETURN_CODE set yet, ensuring any positive template status takes precedence. |
| `callSC()` | Method | The calling method in `JKKKikiIchiranKkKaifukuCC` that invokes a service component and then passes the result (templates, returnCode) to `editErrorInfoCom`. |
| `パラメータ` (param) | Field | Request parameter — carries the entire screen context including control map (status, messages) and application data map (field values). |
| テンプレート (template) | Field | Message template — the CAANMsg object containing the SC response with status code and error messages. |
| サービスインターフェース (service interface) | Concept | The service component interface that processes business logic and returns results via CAANMsg templates. |
