# (DD46) Business Logic — JDKCommon08CC.editError() [33 LOC]

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

## 1. Role

### JDKCommon08CC.editError()

The `editError` method serves as a centralized **error status resolution and override utility** within the BP (Business Process) custom component layer. It is invoked by BPCheck classes across dozens of screen implementations (KKSV*, CRSV*, ZMSV*, SCSV*, CHSV*, FUSV*, DKSV* series) during the error-mapping phase of request processing. The method takes the error templates produced by a preceding BS Mapper and compares their status against the current BP-level return code stored in the parameter map. If the service-component-level error status is more severe than what the BP has already recorded (or if the BP has not yet set a return code), the method **promotes** the service component's error status and its associated user-facing message into the BP-level control map. If `returnCode` is non-zero — indicating a lower-level error already occurred — the method overrides the template status to `9000` (error/failure), ensuring that failure conditions propagate upward. It also validates that the template status maps to a known message key in the `JCMAPLConstMgr` message catalog; if the key is unrecognized, the status is reset to `0` (success/neutral), preventing stale or invalid error codes from reaching the user interface.

The design pattern is a **guarded override with severity promotion**: errors flow from BS Mapper templates upward to the BP layer only when they are both valid and more severe than existing BP-level status. The method acts as a shared utility, called from every BPCheck screen's error-mapping step.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editError param, templates, returnCode"])
    COND_EMPTY{templates.length == 0?}
    GET_TEMPLATE["Get templates[0]"]
    GET_STATUS["template.getInt EKK0161B004CBSMsg.STATUS"]
    COND_RETURN{returnCode != 0?}
    SET_FAIL["templateStatus = 9000"]
    VALIDATE_STATUS["JCMAPLConstMgr.getString RETURN_MESSAGE_ + format(templateStatus)"]
    COND_VALID{message key null?}
    SET_ZERO["templateStatus = 0"]
    INIT_BP_STATUS["bpStatus = 0"]
    GET_BP_RETURN["param.getControlMapData SCControlMapKeys.RETURN_CODE"]
    COND_BP_NULL{obj == null?}
    SET_BP_NEG1["bpStatus = -1"]
    PARSE_BP_STATUS["bpStatus = Integer.parseInt(obj)"]
    COND_COMPARE{templateStatus > bpStatus?}
    FORMAT_STATUS["formatStatus = String.format('%1$04d', templateStatus)"]
    GET_MESSAGE["JCMAPLConstMgr.getString RETURN_MESSAGE_ + formatStatus"]
    SET_BP_CODE["param.setControlMapData SCControlMapKeys.RETURN_CODE formatStatus"]
    SET_BP_MSG["param.setControlMapData SCControlMapKeys.RETURN_MESSAGE message"]
    RETURN_PARAM["Return param"]
    RETURN_EMPTY["Return param early"]

    START --> COND_EMPTY
    COND_EMPTY -->|true| RETURN_EMPTY
    COND_EMPTY -->|false| GET_TEMPLATE
    GET_TEMPLATE --> GET_STATUS
    GET_STATUS --> COND_RETURN
    COND_RETURN -->|true| SET_FAIL
    COND_RETURN -->|false| VALIDATE_STATUS
    SET_FAIL --> VALIDATE_STATUS
    VALIDATE_STATUS --> COND_VALID
    COND_VALID -->|true| SET_ZERO
    COND_VALID -->|false| INIT_BP_STATUS
    SET_ZERO --> INIT_BP_STATUS
    INIT_BP_STATUS --> GET_BP_RETURN
    GET_BP_RETURN --> COND_BP_NULL
    COND_BP_NULL -->|true| SET_BP_NEG1
    COND_BP_NULL -->|false| PARSE_BP_STATUS
    SET_BP_NEG1 --> COND_COMPARE
    PARSE_BP_STATUS --> COND_COMPARE
    COND_COMPARE -->|true| FORMAT_STATUS
    COND_COMPARE -->|false| RETURN_PARAM
    FORMAT_STATUS --> GET_MESSAGE
    GET_MESSAGE --> SET_BP_CODE
    SET_BP_CODE --> SET_BP_MSG
    SET_BP_MSG --> RETURN_PARAM
```

**CRITICAL -- Constant Resolution:**

| Constant | Resolved Value | Source Location |
|----------|---------------|-----------------|
| `EKK0161B004CBSMsg.STATUS` | `"status"` | `EKK0161B004CBSMsg.java:229` |
| `RETURN_MESSAGE_` | `"RETURN_MESSAGE_"` | `JKKEponSwchKjInfSksiConstCC.java:190` |
| `RETURN_MESSAGE_FORMAT` | `"%1$04d"` | `JKKEponSwchKjInfSksiConstCC.java:195` |
| `SCControlMapKeys.RETURN_CODE` | `"returnCode"` (control map key) | `com.fujitsu.futurity.common.x01.sc.SCControlMapKeys` |
| `SCControlMapKeys.RETURN_MESSAGE` | `"returnMessage"` (control map key) | `com.fujitsu.futurity.common.x01.sc.SCControlMapKeys` |

Processing flow:
1. If `templates` is empty, return `param` early (no error to map).
2. Read `status` from the first template via `EKK0161B004CBSMsg.STATUS` (value `"status"`).
3. If `returnCode != 0` (`[-> returnCode != 0 (code:L3497)]`), override `templateStatus = 9000` (failure).
4. Validate that the formatted status key (`"RETURN_MESSAGE_" + "%1$04d".format(templateStatus)`) exists in `JCMAPLConstMgr`. If the lookup returns `null` (`[-> JCMAPLConstMgr.getString() returns null (code:L3498)]`), reset `templateStatus = 0` (success).
5. Read the BP's existing `RETURN_CODE` from the control map. If absent (`[-> obj == null (code:L3503)]`), set `bpStatus = -1` (no prior status). Otherwise parse the existing code as an integer.
6. Compare: if `templateStatus > bpStatus` (`[-> templateStatus > bpStatus (code:L3507)]`), write the promoted status and its message into the BP-level control map (`RETURN_CODE` and `RETURN_MESSAGE` keys).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter map carrying BP-level control data. It holds the current `RETURN_CODE` and `RETURN_MESSAGE` keys that reflect the BP's own error state, and is written back with promoted error data. |
| 2 | `templates` | `CAANMsg[]` | An array of BS Mapper output templates containing error status messages. Each template carries a `status` field (`EKK0161B004CBSMsg.STATUS`) that encodes the service component's return code. Only `templates[0]` is consumed. |
| 3 | `returnCode` | `int` | A raw return code indicating whether a lower-level error occurred during BP execution. Non-zero values force the error status to `9000` (failure), effectively overriding any positive status from the template. |

**External state / instance fields used:** None. The method is purely stateless and operates only on its parameters.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCMAPLConstMgr.getString(String)` | - | System Message Catalog | Reads message text from the `JCMAPLConstMgr` internationalization constant manager using a dynamically built key (`RETURN_MESSAGE_XXXX`). This is a read-only lookup against the static message catalog; no database access. |
| R | `CAANMsg.getInt(String)` | - | - | Reads the `status` field (value `"status"`) from the first template as an integer. This is a read from the in-memory BS Mapper output structure. |
| R | `IRequestParameterReadWrite.getControlMapData(String)` | - | - | Reads the BP-level `RETURN_CODE` from the parameter control map. Reads the existing error severity to compare against the template's status. |
| W | `IRequestParameterReadWrite.setControlMapData(String, String)` | - | - | Writes the promoted `RETURN_CODE` and `RETURN_MESSAGE` into the control map, overriding any prior BP-level error state. This is a write to the in-memory parameter structure. |

**Note:** This method performs **no database operations** and calls **no Service Component (SC) or Business Component (CBS) methods**. It operates entirely in memory on the request parameter map, message templates, and the static message catalog (`JCMAPLConstMgr`).

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 30+ methods.
Terminal operations from this method: `JCMAPLConstMgr.getString` [R], `CAANMsg.getInt` [R], `getControlMapData` [R], `setControlMapData` [W], `setControlMapData` [W]

The `editError` method is a **leaf-level utility** called exclusively from BPCheck classes. There are no screen entry points within 8 hops that flow *through* this method — it is always invoked from the BPCheck's error-mapping phase.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | BPCheck:DKSV0141 | `DKSV0141OPBPCheck.executeBP` -> `dksv0141...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 2 | BPCheck:CRSV0237 | `CRSV0237OPBPCheck.executeBP` -> `crsv0237...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 3 | BPCheck:CRSV0197 | `CRSV0197OPBPCheck.executeBP` -> `crsv0197...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 4 | BPCheck:KKSV0495 | `KKSV0495OPBPCheck.executeBP` -> `kksv0495...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` (called multiple times for different mappers) | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 5 | BPCheck:ZMSV0105 | `ZMSV0105OPBPCheck.executeBP` -> `zmsv0105...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 6 | BPCheck:CRSV0124 | `CRSV0124OPBPCheck.executeBP` -> `crsv0124...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 7 | BPCheck:CHSV9001 | `CHSV9001OPBPCheck.executeBP` -> `chsv9001...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 8 | BPCheck:KKSV0557 | `KKSV0557OPBPCheck.executeBP` -> `kksv0557...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 9 | BPCheck:CRSV0101 | `CRSV0101OPBPCheck.executeBP` -> `crsv0101...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 10 | BPCheck:ZMSV0076 | `ZMSV0076OPBPCheck.executeBP` -> `zmsv0076...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 11 | BPCheck:ZMSV0036 | `ZMSV0036OPBPCheck.executeBP` -> `zmsv0036...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` (called multiple times) | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 12 | BPCheck:SCSV0021 | `SCSV0021OPBPCheck.executeBP` -> `scsv0021...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 13 | BPCheck:KKSV0791 | `KKSV0791OPBPCheck.executeBP` -> `jkkopchrirekilistdlydcc.editErrorInfo(param, templates, returnCode, "KKSV079101CC")` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 14 | BPCheck:CRSV0183 | `CRSV0183OPBPCheck.executeBP` -> `jcrgetdenshifilectl1icc.editErrorInfo(param, templates, returnCode)` -> `JDKCommon08CC.editError` | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |
| 15 | BPCheck:FUSV0193 | `FUSV0193OPBPCheck.executeBP` -> `fusv0193...bsmapper.editErrorInfo(param, templates, returnCode, ...)` -> `JDKCommon08CC.editError` (multiple mapper calls) | `JCMAPLConstMgr.getString [R]`, `CAANMsg.getInt [R]` |

**Pattern:** Every caller follows the same pattern — a BPCheck class invokes a BS Mapper's `editErrorInfo` method, which internally delegates to `JDKCommon08CC.editError`. The method is a universal leaf utility in the error-resolution chain.

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(templates.length == 0)` (L3491)

Early-exit guard: if no error templates are provided, return the parameter unchanged. This handles the case where a BS Mapper produces no error output.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param;` // No templates to process, return as-is |

**Block 2** — [PROCESS] `Get template and initial status` (L3494-3495)

Read the first template and extract its service component status code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `CAANMsg template = templates[0];` // First error template from BS Mapper |
| 2 | SET | `int templateStatus = template.getInt(EKK0161B004CBSMsg.STATUS);` // Read status field -> `status` [-> EKK0161B004CBSMsg.STATUS="status" (EKK0161B004CBSMsg.java:229)] |

**Block 3** — [IF-ELSE] `(returnCode != 0)` (L3496-3498)

Error override: when a lower-level return code is non-zero (indicating an error occurred in the BP), force the template status to `9000` (failure). This ensures failure statuses are not masked by lower-severity statuses from the template.

| # | Type | Code |
|---|------|------|
| 1 | IF | `returnCode != 0` [-> returnCode is non-zero (code:L3497)] |
| 2 | SET | `templateStatus = 9000;` // Force failure status when lower-level error present |
| 3 | ELSE | `returnCode == 0` [-> returnCode is zero, no override (code:L3497)] |
| 4 | (no-op) | // Keep templateStatus as-is from template |

**Block 4** — [IF] `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)) == null` (L3498-3500)

Message catalog validation: checks whether the formatted status key maps to a known message in `JCMAPLConstMgr`. If the key is not found, the template status is reset to `0` (success/neutral), preventing invalid error codes from reaching the UI.

| # | Type | Code |
|---|------|------|
| 1 | IF | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + "%1$04d".format(templateStatus)) == null` [-> RETURN_MESSAGE_="RETURN_MESSAGE_" (JKKEponSwchKjInfSksiConstCC.java:190), RETURN_MESSAGE_FORMAT="%1$04d" (JKKEponSwchKjInfSksiConstCC.java:195)] |
| 2 | SET | `templateStatus = 0;` // Reset to success if message catalog key is missing |
| 3 | ELSE | Key found in message catalog |
| 4 | (no-op) | // Keep templateStatus as computed |

**Block 5** — [PROCESS] `Read BP-level return code` (L3501-3506)

Initialize `bpStatus` by reading the existing `RETURN_CODE` from the parameter's control map. If no prior return code exists (`obj == null`), set `bpStatus = -1`, meaning the BP has no severity set yet and any non-negative template status will be higher.

| # | Type | Code |
|---|------|------|
| 1 | SET | `int bpStatus = 0;` // Initialize BP-level status |
| 2 | SET | `Object obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE);` // Read existing BP return code [-> SCControlMapKeys.RETURN_CODE = "returnCode"] |
| 3 | IF | `obj == null` [-> No existing BP return code set (code:L3503)] |
| 4 | SET | `bpStatus = -1;` // No prior status; any positive template status wins |
| 5 | ELSE | `obj != null` [-> Existing BP return code present (code:L3505)] |
| 6 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE));` // Parse existing code as integer |

**Block 6** — [IF] `(templateStatus > bpStatus)` (L3507-3513)

Severity promotion: if the template's error status is higher than the BP's current status, promote the template's status and its associated message into the BP control map. This is the core business logic — errors flow upward only when they are more severe.

| # | Type | Code |
|---|------|------|
| 1 | IF | `templateStatus > bpStatus` [-> Template error is more severe (code:L3507)] |
| 2 | SET | `String formatStatus = String.format("%1$04d", templateStatus);` // Zero-padded 4-digit status string |
| 3 | SET | `String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus);` // Lookup user-facing message [-> RETURN_MESSAGE_="RETURN_MESSAGE_" (JKKEponSwchKjInfSksiConstCC.java:190)] |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus);` // Write promoted return code [-> SCControlMapKeys.RETURN_CODE = "returnCode"] |
| 5 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message);` // Write associated message [-> SCControlMapKeys.RETURN_MESSAGE = "returnMessage"] |
| 6 | ELSE | `templateStatus <= bpStatus` [-> Template is not more severe (code:L3507)] |
| 7 | (no-op) | // Keep existing BP-level status and message unchanged |

**Block 7** — [RETURN] `return param;` (L3514)

Return the (potentially updated) parameter map to the caller for continued BP execution.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param;` // Return updated parameter with promoted error data |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `templateStatus` | Variable | The status code extracted from the BS Mapper's output template, representing the service component's result code (0 = success, 9000 = failure, etc.) |
| `bpStatus` | Variable | The BP-level return code representing the Business Process's own recorded error severity. Used as a threshold for error promotion |
| `returnCode` | Parameter | Lower-level error code from BP execution. Non-zero indicates an error occurred, triggering forced failure status (9000) |
| `JCMAPLConstMgr` | Class | Japan Common Message Application Library — the global static message catalog manager used to retrieve internationalized error messages by key |
| `RETURN_MESSAGE_XXXX` | Key Pattern | Message catalog key pattern where `XXXX` is a zero-padded 4-digit status code. Each key maps to a human-readable error message in the system |
| `EKK0161B004CBSMsg.STATUS` | Constant | Field name `"status"` — the status field key in the CBS response message object that holds the service component's return code |
| `SCControlMapKeys.RETURN_CODE` | Constant | Control map key `"returnCode"` — stores the BP-level return code for screen display and further processing |
| `SCControlMapKeys.RETURN_MESSAGE` | Constant | Control map key `"returnMessage"` — stores the human-readable error message associated with the current return code |
| BS Mapper | Component | BS Mapper (Business Service Mapper) — a mapping class that translates service component responses into a standardized template format for BP consumption |
| BPCheck | Component | BPCheck (Business Process Check) — screen-level check classes that execute the business process and handle error mapping. Every screen (KKSV, CRSV, ZMSV, etc.) has one |
| CAANMsg | Class | A message container class holding key-value pairs from CBS responses, used to read status codes and other fields from templates |
| 9000 | Status Code | Failure status — forced when `returnCode != 0`, indicating a lower-level error occurred. The highest-severity status code in the system |
| 0 | Status Code | Success/neutral status — used when no error, when the message catalog key is invalid, or when the template status is lower than the current BP status |
| -1 | Status Code | Sentinel value indicating no prior BP-level return code was set in the control map |
| IRequestParameterReadWrite | Interface | The request parameter interface used throughout the BP framework. It carries control map data, error info, and other process-level state between components |
| Format `"%1$04d"` | Constant | Zero-padded 4-digit integer format string [-> `RETURN_MESSAGE_FORMAT="%1$04d"` (JKKEponSwchKjInfSksiConstCC.java:195)] used to ensure status codes are consistently formatted as `"0000"`, `"9000"`, etc. |
| Error Status Promotion | Business Concept | The pattern of comparing error severities and allowing higher-severity errors to override lower-severity ones. Ensures users always see the most critical error message |
