# Business Logic — JKKAdchgKakuteiKikiDslCC.callSC() [75 LOC]

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

## 1. Role

### JKKAdchgKakuteiKikiDslCC.callSC()

`callSC` is a **private reusable bridge method** that delegates to an arbitrary Service Component (SC) in a standardized, uniform manner. Its business purpose is to **wrap the invocation of any SC behind a consistent pattern**: parameter assembly (via `editInMsg`), SC dispatch via `ServiceComponentRequestInvoker.run()`, result extraction, return code normalization, status-based message lookup from the localization manager (`JCMAPLConstMgr`), error information consolidation (via `TemplateErrorUtil.getErrorInfo`), and finally result judgment with exception throwing on failure.

The method implements the **delegation and routing design patterns** — it accepts a `ServiceComponentRequestInvoker` instance that encapsulates the actual SC to invoke, along with the `Object[][] mappingData` that encodes the SC's CBS interface name. The caller is responsible for configuring the `scCall` and `mappingData` to target a specific SC (e.g., `EKK1681B001CBS` or `EKK1681C040CBS`), while `callSC` handles all cross-cutting concerns uniformly: HTTP header propagation (transaction ID, use case ID, operator ID, host name, IP, screen ID), control map data coordination (return code, return message, error info), and error classification.

The `JCMAPLConstMgr.getString` calls reference localized return messages keyed by the `RETURN_MESSAGE_<4-digit-status>` pattern, meaning the framework uses a resource-based message catalog to resolve status messages (e.g., `RETURN_MESSAGE_0000` for success, `RETURN_MESSAGE_9000` for SC-level failures). The method compares template status against a BP-local status (`bpStatus`), adopting the service's status only when the SC's status is "worse" (higher numeric value), which implements a priority escalation pattern where the service component's error supersedes local BP error state.

This method is **called exclusively from within `JKKAdchgKakuteiKikiDslCC.executeKikiDsl`** (the DSL execution entry point), which is itself triggered by the screen operation `KKSV0325OPOperation` via `CCRequestBroker target15`. In the larger system, this CC handles "change confirmation trigger" processing (変更確定契機) — i.e., it determines whether a service contract change should trigger downstream operations (such as exception contract reconciliation or IDO reservation notifications).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["callSC params"])
    START --> STEP1["Step 1: Build paramMap via editInMsg"]
    STEP1 --> STEP2["Step 2: Invoke SC - scCall.run"]
    STEP2 --> STEP3["Step 3: Extract CAANMsg from result"]
    STEP3 --> STEP4["Step 4: Get returnCode and templateStatus"]
    STEP4 --> COND1{returnCode != 0}
    COND1 -->|Yes| SET_ERR["Set templateStatus = 9000"]
    COND1 -->|No| COND2{Valid RETURN_MESSAGE}
    SET_ERR --> COND2
    COND2 -->|No| RESET_STATUS["Set templateStatus = 0"]
    RESET_STATUS --> COND_BP{bpStatus source null}
    COND2 -->|Yes| COND_BP{bpStatus source null}
    COND_BP -->|Yes| BP_NEG1["bpStatus = -1"]
    COND_BP -->|No| BP_PARSE["bpStatus = Integer.parseInt"]
    BP_NEG1 --> COND3{templateStatus > bpStatus}
    BP_PARSE --> COND3
    COND3 -->|Yes| UPDATE_CTRL["Update RETURN_CODE and RETURN_MESSAGE"]
    COND3 -->|No| SKIP_CTRL["Skip status update"]
    UPDATE_CTRL --> SET_INF["Call setErrorInf"]
    SKIP_CTRL --> SET_INF
    SET_INF --> ERR_READ["Read errList from control map"]
    ERR_READ --> ERR_INIT{errList == null}
    ERR_INIT -->|Yes| ERR_CREATE["Create new ArrayList"]
    ERR_INIT -->|No| ERR_EXIST["Use existing errList"]
    ERR_CREATE --> ERR_SET["Set ERROR_INFO via TemplateErrorUtil"]
    ERR_EXIST --> ERR_SET
    ERR_SET --> RESULT_CHECK{rtnCode is zero and status is 0}
    RESULT_CHECK -->|Yes| RETURN_MSG["Return msg"]
    RESULT_CHECK -->|No| THROW["Throw SCCallException"]
    RETURN_MSG --> END(["End"])
    THROW --> END
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | The EJBC session handle providing runtime context (connection, transaction) for the SC invocation. Used as-is when dispatching `scCall.run(paramMap, handle)`. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | A prepared service invoker bound to a specific SC CBS class. Encapsulates which service component to call and how to serialize/deserialize its request/response payloads. |
| 3 | `param` | `IRequestParameterReadWrite` | The request parameter carrier holding operational context (operator ID, operation date/time, host name, IP address, screen ID) and control map data (return code, return message, error info). Acts as both input source and output carrier for cross-component coordination. |
| 4 | `dataMapKey` | `String` | A key into the parameter's data map — used to retrieve the target HashMap that `setErrorInf` populates with error information. Acts as a namespace for per-SC error data buckets. [-> JCMConstants keys for data map access] |
| 5 | `mappingData` | `Object[][]` | A 2D array where each row defines a field-to-value mapping for building the SC request. The first row `[0][1]` is the CBS interface name (`svcIf`) used to construct the CAANMsg template path. Each subsequent row contains `[{field_constant}, {value}]` pairs. |

**External state / instance fields read:** None directly. All external dependencies are injected via parameters or accessed through static/utility classes (`JCMAPLConstMgr`, `JCMConstants`, `TemplateErrorUtil`, `SCControlMapKeys`).

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `ServiceComponentRequestInvoker.run` | (dynamic — caller-configured) | (dynamic — caller-configured) | Invokes the target service component with a fully assembled parameter map. The actual SC Code and entity depend on the `mappingData[0][1]` CBS interface name (e.g., `EKK1681B001CBS` maps to SC Code `EKK1681B001`). This method is the generic SC dispatcher used by all callers. |
| U | `JKKAdchgKakuteiKikiDslCC.editInMsg` | - | - | Assembles the request parameter map by extracting headers from the Telegram and user control map data, then constructing a typed `CAANMsg` template and populating it with operator ID, operation date, and operation time. |
| U | `JKKAdchgKakuteiKikiDslCC.setErrorInf` | - | - | Populates error information into the data map identified by `dataMapKey`. Called after the SC completes to propagate any errors from the SC response into the calling context. |
| R | `TemplateErrorUtil.getErrorInfo` | - | - | Extracts and consolidates error information from the SC result map into an `ArrayList<Object>` using the existing error list as a base. Reads the result from the service component's response. |

**SC Code inference from callers:**
The callers of `callSC` (within `executeKikiDsl`) invoke it with `mappingData` targeting specific CBS classes:

| Caller Context | CBS Interface (mappingData[0][1]) | Inferred SC Code | Business Operation |
|---------------|-----------------------------------|------------------|-------------------|
| `executeKikiDsl` — anomaly contract reconciliation | `EKK1681B001CBS` | `EKK1681B001` | Fetch anomaly (discrepancy) contract details |
| `executeKikiDsl` — reservation date update | `EKK1681C040CBS` | `EKK1681C040` | Update reservation application date |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 2 methods (both in `JKKAdchgKakuteiKikiDslCC`).
Terminal operations from this method: `run` [-] (SC dispatch), `editInMsg` [U], `setErrorInf` [U], `getErrorInfo` [R].

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKSV0325 | `KKSV0325OPOperation` -> CCRequestBroker target15 -> `JKKAdchgKakuteiKikiDslCC.executeKikiDsl` -> `callSC` (EKK1681B001CBS / EKK1681C040CBS) | `scCall.run [R/U] (dynamic SC)` |

**Caller details:**
- `callSC` is a **private** method. All callers reside in `JKKAdchgKakuteiKikiDslCC.executeKikiDsl` (lines 1559 and 1574 of the source).
- `executeKikiDsl` is invoked by screen `KKSV0325` (likely a "Service Contract Change Confirmation" screen) via the `CCRequestBroker` mechanism. The broker routes through `KKSV0325OPOperation.target15` which targets `JKKAdchgKakuteiKikiDslCC.executeKikiDsl` with screen class `KKSV032513CC`.

## 6. Per-Branch Detail Blocks

**Block 1** — [EXEC] `editInMsg(param, mappingData)` (L1608)

> Assembles the request parameter map from the current Telegram headers and user control map data, then constructs a typed CAANMsg template for the SC. This is a private helper method that builds `paramMap`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `editInMsg(param, mappingData)` → `HashMap<String, Object>` |

**Block 2** — [EXEC] `scCall.run(paramMap, handle)` (L1610)

> Dispatches to the target service component. The actual SC is determined by how `scCall` was configured by the caller (via `ServiceComponentRequestInvoker` preparation in `executeKikiDsl`).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `scCall.run(paramMap, handle)` → `Map<?, ?> result` |

**Block 3** — [SET] Extract CAANMsg from result map (L1612-1613)

| # | Type | Code |
|---|------|------|
| 1 | SET | `CAANMsg[] templates = (CAANMsg[])result.get(JCMConstants.TEMPLATE_LIST_KEY)` // Extract the list of CAANMsg templates from the SC result [-> JCMConstants.TEMPLATE_LIST_KEY] |
| 2 | SET | `CAANMsg msg = templates[0]` // Take the first template as the response message |

**Block 4** — [SET] Get return code and template status (L1616-1617)

> Extracts the return code and template status from the SC result. The return code indicates SC-level execution result; template status is a screen/application-level status code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `int returnCode = (Integer)result.get(JCMConstants.RET_CD_INT_KEY)` // Get return code [-> JCMConstants.RET_CD_INT_KEY] |
| 2 | SET | `int templateStatus = msg.getInt(JCMConstants.STATUS_INT_KEY)` // Get template status [-> JCMConstants.STATUS_INT_KEY] |

**Block 5** — [IF] Return code is non-zero — override template status to error (L1619-1622)

> If the SC returned a non-zero return code, this overrides the template status to `9000`, which represents an SC-level failure. This ensures that even if the individual template's status is OK, a system-level return code failure will be detected.

| # | Type | Code |
|---|------|------|
| 1 | COND | `0 != returnCode` |
| 2 | SET | `templateStatus = 9000` // Override status to SC error code |

**Block 6** — [IF] Validate return message exists for template status (L1624-1627)

> Queries the localized message catalog (`JCMAPLConstMgr.getString`) for `RETURN_MESSAGE_<4-digit-templateStatus>`. If no message exists for the current template status, the status is reset to `0`. This acts as a sanity check — if the system has no defined message for a status, the status is considered invalid and normalized to success (0).

| # | Type | Code |
|---|------|------|
| 1 | COND | `null == JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus))` // Check if a localized message exists for this status [-> RETURN_MESSAGE_XXXX pattern] |
| 2 | SET | `templateStatus = 0` // Reset to success — no message defined means treat as OK |

**Block 7** — [IF/ELSE] Calculate bpStatus from control map (L1629-1638)

> Reads the BP-local return code from the control map. If absent (null), sets `bpStatus` to `-1` (meaning no local status has been set yet, so any SC status should override). If present, parses the string to an integer. This enables comparison: if the SC status is "worse" than the local status, the SC status takes priority.

| # | Type | Code |
|---|------|------|
| 1 | SET | `int bpStatus = 0` // Initialize BP status to zero |
| 2 | EXEC | `Object obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Read BP return code [-> SCControlMapKeys.RETURN_CODE] |
| 3 | IF | `null == obj` |
| 4 | SET | `bpStatus = -1` // No local status set |
| 5 | ELSE | — |
| 6 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse existing local status |

**Block 8** — [IF] Template status supersedes BP status — update control map (L1640-1646)

> If the SC's template status is numerically higher (worse) than the BP's own status, adopt the SC's status and fetch the corresponding localized message. This ensures error statuses always propagate upward. The formatted status (`"%1$04d"`) is stored back as a 4-digit string, and the localized message is retrieved via `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)`.

| # | Type | Code |
|---|------|------|
| 1 | COND | `templateStatus > bpStatus` |
| 2 | SET | `String formatStatus = String.format("%1$04d", templateStatus)` // Format status as 4-digit zero-padded string |
| 3 | SET | `String message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Fetch localized message [-> RETURN_MESSAGE_XXXX pattern] |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Store formatted status [-> SCControlMapKeys.RETURN_CODE] |
| 5 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Store localized error message [-> SCControlMapKeys.RETURN_MESSAGE] |

**Block 9** — [EXEC] Propagate errors to data map (L1648)

> Calls the `setErrorInf` helper method to populate the data map (keyed by `dataMapKey`) with error information extracted from the SC response message. This is a side-effect operation that enriches the calling context with error details.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `setErrorInf(msg, (HashMap<String, Object>)param.getData(dataMapKey))` |

**Block 10** — [IF/ELSE] Initialize or reuse error list (L1651-1656)

> Reads the existing error list from the control map. If null, creates a fresh `ArrayList<Object>`. This supports incremental error accumulation across multiple SC calls within the same request flow.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ArrayList<Object> errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO)` // Read existing error list [-> SCControlMapKeys.ERROR_INFO] |
| 2 | IF | `null == errList` |
| 3 | SET | `errList = new ArrayList<Object>()` // Initialize new error list |

**Block 11** — [EXEC] Consolidate error info via utility (L1659)

> Delegates to `TemplateErrorUtil.getErrorInfo(result, errList)` to extract and consolidate error information from the SC result map. The existing error list is passed as a base so errors from prior SC calls are preserved. The result replaces the control map's `ERROR_INFO` entry.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(result, errList))` // Consolidate errors [-> SCControlMapKeys.ERROR_INFO] |

**Block 12** — [IF] Final result judgment — throw exception on failure (L1664-1668)

> Performs the ultimate success/failure determination. Both the return code MUST be `"0"` AND the template status MUST be `0` for the invocation to be considered successful. If either condition fails, an `SCCallException` is thrown with the literal message "返回值不正" (return value abnormal/invalid), the return code string, and the status integer.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String rtnCode = result.get(JCMConstants.RET_CD_INT_KEY).toString()` // Re-read return code as string [-> JCMConstants.RET_CD_INT_KEY] |
| 2 | SET | `Integer status = msg.getInt(JCMConstants.STATUS_INT_KEY)` // Re-read status from message [-> JCMConstants.STATUS_INT_KEY] |
| 3 | COND | `!("0".equals(rtnCode) && 0 == status.intValue())` |
| 4 | SET | `SCCallException scCallEx = new SCCallException("返回值不正", rtnCode, status)` // "返回值不正" = return value abnormal |
| 5 | EXEC | `throw scCallEx` |

**Block 13** — [RETURN] Return the SC response message (L1669)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return msg` // Return the CAANMsg from the SC |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| SC | Acronym | Service Component — a Fujitsu BP (Business Platform) service component that encapsulates a specific business operation as a CBS (Business Common Service) call |
| CC | Acronym | Common Component — a shared Java class providing reusable business logic across screen CBS handlers |
| CBS | Acronym | Business Common Service — the service layer that wraps database/entity operations and SC calls |
| CAANMsg | Technical | CAAN (Common Application Architecture Network) Message — the message object used for SC request/response payloads in the Fujitsu BP framework |
| DSL | Acronym | Domain-Specific Language — in this context, a DSL execution mechanism (`KKDslRunCC`) that routes and executes business logic based on configuration |
| CCRequestBroker | Technical | A routing mechanism that invokes a target CC method by class name, method name, and screen class name |
| Template Status | Field | Application-level status code returned by an SC. Values like `0` (success), `9000` (SC error) are used. Looked up in `JCMAPLConstMgr` for localization via `RETURN_MESSAGE_XXXX` keys. |
| Return Code (returnCode) | Field | SC-level execution return code extracted from the SC result map. `0` indicates success; non-zero indicates SC-level failure. |
| bpStatus | Field | BP-local return code stored in the control map. Represents the cumulative error state from prior processing steps within the same request. Higher numeric values = worse status. |
| editInMsg | Method | Private helper that builds the SC request parameter map by extracting Telegram headers (transaction ID, use case ID, operation ID, call type) and user control map data (hostname, IP, screen ID, operator ID, operation date/time), then constructing a typed CAANMsg template. |
| setErrorInf | Method | Private helper that populates the data map with error information from the SC response message. |
| TemplateErrorUtil.getErrorInfo | Utility | Extracts error information from the SC result map and consolidates it with any existing error list, supporting incremental error accumulation across multiple SC calls. |
| JCMConstants | Constant class | Framework constants for keys in request/result maps (TEMPLATE_LIST_KEY, STATUS_INT_KEY, RET_CD_INT_KEY, TRANZACTION_ID_KEY, USECASE_ID_KEY, etc.) |
| JCMAPLConstMgr | Utility class | Localized constant/message manager. `getString(key)` retrieves localized strings from a resource catalog, e.g., `RETURN_MESSAGE_0000` for success, `RETURN_MESSAGE_9000` for SC errors. |
| SCControlMapKeys | Constant class | Keys for the control map used by SC framework (RETURN_CODE, RETURN_MESSAGE, ERROR_INFO, REQ_HOSTNAME, REQ_HOSTIP, REQ_VIEWID, OPERATOR_ID, OPE_DATE, OPE_TIME) |
| EKK1681B001CBS | CBS class | Contract-related CBS (EKK prefix) for anomaly/discrepancy contract reconciliation. Invoked with reconciliation function code, reservation detail code `013`, and key reservation status code. |
| EKK1681C040CBS | CBS class | Contract-related CBS for updating reservation application dates. Takes IDO reservation number, reservation application date, and pre-update datetime. |
| dataMapKey | Parameter | Namespace key for per-SC error data bucket in the parameter's data map |
| mappingData | Parameter | 2D mapping array where `mappingData[0][1]` holds the CBS interface name (e.g., `EKK1681B001CBS`) used to construct the CAANMsg template path `eo.ejb.cbs.cbsmsg.{svcIf}CBSMsg` |
| 変更確定契機 | Japanese term | "Change confirmation trigger" — the business context for this CC. Determines whether service contract changes require downstream actions (reconciliation, notifications). |
| 返回值不正 | Japanese/Chinese literal | "Return value abnormal" — the error message embedded in `SCCallException` when the SC returns a non-success result |
