# Business Logic — JKKKikiKaifukuWrisvcCC.callSC() [37 LOC]

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

## 1. Role

### JKKKikiKaifukuWrisvcCC.callSC()

This method is the central dispatch hub for invoking Service Component (SC) business logic within the Fujitsu Futurity order management system. It executes a generic, re-entrant pattern whereby an arbitrary SC — identified at call-site by the `ServiceComponentRequestInvoker` instance (`scCall`) — is invoked with a prepared parameter map and session handle, then normalizes the response into a canonical `CAANMsg` return value.

Concretely, `callSC` performs a four-step lifecycle: **(1) Request preparation** — it delegates parameter serialization to `editInMsg()`, converting request-level input data into a `HashMap` suitable for SC consumption; **(2) SC invocation** — it calls the injected `ServiceComponentRequestInvoker.run()` method, which routes the request to the actual CBS/SC implementation (the specific service type is determined by the caller that constructed the `scCall` instance); **(3) Response normalization** — it extracts the response template array from the result map, takes the first template as the canonical message, and pulls back the return code and status fields; **(4) Error handling** — it delegates error-info accumulation to `editErrorInfoCom()`, refreshes the error control map via `TemplateErrorUtil.getErrorInfo()`, and validates the final status. If either the return code is non-zero or the status field is non-zero, the method throws an `SCCallException` with the returned code and status as diagnostic context.

The method implements a **delegation and routing** pattern: callers supply both the SC invoker and the parameter map, making `callSC` agnostic to the specific service type being invoked. This makes it a true utility shared across multiple screenCBS methods (e.g., `execKikiKaifukuWrisvc()` for service recovery and `execKikiTorokuWrisvc()` for service registration), eliminating duplication in the common request-response cycle.

The business purpose is universal across all callers: it executes the requested service operation and returns the structured message, or fails fast with a typed exception carrying the SC return code and application status.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["callSC(params)"])
    
    START --> STEP1["editInMsg(param, mappingData)"]
    
    STEP1 --> STEP2["paramMap = editInMsg()"]
    
    STEP2 --> STEP3["scCall.run(paramMap, handle)"]
    
    STEP3 --> STEP4["result = scCall.run()"]
    
    STEP4 --> STEP5["templates = result.get(TEMPLATE_LIST_KEY)"]
    
    STEP5 --> STEP6["msg = templates[0]"]
    
    STEP6 --> STEP7["return_code = result.get(RET_CD_INT_KEY)"]
    
    STEP7 --> STEP8["status = msg.getInt(STATUS_INT_KEY)"]
    
    STEP8 --> STEP9["editErrorInfoCom(param, templates, return_code, dataMapKey, mappingData)"]
    
    STEP9 --> STEP10["errList = param.getControlMapData(ERROR_INFO)"]
    
    STEP10 --> NESTED1{"errList == null?"}
    
    NESTED1 -->|true| STEP11["errList = new ArrayList<Object>()"]
    NESTED1 -->|false| STEP12["use existing errList"]
    
    STEP11 --> STEP13["param.setControlMapData(ERROR_INFO, TemplateErrorUtil.getErrorInfo(result, errList))"]
    STEP12 --> STEP13
    
    STEP13 --> CHECK{"return_code != 0 OR status != 0?"}
    
    CHECK -->|true| THROW["throw SCCallException"]
    CHECK -->|false| RETURN["return msg"]
    
    THROW --> END(["End / Next"])
    RETURN --> END
```

**Constant Resolution Notes:**
- `JCMConstants.TEMPLATE_LIST_KEY` — key to retrieve the `CAANMsg[]` template array from the SC result map. (Constant class is in library dependency; exact string value not available in source.)
- `JCMConstants.RET_CD_INT_KEY` — key to retrieve the integer return code from the SC result map. (Return code `"0"` indicates success.)
- `JCMConstants.STATUS_INT_KEY` — key to retrieve the application status code from the `CAANMsg` template. (`0` indicates no error.)
- `SCControlMapKeys.ERROR_INFO` — key used to store/retrieve error information list in the parameter control map.

**Design Pattern:** This method follows a **Template Method + Delegation** pattern. The structure (prepare, invoke, normalize, validate) is fixed and shared by all callers. The actual service type is abstracted via the `ServiceComponentRequestInvoker` parameter, making `callSC` a universal SC dispatching utility.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | The session context carrying the user's database connection and transaction state. Used to route the SC request to the correct data source and transaction scope. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | The service component invoker instance that encapsulates the specific CBS/SC to execute. Each caller constructs an appropriate invoker (e.g., for service recovery, service registration). The specific service type is determined at call-site, not within this method. |
| 3 | `param` | `IRequestParameterReadWrite` | The request parameter object that carries input data for the SC operation and receives output/error data via its control map. It is the primary data carrier between the screen/CBS layer and the SC layer. |
| 4 | `dataMapKey` | `String` | A key used by `editErrorInfoCom` to correlate error information with a specific data scope. Passed through to the error-info accumulation method without modification. |
| 5 | `mappingData` | `Object[][]` | A 2D mapping array that encodes field-level mappings between request parameters and internal data structures. Passed to `editInMsg()` for parameter preparation. |

**External State / Instance Fields Read:**
- None directly. This method is stateless; it relies entirely on passed parameters and static constants.

## 4. CRUD Operations / Called Services

All method calls in `callSC` are either internal utility calls within the same class, or invocations through the SC framework. No direct entity/DB table access occurs at this level — all persistence is delegated to the invoked SC.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| CALL | `editInMsg` (internal) | JKKKikiKaifukuWrisvcCC | - | Prepares and returns the `paramMap` HashMap from request parameters and mapping data for SC consumption. |
| R | `scCall.run(paramMap, handle)` | (Determined by caller; e.g., EKK0361A010SC, EKK0361A020SC) | (Depends on invoked SC) | Invokes the actual Service Component business logic. The SC type is determined by the caller's `scCall` instance. The pre-computed callers `execKikiKaifukuWrisvc()` and `execKikiTorokuWrisvc()` suggest this is used for both service recovery (Kaifuku) and service registration (Toroku) operations. |
| CALL | `editErrorInfoCom` (internal) | JKKKikiKaifukuWrisvcCC | - | Accumulates error information from the SC response into the parameter's error tracking structures. |
| R | `TemplateErrorUtil.getErrorInfo(result, errList)` | (Library utility) | - | Extracts and consolidates error details from the SC result map into the error list for downstream error reporting. |

**CRUD classification rationale:**
- The method itself performs no direct Create/Read/Update/Delete operations on entities or database tables.
- It acts as a **wrapper** around the SC invocation — all actual CRUD is performed by the SC that `scCall.run()` delegates to.
- The SC invoked is determined by the caller: `execKikiKaifukuWrisvc()` calls `callSC` in the context of service recovery, while `execKikiTorokuWrisvc()` calls it for service registration.

## 5. Dependency Trace

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

Direct callers: 2 methods (within `JKKKikiKaifukuWrisvcCC`).
Terminal operations from this method: `editInMsg` [CALL], `scCall.run` [R (delegated)], `editErrorInfoCom` [CALL], `getErrorInfo` [R].

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS:JKKKikiKaifukuWrisvcCC.execKikiKaifukuWrisvc | `execKikiKaifukuWrisvc` -> `callSC` | SC-invoked operation (service recovery) |
| 2 | CBS:JKKKikiKaifukuWrisvcCC.execKikiTorokuWrisvc | `execKikiTorokuWrisvc` -> `callSC` | SC-invoked operation (service registration) |

**Call chain details:**
- **execKikiKaifukuWrisvc** — Executed in the context of **service recovery** (起復 = restoration/recovery). The caller constructs a `ServiceComponentRequestInvoker` targeting the service recovery SC, passes in the parameter map, and invokes `callSC` to execute the SC and process the result.
- **execKikiTorokuWrisvc** — Executed in the context of **service registration** (登録 = registration). The caller constructs a `ServiceComponentRequestInvoker` targeting the service registration SC and delegates the invoke to `callSC`.

Both callers follow the same pattern: prepare parameters, invoke `callSC`, and propagate the returned `CAANMsg` or handle the `SCCallException`.

## 6. Per-Branch Detail Blocks

**Block 1** — [EXEC/ASSIGN] Parameter preparation (L437)

> Prepares the parameter map by delegating to `editInMsg()`, which serializes request parameters and mapping data into a HashMap for SC consumption.

| # | Type | Code |
|---|------|------|
| 1 | ASSIGN | `paramMap = editInMsg(param, mappingData)` | `editInMsg` method converts the `IRequestParameterReadWrite` and `Object[][]` mappingData into a `HashMap<String, Object>` parameter map for the SC invocation. |
| 2 | ASSIGN | `paramMap = new HashMap<>(...)` | Internal to `editInMsg` — creates the return map. |

---

**Block 2** — [EXEC/ASSIGN] SC invocation (L440)

> Invokes the actual Service Component business logic through the `ServiceComponentRequestInvoker.run()` method.

| # | Type | Code |
|---|------|------|
| 1 | ASSIGN | `result = scCall.run(paramMap, handle)` | The `ServiceComponentRequestInvoker.run()` method routes the request to the specific CBS/SC. The result map contains: `TEMPLATE_LIST_KEY` (CAANMsg array), `RET_CD_INT_KEY` (return code). |

---

**Block 3** — [ASSIGN] Response extraction (L442-L446)

> Extracts the response template message and return code/status from the SC result map.

| # | Type | Code |
|---|------|------|
| 1 | ASSIGN | `templates = (CAANMsg[])result.get(JCMConstants.TEMPLATE_LIST_KEY)` | Retrieves the `CAANMsg[]` template array from the result map. Contains the response message objects. |
| 2 | ASSIGN | `msg = templates[0]` | Takes the first template as the canonical response message. |
| 3 | ASSIGN | `return_code = result.get(JCMConstants.RET_CD_INT_KEY)` | Retrieves the SC return code object. `"0"` indicates success. (Japanese comment: リターンコード取得 — "Retrieve return code") |
| 4 | ASSIGN | `status = msg.getInt(JCMConstants.STATUS_INT_KEY)` | Reads the application-level status code from the message. `0` indicates no error. |

---

**Block 4** — [EXEC] Error info accumulation (L448)

> Delegates error-info accumulation to the internal `editErrorInfoCom` method.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `editErrorInfoCom(param, templates, (Integer)return_code, dataMapKey, mappingData)` | Accumulates error information from the SC response (templates and return code) into the parameter's error tracking structures. |

---

**Block 5** — [ASSIGN] Error list retrieval (L451-L454)

> Retrieves or initializes the error information list from the parameter's control map. (Japanese comment: エラー情報のマップを取得 — "Retrieve the error information mapping")

| # | Type | Code |
|---|------|------|
| 1 | ASSIGN | `errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO)` | Retrieves the existing error list from the control map, or `null` if none has been set yet. |
| 2 | IF | `if (errList == null)` | Checks if the error list was initialized. |

---

**Block 5.1** — [ASSIGN] Error list initialization (L453-L454)

> Nested inside Block 5's IF branch — initializes a new empty error list if none existed.

| # | Type | Code |
|---|------|------|
| 1 | ASSIGN | `errList = new ArrayList<Object>()` | Creates a fresh error list when the control map did not yet contain one. |

---

**Block 6** — [EXEC] Error info refresh (L457)

> Refreshes the error information in the parameter control map using `TemplateErrorUtil.getErrorInfo()`. (Japanese comment: コントロールマップに設定 — "Set in the control map")

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(result, errList))` | Consolidates error details from the SC result map and the existing error list, then stores the consolidated result back into the parameter's control map for downstream error reporting. |

---

**Block 7** — [IF/THROW] Status validation (L460-L462)

> Validates the SC response status. If the return code is non-zero OR the status is non-zero, throws an `SCCallException`. (Japanese comment: 異常の場合、SCCallExceptionを生成してスローする — "In case of abnormality, generate and throw SCCallException")

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (!("0".equals(return_code.toString()) && 0 == status))` | Condition: return code is not `"0"` OR status is not `0`. Either indicates an error occurred during SC execution. |
| 2 | THROW | `throw new SCCallException("戻値不正", return_code.toString(), status)` | Throws `SCCallException` with the message "戻値不正" (Invalid return value), the return code string, and the status integer. |

---

**Block 8** — [RETURN] Success path (L463)

> Returns the canonical response message to the caller when no error was detected.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return msg` | Returns the first `CAANMsg` template from the SC response. This message contains the structured output data for the calling CBS/screen. |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| SC | Acronym | Service Component — a business logic component in the Fujitsu Futurity framework that encapsulates CBS/SC operations for order management. |
| CBS | Acronym | Component-Based System — the middleware layer where SCs are deployed and executed. |
| CAANMsg | Acronym | CAAN Message — the standard message type used for request/response data exchange between CBS and SC layers. Contains typed fields (int, string, etc.) and templates. |
| ServiceComponentRequestInvoker | Class | The invoker that routes SC requests. Each instance is bound to a specific SC service type. |
| IRequestParameterReadWrite | Interface | The parameter carrier that holds input data for SC operations and receives output/error data via control maps. |
| SessionHandle | Class | Session context carrying database connection and transaction state for the current user session. |
| `editInMsg` | Method | Internal method that prepares the parameter map from request parameters and mapping data. |
| `editErrorInfoCom` | Method | Internal method that accumulates error information from SC responses into the parameter's error tracking structures. |
| `TemplateErrorUtil.getErrorInfo` | Method | Utility that extracts and consolidates error details from the SC result map. |
| `SCCallException` | Class | Custom exception thrown when an SC invocation returns a non-success status. Carries the return code and status as diagnostic context. |
| `戻値不正` | Japanese field | "Invalid return value" — error message thrown when the SC return code or status is non-zero. |
| リターンコード取得 | Japanese comment | "Retrieve return code" — comment at the line extracting `return_code` from the result map. |
| エラー情報のマップを取得 | Japanese comment | "Retrieve the error information mapping" — comment at the block retrieving error list from the control map. |
| コントロールマップに設定 | Japanese comment | "Set in the control map" — comment at the block storing error info back to the control map. |
| 異常の場合、SCCallExceptionを生成してスローする | Japanese comment | "In case of abnormality, generate and throw SCCallException" — comment at the status validation block. |
| TEMPLATE_LIST_KEY | Constant | Key in the SC result map to retrieve the `CAANMsg[]` template array. |
| RET_CD_INT_KEY | Constant | Key in the SC result map to retrieve the integer return code. `"0"` = success. |
| STATUS_INT_KEY | Constant | Key in the `CAANMsg` to retrieve the application-level status code. `0` = no error. |
| ERROR_INFO | Constant | Key in the parameter control map used to store/retrieve the error information list. |
| SCControlMapKeys | Class | Constant class defining keys for parameter control map entries. |
| JCMConstants | Class | Constant class defining keys for result map entries. (JCM = Fujitsu Futurity Common Constants library.) |
| 起復 (Kaifuku) | Japanese term | Service recovery/restoration — the business operation of recovering or reinstating a service (e.g., after suspension). |
| 登録 (Toroku) | Japanese term | Service registration — the business operation of registering or activating a new service. |
| execKikiKaifukuWrisvc | Method | CBS method that handles service recovery workflow and delegates to `callSC`. |
| execKikiTorokuWrisvc | Method | CBS method that handles service registration workflow and delegates to `callSC`. |
