# Business Logic — JKKSvkeiShosaChkCC.editErrorInfoCom() [89 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKSvkeiShosaChkCC` |
| Layer | CC/Common Component — shared business logic component within the `common` package |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKSvkeiShosaChkCC.editErrorInfoCom()

The `editErrorInfoCom` method is a shared error-processing utility that reconciles status codes and copies validation error details from a CAANMsg template into the request parameter map, enabling screen-level error display. It first determines the effective template status by taking the status from the first template message, overriding it to the generic error code 9000 if the caller passed a non-zero errorCode, and then validating whether a message template string actually exists for that status — resetting to 0 if the lookup fails. It then compares the effective template status against the current business process (BP) return code stored in the control map, and if the template status is higher, it overwrites the BP return code and writes the localized error message so that the most severe status wins. Finally, it iterates over all key-value pairs in the template's HashMap, matching any key that ends with the `_err` error-item suffix, stripping the suffix to derive the base field name, and copying the error description value into the inMap only if that base field already exists in the data map. The method is called by `callSC()` within the same class after a service component returns, making it a standard post-processing step in the screen-to-service call pattern for the Service Contract Inspection (KKSV0004) workflow.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfoCom"])
    START --> GET_TEMPLATE["Get CAANMsg template from templates[0]"]
    GET_TEMPLATE --> GET_STATUS["Get template status via JCMConstants.STATUS_INT_KEY"]
    GET_STATUS --> CHECK_ERROR{"errorCode != 0?"}
    CHECK_ERROR -->|yes| OVERRIDE_STATUS["Set templateStatus = 9000"]
    CHECK_ERROR -->|no| CHECK_MESSAGE["Check message template exists"]
    OVERRIDE_STATUS --> CHECK_MESSAGE
    CHECK_MESSAGE --> VERIFY_STATUS{"Message template valid?"}
    VERIFY_STATUS -->|no| RESET_STATUS["Set templateStatus = 0"]
    VERIFY_STATUS -->|yes| GET_BP_STATUS["Get bpStatus from param control map (RETURN_CODE key)"]
    RESET_STATUS --> GET_BP_STATUS
    GET_BP_STATUS --> CHECK_BP_OBJ{"Control map object null?"}
    CHECK_BP_OBJ -->|yes| SET_BP_NEG1["Set bpStatus = -1"]
    CHECK_BP_OBJ -->|no| PARSE_BP["Parse bpStatus from String to int"]
    SET_BP_NEG1 --> CMP_STATUS{"templateStatus > bpStatus?"}
    PARSE_BP --> CMP_STATUS
    CMP_STATUS -->|yes| SET_RETURN["Set RETURN_CODE and RETURN_MESSAGE on param"]
    CMP_STATUS -->|no| EXTRACT_DATA["Extract inMap from param.getData(dataMapKey)"]
    SET_RETURN --> EXTRACT_DATA
    EXTRACT_DATA --> GET_TEMPLATE_MAP["Get HashMap from template"]
    GET_TEMPLATE_MAP --> ITERATE_KEYS["Iterate over template map keys"]
    ITERATE_KEYS --> CHECK_ARRAY{"Value is HashMap[]?"}
    CHECK_ARRAY -->|yes| ITERATE_CHILD["For each childMap, iterate child keys"]
    CHECK_ARRAY -->|no| CHECK_SINGLE{"Key ends with _err?"}
    ITERATE_CHILD --> CHECK_CHILD_KEY{"Child key ends with _err?"}
    CHECK_CHILD_KEY -->|yes| STRIP_CHILD["Strip _err suffix, verify inMap has base, put child error"]
    CHECK_CHILD_KEY -->|no| CONTINUE_CHILD["Continue child iteration"]
    CHECK_SINGLE -->|yes| STRIP_SINGLE["Strip _err suffix, verify inMap has base, put error"]
    CHECK_SINGLE -->|no| CONTINUE_SINGLE["Continue iteration"]
    STRIP_CHILD --> CONTINUE_CHILD
    STRIP_SINGLE --> CONTINUE_SINGLE
    CONTINUE_CHILD --> ITERATE_KEYS
    CONTINUE_SINGLE --> ITERATE_KEYS
    ITERATE_KEYS --> RETURN_PARAM["Return param"]
```

**Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|-----------------|
| `RETURN_MESSAGE_STRING` | `"RETURN_MESSAGE_"` | Prefix for localized message keys [-> RETURN_MESSAGE_STRING="RETURN_MESSAGE_" (JKKSvkeiShosaChkConstCC.java:141)] |
| `RETURN_MESSAGE_FORMAT` | `"%1$04d"` | Zero-padded 4-digit format for status codes [-> RETURN_MESSAGE_FORMAT="%1$04d" (JKKSvkeiShosaChkConstCC.java:142)] |
| `ERRITEM_SUFFIX` | `"_err"` | Suffix appended to error item keys to distinguish error descriptions from data fields |
| `JCMConstants.STATUS_INT_KEY` | — | Constant key for extracting integer status from CAANMsg |
| `SCControlMapKeys.RETURN_CODE` | — | Control map key for the return status code |
| `SCControlMapKeys.RETURN_MESSAGE` | — | Control map key for the localized error message text |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying both control-map metadata (return code, return message) and business data maps (keyed by `dataMapKey`). It flows from the screen's operation layer through service component calls and back, carrying errors and results. |
| 2 | `templates` | `CAANMsg[]` | An array of message templates returned by a called service component (SC). `templates[0]` is the primary response message containing the status code and error-item key-value pairs. |
| 3 | `errorCode` | `int` | The raw return code (status) from the service component call. A non-zero value indicates an error, triggering an override of the template status to the generic error status `9000`. When zero, the template's own status is used as-is. |
| 4 | `dataMapKey` | `String` | The key used to retrieve the business data HashMap from `param.getData()`. This map holds the structured data fields for the current screen context, where error items will be written. |

**External state read by this method:**
- No instance fields are read — the method is stateless and operates purely on parameters.

## 4. CRUD Operations / Called Services

The `editErrorInfoCom` method does not directly invoke any SCs, CBS services, or perform DB operations. All its calls are internal parameter manipulations and framework-level reads. The pre-computed evidence table below maps the actual method-level calls made within this method.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `CAANMsg.getInt` | — | — | Reads integer status code from CAANMsg template using `JCMConstants.STATUS_INT_KEY` |
| R | `JCMAPLConstMgr.getString` | — | — | Looks up localized message string by constructing the key from `RETURN_MESSAGE_STRING` prefix + formatted status |
| R | `IRequestParameterReadWrite.getControlMapData` | — | — | Reads the current BP return code from the control map using `SCControlMapKeys.RETURN_CODE` |
| W | `IRequestParameterReadWrite.setControlMapData` | — | — | Writes the resolved return code format string and error message to the control map |
| R | `IRequestParameterReadWrite.getData` | — | — | Retrieves the business data HashMap identified by `dataMapKey` |
| R | `CAANMsg.getHashMap` | — | — | Extracts the full key-value HashMap from the CAANMsg template for error-item scanning |
| R | `HashMap.keySet` (template map) | — | — | Iterates over all keys in the template's error-message map |
| R | `HashMap.get` / `HashMap.containsKey` / `HashMap.put` | — | — | Reads and writes error item values in the inMap, matching keys by `_err` suffix pattern |
| R | `HashMap.keySet` (child map) | — | — | Iterates over keys within nested `HashMap[]` error items |

**Note:** This method is purely a message/template processing utility. It does not perform any Create/Read/Update/Delete operations on database tables or external services. All data manipulation occurs in-memory on HashMaps and control maps within the request parameter object.

## 5. Dependency Trace

The `editErrorInfoCom` method is invoked as a post-service-call processing step. Its direct caller is the `callSC()` method within the same class `JKKSvkeiShosaChkCC`.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKSV0004 (Service Contract Inspection) | `KKSV0004OPOperation` -> `JKKSvkeiShosaChkCC.callSC` -> `JKKSvkeiShosaChkCC.editErrorInfoCom` | `param.setControlMapData` [W], `param.getData` [R], `CAANMsg.getHashMap` [R], `JCMAPLConstMgr.getString` [R] |
| 2 | Screen:KKSV0004 (via KKSV0004Flow) | `KKSV0004Flow` -> `KKSV0004OPOperation` -> `JKKSvkeiShosaChkCC.callSC` -> `JKKSvkeiShosaChkCC.editErrorInfoCom` | Same as above |

**Terminal operations from this method:**
- `getControlMapData` [R] — reads BP return code from control map
- `setControlMapData` [W] — writes resolved return code and error message
- `getData` [R] — retrieves business data map
- `getHashMap` [R] — extracts template error-item map
- `getString` [R] — looks up localized error message from constant manager
- `keySet` [R] — iterates template and child map keys
- `containsKey` [R] — validates base field existence before copying error
- `put` [W] — writes error items into business data map

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(errorCode != 0)` (L2018)

> If the caller passed a non-zero errorCode (indicating a service component error), override the template status to the generic error status 9000. This ensures a consistent error indicator regardless of what specific status the template carried.

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

**Block 2** — [IF] `(null == JCMAPLConstMgr.getString(...))` (L2022)

> Validates whether a localized message template actually exists for the current `templateStatus`. The lookup key is constructed as `RETURN_MESSAGE_STRING + format(templateStatus, "%1$04d")`. If no message exists (i.e., `getString` returns null), reset the status to 0 to prevent referencing a non-existent message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatKey = RETURN_MESSAGE_STRING + String.format(RETURN_MESSAGE_FORMAT, templateStatus)` [-> RETURN_MESSAGE_STRING="RETURN_MESSAGE_" (JKKSvkeiShosaChkConstCC.java:141), -> RETURN_MESSAGE_FORMAT="%1$04d" (JKKSvkeiShosaChkConstCC.java:142)] |
| 2 | EXEC | `JCMAPLConstMgr.getString(formatKey)` // Lookup localized message template |
| 3 | SET | `templateStatus = 0` // Reset if template not found |

**Block 3** — [IF / ELSE] `(null == obj)` where `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` (L2032–L2039)

> Attempts to read the current business process (BP) return code from the control map. If the key does not exist (`null`), default `bpStatus` to -1 so that any positive template status will be considered higher and trigger the return code update. If the value exists, parse it from String to int.

| # | Type | Code |
|---|------|------|
| 1 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read current BP status |
| 2 | SET | `bpStatus = -1` // Default when control map entry is absent |
| 3 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse existing status |

**Block 4** — [IF] `(templateStatus > bpStatus)` (L2041)

> Compares the effective template status against the current BP return code. When the template's status is higher (more severe), overwrite the BP return code and error message on the control map so that the most severe status is reflected to the end user.

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format(RETURN_MESSAGE_FORMAT, templateStatus)` // Format as "%1$04d" |
| 2 | SET | `message = JCMAPLConstMgr.getString(RETURN_MESSAGE_STRING + formatStatus)` // Resolve localized message |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Write formatted status |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Write localized error message |

**Block 5** — [EXTRACT DATA] (L2048)

> Retrieves the business data HashMap from the parameter object using the provided `dataMapKey`. This `inMap` is the destination for error item population. Also extracts the template's full key-value HashMap for scanning.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = (HashMap<String, Object>)param.getData(dataMapKey)` // Business data map |
| 2 | SET | `map = template.getHashMap()` // Template error-message map |

**Block 6** — [WHILE / FOR] Iterate over template map keys, then child maps (L2051–L2083)

> The core error-item transfer logic. Iterates over all keys in the template's HashMap. For each key-value pair, branches on whether the value is a `HashMap[]` array (nested error items) or a single value. For each key that ends with the `_err` suffix, it strips the suffix to derive the base field name, checks if that base field exists in the business data map, and if so, copies the error item into the inMap.

**Block 6.1** — [IF] `(value instanceof HashMap[])` (L2053)

> When the value is an array of HashMap objects, iterate each child map's keys to find error items. This handles multi-dimensional error scenarios where errors are associated with a list of child records.

**Block 6.1.1** — [FOR] `(for (HashMap childMap : childMapList))` (L2056)

**Block 6.1.2** — [WHILE] `(childIt.hasNext())` (L2058)

**Block 6.1.3** — [IF] `(childKey.endsWith(ERRITEM_SUFFIX))` [ERRITEM_SUFFIX="_err"] (L2061)

> Checks if the child key ends with the `_err` suffix to identify it as an error description item. If it matches, strips the suffix to get the base key.

| # | Type | Code |
|---|------|------|
| 1 | SET | `childKey = (String)childIt.next()` // Next child key |
| 2 | SET | `keyIdx = childKey.lastIndexOf(ERRITEM_SUFFIX)` // Position of "_err" suffix [-> ERRITEM_SUFFIX="_err"] |
| 3 | IF | `inMap.containsKey(childKey.substring(0, keyIdx))` // Verify base field exists in data map |
| 4 | EXEC | `inMap.put(childKey, childMap.get(childKey))` // Copy error item to business data map |

**Block 6.2** — [ELSE] `(value is not HashMap[])` (L2070)

> When the value is a single object (not an array), check the key directly for the error suffix. This handles flat error-item scenarios at the top level of the template map.

**Block 6.2.1** — [IF] `(key.endsWith(ERRITEM_SUFFIX))` [ERRITEM_SUFFIX="_err"] (L2072)

> Checks if the top-level key ends with `_err`. If so, strips the suffix and verifies the base field exists in the inMap before copying.

| # | Type | Code |
|---|------|------|
| 1 | SET | `key = (String)it.next()` // Next template map key |
| 2 | SET | `keyIdx = key.lastIndexOf(ERRITEM_SUFFIX)` // Position of "_err" suffix [-> ERRITEM_SUFFIX="_err"] |
| 3 | IF | `inMap.containsKey(key.substring(0, keyIdx))` // Verify base field exists |
| 4 | EXEC | `inMap.put(key, map.get(key))` // Copy error item to business data map |

**Block 7** — [RETURN] (L2087)

> Returns the modified `param` object with updated control map data (status and message) and populated error items in the data map.

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `param` | Field | Request Parameter — the bidirectional carrier object holding control-map metadata (return code, error message) and business data maps (keyed by `dataMapKey`). |
| `CAANMsg` | Type | Fujitsu CAAN (Common Application API Network) Message — a message container class that holds status codes, key-value pairs, and HashMaps used for inter-layer communication between screens and service components. |
| `errorCode` | Parameter | Service Component return code — a non-zero integer indicating that the called service component encountered an error condition. |
| `dataMapKey` | Parameter | Data Map key — the identifier used to retrieve the business data HashMap from the parameter object. This map contains the screen's structured data fields. |
| `templateStatus` | Variable | Effective status code from the CAANMsg template — the operational status after considering the `errorCode` override and message template validation. |
| `bpStatus` | Variable | Business Process return code — the current status code stored in the control map by earlier processing stages in the BP flow. |
| `RETURN_CODE` | Constant | Control map key for the BP return status code — indicates the current processing status (e.g., "9000" for error). |
| `RETURN_MESSAGE` | Constant | Control map key for the localized error message text — the user-facing error description resolved from message templates. |
| `RETURN_MESSAGE_STRING` | Constant | `"RETURN_MESSAGE_"` — prefix for constructing localized message template keys. |
| `RETURN_MESSAGE_FORMAT` | Constant | `"%1$04d"` — zero-padded 4-digit format string for status code keys. |
| `ERRITEM_SUFFIX` | Constant | `"_err"` — suffix appended to error item keys to distinguish error descriptions from regular data fields (e.g., `address` vs `address_err`). |
| `_err` | Pattern | Error item suffix convention — base field names appended with `_err` in the template map to indicate error description values for that field. |
| KKSV0004 | Screen Code | Service Contract Inspection Screen — the primary screen for reviewing and confirming service contract details. |
| SC | Abbreviation | Service Component — a service-layer module that performs business operations and returns results via CAANMsg templates. |
| BP | Abbreviation | Business Process — the screen-level operation flow managed by the BPM framework, carrying request parameters between screens and services. |
| Control Map | Type | A sub-map within the IRequestParameterReadWrite object for metadata keys (return codes, error messages, operator info) separate from business data maps. |
| KKKSvkeiShosaChkCC | Class | Service Contract Inspection Check Component — the common component class containing validation and error processing logic for the service contract inspection workflow. |
