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

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

## 1. Role

### JKKKikiKaifukuWrisvcCC.editErrorInfoCom()

This method serves as a **shared error information consolidation utility** within the KK Kiki Kaifuku (equipment restoration) business process. Its primary responsibility is to unify and standardize return code and message handling across service interfaces before passing control back to the caller screen. 

It implements a **priority-based status resolution pattern**: it compares the template's status code (the service layer's returned status) against a business-process-level status (bpStatus) stored in the control map. When the template's status is numerically higher, it overrides the bpStatus — ensuring the most severe status wins. This is a common pattern in enterprise Fujitsu CAAC (CAAN) framework applications where multiple layers may set status codes and the system must propagate the most critical one upward.

The method also handles **error message population from templates**. It iterates over a mapping data array to copy any `_err` suffixed template entries (error message text for specific fields) into an in-map, but only if the template contains them and the in-map has not already populated the same key — preventing overwrites of previously set error messages.

Additionally, it implements **graceful constant-based message lookup**. It checks whether a formatted `RETURN_MESSAGE_XXXX` constant exists for the resolved template status in `JCMAPLConstMgr`. If no such constant exists, it resets the status to `0` (success/default), avoiding broken message references.

It is called directly by `callSC()` in the same class, which invokes Service Components. This method ensures that after an SC call returns, the result is normalized into a consistent format — return code, return message, and per-field error messages — before being handed back to the screen/controller layer.

**Design patterns used:**
- **Priority Override**: The highest status code wins (templateStatus vs bpStatus).
- **Defensive Lookup**: Constant lookup is guarded with null check to prevent missing message exceptions.
- **Idempotent Population**: Error messages from templates are only set if the key does not already exist, preserving earlier-set values.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfoCom start"])
    START --> EXTRACT["Extract template and templateStatus"]
    EXTRACT --> CHECK_RETURN{"returnCode != 0"}
    CHECK_RETURN -->|Yes| OVERRIDE["templateStatus = 9000"]
    CHECK_RETURN -->|No| VALIDATE["Validate templateStatus"]
    OVERRIDE --> VALIDATE
    VALIDATE --> CONST_CHECK{"Message constant exists?"}
    CONST_CHECK -->|No| RESET["templateStatus = 0"]
    CONST_CHECK -->|Yes| GET_BP_STATUS["Get bpStatus from control map"]
    RESET --> GET_BP_STATUS
    GET_BP_STATUS --> BP_NULL{"bpStatus is null?"}
    BP_NULL -->|Yes| SET_MINUS1["bpStatus = -1"]
    BP_NULL -->|No| PARSE_STATUS["bpStatus = parseInt(controlMapData)"]
    SET_MINUS1 --> COMPARE{"templateStatus gt bpStatus?"}
    PARSE_STATUS --> COMPARE
    COMPARE -->|Yes| FORMAT["formatStatus = 04d format"]
    FORMAT --> GET_MSG["Get message from constant manager"]
    GET_MSG --> SET_RETURN["setControlMapData RETURN_CODE"]
    SET_RETURN --> SET_MSG["setControlMapData RETURN_MESSAGE"]
    SET_MSG --> INIT_INMAP["inMap = param.getData dataMapKey"]
    COMPARE -->|No| INIT_INMAP
    INIT_INMAP --> LOOP_START["for each mappingData"]
    LOOP_START --> NULL_CHECK{"template has _err key?"}
    NULL_CHECK -->|No| NEXT_ITER["Next iteration"]
    NULL_CHECK -->|Yes| KEY_CHECK{"inMap has _err key?"}
    KEY_CHECK -->|Yes| NEXT_ITER
    KEY_CHECK -->|No| PUT_ERR["inMap put err message"]
    PUT_ERR --> NEXT_ITER
    NEXT_ITER --> LOOP_END{"More iterations?"}
    LOOP_END -->|Yes| LOOP_START
    LOOP_END -->|No| END_RETURN["return param"]
    END_RETURN(["editErrorInfoCom end"])
    CHECK_RETURN --> VALIDATE
```

**Processing Flow Description:**

1. **Template Extraction**: The first element of the `templates` array is extracted, and its status is read from the `STATUS_INT_KEY` field of the `CAANMsg` template. The Japanese comment `本来はサービスインターフェース分の処理が必要` means "Originally, processing for service interfaces is necessary" — indicating this method was intended to have richer service interface handling but currently focuses on error info consolidation.

2. **Return Code Override**: If `returnCode` is non-zero (indicating an error from the service component), the `templateStatus` is unconditionally set to `9000`. This is the framework's standard error status code.

3. **Constant Validation**: The method checks whether a message constant named `RETURN_MESSAGE_` concatenated with the zero-padded `templateStatus` exists in `JCMAPLConstMgr`. If the constant does not exist (returns null), the status is reset to `0` (success). This prevents the system from referencing non-existent error messages.

4. **Business Process Status Comparison**: The bpStatus is retrieved from the control map using `SCControlMapKeys.RETURN_CODE`. If it is null, it defaults to `-1`. Otherwise, it is parsed as an integer. If the `templateStatus` is greater than `bpStatus`, the template's status (and its associated message) is written into the control map — implementing the priority override.

5. **Error Map Population**: The method extracts a HashMap from `param.getData(dataMapKey)` and iterates over `mappingData`. For each row, if the template has a key suffixed with `_err` (indicating an error message for a field), and the inMap does not already contain that key, the error message is copied from the template into the inMap. This ensures error messages are propagated without overwriting existing ones.

6. **Return**: The modified `param` object is returned with updated control map data and populated error map.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object that carries both control map data (return code, return message) and business data (the error map). This is the primary data carrier in the CAAN framework, passed through all layers of the request processing pipeline. |
| 2 | `templates` | `CAANMsg[]` | Array of CAAN message templates used for error message resolution. The first element (`templates[0]`) contains the status code and any per-field error messages with `_err` suffixes. These templates are typically populated by Service Components or screen-level message definitions. |
| 3 | `returnCode` | `int` | The raw return code from a Service Component call. `0` indicates success; any non-zero value indicates an error. When non-zero, the status is overridden to `9000` (the framework's universal error code). |
| 4 | `dataMapKey` | `String` | The key used to retrieve the error data HashMap from the parameter object. This key identifies which data map within `param` contains the per-field error information that will be populated. |
| 5 | `mappingData` | `Object[][]` | A 2D array defining field mappings. Each row contains at least one element — a field name string — which is used to look up error messages in the template (appended with `_err` suffix). The length of this array determines how many error fields are processed. |

**External state / constants referenced:**

| Constant / Key | Resolved Value | Source | Business Meaning |
|---------------|----------------|--------|------------------|
| `JCMConstants.STATUS_INT_KEY` | `"status"` (framework constant) | JCMConstants | The key used to extract the integer status code from a CAANMsg template. |
| `SCControlMapKeys.RETURN_CODE` | `"returnCode"` (framework constant) | SCControlMapKeys | The control map key for storing the business process return status code. |
| `SCControlMapKeys.RETURN_MESSAGE` | `"returnMessage"` (framework constant) | SCControlMapKeys | The control map key for storing the human-readable return message. |
| `JCMAPLConstMgr.getString(...)` | N/A | Framework | Constant manager that looks up `RETURN_MESSAGE_XXXX` formatted keys for human-readable status messages. |
| `9000` | `9000` | Hardcoded | Framework error status code — set when `returnCode` is non-zero. |
| `0` | `0` | Hardcoded | Default/success status — used when a message constant is not found, or as initial bpStatus. |
| `-1` | `-1` | Hardcoded | Fallback bpStatus when the control map returns null for RETURN_CODE. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCMAPLConstMgr.getString` | N/A | N/A | Reads a message constant for a formatted return status key (e.g., `RETURN_MESSAGE_9000`). Framework constant manager lookup. |
| R | `param.getControlMapData` | N/A | N/A | Retrieves the current bpStatus from the control map data store. |
| R | `param.getData` | N/A | N/A | Retrieves the error data HashMap from the parameter's data map by key. |
| R | `template.getInt` | N/A | N/A | Extracts the integer status code from the CAANMsg template. |
| R | `template.isNull` | N/A | N/A | Checks whether a `_err` suffixed key exists in the template (has an error message). |
| R | `template.getString` | N/A | N/A | Reads the error message text for a `_err` suffixed field from the template. |
| W | `param.setControlMapData` | N/A | N/A | Sets the return code and return message in the control map data store (write). |
| W | `inMap.put` | N/A | N/A | Adds an error message entry to the inMap HashMap (write). |

**Note:** This method does not directly call any Service Component (SC) or Business Component System (CBS) layers. It operates purely at the parameter/data manipulation layer, acting as a bridge between the SC response (carried in `templates`) and the screen/controller response (carried in `param`). All operations are in-memory data transformations.

## 5. Dependency Trace

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

**Caller Details:**
- `callSC()` in `JKKKikiKaifukuWrisvcCC` is the direct caller. It invokes this method to consolidate error information returned from Service Components. After an SC call completes, `callSC()` passes the templates (with status codes and error messages), the return code, the data map key, and the mapping data to `editErrorInfoCom` to normalize the response before returning to the caller.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(L554-555)` Extract template and status code

> `本来はサービスインターフェース分の処理が必要` (Translation: "Originally, processing for service interfaces is necessary")

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

**Block 2** — [IF] `(returnCode != 0)` (L557-559)

> If the Service Component returned a non-zero error code, override the template status to the framework's universal error code `9000`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` // Framework error status code |

**Block 3** — [IF] `(L561-565)` Validate message constant exists

> Check whether a `RETURN_MESSAGE_XXXX` constant exists for the current template status. If not found, reset status to `0` (success/default).

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Zero-padded 4-digit status string |
| 2 | EXEC | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Lookup message constant |
| 3 | SET | `templateStatus = 0` // Reset if constant not found |

**Block 4** — [IF/ELSE] `(L567-573)` Get bpStatus from control map

> Retrieve the business process status from the control map. If null, default to -1. Otherwise parse as integer.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = 0` // Initialize bpStatus |
| 2 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read control map |
| 3 | IF (obj == null) | `bpStatus = -1` // Default when control map is null |
| 4 | ELSE | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse existing status |

**Block 5** — [IF] `(templateStatus > bpStatus)` (L575-582)

> Priority override: if the template's status is more severe (higher) than the bpStatus, set the control map with the template's status and its human-readable message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Zero-padded status string |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Human-readable message |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Set return code |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Set return message |

**Block 6** — [SET] `(L584-585)` Initialize inMap

> Extract the error data HashMap from the parameter's data map for population.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = null` // Initialize reference |
| 2 | SET | `inMap = (HashMap<String, String>)param.getData(dataMapKey)` // Cast and extract data map |

**Block 7** — [FOR] `(i = 0; i < mappingData.length; i++)` (L587-596)

> Iterate over each field mapping entry to populate error messages from templates into the inMap.

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

> Check if the template contains an error message for this field (key = field name + "_err" suffix).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `!template.isNull(mappingData[i][0] + "_err")` // Has _err key in template? |

**Block 7.2** — [IF] `(L589)` `!inMap.containsKey(mappingData[i][0] + "_err")`

> Nested check: only populate the error message if it has not already been set in the inMap (idempotent behavior).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `!inMap.containsKey(mappingData[i][0] + "_err")` // Key not yet in map? |
| 2 | EXEC | `inMap.put(mappingData[i][0] + "_err", template.getString(mappingData[i][0] + "_err"))` // Copy error message from template |

**Block 8** — [RETURN] `(L597)`

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return modified parameter with updated control map and error data |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `editErrorInfoCom` | Method | Error information consolidation utility — standardizes error status and messages across service interfaces |
| `KK Kiki Kaifuku` | Business term | Equipment Restoration — a business domain related to telecom equipment restoration/repair processes |
| `JKKKikiKaifukuWrisvcCC` | Class | Equipment Restoration Web Service Common Component — a shared component class for the KK Kiki Kaifuku (equipment restoration) module |
| `CAANMsg` | Acronym | CAAC Message — Fujitsu's CAAC (Common Application Architecture Component) message object used for request/response data exchange. The `CAANMsg` class is the message-oriented data carrier. |
| `IRequestParameterReadWrite` | Interface | Request parameter interface — the CAAN framework interface for bidirectional access to request data, including control map and business data maps. |
| `templateStatus` | Field | Template status code — the status code returned by the Service Component, representing the result of the SC call (e.g., 0 = success, 9000 = error). |
| `bpStatus` | Field | Business Process status code — the status code maintained by the business process layer for tracking processing state. Used in priority comparison with templateStatus. |
| `returnCode` | Field | Service Component return code — raw integer returned by the SC. Non-zero indicates an error occurred at the SC level. |
| `dataMapKey` | Field | Data map key — the identifier used to retrieve the error data HashMap from the parameter object's data store. |
| `mappingData` | Field | Field mapping data — a 2D array defining which fields need error message propagation. Each row's first element is a field name that gets `_err` appended for error message lookup. |
| `inMap` | Field | Error data HashMap — a map storing field-to-error-message pairs. Keys are field names with `_err` suffix; values are the human-readable error message strings. |
| `STATUS_INT_KEY` | Constant | `"status"` — the key used to extract the integer status code from a CAANMsg template. Defined in `JCMConstants`. |
| `SCControlMapKeys.RETURN_CODE` | Constant | `"returnCode"` — the control map key for storing the return status code. |
| `SCControlMapKeys.RETURN_MESSAGE` | Constant | `"returnMessage"` — the control map key for storing the human-readable return message. |
| `JCMAPLConstMgr` | Class | CAAN Message Platform Constant Manager — a framework class that provides lookup of application-specific message constants by key name. |
| `RETURN_MESSAGE_XXXX` | Constant pattern | Message constant naming convention — message keys formatted as `RETURN_MESSAGE_` followed by a zero-padded 4-digit status code (e.g., `RETURN_MESSAGE_9000`). Each maps to a human-readable error message string. |
| `9000` | Constant | Framework error code — the universal error status code in the CAAC framework, used to indicate a generic error condition. |
| `_err` | Suffix | Error field suffix — appended to field names to form keys for error message lookup in templates and maps (e.g., `address_err` for the error message of the address field). |
| `callSC` | Method | Service Component caller — the method in the same class that invokes this method to consolidate error info after an SC call completes. |
