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

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JFUTicketUseShinIraiCC` |
| Layer | CC/Common Component (Business Common — shared utility across ticket-based screens) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JFUTicketUseShinIraiCC.editErrorInfoCom()

This method is a **shared error-information editing utility** that prepares the response parameters for a Futurity ticket-based screen (ticket: Shin Irai / new order). It normalizes the **template status code** returned from the Service Component layer and, if it represents a failure, **overrides the business-process-level return code** with the more severe status from the template. It then copies any error messages stored in the template into the business-process parameter map according to a configurable mapping table (`mappingData`). The method implements a **template-based message routing** pattern: error keys are prefixed (`key_`) and error values are suffixed (`_err`), allowing screens to declaratively define which fields need error propagation without hard-coding field names. Its role in the larger system is to centralize error-response assembly so that every ticket screen reuses the same status-priority logic and error-copying logic, ensuring consistent error display behavior across the application.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START([\"editErrorInfoCom call\"])
    STEP1[\"Extract template[0] from templates\"]
    STEP2[\"Get templateStatus from template.getInt(STATUS_INT_KEY)\"]
    COND1{\"returnCode != 0?\"}
    SET1[\"templateStatus = 9000\"]
    STEP3[\"Check message resource
JCMAPLConstMgr.getString(KEY_RETURN_MESSAGE + STATUS_FORMAT(templateStatus))\"]
    COND2{\"message resource null?\"}
    SET2[\"templateStatus = 0\"]
    STEP4[\"Get bpStatus from param.getControlMapData(RETURN_CODE)
Fallback to -1 if not found\"]
    STEP5[\"Format templateStatus: formatStatus = STATUS_FORMAT(templateStatus)\"]
    STEP6[\"Get message from resource: message = JCMAPLConstMgr.getString(KEY_RETURN_MESSAGE + formatStatus)\"]
    COND3{\"templateStatus > bpStatus?\"}
    STEP7[\"Set control map: RETURN_CODE = formatStatus\"]
    STEP8[\"Set control map: RETURN_MESSAGE = message\"]
    STEP9[\"Get inMap from param.getData(dataMapKey)\"]
    LOOP_START[\"For each mappingData[i]\"]
    COND4{\"mappingData[i][0] starts with PREFIX_KEY_ITEM?\"}
    COND5{\"template.isNull(mappingData[i][0] + PREFIX_ERR_ITEM)?\"}
    COND6{\"inMap.containsKey(mappingData[i][0] + PREFIX_ERR_ITEM)?\"}
    STEP10[\"inMap.put(mappingData[i][0] + PREFIX_ERR_ITEM, template.getString(mappingData[i][0] + PREFIX_ERR_ITEM))\"]
    LOOP_END[\"Next mappingData[i]\"]
    STEP11[\"Return param\"]
    END_NODE([\"End\"])

    START --> STEP1 --> STEP2 --> COND1
    COND1 -->|false| STEP3
    COND1 -->|true| SET1 --> STEP3
    STEP3 --> COND2
    COND2 -->|false| STEP4
    COND2 -->|true| SET2 --> STEP4
    STEP4 --> STEP5 --> STEP6 --> COND3
    COND3 -->|true| STEP7 --> STEP8 --> STEP9
    COND3 -->|false| STEP9
    STEP9 --> LOOP_START --> COND4
    COND4 -->|false| LOOP_END
    COND4 -->|true| COND5
    COND5 -->|false| COND6
    COND5 -->|true| LOOP_END
    COND6 -->|false| STEP10
    COND6 -->|true| LOOP_END
    STEP10 --> LOOP_END
    LOOP_END -->|more items| LOOP_START
    LOOP_END -->|done| STEP11 --> END_NODE
```

**CRITICAL — Constant Resolution:**

| Constant Name | Resolved Value | Business Meaning |
|--------------|---------------|-----------------|
| `STATUS_FORMAT` | `"%1$04d"` | Zero-padded 4-digit status code format (e.g., `9000`, `0000`) |
| `PREFIX_KEY_ITEM` | `"key_"` | Prefix applied to data keys identifying mapped error fields |
| `PREFIX_ERR_ITEM` | `"_err"` | Suffix appended to data keys to form error message keys |
| `KEY_RETURN_MESSAGE` | `"RETURN_MESSAGE_"` | Resource-bundle key prefix for building localized error messages |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter map carrying the business-process state. Holds control-map entries (`RETURN_CODE`, `RETURN_MESSAGE`) and user-data keyed by `dataMapKey`. Used as both input (read status) and output (written error info). |
| 2 | `templates` | `CAANMsg[]` | Array of CAAN message templates containing error messages from the SC layer. `templates[0]` holds the primary template with status code and per-field error strings (e.g., `"key_name_err"`). |
| 3 | `returnCode` | `int` | The BP-level return code. If non-zero, it signals an error and the method sets `templateStatus` to `9000` (fallback error). If zero, the template's own status is used. |
| 4 | `dataMapKey` | `String` | The key used to retrieve the user-data `HashMap<String, String>` from `param`. This map is the destination for copied error messages. |
| 5 | `mappingData` | `Object[][]` | A 2D mapping table defining which template fields should be copied as error messages. Each row: `mappingData[i][0]` is the base key (e.g., `"key_name"`). The method only processes entries starting with `"key_"` and copies the corresponding `"_err"` suffixed message. |

**External/Instance State Read:**
- None directly. All constants used are `private static final` fields of this class (`STATUS_FORMAT`, `PREFIX_KEY_ITEM`, `PREFIX_ERR_ITEM`, `KEY_RETURN_MESSAGE`).

## 4. CRUD Operations / Called Services

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

This method performs **parameter manipulation and message routing** — it does not directly access databases. All calls are utility reads from message resources and parameter maps.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `template.getInt` | CAANMsg | - | Reads the status code integer from the template message object (STATUS_INT_KEY) |
| R | `JCMAPLConstMgr.getString` | JCMAPLConstMgr | - | Resource-bundle lookup: checks if a localized return-message key exists for the given status code |
| R | `param.getControlMapData` | IRequestParameterReadWrite | - | Retrieves the business-process return code from the control map; used for severity comparison |
| W | `param.setControlMapData` | IRequestParameterReadWrite | - | Writes the normalized return code (zero-padded) and localized error message into the control map |
| R | `param.getData` | IRequestParameterReadWrite | - | Retrieves the user-data HashMap (keyed by `dataMapKey`) where error messages are accumulated |
| R | `template.isNull` | CAANMsg | - | Checks whether the template contains a non-null error message for a given field key |
| R | `inMap.containsKey` | HashMap | - | Idempotency check: avoids overwriting an existing error message already set for this field |
| R | `template.getString` | CAANMsg | - | Reads the localized error message string from the template for the error field |
| W | `inMap.put` | HashMap | - | Stores the copied error message into the user-data map under the error-key (e.g., `"key_name_err"`) |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `JFUTicketUseShinIraiCC.callSC` | `callSC` -> `editErrorInfoCom(param, templates, returnCode, dataMapKey, mappingData)` | `template.getInt [R] STATUS_INT_KEY`<br>`JCMAPLConstMgr.getString [R] RETURN_MESSAGE_*`<br>`param.getControlMapData [R] RETURN_CODE`<br>`param.setControlMapData [W] RETURN_CODE, RETURN_MESSAGE`<br>`template.isNull [R] field_err`<br>`template.getString [R] field_err`<br>`inMap.put [W] field_err -> message` |

**Notes:**
- The only direct caller is `JFUTicketUseShinIraiCC.callSC()`, meaning this method is a **private helper** within the same ticket CC class.
- No screen/batch entry points were found within 8 hops — this confirms the method is a deep utility called from the ticket's central dispatch method (`callSC`).
- Terminal operations are all parameter reads/writes and message resource lookups — no database or SC/CBS calls originate directly from this method.

## 6. Per-Branch Detail Blocks

### Block 1 — EXTRACT (L274)

> Extracts the primary template and initial status from the templates array.
> Original comment: 「本来はサービスインターフェース分の処理が必要」 — "Originally, per-service-interface processing is required."

| # | Type | Code |
|---|------|------|
| 1 | SET | `template = templates[0]` |
| 2 | SET | `templateStatus = template.getInt(JCMConstants.STATUS_INT_KEY)` |

---

### Block 2 — IF `(returnCode != 0)` (L278)

> If the BP-level return code is non-zero (error), override the template status to `9000` as a generic error indicator.

| # | Type | Code |
|---|------|------|
| 1 | COND | `returnCode != 0` |
| 2 | SET | `templateStatus = 9000` |

---

### Block 3 — IF `(message resource null)` (L285)

> Validates the status code against the resource bundle. If no message resource key exists for `RETURN_MESSAGE_` + formatted status, the status is reset to `0` (success), effectively treating the status code as unrecognized and suppressing error override.
> Original comment: N/A (resource validation step)

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format(STATUS_FORMAT, templateStatus)` |
| 2 | EXEC | `JCMAPLConstMgr.getString(KEY_RETURN_MESSAGE + formatStatus)` |
| 3 | COND | `result == null` |
| 4 | SET | `templateStatus = 0` | `[-> KEY_RETURN_MESSAGE="RETURN_MESSAGE_"]` `[-> STATUS_FORMAT="%1$04d"]` |

---

### Block 4 — IF/ELSE `(bpStatus determination)` (L289-L296)

> Determines the business-process-level status by reading `RETURN_CODE` from the control map. If the key is absent, defaults to `-1` so that any valid template status (>= 0) will be considered higher.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = 0` |
| 2 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` |
| 3 | COND | `obj == null` |
| 4 | SET | `bpStatus = -1` |
| 5 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` | `[-> SCControlMapKeys.RETURN_CODE = "RETURN_CODE"]` |

---

### Block 5 — IF `(templateStatus > bpStatus)` (L298)

> If the template's status code (after override/validation) is **higher** than the BP-level status, the method considers the template error to be more severe and overwrites the control map with the template's status and its corresponding localized message.
> Original comment: 「BPにサービスコンポーネントのステータスを設定する。」 — "Set the service component's status in the BP."

| # | Type | Code |
|---|------|------|
| 1 | COND | `templateStatus > bpStatus` |
| 2 | SET | `formatStatus = String.format(STATUS_FORMAT, templateStatus)` |
| 3 | SET | `message = JCMAPLConstMgr.getString(KEY_RETURN_MESSAGE + formatStatus)` |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` |
| 5 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` | `[-> SCControlMapKeys.RETURN_CODE="RETURN_CODE"]` `[-> SCControlMapKeys.RETURN_MESSAGE="RETURN_MESSAGE"]` |

---

### Block 6 — USER DATA MAP ACQUISITION (L304)

> Retrieves the user-data HashMap from the parameter object using `dataMapKey`. This is the destination map into which error messages will be written.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = (HashMap<String, String>)param.getData(dataMapKey)` |

---

### Block 7 — FOR LOOP `(mappingData[i])` (L308-L327)

> Iterates through the mapping table. For each entry, if the key starts with `"key_"`, checks whether the template has a non-null error message for the corresponding `"_err"` suffixed key, and whether the user-data map already contains it. If both checks pass, copies the error message from the template into the user-data map.
> Original comment: 「ユーザーデータ情報」 — "User data information"

| # | Type | Code |
|---|------|------|
| 1 | LOOP | `for (int i = 0; i < mappingData.length; i++)` |
| 2 | COND | `mappingData[i][0].startsWith(PREFIX_KEY_ITEM)` |
| 3 | COND | `!template.isNull(mappingData[i][0] + PREFIX_ERR_ITEM)` |
| 4 | COND | `!inMap.containsKey(mappingData[i][0] + PREFIX_ERR_ITEM)` |
| 5 | EXEC | `inMap.put(mappingData[i][0] + PREFIX_ERR_ITEM, template.getString(mappingData[i][0] + PREFIX_ERR_ITEM))` | `[-> PREFIX_KEY_ITEM="key_"]` `[-> PREFIX_ERR_ITEM="_err"]` |

**Block 7.1 — FOR LOOP EXIT (L327)**

> After the loop finishes, returns the modified parameter object.

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `editErrorInfoCom` | Method | Error information editing utility — centralizes error status override and message copying for ticket screens |
| `template` | Concept | CAAN message template carrying status codes and per-field localized error messages from the Service Component layer |
| `templateStatus` | Variable | The normalized status code extracted from the template; possibly overridden to 9000 on BP error or 0 if resource-missing |
| `bpStatus` | Variable | Business-process-level status read from the control map; serves as comparison baseline |
| `returnCode` | Parameter | BP-level return code from the calling method; non-zero indicates a BP error |
| `formatStatus` | Variable | Zero-padded 4-digit string representation of the status code (e.g., `9000`) |
| `inMap` | Variable | HashMap of user data (field key -> value) where error messages are accumulated |
| `mappingData` | Parameter | 2D mapping table defining which template fields map to user-data error keys |
| `key_` | Constant | Prefix (`PREFIX_KEY_ITEM`) — identifies a data key as an error-mapped field |
| `_err` | Constant | Suffix (`PREFIX_ERR_ITEM`) — forms the error-message key by appending to the base key |
| `RETURN_MESSAGE_` | Constant | Prefix (`KEY_RETURN_MESSAGE`) — builds the resource-bundle lookup key for localized error messages |
| `%1$04d` | Constant | Format string (`STATUS_FORMAT`) — zero-pads a status integer to 4 digits |
| `CAANMsg` | Class | Fujitsu's message wrapper class holding typed values (strings, ints) keyed by string identifiers |
| `IRequestParameterReadWrite` | Interface | Parameter interface for ticket-based screens; supports `getData`, `getControlMapData`, `setControlMapData` |
| `JCMConstants.STATUS_INT_KEY` | Constant | Key used to read the status integer from a CAANMsg template |
| `SCControlMapKeys.RETURN_CODE` | Constant | Key for the return code in the control map; value is the zero-padded status string |
| `SCControlMapKeys.RETURN_MESSAGE` | Constant | Key for the localized error message in the control map |
| `JCMAPLConstMgr` | Class | Application-level resource bundle manager for loading localized strings |
| `JFUTicketUseShinIraiCC` | Class | New order (Shin Irai) ticket common component — shared logic across the ticket's screens |
| Shin Irai (新規依頼) | Domain term | New order / new service request — the business domain for this ticket |
| `RequestParameterException` | Exception | Thrown when parameter read/write operations fail |
