# Business Logic — JKKOrsjgsUseStpRlsRunCC.callSC() [74 LOC]

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

## 1. Role

### JKKOrsjgsUseStpRlsRunCC.callSC()

This method is the **central Service Component (SC) invocation gateway** within the BP (Business Process) custom common layer. It provides a unified, generic wrapper that delegates to any configured SC — dynamically determined by the `mappingData` parameter — while handling the complete lifecycle of request preparation, execution, response parsing, status normalization, error aggregation, and result validation. It implements the **delegation and adapter** design pattern: it transforms incoming request parameters and mapping tables into a standardized `CAANMsg` template, injects operational metadata (transaction ID, use-case ID, operator, hostname, IP, screen ID), invokes the SC engine via `ServiceComponentRequestInvoker`, and then normalizes and propagates the results back to the caller's control map and message objects. Its **role in the larger system** is that of a shared utility called by multiple BP screen methods (e.g., `orsjgsUseStpRlsKanrencheck()`), serving as the single entry point for all SC calls originating from the `JKKOrsjgsUseStpRlsRunCC` class. The method handles three distinct processing paths: (1) **normal SC execution** — prepares the request, invokes the SC, and validates the return code and status; (2) **error code correction** — when the SC returns a non-zero return code, it forces a template status of 9000; when the SC returns an unrecognized status code, it resets to 0; (3) **status precedence** — BP-level status is overridden by SC-level status when the SC status is numerically higher; and (4) **exception throwing** — when both return code and status indicate an abnormal condition, an `SCCallException` is thrown with the specific return code and status values.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["callSC(params)"])
    START --> STEP1["editInMsg(param, mappingData)"]
    STEP1 --> STEP2["scCall.run(paramMap, handle)"]
    STEP2 --> STEP3["Extract TEMPLATE_LIST_KEY and RET_CD_INT_KEY"]
    STEP3 --> STEP4["Get status from msg (ECK0011A010CBSMsg.STATUS)"]
    STEP4 --> COND_RETURN{"returnCode != 0?"}
    COND_RETURN -->|Yes| SET_RETURN["templateStatus = 9000"]
    COND_RETURN -->|No| COND_MSG{"RETURN_MESSAGE_<status> exists?"}
    SET_RETURN --> COND_MSG
    COND_MSG -->|No| SET_STATUS["templateStatus = 0"]
    COND_MSG -->|Yes| GET_BP
    SET_STATUS --> GET_BP["bpStatus = param.getControlMapData(RETURN_CODE)"]
    GET_BP --> OBJ_NULL{obj == null?}
    OBJ_NULL -->|Yes| SET_BP["bpStatus = -1"]
    OBJ_NULL -->|No| PARSE_BP["bpStatus = Integer.parseInt(returnCode)"]
    SET_BP --> COND_BPS
    PARSE_BP --> COND_BPS{"templateStatus > bpStatus?"}
    COND_BPS -->|Yes| UPDATE_MAP["Set RETURN_CODE and RETURN_MESSAGE in control map"]
    COND_BPS -->|No| SET_ERR
    UPDATE_MAP --> SET_ERR["setErrorInf(msg, paramMap)"]
    SET_ERR --> ERR_LIST["Get or create errList from control map"]
    ERR_LIST --> SET_ERR_INFO["setControlMapData(ERROR_INFO, TemplateErrorUtil.getErrorInfo(result, errList))"]
    SET_ERR_INFO --> EXTRACT_RESULT["Extract rtnCode and status from result"]
    EXTRACT_RESULT --> COND_EXCEPT{"rtnCode != 0 OR status != 0?"}
    COND_EXCEPT -->|Yes| THROW["Throw SCCallException('Return value invalid')"]
    COND_EXCEPT -->|No| RETURN
    THROW --> END(["Exception"])
    RETURN(["Return msg"])
    END --> FINISH(["callSC() completes"])
    RETURN --> FINISH
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Session management handle containing session context, transaction boundaries, and manager references used by the SC execution engine. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | The SC invocation engine that executes the actual service component. The target SC is determined by the `mappingData` content — this parameter is a generic invoker reused across all SC types. |
| 3 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying the model group, control map (operator ID, hostname, IP address, screen ID, operation date/time), and data map. It provides both input values read during request preparation and output slots for error info, return code, and return message. |
| 4 | `dataMapKey` | `String` | The key used to retrieve the target `HashMap<String, Object>` data map from `param.getData()`. This map is used to collect error fields (keys ending in `_err`) extracted from the SC response message. |
| 5 | `mappingData` | `Object[][]` | A two-dimensional mapping table where each row defines a field-to-value assignment for the SC request. `mappingData[i][0]` is the field name (key) and `mappingData[i][1]` is the value. The first row's second element (`mappingData[0][1]`) also serves as the service interface name used to construct the `CAANMsg` template class name (e.g., `"eo.ejb.cbs.cbsmsg.EKK0081A010CBSMsg"`). |

**Instance fields / external state:**
- None directly read. This method is stateless — all state is carried through parameters.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `scCall.run` | (dynamic, determined by mappingData) | (SC-specific) | Invokes the target SC generically — the actual SC/CBS is determined at runtime by the `svcIf` value in `mappingData[0][1]`, which constructs the message template class name (e.g., `EKK0081A010CBSMsg`, `ECK0011A010CBSMsg`, `ECH0911A010CBSMsg`). |
| R | `TemplateErrorUtil.getErrorInfo` | (Utility) | - | Extracts error information from the SC result map into an error list. |
| U | `JKKOrsjgsUseStpRlsRunCC.editInMsg` | (Internal) | - | Prepares the inbound parameter map by extracting telegram, use-case, operator, and mapping data into a structured request. |
| U | `JKKOrsjgsUseStpRlsRunCC.setErrorInf` | (Internal) | - | Iterates the SC response message schema for keys ending in `_err` and copies non-null error values into the data map. |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.
Terminal operations from this method: `scCall.run` [-], `getErrorInfo` [R], `editInMsg` [U], `setErrorInf` [U].

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | BP:JKKOrsjgsUseStpRlsRunCC.orsjgsUseStpRlsKanrencheck | `orsjgsUseStpRlsKanrencheck` -> `callSC(handle, scCall, param, fixedText, mappingData)` | `scCall.run` (dynamic SC), `getErrorInfo` [R], `editInMsg` [U], `setErrorInf` [U] |

## 6. Per-Branch Detail Blocks

**Block 1** — [ASSIGN] `(request preparation)` (L6518)

> Builds the parameter map by delegating to `editInMsg`, which extracts operational metadata (transaction ID, use-case ID, operator ID, hostname, IP address, screen ID) and maps the `mappingData` into a `CAANMsg` template.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `editInMsg(param, mappingData)` // Prepares paramMap with operational metadata and template |

**Block 2** — [ASSIGN] `(SC invocation)` (L6519)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `scCall.run(paramMap, handle)` // Invokes the dynamically-targeted SC |

**Block 3** — [ASSIGN] `(response extraction)` (L6521)

| # | Type | Code |
|---|------|------|
| 1 | SET | `templates = result.get(JCMConstants.TEMPLATE_LIST_KEY)` // Extract CAANMsg[] array from SC result |
| 2 | SET | `msg = templates[0]` // Get the primary response message |

**Block 4** — [ASSIGN] `(status and return code extraction)` (L6523)

| # | Type | Code |
|---|------|------|
| 1 | SET | `returnCode = (Integer)result.get(JCMConstants.RET_CD_INT_KEY)` // Return code from SC result |
| 2 | SET | `templateStatus = msg.getInt(ECK0011A010CBSMsg.STATUS)` // Status field from SC response message |

**Block 5** — [IF] `(return code correction)` `returnCode != 0` (L6525)

> If the SC returns a non-zero return code, override the template status to 9000 (system error indicator).

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

**Block 6** — [IF] `(status code validation)` `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + format(templateStatus)) == null` (L6530)

> Validates that the template status maps to a known return message. If the status code has no corresponding message entry, reset status to 0 (unknown status fallback).

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 0` // Reset to 0 when no message template exists for this status |

**Block 7** — [ASSIGN] `(BP status retrieval)` (L6534)

> Reads the BP-level return code from the control map. This represents any prior status set by the calling BP logic.

| # | Type | Code |
|---|------|------|
| 1 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read BP-level return code |
| 2 | SET | `bpStatus = 0` // Default to 0 |

**Block 8** — [IF-ELSE] `(BP status parsing)` `obj == null` (L6536)

> Determines whether a BP-level return code was previously set. If not set (null), default to -1 (indicating no prior BP status).

| # | Type | Code |
|---|------|------|
| 1 | IF | `obj == null` |
| 2 | SET | `bpStatus = -1` // No prior BP status set |
| 3 | ELSE | |
| 4 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse BP-level return code |

**Block 9** — [IF] `(status precedence)` `templateStatus > bpStatus` (L6542)

> Compares SC-level status against BP-level status. If the SC status is numerically higher (more severe), override the BP's return code and return message with the SC's values. This implements a "worst status wins" policy.
>
> Comment: BPにサービスコンポーネントのステータスを設定する。(Set SC status on BP.)

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Format status as 4-digit zero-padded string (e.g., "0001") |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Fetch corresponding return message |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Set formatted status |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Set status message |

**Block 10** — [ASSIGN] `(error information collection)` (L6548)

> Extracts error fields from the SC response message schema (keys ending in `_err`) and stores them in the data map.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `setErrorInf(msg, (HashMap<String, Object>)param.getData(dataMapKey))` // Collect _err fields from SC response |

**Block 11** — [ASSIGN] `(error list preparation)` (L6551)

> Retrieves the existing error list from the control map or creates a new one.

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

**Block 12** — [IF] `(error list initialization)` `errList == null` (L6552)

> If no error list existed, initialize an empty one.

| # | Type | Code |
|---|------|------|
| 1 | SET | `errList = new ArrayList<Object>()` // Create new empty error list |

**Block 13** — [ASSIGN] `(error info aggregation)` (L6556)

> Aggregates error information from the SC result and stores it back in the control map.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(result, errList))` // Set aggregated error info |

**Block 14** — [ASSIGN] `(result validation extraction)` (L6560)

> Reads back the return code and status from the result for final validation.
>
> Comment: 処理結果の判定 (Determine processing result) / 取得したリターンコード、ステータスの内容を見て異常かどうかの判定をする。(Check if abnormal based on returned code and status.)

| # | Type | Code |
|---|------|------|
| 1 | SET | `rtnCode = result.get(JCMConstants.RET_CD_INT_KEY).toString()` // Return code as string |
| 2 | SET | `status = msg.getInt(JCMConstants.STATUS_INT_KEY)` // Status from message |

**Block 15** — [IF] `(exception throw condition)` `"0".equals(rtnCode) && 0 == status.intValue()` negated (L6563)

> If the return code is non-zero OR the status is non-zero, the SC execution is considered abnormal. An `SCCallException` is thrown with the Japanese message "戻値不正" (Return value invalid) along with the actual return code and status.
>
> Comment: 異常の場合、SCCallExceptionを生成してスローする。(In case of abnormality, generate and throw SCCallException.)

| # | Type | Code |
|---|------|------|
| 1 | THROW | `throw new SCCallException("戻値不正", rtnCode, status)` // "Return value invalid" — Throw exception with return code and status details |

**Block 16** — [RETURN] `(success path)` (L6565)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return msg` // Return the primary CAANMsg response to caller |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| SC | Acronym | Service Component — a Fujitsu EJB-based service module that performs business logic operations (e.g., data validation, CRUD, external system calls). |
| BP | Acronym | Business Process — the top-level business screen/transaction in the K-Opticom system. |
| CAANMsg | Technical | CAAN Message — a message object carrying structured data fields and a schema definition, used as the request/response container for SC invocations. |
| CAANSchemaInfo | Technical | Base class for CAANMsg that defines the schema (field names and types) of a message. |
| ECK0011A010CBSMsg | Technical | CBS (Call-Based Service) message class for the customer consent inquiry service. Contains fields: `TEMPLATEID`, `STATUS`, `OPERATORID`, `OPERATEDATE`, `OPERATEDATETIME`, etc. |
| JCMConstants | Technical | Constants class for JCM (Java Component Message) — defines keys like `TEMPLATE_LIST_KEY`, `RET_CD_INT_KEY`, `STATUS_INT_KEY` used to access SC result data. |
| JCMAPLConstMgr | Technical | Constant manager for JCM Application Platform — provides `getString()` lookup for application-level message strings keyed by name (e.g., `RETURN_MESSAGE_0001`). |
| SCControlMapKeys | Technical | Constants class for SC control map data keys — defines keys like `RETURN_CODE`, `RETURN_MESSAGE`, `ERROR_INFO`, `REQ_HOSTNAME`, `REQ_HOSTIP`, `REQ_VIEWID`, `OPERATOR_ID`, `OPE_DATE`, `OPE_TIME`. |
| RETURN_CODE | Field | Control map key for the return/status code returned by the SC or set by the BP. |
| RETURN_MESSAGE | Field | Control map key for the human-readable message corresponding to a return code. |
| ERROR_INFO | Field | Control map key for a list of error information objects aggregated from SC responses. |
| templateStatus | Field | Status integer extracted from the SC response message — indicates the processing outcome (0 = normal, 9000 = SC error, other values = specific error codes). |
| bpStatus | Field | BP-level return code retrieved from the control map — represents any status previously set by the calling business process logic. |
| formatStatus | Field | Status formatted as a 4-digit zero-padded string (e.g., `0001`, `9000`) used for message lookup and storage. |
| rtnCode | Field | Return code from the SC result as a string — `"0"` indicates success, any other value indicates an error condition. |
| mappingData[i][0] | Field | Column 0 of the mapping table — the target field name in the SC request message. |
| mappingData[i][1] | Field | Column 1 of the mapping table — the value to assign to the field; also `mappingData[0][1]` serves as the service interface name. |
| SCCallException | Technical | Custom exception thrown when an SC call returns an abnormal condition (non-zero return code or non-zero status). |
| エラー情報のマップを取得 | Comment | Acquire error information map — the process of extracting error fields from the SC result and aggregating them into a controlled error list. |
| 処理結果の判定 | Comment | Determine processing result — the final validation step that checks return code and status to decide whether to throw an exception or return successfully. |
| 戻値不正 | Comment | "Return value invalid" — the error message embedded in SCCallException when the SC result is deemed abnormal. |
| サービスコンポーネントのステータスを設定する | Comment | Set SC status on BP — the operation of overriding BP-level return code/message with SC-level values when SC status is more severe. |
