# Business Logic — JKKOpsvkeiTelIktAddCC.editErrorInfoCom() [59 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKOpsvkeiTelIktAddCC` |
| Layer | CC/Common Component (Business Process Common utility, part of the CC tier) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKOpsvkeiTelIktAddCC.editErrorInfoCom()

This method acts as a **centralized error/info message resolution and merging utility** used across multiple business process (BP) screens in the K-Opticom telecom customer management system. Its primary role is to take a CAANMsg template (produced by a CBS layer — typically the service status response from `ECK0011B002CBS`), resolve the human-readable return message via the JCMAPL constant manager, compare service template status codes against the existing BP status, and merge any error fields (`_err`-suffixed keys) from the template into the caller's data map.

The method follows a **delegation pattern** — it does not perform business operations itself but instead coordinates the transfer of status codes and error messages from the CBS response layer into the screen's control map and data map. This ensures that when a CBS call fails, the screen consistently surfaces the correct status code and corresponding error message to the end user.

The conditional branches handle: (1) error override — if `returnCode` is non-zero (indicating an exception or error from the caller), the template status is forcibly set to `9000` (a generic error status). (2) Message validation — if the constant system has no message defined for the resolved status code, the status is reset to `0` (no error/info). (3) Status priority — only the higher status code (template vs. BP) is retained, preventing a lower-priority status from overwriting a higher-priority one. (4) Error field merging — all `_err`-suffixed keys from the template are copied into the in-map, allowing the screen to display field-level validation errors.

This method is a shared utility called by CBS mapper classes (e.g., `KKSV0781_KKSV0781OP_EKK0081B010BSMapper`, `WCSV0018_WCSV0018OP_EWC0101B010BSMapper`) at the end of service invocation flows, making it a critical bridge between the CBS error layer and the presentation layer.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfoCom params"])
    START --> S1["template = templates[0]"]
    S1 --> S2["templateStatus = template.getInt ECK0011B002CBSMsg.STATUS"]
    S2 --> COND1{returnCode != 0?}
    COND1 -->|Yes| S3["templateStatus = 9000"]
    COND1 -->|No| S4["templateStatus unchanged"]
    S3 --> S5["JCMAPLConstMgr.getString RETURN_MESSAGE_ templateStatus"]
    S4 --> S5
    S5 --> COND2{Message null?}
    COND2 -->|Yes| S6["templateStatus = 0"]
    COND2 -->|No| S7["templateStatus unchanged"]
    S6 --> S8["bpStatus = -1 if returnCode key null else Integer.parseInt"]
    S7 --> S8
    S8 --> COND3{templateStatus gt bpStatus?}
    COND3 -->|Yes| S9["Set RETURN_CODE formatStatus and RETURN_MESSAGE on param"]
    COND3 -->|No| S10["Skip update"]
    S9 --> S11["inMap = param.getData dataMapKey"]
    S10 --> S11
    S11 --> S12["it = template.getHashMap.keySet iterator"]
    S12 --> LOOP{"hasNext?"}
    LOOP -->|Yes| S13["key = it.next"]
    S13 --> COND4{endsWith _err?}
    COND4 -->|Yes| COND5{isNull key?}
    COND4 -->|No| LOOP
    COND5 -->|No| S14["inMap.put key template.getString key"]
    COND5 -->|Yes| LOOP
    S14 --> LOOP
    LOOP -->|No| S15["return param"]
    S15 --> END(["Return param"])
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter container holding the screen's control map and data map. It carries both control-level data (status codes, messages) and business data (form fields). The method reads and mutates this object to propagate CBS error status and field-level error messages back to the screen. |
| 2 | `templates` | `CAANMsg[]` | An array of CAANMsg objects, each representing a CBS response message template. The method accesses `templates[0]` to extract the CBS status field (`status`/`STATUS` from `ECK0011B002CBSMsg`) and any `_err`-suffixed error fields. These come from the CBS layer after a service call completes. |
| 3 | `returnCode` | `int` | The caller's error return code. A value of `0` indicates normal success. Any non-zero value indicates an error occurred at the caller level, in which case the method forces `templateStatus` to `9000` (generic error). This acts as an error override mechanism. |
| 4 | `dataMapKey` | `String` | The key used to retrieve the business data map (`HashMap<String, String>`) from the `param` object. This data map holds field-level values and error flags that the screen renders. Error messages from the template are merged into this map. |

**External state read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `JCMAPLConstMgr.getString(String)` | Static method | Resolves human-readable message strings from the JCMAPL constant configuration. Called with keys like `RETURN_MESSAGE_0001`, `RETURN_MESSAGE_9000`, etc. |
| `SCControlMapKeys.RETURN_CODE` | Constant key | The control map key name for storing the return status code. Maps to a string code for the screen to display. |
| `SCControlMapKeys.RETURN_MESSAGE` | Constant key | The control map key name for storing the human-readable return message text. |
| `ECK0011B002CBSMsg.STATUS` | Constant key | The CBS message schema key for the `status` integer field. Always resolves to the string `"status"`. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCMAPLConstMgr.getString` | (Config) | JCMAPL Constant Store | Reads return message texts from the JCMAPL constant configuration. Used to resolve human-readable messages for numeric status codes (e.g., `RETURN_MESSAGE_0100`). |
| R | `param.getControlMapData` | (Param) | Control Map | Reads the existing BP return code from the request parameter's control map for comparison with the template status. |
| R | `param.getData` | (Param) | Data Map | Retrieves the business data map (HashMap) keyed by `dataMapKey` for later error field merging. |
| R | `template.getInt` | ECK0011B002CBS | CBS Response | Reads the integer status value from the CBS response template. The CBS `status` field encodes the service operation result (e.g., success, failure, warning). |
| R | `template.getHashMap.keySet` | (Param) | CBS Template | Iterates over all keys in the CBS message template to find error fields. |
| R | `template.isNull` | (Param) | CBS Template | Checks whether a specific `_err`-suffixed key in the CBS template has a null value (i.e., no error on that field). |
| R | `template.getString` | (Param) | CBS Template | Extracts the error message text for a specific `_err` key from the CBS template. |
| U | `param.setControlMapData` | (Param) | Control Map | Sets the resolved return code (formatted as `"%1$04d"`) and return message text into the control map. |
| U | `inMap.put` | (Param) | Data Map | Copies error field values from the CBS template into the business data map for screen rendering. |

**Note:** This method performs no direct database access. All operations are in-memory parameter transformations — reading from the CBS response template, constant store, and request parameter; writing back into the control map and data map.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Caller: JKKOpsvkeiTelIktAddCC.callSC() | `callSC()` -> `editErrorInfoCom(param, templates, returnCode, dataMapKey)` | `param.setControlMapData [U] Control Map`, `inMap.put [U] Data Map` |

**Caller analysis:** The method is called by `callSC()` within the same class `JKKOpsvkeiTelIktAddCC`, which handles telecom service order operations (FTTH registration, line changes, etc.). The caller invokes this method after executing a CBS service call to propagate the CBS response status and any field-level errors back into the request parameter.

Terminal operations reached from this method: `setControlMapData` [U], `put` [U], `setControlMapData` [U], `put` [U].

## 6. Per-Branch Detail Blocks

**Block 1** — SET `(L2709)`

> Extract the CBS status from the first template and check if the caller signaled an error.

| # | Type | Code |
|---|------|------|
| 1 | SET | `template = templates[0]` // Get first CBS response template |
| 2 | SET | `templateStatus = template.getInt(ECK0011B002CBSMsg.STATUS)` // Read integer status from CBS (e.g., 0100, 0200, 9000) |

**Block 2** — IF `(returnCode != 0)` `(L2711)`

> If the caller detected an error (non-zero returnCode), force the status to the generic error code 9000.

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

**Block 3** — IF `(JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatted templateStatus) == null)` `(L2715)`

> Validate that a message exists for this status code. If not, reset status to 0 (no error). The formatted status is zero-padded to 4 digits (e.g., `0900`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 0` // No message for this status, reset to OK [-> templateStatus=0] |

**Block 4** — SET `(L2720)`

> Read the existing BP return code for comparison. Default to -1 if not set.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = -1` [-> default value when null] |
| 2 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Check existing BP status |
| 3 | SET | `bpStatus = Integer.parseInt((String) obj)` [-> parse string to int, e.g., "0100" -> 100] |

**Block 5** — IF `(templateStatus > bpStatus)` `(L2725)`

> Priority comparison: only set the template's status/message if it is higher (more severe) than the BP's current status.

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Zero-padded, e.g., "0900" |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Look up human-readable message [-> "RETURN_MESSAGE_0900"] |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Set status code in control map |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Set error text in control map |

**Block 6** — ELSE `(L2729)` — no action

> When `templateStatus <= bpStatus`, the BP's existing status takes precedence. No update is performed.

**Block 7** — SET `(L2732)`

> Retrieve the business data map for merging error fields.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = (HashMap<String, String>) param.getData(dataMapKey)` // Get business data map from param |

**Block 8** — WHILE `{it.hasNext()}` `(L2735)`

> Iterate over all keys in the CBS template. For each key ending with `_err` (error field suffix), check if the template has a non-null value and copy it into the in-map. This merges field-level error messages (e.g., `address_err`, `name_err`) from the CBS response into the screen's data map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `it = template.getHashMap().keySet().iterator()` // Iterate CBS template keys |
| 2 | SET | `key = it.next()` |
| 3 | SET | `if (key.endsWith("_err"))` [-> error field filter, e.g., "address_err", "telNo_err"] |

**Block 8.1** — IF `{!template.isNull(key)}` `(L2743)`

> Only copy the error field if the template actually has a value for it (non-null). This avoids polluting the data map with empty error entries.

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `templateStatus` | Field | CBS response status — an integer code representing the result of a CBS service operation (0 = success, 9000 = generic error, other values = specific statuses) |
| `bpStatus` | Field | Business Process return code — the status code currently stored in the BP's control map, used for priority comparison against template status |
| `formatStatus` | Field | Zero-padded 4-digit status string (e.g., `"0900"`) used as a suffix for JCMAPL constant lookups |
| CAANMsg | Type | K-Opticom message wrapper class used for CBS request/response data. Holds key-value pairs and supports `getInt`, `getString`, `isNull`, `getHashMap` operations |
| JCMAPLConstMgr | Type | JCMAPL constant manager — static utility for retrieving localized message strings from the JCMAPL configuration system |
| ECK0011B002CBSMsg | Type | CBS message schema class defining the structure of CBS responses, including the `status` field and error fields |
| RETURN_CODE | Constant | Control map key for storing the numeric return status code |
| RETURN_MESSAGE | Constant | Control map key for storing the human-readable error/info message text |
| `_err` suffix | Field convention | Naming convention for CBS error fields (e.g., `address_err`, `name_err`) that carry field-level validation error messages |
| SCControlMapKeys | Type | Constant holder class defining keys for screen control map data (e.g., `RETURN_CODE`, `RETURN_MESSAGE`) |
| dataMapKey | Parameter | Key used to retrieve the business data map from `IRequestParameterReadWrite`, where form-level data and field errors are stored |
| requestCode | Parameter | Caller-provided error return code; non-zero indicates an error was detected at the caller level, triggering error override |
| controlMapData | Data structure | Key-value storage within `IRequestParameterReadWrite` for screen-level metadata (status codes, messages) |
| JCMAPL | Acronym | Japan Cloud Management and Automation Platform Layer — Fujitsu's enterprise application platform used in K-Opticom systems |
| CBS | Acronym | Central Business System — the core backend service layer handling telecom service operations (registration, changes, cancellations) |
| BP | Acronym | Business Process — the screen/controller layer that orchestrates user-facing operations and calls CBS services |
