# Business Logic — JKKWrisvcAutoAplyGetSvcInfoCC.setControlMapErrInfo() [34 LOC]

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

## 1. Role

### JKKWrisvcAutoAplyGetSvcInfoCC.setControlMapErrInfo()

This method performs error-information storage and mapping for the control map in the discounted-service auto-application processing workflow. Its business purpose is to determine whether a template-based error status should propagate to the request parameters, overriding any existing status that is already stored in the control map. The method first validates whether a non-zero `returnCode` was explicitly provided (a non-zero code signals that an actual error occurred in the calling CBS/SC); in that case, it forces the effective status to `9000`, an error-level indicator. It then verifies against the message registry whether a localized error message exists for that status — if no message is registered, the status is treated as invalid and reset to `0`. After resolving the effective `templateStatus`, the method retrieves the current `RETURN_CODE` from the control map and compares it with the resolved status. Only if the new status is **higher** (i.e., a more severe error) than the existing status does it overwrite the control map with the new status and message. This is a shared utility method defined as `private`, used by multiple CC classes across the K-Opticom customer foundation system (e.g., `JKKCancelUsePlaceInfoCC`, `JKKKapSecurityPackOperateCC`, `JKKAdchgAddSvcKeiTvCC`, `JKKUpdSvcKeiTelCC`) whenever a template error needs to be safely mapped without losing a more critical prior error. It implements a **guard-and-compare** design pattern — protecting existing error state from being downgraded by less severe template errors.

> Javadoc (original): コントロールマップエラー情報格納処理を行います。 (Performs control map error information storage processing.)

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["setControlMapErrInfo"])
    CHECK_RETURN_CODE["returnCode != 0"]
    SET_ERROR_STATUS["templateStatus = 9000"]
    RESET_STATUS["templateStatus = itemplateStatus"]
    VERIFY_MESSAGE["JCMAPLConstMgr.getString(messageKey) == null"]
    CLEAR_TEMPLATE["templateStatus = 0"]
    KEEP_TEMPLATE["keep templateStatus"]
    READ_BP_STATUS["Object obj = param.getControlMapData(RETURN_CODE)"]
    CHECK_BP_NULL["obj == null"]
    SET_BP_NEG1["bpStatus = -1"]
    PARSE_BP_STATUS["bpStatus = Integer.parseInt(obj)"]
    COMPARE_STATUS["templateStatus > bpStatus"]
    UPDATE_CONTROL_MAP["Set RETURN_CODE and RETURN_MESSAGE in control map"]
    RETURN_PARAM["return param"]

    START --> CHECK_RETURN_CODE
    CHECK_RETURN_CODE -->|false| RESET_STATUS
    CHECK_RETURN_CODE -->|true| SET_ERROR_STATUS
    SET_ERROR_STATUS --> VERIFY_MESSAGE
    RESET_STATUS --> VERIFY_MESSAGE
    VERIFY_MESSAGE -->|true| CLEAR_TEMPLATE
    VERIFY_MESSAGE -->|false| KEEP_TEMPLATE
    CLEAR_TEMPLATE --> READ_BP_STATUS
    KEEP_TEMPLATE --> READ_BP_STATUS
    READ_BP_STATUS --> CHECK_BP_NULL
    CHECK_BP_NULL -->|true| SET_BP_NEG1
    CHECK_BP_NULL -->|false| PARSE_BP_STATUS
    SET_BP_NEG1 --> COMPARE_STATUS
    PARSE_BP_STATUS --> COMPARE_STATUS
    COMPARE_STATUS -->|true| UPDATE_CONTROL_MAP
    COMPARE_STATUS -->|false| RETURN_PARAM
    UPDATE_CONTROL_MAP --> RETURN_PARAM
```

**Processing Summary:**
1. **Initialize** — Copy `itemplateStatus` into local `templateStatus`.
2. **Override on explicit error** — If `returnCode` is non-zero, set `templateStatus` to `9000` (forced error state).
3. **Validate message existence** — Look up the message key built from `RETURN_MESSAGE_STRING` + formatted status. If the message is null (not registered), reset `templateStatus` to `0` (no error).
4. **Read current control-map status** — Get `bpStatus` from the control map's `RETURN_CODE` key. If the key is missing, treat it as `-1` (no prior status).
5. **Compare and conditionally update** — If the resolved `templateStatus` is strictly greater than `bpStatus`, overwrite the control map with the new status and the corresponding localized message. Return the parameter object.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object that carries the control map — a key-value store holding screen-level state including the current return code and error message. It is both read (to get existing status) and written (to update status/message on error). |
| 2 | `itemplateStatus` | `int` | The status code derived from a template error. This is the "template-level" severity that would normally be propagated. Typical values include `0` (OK), or various numeric codes mapped in the message registry. If the caller passes a non-zero `returnCode`, this value is overridden to `9000`. |
| 3 | `returnCode` | `int` | The return code from the CBS/SC execution. A value of `0` means success/no error. A non-zero value signals that an actual error occurred during the business transaction, triggering a forced error state (`9000`). |

**External state read:**
- `JCMAPLConstMgr.getString(key)` — Reads from the application constant manager's message registry. Used to verify that a localized message exists for the given status code.
- Instance/static fields: `RETURN_MESSAGE_STRING` (constant prefix for error message keys), `RETURN_MESSAGE_FORMAT` (constant `String.format` pattern for constructing message keys with status codes).

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCMAPLConstMgr.getString` | - | - | Reads localized error message from the message registry. No database interaction; consults in-memory constant/message store. |
| R | `param.getControlMapData(SCControlMapKeys.RETURN_CODE)` | - | - | Reads the existing return code value from the control map (in-memory state). |
| R | `Integer.parseInt(String)` | - | - | Parses the string-valued return code from the control map into an integer for comparison. |
| U | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, ...)` | - | - | Overwrites the RETURN_CODE key in the control map with the new status code string. |
| U | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, ...)` | - | - | Overwrites the RETURN_MESSAGE key with the localized error message string. |

**Analysis:** This method performs **pure in-memory state management**. It reads and writes data within the `IRequestParameterReadWrite` control map and consults the constant/message manager. No database reads, no CBS/SC calls, no entity operations. It is a lightweight error-state reconciliation step.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: multiple CC classes (shared utility).
Terminal operations from this method: `getString` [R], `getControlMapData` [R], `setControlMapData` [R], `setControlMapData` [R].

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CC:JKKWrisvcAutoAplyGetSvcInfoCC | `editErrInfoEKK0081A010` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 2 | CC:JKKCancelUsePlaceInfoCC | `...` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 3 | CC:JKKKapSecurityPackOperateCC | `...` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 4 | CC:JKKAdchgAddSvcKeiTvCC | `...` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 5 | CC:JKKUpdSvcKeiTelCC | `...` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 6 | CC:JKKUpdIcjknSetteCC | `...` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 7 | CC:JKKGetKojiakStatCC | `...` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 8 | CC:JKKHoseiTaMskmCC | `...` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 9 | CC:JKKCancelSvcKeiAdslCC | `...` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 10 | CC:JFUAddSvcKeiTvCC | `...` → `setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |
| 11 | CC:JFUGhMksmViewCtrlCC | `...` → `super.setControlMapErrInfo` | `param.getControlMapData [R]`, `param.setControlMapData [U]` |

**Notes:**
- This method is a **private shared utility** defined in `JKKWrisvcAutoAplyGetSvcInfoCC` and copied/overridden in multiple CC classes across the system. It is not a screen entry point — it is invoked by CBS/SC error-handling code after a service call returns.
- The pre-computed caller table in the spec lists `JKKWrisvcAutoAplyGetSvcInfoCC.editErrInfoEKK0081A010()` as the direct caller.
- The terminal operations are all in-memory — no DB tables or SC codes are involved.

## 6. Per-Branch Detail Blocks

**Block 1** — SET `(initialize templateStatus)` (L647)

> Copy the `itemplateStatus` parameter to a local variable. This creates a modifiable copy so the original parameter is not directly mutated.

| # | Type | Code |
|---|------|------|
| 1 | SET | `int templateStatus = itemplateStatus;` // Copy input status to local variable |

**Block 2** — IF `(returnCode != 0)` — override to forced error state (L649-L652)

> If the caller passed a non-zero returnCode, this means the CBS/SC execution actually encountered an error. The method forces the effective status to 9000, a reserved error-level status code.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (returnCode != 0)` [returnCode is non-zero = CBS/SC error detected] |
| 2 | SET | `templateStatus = 9000;` // Force error status when explicit error flag is set |

**Block 3** — IF `(JCMAPLConstMgr.getString(...) == null)` — validate message existence (L653-L656)

> Constructs the message key by concatenating `RETURN_MESSAGE_STRING` with the formatted status (e.g., `RETURN_MESSAGE_STRING + String.format(RETURN_MESSAGE_FORMAT, templateStatus)`). If no message is registered for this key, the status is considered invalid and reset to 0 (OK/no error). This prevents mapping a status code that has no associated error message, which would leave the screen with an unexplained numeric status.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (JCMAPLConstMgr.getString(RETURN_MESSAGE_STRING + String.format(RETURN_MESSAGE_FORMAT, templateStatus)) == null)` [message key not found = status has no registered error message] |
| 2 | SET | `templateStatus = 0;` // Reset to OK when no message exists |

**Block 4** — SET `(read current control-map bpStatus)` (L658-L667)

> Read the existing return code from the control map. If the key is absent (no prior status set), treat it as -1 (indicating no status, lower than any error code). Otherwise, parse the string value to an integer for numeric comparison.

| # | Type | Code |
|---|------|------|
| 1 | SET | `int bpStatus = 0;` // Initialize default status |
| 2 | SET | `Object obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE);` // Read existing return code from control map |
| 3 | IF | `if (obj == null)` [control map does not yet contain RETURN_CODE key] |
| 4 | SET | `bpStatus = -1;` // No prior status = treat as lowest priority |
| 5 | ELSE | — |
| 6 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE));` // Parse existing status to int |

**Block 5** — IF `(templateStatus > bpStatus)` — conditionally update control map (L669-L675)

> Compare the resolved template status against the existing control-map status. Only update if the new status is strictly more severe (higher numeric value). This prevents downgrading an existing error — if the user already has a status 5000 error, a template status 3000 will not overwrite it. If the new status is more severe, build the formatted status string and retrieve the corresponding localized message, then write both to the control map.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (templateStatus > bpStatus)` [new status is more severe than existing = conditionally overwrite] |
| 2 | SET | `String formatStatus = String.format(RETURN_MESSAGE_FORMAT, templateStatus);` // Build formatted status string (e.g., "9000") |
| 3 | SET | `String message = JCMAPLConstMgr.getString(RETURN_MESSAGE_STRING + formatStatus);` // Get localized error message for this status |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus);` // Update control map with new status code |
| 5 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message);` // Update control map with localized error message |
| 6 | RETURN | `return param;` // Return the parameter object with updated control map |

**Block 6** — ELSE-implicit `(templateStatus <= bpStatus)` — no update (L677)

> When the new template status is not more severe than the existing status, skip the update entirely. The control map retains its current values. Return the parameter unchanged.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param;` // No update needed — existing status is equal or more severe |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `templateStatus` | Field | Template error status — a numeric code representing the severity level of a template-based error. Values like `0` (OK) or `9000` (forced error) are used. |
| `bpStatus` | Field | Business platform status — the current return code stored in the control map, representing the most severe error status encountered so far in the request lifecycle. |
| `returnCode` | Field | Return code — the CBS/SC execution result indicator. `0` = success, non-zero = error occurred. |
| `RETURN_CODE` | Constant | Control map key for the return status code value. Used to read and write the current error status in the control map. |
| `RETURN_MESSAGE` | Constant | Control map key for the localized error message text associated with the return status code. |
| `RETURN_MESSAGE_STRING` | Constant | Prefix string used to construct message keys in the application constant manager's registry. |
| `RETURN_MESSAGE_FORMAT` | Constant | `String.format` pattern used to embed the status code into a message key (e.g., `"%s"` pattern). |
| control map | Concept | An in-memory key-value store (`IRequestParameterReadWrite`) attached to the request parameter, used to share screen-level state (status codes, messages, flags) between CBS, SC, and CC layers. |
| `JCMAPLConstMgr` | Class | Application constant manager — an in-memory registry that provides localized messages and constant values via key-based lookup. |
| `IRequestParameterReadWrite` | Interface | Request parameter interface that supports both reading and writing control map data. Used to pass state between request handling layers. |
| CC (Common Component) | Acronym | Common Component — a reusable class in the K-Opticom framework that encapsulates shared business logic across multiple screens and CBS modules. Inherits from `AbstractCommonComponent`. |
| CBS (Call Business Service) | Acronym | Call Business Service — a service component layer that coordinates business logic and SC calls. CBS methods return status codes via `STATUS` fields. |
| SC (Service Component) | Acronym | Service Component — the data access and business processing layer that performs CRUD operations on entities and database tables. |
| `RequestParameterException` | Exception | Thrown when an error occurs while reading or writing request parameters. Propagates to the calling CBS for error handling. |
| `editErrInfoEKK0081A010` | Method | The specific method in `JKKWrisvcAutoAplyGetSvcInfoCC` that calls `setControlMapErrInfo` to handle error information for service contract agreement meeting processing. |
