# Business Logic — JKKOpsvkeiTelIktAddCC.editResultRP() [99 LOC]

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

## 1. Role

### JKKOpsvkeiTelIktAddCC.editResultRP()

This method is a **shared result-mapping utility** used across the K-Opticom telecom customer backbone system for processing service component (SC) return values after asynchronous service calls (such as FTTH registration, mail changes, or general operation service contracts). After the SC layer executes a business transaction, it returns a structured response wrapped in a `Map` containing `CAANMsg` objects — this method's job is to extract those results and map them back into the request parameter object (`IRequestParameterReadWrite`) so that the calling screen or controller can render the outcome to the end user.

Specifically, it performs four coordinated tasks: (1) it evaluates the service component's return code and template status, overriding the status to `9000` (service-level error) when the SC returns a non-zero return code; (2) it selects the most severe status between the SC's status and the BP's current status, writing the authoritative return code and human-readable message into the control map; (3) it maps error IDs from the response template into the user data map by scanning for fields whose names contain `_err` suffixes, using the template's item layout (`Object[][] contents`) to determine which fields to check; (4) it handles line-item (detail) data mapping when the template contains a child message list (`CBSMsg1List`), iterating over child templates and recursively mapping error IDs for each row; and (5) it aggregates error information from the `msgList` via `TemplateErrorUtil.getErrorInfo()` and stores it back on the control map.

The method implements a **delegation pattern** — it does not execute business logic itself but transforms and routes data between the SC response envelope and the BP parameter object. It is a shared utility called by multiple screen-facing dispatch methods (`callEKK0371C010SC`, `callEKK0371D010SC`, `callSCCmn`) within the same `JKKOpsvkeiTelIktAddCC` component, serving as the canonical result-post-processing step for all service contract registration operations in the phone service one-time registration module.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editResultRP starts"])
    
    START --> GET1["Extract CAANMsg templates from msgList"]
    GET1 --> GET2["Get returnCode from msgList"]
    GET2 --> GET3["Get templateId and templateStatus from template"]
    
    GET3 --> RC_CHECK{returnCode
not equal to 0 ?}
    RC_CHECK -->|true| SET9000["Set templateStatus = 9000"]
    SET9000 --> MSG_CHECK
    RC_CHECK -->|false| MSG_CHECK{templateStatus message
exists in JCMAPLConstMgr ?}
    MSG_CHECK -->|false| SET_STATUS0["Set templateStatus = 0"]
    MSG_CHECK -->|true| BP_STATUS_GET["Get bpStatus from param control map data"]
    SET_STATUS0 --> BP_STATUS_GET
    
    BP_STATUS_GET --> STATUS_CMP{templateStatus
greater than bpStatus ?}
    STATUS_CMP -->|true| MAP_STATUS["Set RETURN_CODE and
RETURN_MESSAGE on param"]
    STATUS_CMP -->|false| GET_USER_DATA["Get user data HashMap inMap
via param.getData(fixedText)"]
    MAP_STATUS --> GET_USER_DATA
    
    GET_USER_DATA --> GET_CONT["getContents(templateId)"]
    GET_CONT --> MAP_ERR1["mappingErrId(inMap, template, contents)"]
    MAP_ERR1 --> MSG1_BUILD["Build msg1ListId = templateId + CBSMsg1List"]
    MSG1_BUILD --> MSG1_GET["Get templateArray from
template.getCAANMsgList(msg1ListId)"]
    
    MSG1_GET --> MSG1_NULL{templateArray
is null ?}
    MSG1_NULL -->|false| ERR_LIST["Get errList from control map data,
init if null"]
    MSG1_NULL -->|true| INIT_LIST{inList from
inMap is null ?}
    INIT_LIST -->|true| CREATE_LIST["inList = new ArrayList,
inMap.put(msg1ListId, inList)"]
    INIT_LIST -->|false| FOR_START["For each CAANMsg childTemplate
in templateArray"]
    CREATE_LIST --> FOR_START
    
    FOR_START --> ADD_MAP_CHECK{i
greater than or equal to inList.size ?}
    ADD_MAP_CHECK -->|true| ADD_MAP["inList.add(new HashMap)"]
    ADD_MAP_CHECK -->|false| PROCESS_CHILD["childMap = inList.get(i)"]
    ADD_MAP --> PROCESS_CHILD
    PROCESS_CHILD --> GET_CHILD_CONT["getContents(msg1ListId)"]
    GET_CHILD_CONT --> MAP_CHILD_ERR["mappingErrId(childMap, childTemplate, msg1ListContents)"]
    MAP_CHILD_ERR --> NEXT_CHILD{i
current index less than array length ?}
    NEXT_CHILD -->|true| NEXT_I["i++"]
    NEXT_I --> PROCESS_CHILD
    NEXT_CHILD -->|false| ERR_LIST
    
    ERR_LIST --> SET_ERR["Set ERROR_INFO via
TemplateErrorUtil.getErrorInfo(msgList, errList)"]
    SET_ERR --> END_NODE(["Return param"])
```

**Processing Flow Summary:**

1. **Extract SC return data** — Pulls the `CAANMsg[]` template list and the integer return code from the `msgList` map using keys defined in `JCMConstants`.
2. **Override status on SC error** — If the SC return code is non-zero, the template status is forced to `9000` (indicating a service-level error). If no return message mapping exists for the resulting template status in `JCMAPLConstMgr`, the status resets to `0` (success).
3. **Status comparison and mapping** — Compares the SC template status against the BP's stored status code (`bpStatus`). If the SC status is worse, writes the formatted status code and its human-readable message into the control map via `SCControlMapKeys.RETURN_CODE` and `SCControlMapKeys.RETURN_MESSAGE`.
4. **Top-level error ID mapping** — Retrieves the user data map (`HashMap`) from `param` using `fixedText` as the key. Fetches the item layout for the template via `getContents(templateId)`, then calls `mappingErrId()` to copy any field with an `_err` suffix from the template into the user data map.
5. **Detail (line-item) error ID mapping** — If the template contains a child message list (`CBSMsg1List`), iterates over each child template. For each child beyond the existing list size, it creates a new `HashMap`. Then maps error IDs for each child row, mirroring the top-level error mapping logic.
6. **Error info aggregation** — Calls `TemplateErrorUtil.getErrorInfo(msgList, errList)` to extract structured error information from the `msgList` and stores it back on the control map under `SCControlMapKeys.ERROR_INFO`.
7. **Return** — Returns the enriched `param` object for the caller to inspect and route to the appropriate screen.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `msgList` | `Map<?, ?>` | The complete response envelope from the service component (SC) invocation. Contains the `CAANMsg[]` template list (keyed by `JCMConstants.TEMPLATE_LIST_KEY`), the return code (keyed by `JCMConstants.RET_CD_INT_KEY`), and raw error data. Each `CAANMsg` carries structured field values returned by the SC, including status codes and template IDs. |
| 2 | `param` | `IRequestParameterReadWrite` | The business data carrier that both reads and writes request/response data. Holds the user data map (accessible via `getData(fixedText)`), control map data (return code, return message, error info), and serves as the return value. After this method completes, `param` contains the mapped status codes, messages, and error IDs ready for screen rendering. |
| 3 | `fixedText` | `String` | A user-specified string that serves as the key for accessing the user data `HashMap` within `param`. It identifies which data segment (e.g., a specific screen or transaction context) the error mappings should be written into. |

**Fields and constants referenced by this method:**

| Name | Type | Business Meaning |
|------|------|-----------------|
| `JCMConstants.TEMPLATE_LIST_KEY` | String constant key | Map key for extracting the `CAANMsg[]` template array from the SC response |
| `JCMConstants.RET_CD_INT_KEY` | String constant key | Map key for extracting the integer return code from the SC response |
| `JCMConstants.TEMPLATE_ID_KEY` | String constant key | Key within a `CAANMsg` to retrieve the template identifier |
| `JCMConstants.STATUS_INT_KEY` | String constant key | Key within a `CAANMsg` to retrieve the integer status code |
| `SCControlMapKeys.RETURN_CODE` | String constant key | Control map key for the formatted return code (e.g., "0000", "9000") |
| `SCControlMapKeys.RETURN_MESSAGE` | String constant key | Control map key for the human-readable return message |
| `SCControlMapKeys.ERROR_INFO` | String constant key | Control map key for the aggregated error info `ArrayList<Object>` |
| `JCMAPLConstMgr` | Utility class | Provides string lookups for return messages keyed by pattern `RETURN_MESSAGE_XXXX` |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKOpsvkeiTelIktAddCC.getContents(String)` | - | - | Reads the item layout (field definitions) for a given template ID. Returns `Object[][]` where each row contains field metadata including field names and sort order. |
| - | `JKKOpsvkeiTelIktAddCC.mappingErrId(HashMap, CAANMsg, Object[][])` | - | - | Internal helper that reads field values from a `CAANMsg` template and copies fields whose names contain `_err` suffixes into the input `HashMap`. |
| R | `TemplateErrorUtil.getErrorInfo(Map<?, ?>, ArrayList<Object>)` | - | - | Extracts structured error information from the SC response `msgList`. Produces an `ArrayList<Object>` of error entries containing error IDs and messages. |

**Notes:** This method is a pure post-processing / result-mapping component. It does not call any service components (SCs), CBS (Business Service) methods, or perform direct database operations. All three called methods are local to the same common component or a shared utility class, performing data extraction and transformation only (Read operations).

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Common Component: `callEKK0371C010SC` | `callEKK0371C010SC()` -> `editResultRP(msgList, param, fixedText)` | `getErrorInfo` [R], `getContents` [R], `mappingErrId` [-] |
| 2 | Common Component: `callEKK0371D010SC` | `callEKK0371D010SC()` -> `editResultRP(msgList, param, fixedText)` | `getErrorInfo` [R], `getContents` [R], `mappingErrId` [-] |
| 3 | Common Component: `callSCCmn` | `callSCCmn()` -> `editResultRP(msgList, param, fixedText)` | `getErrorInfo` [R], `getContents` [R], `mappingErrId` [-] |

**Call Chain Details:**

| Caller Class | Caller Method | Context |
|-------------|---------------|---------|
| `JKKOpsvkeiTelIktAddCC` | `callEKK0371C010SC()` | Processes result for SC call `EKK0371C010SC` — likely an FTTH (Fiber To The Home) service contract addition operation |
| `JKKOpsvkeiTelIktAddCC` | `callEKK0371D010SC()` | Processes result for SC call `EKK0371D010SC` — likely an FTTH service contract modification/deletion operation |
| `JKKOpsvkeiTelIktAddCC` | `callSCCmn()` | Generic/common SC result processing for non-routed service component calls |

This method is not directly invoked by any screen entry point (no `KKSV*` screen class). Instead, it is called internally by screen-facing dispatch methods within the same common component, which are themselves invoked by screens handling the phone service one-time registration (電話オプションサービス一括登録) operation.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Extract SC response data from msgList (L2190–L2194)

This block extracts the raw service component response from the input `msgList` map. The SC response is structured as a map containing a `CAANMsg[]` template array and an integer return code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `CAANMsg[] templates = (CAANMsg[])msgList.get(JCMConstants.TEMPLATE_LIST_KEY)` // Extract CAANMsg array from SC response |
| 2 | SET | `CAANMsg template = templates[0]` // Take the first (primary) template |
| 3 | SET | `Integer returnCode = (Integer)msgList.get(JCMConstants.RET_CD_INT_KEY)` // Get SC return code |
| 4 | SET | `String templateId = template.getString(JCMConstants.TEMPLATE_ID_KEY)` // Extract template ID |
| 5 | SET | `int templateStatus = template.getInt(JCMConstants.STATUS_INT_KEY)` // Extract template status code |

> Japanese comment: `SCからの戻り値からCAANMsgを取得。` — Extract CAANMsg from SC return value.
> Japanese comment: `リターンコード取得` — Get return code.
> Japanese comment: `テンプレートID、ステータス取得` — Get template ID and status.

**Block 2** — [IF] Override status on non-zero return code (L2195–L2197)

When the SC returns a non-zero return code, the template status is forced to `9000` to indicate a service-level error condition.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` // Force error status when SC return code is non-zero |

> Japanese comment: `SCからの戻り値からCAANMsgを取得。` — (context: handling SC return values)

**Block 3** — [IF] Validate template status against message dictionary (L2198–L2201)

Checks whether a return message mapping exists in `JCMAPLConstMgr` for the template status. If no message exists (the lookup returns `null`), the status is reset to `0` (success). This acts as a validation guard — only known status codes with defined messages are considered valid.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 0` // Reset to success when no mapped message exists [-> "RETURN_MESSAGE_" + formattedStatus not found in JCMAPLConstMgr] |

**Block 4** — [SET] Determine BP's current status level (L2203–L2211)

Retrieves the BP's stored return code from the control map and parses it into an integer for comparison with the SC template status. If no return code is set in the control map, `bpStatus` defaults to `-1` (lower than any valid status code), ensuring the SC status always takes precedence when the BP has no prior status.

| # | Type | Code |
|---|------|------|
| 1 | SET | `int bpStatus = 0` // Default BP status |
| 2 | SET | `Object obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read current return code |
| 3 | SET | `bpStatus = -1` // Default when no return code exists |
| 4 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse existing return code |

> Japanese comment: `テンプレートID、ステータス取得` — (continuation of status acquisition context)

**Block 5** — [IF] Compare and write SC status if more severe (L2213–L2220)

If the SC template status is worse (higher numeric value) than the BP's current status, writes the SC status and its mapped message into the control map. This ensures the caller always sees the most severe status between the SC result and any pre-existing BP status.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String formatStatus = String.format("%1$04d", templateStatus)` // Format as 4-digit zero-padded (e.g., "0000", "9000") |
| 2 | SET | `String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Get human-readable message |
| 3 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Write formatted return code |
| 4 | SET | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Write return message |

> Japanese comment: `BPにサービスコンポーネントのステータスを設定する。` — Set the SC status on the BP.

**Block 6** — [SET] Retrieve user data map (L2222–L2223)

Gets the user data `HashMap` from `param` using `fixedText` as the key. This map is where field-level error IDs will be mapped into the user data for screen display.

| # | Type | Code |
|---|------|------|
| 1 | SET | `HashMap inMap = (HashMap)param.getData(fixedText)` // Get user data map |

> Japanese comment: `ユーザデータ情報` — User data information.

**Block 7** — [EXEC] Map top-level error IDs (L2225–L2230)

Fetches the item layout (field definitions) for the current template and calls `mappingErrId()` to copy any fields with `_err` suffixes from the template into the user data map.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `Object[][] contents = getContents(templateId)` // Get item layout for template |
| 2 | EXEC | `mappingErrId(inMap, template, contents)` // Map error ID fields |

> Japanese comment: `ユーザデータ情報にエラー情報をマップ` — Map error information to user data.
> Japanese comment: `項目の配置を取得` — Get item layout/arrangement.
> Japanese comment: `エラーIDをマップ` — Map error ID.

**Block 8** — [IF] Detail (line-item) error ID mapping (L2232–L2257)

Handles mapping of error IDs for child/line-item data when the template contains a nested `CBSMsg1List` (detail message list). Only supports detail level 1 (明細1). For each child template beyond the existing list size, a new `HashMap` is created. Then error IDs are mapped for each child row.

**Block 8.1** — [SET] Build child list key and retrieve child templates (L2233–L2235)

| # | Type | Code |
|---|------|------|
| 1 | SET | `String msg1ListId = templateId + "CBSMsg1List"` // Construct child list key |
| 2 | SET | `CAANMsg[] templateArray = template.getCAANMsgList(msg1ListId)` // Get child template array |

> Japanese comment: `明細に対するマッピング処理` — Mapping process for details.
> Japanese comment: `※明細1のみ対応` — Supports detail level 1 only.

**Block 8.2** — [IF] Initialize list if null (L2236–L2241)

| # | Type | Code |
|---|------|------|
| 1 | SET | `ArrayList inList = (ArrayList)inMap.get(msg1ListId)` // Get existing detail list |
| 2 | SET | `inList = new ArrayList()` // Create new list |
| 3 | SET | `inMap.put(msg1ListId, inList)` // Store new list in user data map |

**Block 8.3** — [FOR] Iterate over child templates (L2242–L2256)

For each child template in the detail message list:

| # | Type | Code |
|---|------|------|
| 1 | [IF] | `if (i >= inList.size())` — Create new child `HashMap` if index exceeds list size |
| 2 | SET | `inList.add(new HashMap())` // Add new empty map for this child row |
| 3 | SET | `HashMap childMap = (HashMap)inList.get(i)` // Reference the current child map |
| 4 | SET | `CAANMsg childTemplate = templateArray[i]` // Reference the current child template |
| 5 | SET | `Object[][] msg1ListContents = getContents(msg1ListId)` // Get item layout for child list |
| 6 | EXEC | `mappingErrId(childMap, childTemplate, msg1ListContents)` // Map error IDs for child |

> Japanese comment: `※明細1のみ対応` — Supports detail level 1 only.

**Block 9** — [SET] Initialize error info list (L2258–L2262)

Retrieves the existing error info list from the control map, or creates a new one if none exists.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ArrayList<Object> errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO)` // Get existing error list |
| 2 | SET | `errList = new ArrayList<Object>()` // Create new if null |

> Japanese comment: `エラー情報のマップを取得` — Get error information map.

**Block 10** — [SET] Set aggregated error info on control map (L2264–L2265)

Calls `TemplateErrorUtil.getErrorInfo()` to extract structured error information from the SC response and writes it to the control map under `SCControlMapKeys.ERROR_INFO`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(msgList, errList))` // Set error info on control map |

> Japanese comment: `コントロールマップに設定` — Set on control map.

**Block 11** — [RETURN] Return enriched param (L2267)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return the enriched parameter object |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `CAANMsg` | Class | Fujitsu's standard message class carrying structured field data returned from service components. Acts as a key-value container for SC responses, with typed accessors (`getString`, `getInt`, `getCAANMsgList`). |
| `IRequestParameterReadWrite` | Interface | The bidirectional request/response data carrier used throughout the BP (Business Process) framework. Holds user data (via `getData`) and control data (via `setControlMapData`/`getControlMapData`). |
| `msgList` | Field | The service component response envelope — a `Map` containing the `CAANMsg` template array and return code. |
| `templateId` | Field | The template identifier from the SC response, used to look up the item layout via `getContents()`. |
| `templateStatus` | Field | The status code returned by the SC in the template. `0` means success; `9000` is forced when the SC returns a non-zero return code. Other values represent specific success/error conditions. |
| `bpStatus` | Field | The BP's current status level stored in the control map, used to determine whether the SC status should override it. |
| `fixedText` | Field | A user-specified string key used to access the user data `HashMap` within `param`. Identifies the data segment context. |
| `inMap` | Field | The user data `HashMap` where field-level error IDs are mapped for screen display. |
| `contents` | Field | The item layout returned by `getContents(templateId)`, an `Object[][]` where each row contains field metadata (field name, sort order) for the template. |
| `mappingErrId` | Method | Internal helper that scans `contents` for fields with `_err` suffix and copies their values from the `CAANMsg` template into the input `HashMap`. |
| `msg1ListId` | Field | The composite key for child/detail message data, constructed as `templateId + "CBSMsg1List"`. |
| `CBSMsg1List` | Constant string | Suffix appended to a template ID to reference its detail/line-item message list. Only level-1 details are supported. |
| `RETURN_CODE` | Constant key | Control map key for the formatted return code (4-digit zero-padded string, e.g., "0000", "9000"). |
| `RETURN_MESSAGE` | Constant key | Control map key for the human-readable return message looked up from `JCMAPLConstMgr`. |
| `ERROR_INFO` | Constant key | Control map key for the aggregated `ArrayList<Object>` of structured error information from `TemplateErrorUtil.getErrorInfo()`. |
| `JCMConstants` | Class | Centralized constant definition class for common message keys (`TEMPLATE_LIST_KEY`, `RET_CD_INT_KEY`, `TEMPLATE_ID_KEY`, `STATUS_INT_KEY`). |
| `SCControlMapKeys` | Class | Centralized constant definition class for control map data keys (`RETURN_CODE`, `RETURN_MESSAGE`, `ERROR_INFO`). |
| `JCMAPLConstMgr` | Class | Configuration manager that provides string lookups keyed by pattern (e.g., `RETURN_MESSAGE_0000`). Returns `null` for unmapped keys. |
| `TemplateErrorUtil` | Class | Shared utility class that extracts structured error information from the SC response envelope. |
| SC | Acronym | Service Component — the service layer module that executes business logic and returns structured responses. |
| BP | Acronym | Business Process — the higher-level orchestration layer that calls SCs and maps results to screen parameters. |
| CC | Acronym | Common Component — shared business logic components (extending `AbstractCommonComponent`) used across multiple screens. |
| FP (9000) | Business term | Service-level error status code — forced when the SC returns a non-zero return code, indicating the SC call itself failed. |
| `_err` suffix | Naming convention | Field naming pattern in SC response templates — fields ending with `_err` contain error IDs or error messages that need to be mapped to the user data for screen display. |
| K-Opticom | Business term | Japanese telecommunications carrier (K-Opticom) — the domain context. This system manages service contract operations including phone options, FTTH, and mail services. |
| 電話オプションサービス一括登録 | Japanese term | Phone Option Service One-Time Registration — the business operation managed by `JKKOpsvkeiTelIktAddCC`. |
| 明細 | Japanese term | Detail/line item — refers to child/row-level data within a transaction (e.g., individual service lines within a contract). |
| コントロールマップ | Japanese term | Control map — a data structure within `IRequestParameterReadWrite` holding metadata (return codes, messages, error info) separate from user business data. |
