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

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

## 1. Role

### JKKTvSvcKeiCancelCC.callSC()

`callSC` is the central service component execution wrapper for the telecom service cancellation system. Its business purpose is to serve as a **single, unified dispatch mechanism** that invokes any service component (SC) — which may handle FTTH authorization changes, mail order additions, ENUM service changes, or various other telecom service modifications — and normalizes the response across all callers. The method implements a **delegate pattern**: it receives a pre-configured `ServiceComponentRequestInvoker` (`scCall`), a prepared input message (`inCAANMsg`), and a data map key, then handles the entire lifecycle of SC execution — building the parameter map, dispatching the call, extracting and validating results, and collecting error information. It plays the role of a **shared utility called by many screens and business components** within the `JKKTvSvcKeiCancelCC` class; all callers (`cancel`, `execMskm`, `registProgressInfo`, `svcCancel`) go through this single method, ensuring consistent error handling, return code validation, and message extraction across every service component invocation in the service cancellation workflow.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["callSC(params)"])

    START --> STEP1["editInMsg: Build parameter map from request params and input message"]

    STEP1 --> STEP2["scCall.run: Execute SC with paramMap"]

    STEP2 --> STEP3["Extract templates and return_code from result"]

    STEP3 --> STEP4["status = templates[0].getInt(status)"]

    STEP4 --> STEP5["editErrorInfoCom: Update error info from result"]

    STEP5 --> STEP6["Read ERROR_INFO from control map"]

    STEP6 --> STEP7["Set ERROR_INFO = TemplateErrorUtil.getErrorInfo(result, errList)"]

    STEP7 --> COND{"return_code = 0 AND status = 0?"}

    COND -->|"Yes"| RETURN["Return msg"]
    COND -->|"No"| THROWS["Throw SCCallException"]

    RETURN --> END(["END"])
    THROWS --> END
```

**Processing Flow:**

1. **editInMsg** — Transforms the `IRequestParameterReadWrite` request and the input `CAANMsg` into a `HashMap<String, Object>` parameter map, extracting and mapping all required business fields for the service component.
2. **scCall.run** — Dispatches the service component execution using the parameter map and session handle. The actual SC behavior (which telecom service is being cancelled/modified) is determined by the caller's input message.
3. **Extract templates & return_code** — Retrieves the response message templates and return code from the SC result map.
4. **Extract status** — Reads the integer `status` field from the first template to determine the SC's execution state.
5. **editErrorInfoCom** — Post-processes error information from the templates, correlating errors with the data map key for structured error reporting.
6. **Read ERROR_INFO from control map** — Fetches any pre-existing error list from the control map's `ERROR_INFO` key.
7. **Set ERROR_INFO** — Updates the control map with enriched error information via `TemplateErrorUtil.getErrorInfo`.
8. **Validate** — Checks that both the return code is `"0"` (success) and the status is `0`. If either condition fails, an `SCCallException` is thrown with the actual return code and status values.
9. **Return** — Returns the result `CAANMsg` on successful execution.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | The database/session handle providing the transactional context for the service component call. Carries the current user's session state, database connection, and transaction boundary used throughout the service cancellation workflow. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | The service component dispatcher that wraps the actual telecom service backend call. Determines which service component (e.g., authorization change, order addition, ENUM modification) is executed — configured by the caller with the target SC endpoint before being passed here. |
| 3 | `param` | `IRequestParameterReadWrite` | The request parameter container that holds all input business data for the service component. Contains fields such as order content codes (`odr_naiyo_cd`), service detail work numbers (`svc_kei_ucwk_no`), and account information. Read and written throughout the method lifecycle. |
| 4 | `dataMapKey` | `String` | A key used to correlate error information and results within the broader request data map. Allows the error handling methods (`editErrorInfoCom`, `TemplateErrorUtil.getErrorInfo`) to scope error entries to the specific invocation context. |
| 5 | `inCAANMsg` | `CAANMsg` | The input service component message containing the business payload to send to the service component. Carries fields such as cancellation reason codes, account identifiers, service type indicators (FTTH, Mail, ENUM), and order detail codes. |

**External state accessed:**

| Source | Description |
|--------|-------------|
| `JCMConstants.TEMPLATE_LIST_KEY` | Constant key for extracting the response message template array from the SC result. |
| `JCMConstants.RET_CD_INT_KEY` | Constant key for extracting the return code string from the SC result. |
| `SCControlMapKeys.ERROR_INFO` | Constant key for the control map entry where aggregated error information is stored and retrieved. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatACECBuyIfTrkm.getErrorInfo` | JBSbatACECBuyIfTrkm | - | Calls `getErrorInfo` in `JBSbatACECBuyIfTrkm` |
| R | `JBSbatACKojiChrgInfoTrkm.getErrorInfo` | JBSbatACKojiChrgInfoTrkm | - | Calls `getErrorInfo` in `JBSbatACKojiChrgInfoTrkm` |
| - | `CHSV0065OPOperation.run` | CHSV0065OPOperation | - | Calls `run` in `CHSV0065OPOperation` |
| - | `CHSV0066Flow.run` | CHSV0066Flow | - | Calls `run` in `CHSV0066Flow` |
| - | `CHSV0066OPOperation.run` | CHSV0066OPOperation | - | Calls `run` in `CHSV0066OPOperation` |
| - | `CHSV0067Flow.run` | CHSV0067Flow | - | Calls `run` in `CHSV0067Flow` |
| - | `CHSV0067OPOperation.run` | CHSV0067OPOperation | - | Calls `run` in `CHSV0067OPOperation` |
| U | `JKKTvSvcKeiCancelCC.editErrorInfoCom` | JKKTvSvcKeiCancelCC | - | Calls `editErrorInfoCom` in `JKKTvSvcKeiCancelCC` — post-processes error information from the service component response |
| U | `JKKTvSvcKeiCancelCC.editInMsg` | JKKTvSvcKeiCancelCC | - | Calls `editInMsg` in `JKKTvSvcKeiCancelCC` — builds the parameter map from request and input message |
| R | `ApiBpInterface.getErrorInfo` | ApiBpInterface | - | Calls `getErrorInfo` in `ApiBpInterface` |

**Notes on SC Code inference:**

The actual SC code invoked at runtime (e.g., `EKK0081A010SC`, `EKK0791A010SC`, `EKK1091D010SC`, `EKK0161B004SC`, `EKK0341B501SC`, `EKK0351B002SC`) is determined by the caller's configuration of the `scCall` invoker and the `inCAANMsg` payload. The `scCall.run()` call is a generic dispatch — the specific SC code depends on which method invoked `callSC` (e.g., `cancel` passes `EKK0081A010SC` data, `execMskm` passes `EKK0791A010SC` data). Entity/DB tables are determined by the target SC implementation and are not directly referenced in this method.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Method: `JKKTvSvcKeiCancelCC.cancel()` (L~175) | `cancel()` -> `callSC(handle, scCall, param, dataMapKey, ekk0081a010IN)` | SC result [R], `getErrorInfo` [R], `editErrorInfoCom` [U], `editInMsg` [U] |
| 2 | Method: `JKKTvSvcKeiCancelCC.execMskm()` (L~223) | `execMskm()` -> `callSC(handle, scCall, param, dataMapKey, ekk0791a010IN)` | SC result [R], `getErrorInfo` [R], `editErrorInfoCom` [U], `editInMsg` [U] |
| 3 | Method: `JKKTvSvcKeiCancelCC.registProgressInfo()` (L~375) | `registProgressInfo()` -> `callSC(handle, scCall, param, dataMapKey, ekk1091d010IN)` | SC result [R], `getErrorInfo` [R], `editErrorInfoCom` [U], `editInMsg` [U] |
| 4 | Method: `JKKTvSvcKeiCancelCC.svcCancel()` (L~419+) | `svcCancel()` -> `callSC(handle, scCall, param, dataMapKey, variousMsgs)` | SC result [R], `getErrorInfo` [R], `editErrorInfoCom` [U], `editInMsg` [U] |

**Terminal operations from this method:** `getErrorInfo` [R], `getErrorInfo` [R], `getErrorInfo` [R], `editErrorInfoCom` [U], `run` [-], `run` [-], `run` [-], `run` [-], `run` [-], `editInMsg` [U]

## 6. Per-Branch Detail Blocks

**Block 1** — [SET/EXEC] `(Build parameter map)` (L852)

Build the parameter map by delegating to `editInMsg`, which extracts and maps request parameters and the input message into a HashMap.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `HashMap<String, Object> paramMap = editInMsg(param, inCAANMsg);` | Transforms the `IRequestParameterReadWrite` and input `CAANMsg` into a parameter map. Contains all business fields needed by the service component (order codes, account info, cancellation details). |

**Block 2** — [EXEC] `(Execute service component)` (L854)

Invoke the service component through the dispatcher with the prepared parameter map and session context.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `Map<?, ?> result = scCall.run(paramMap, handle);` | Dispatches the service component execution. The actual service type (FTTH auth change, mail order, ENUM, etc.) is determined by how the caller configured `scCall` and populated the parameter map. Returns a result map containing templates, return code, and status. |

**Block 3** — [SET/SET] `(Extract response data)` (L856–858)

Extract the response message templates and return code from the SC result map.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `CAANMsg[] templates = (CAANMsg[])result.get(JCMConstants.TEMPLATE_LIST_KEY);` | Extract the message template array from the SC result. `TEMPLATE_LIST_KEY` is the constant key used to retrieve templates. |
| 2 | SET | `CAANMsg msg = templates[0];` | The first template in the array is the primary response message. |
| 3 | EXEC | `Object return_code = result.get(JCMConstants.RET_CD_INT_KEY);` | Extract the return code (e.g., `"0"` for success, non-zero for errors). `RET_CD_INT_KEY` is the constant key for the return code. |
| 4 | SET | `int status = templates[0].getInt("status");` | Read the integer status field from the response template. Status `0` indicates normal completion; non-zero indicates an exception or warning. |

**Block 4** — [EXEC] `(Post-process error info)` (L860)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `editErrorInfoCom(param, templates, (Integer)return_code, dataMapKey);` | Post-processes error information from the response templates. Correlates errors with the data map key for structured error reporting. The `return_code` is cast to `Integer` for compatibility with the method signature. |

**Block 5** — [SET/SET] `(Read and set error list from control map)` (L862–869)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `ArrayList<Object> errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO);` | Retrieves any existing error list from the control map using the `ERROR_INFO` key. `SCControlMapKeys.ERROR_INFO` is the constant key for error info storage. |
| 2 | [IF] `(errList == null)` (L863) | | No pre-existing error list found in the control map. |
| 2.1 | SET | `errList = new ArrayList<Object>();` | (PARENTHESIS: 「コントロールマップに設定」 — "Set in control map") Creates a new empty error list to collect errors from this SC result. |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(result, errList));` | (PARENTHESIS: 「エラー情報のマップを取得」 — "Get error information map") Enriches the error list with error details from the SC result and stores it back in the control map. `TemplateErrorUtil.getErrorInfo` extracts error codes and descriptions from the result map. |

**Block 6** — [IF] `(Validate success: return_code == "0" AND status == 0)` (L872)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | IF | `!("0".equals(return_code.toString()) && 0 == status)` | (PARENTHESIS: 「異常の場合、SCCallExceptionを生成してスローする」 — "If abnormal, generate and throw SCCallException") Validates that both the return code is `"0"` (success indicator) AND the status is `0` (normal completion). Either condition being false indicates an error condition. |
| 1.1 | EXEC | `throw new SCCallException("戻値不正", return_code.toString(), status);` | (PARENTHESIS: 「戻値不正」 — "Invalid return value") Throws an `SCCallException` with the message "Invalid return value", the actual return code string, and the actual status integer. This propagates the error to the caller (e.g., `cancel`, `svcCancel`, `execMskm`, `registProgressInfo`) for screen-level error handling. |
| 2 | RETURN | `return msg;` | Returns the primary response `CAANMsg` on successful SC execution. The caller typically extracts specific message lists or fields from this response. |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `callSC` | Method | Call Service Component — generic service component dispatch wrapper in the service cancellation common component |
| `scCall` | Parameter | Service Component Request Invoker — the dispatcher that wraps the actual telecom service backend invocation |
| `param` | Parameter | Request Parameter ReadWrite — container holding all input/output business fields for the service component |
| `dataMapKey` | Parameter | Data Map Key — scoping key used to correlate error entries within the broader request context |
| `inCAANMsg` | Parameter | Input CAAN Message — the input message carrying the business payload (order codes, account info, cancellation details) to send to the service component |
| `handle` | Parameter | Session Handle — database/session handle providing transactional context (user session, DB connection, transaction boundary) |
| CAANMsg | Class | Cancellation/Approval/Notification message — the message format used for all SC input/output in this system |
| `TEMPLATE_LIST_KEY` | Constant | Key constant for extracting the response message template array from the SC result map |
| `RET_CD_INT_KEY` | Constant | Key constant for extracting the return code string from the SC result map |
| `ERROR_INFO` | Constant | Key constant (`SCControlMapKeys.ERROR_INFO`) for the control map entry where aggregated error information is stored |
| `editInMsg` | Method | Edit Input Message — builds the parameter map from request params and input message |
| `editErrorInfoCom` | Method | Edit Error Info Common — post-processes and correlates error information from SC templates |
| `TemplateErrorUtil.getErrorInfo` | Utility | Extracts error codes and descriptions from the SC result map, enriching the error list |
| `SCCallException` | Exception | Service Component Call Exception — thrown when the SC returns a non-success return code or non-zero status |
| `JCMConstants` | Class | JCM Constants — constants class defining standard result map keys (template list, return code) |
| `SCControlMapKeys` | Class | Service Component Control Map Keys — constants class defining control map entry keys (e.g., `ERROR_INFO`) |
| FTTH | Business term | Fiber To The Home — fiber-optic internet service; one of the telecom service types cancelled/modified by this system |
| ENUM | Business term | ENUM service — telephone number mapping service in the telecom domain |
| ODR_NAIYO_CD | Field | Order Content Code — classifies the type of order (FTTH registration, mail change, etc.) |
| SVC_KEI_UCWK_NO | Field | Service Detail Work Number — internal tracking ID for service contract line items |
