# Business Logic — JKKMainSubKeiJudgeCC.runMskj() [15 LOC]

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

## 1. Role

### JKKMainSubKeiJudgeCC.runMskj()

This method serves as the **primary entry point for main/sub (parent-child) service contract switching** — the business operation of transitioning a secondary (subordinate) service contract line to become the primary (master) contract, or vice versa, within the K-Opticom customer base system (eo顧客基盤システム / eo Customer Base System). The method name "runMskj" is an abbreviation of "Main Sub Kei Judge" (主従判断 — main/sub judgment).

The method acts as a **delegating wrapper** that coordinates the main/sub contract switching workflow by: (1) initializing the processing context via `init()`, (2) extracting the service contract number (サービス契約番号) from the parameter object, and (3) delegating the actual switching logic to `JKKBpCommon.runMainSubKeijudge()`, which in turn instantiates and invokes `JKKMainSubKeiJudge.runMainSubKeijudge()`. The downstream `JKKMainSubKeiJudge` class contains the detailed logic for determining whether a contract change occurred and applying applicable discount processing (割引適用処理) through `runMskjWrisvcAutoAply()`.

This is a **shared utility method** called by multiple screen operations (KKSV0150, KKSV0612) and the cancellation process (JKKKikiIchiranCancelCC), making it a central coordination point for any screen or batch operation that requires main/sub service contract reassignment. The method implements the **delegation pattern** — it does not contain the business logic itself but orchestrates initialization, data extraction, and handoff to specialized components.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["runMskj(handle, param, fixedText)"])
    STEP1["init(param, fixedText)"]
    STEP2["HashMap inMap = param.getData(fixedText)"]
    STEP3["JKKBpCommon.runMainSubKeijudge(handle, param, inMap, fixedText)"]
    STEP4["JKKMainSubKeiJudge instantiated and<br>runMainSubKeijudge() executed"]
    STEP5["Main/Sub contract switching logic<br>including change detection and discount application"]
    STEP6["return param"]
    END(["End"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> STEP4
    STEP4 --> STEP5
    STEP5 --> STEP6
    STEP6 --> END
```

**Processing Flow:**

1. **Initialize (L76)**: Call `init(param, fixedText)` to set up the processing context with the fixed text key and clear any stale data from previous operations.
2. **Extract Input Map (L79)**: Retrieve the HashMap stored under the `fixedText` key from `param.getData()`. This map contains the business data for the main/sub switching operation, including the service contract number (サービス契約番号 / `svc_kei_no`).
3. **Delegate to Main/Sub Judgment (L82)**: Call `JKKBpCommon.runMainSubKeijudge()` — a static helper that instantiates `JKKMainSubKeiJudge` and delegates to its `runMainSubKeijudge()` method. The downstream component performs the core business logic: determining if a main/sub contract change has occurred and, if so, applying discount processing (割引適用処理).
4. **Return (L84)**: Return the original `param` object, which has been mutated in place by the downstream processing.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Session manager handle carrying the current user session context, database connection, and transaction boundary. Used by downstream services to execute data access operations under the correct session. |
| 2 | `param` | `IRequestParameterReadWrite` | Request parameter object containing the model group and control map. It stores business data maps indexed by keys (such as the `fixedText` key) and is mutated in place during processing — the downstream main/sub switching logic writes results back into this object. |
| 3 | `fixedText` | `String` | User-defined arbitrary string used as a key to identify and store/retrieve the business data HashMap within `param`. Acts as the namespace for the input/output data exchange between this CC and downstream components. |

**Instance Fields Read:** None — this method reads no instance fields; all state is passed through parameters or accessed via the `handle` and `param` objects.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JKKBpCommon.runMainSubKeijudge` | JKKBpCommon | - | Static delegation method — instantiates `JKKMainSubKeiJudge` and delegates to its `runMainSubKeijudge()` |
| - | `JKKMainSubKeiJudge.runMainSubKeijudge` | JKKMainSubKeiJudge | - | Main/sub service contract switching judgment — determines if a contract change occurred and triggers discount application |
| - | `JKKMainSubKeiJudge.runMskjWrisvcAutoAply` | JKKMainSubKeiJudge | - | Discount application processing for changed contracts (割引適用処理) |
| - | `JKKMainSubKeiJudgeCC.init` | JKKMainSubKeiJudgeCC | - | Initialization — sets up the fixed text key and clears parameter data |

**Notes:**
- This method itself is a **thin orchestrator** — it does not perform direct CRUD operations. All data access (Read/Write) happens within the downstream `JKKMainSubKeiJudge` class and its called service components.
- The downstream `runMainSubKeijudge()` in `JKKMainSubKeiJudge` reads service contract data to determine if a main/sub switch is needed, and conditionally writes discount application results.
- SC Codes, CBS identifiers, and specific entity/DB table references are not visible in this 15-LOC wrapper method but exist within the downstream `JKKMainSubKeiJudge` implementation.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 3 methods.
Terminal operations from this method: `runMainSubKeijudge` [-], `init` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKSV0150 | `KKSV0150OPOperation` (CCRequestBroker target26) -> `KKSV015011CC` -> `JKKMainSubKeiJudgeCC.runMskj` | `runMainSubKeijudge` [-] |
| 2 | Screen:KKSV0612 | `KKSV0612OPOperation` (CCRequestBroker target5) -> `KKSV061203CC` -> `JKKMainSubKeiJudgeCC.runMskj` | `runMainSubKeijudge` [-] |
| 3 | CC:JKKKikiIchiranCancelCC | `JKKKikiIchiranCancelCC.execMainSubKeijudgeCC` -> `mainSubKeyJudgeCC.runMskj(handle, param, JKK_MAIN_SUB_KEI_JUDGE_CC)` | `runMainSubKeijudge` [-] |

**Caller details:**
- **KKSV0150** (e.g., KKSV015011CC): A screen operation for service contract management, registered via `CCRequestBroker target26` as part of the ANK-2197-00-00 change set (2015/11/02).
- **KKSV0612** (e.g., KKSV061203CC): A screen operation for service contract operations, registered via `CCRequestBroker target5`, also part of ANK-2197-00-00.
- **JKKKikiIchiranCancelCC**: The cancellation inquiry screen controller that performs main/sub contract switching during cancellation processing. It calls `runMskj` with the key `JKK_MAIN_SUB_KEI_JUDGE_CC`, then removes the data entry afterward (`param.removeData(...)`).

## 6. Per-Branch Detail Blocks

**Block 1** — [EXEC] Initialization `(L76)`

> Initialize the processing context by calling the inherited `init()` method (from `AbstractCommonComponent`). This sets up the fixed text key and prepares the parameter object for the main/sub switching operation.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `init(param, fixedText)` | Initialize parameter processing context — sets up the fixedText key in the parameter's control map and clears any stale data from prior operations |

**Block 2** — [EXEC] Input data extraction `(L79)`

> Retrieve the business data HashMap from the parameter object using the `fixedText` key. This map carries the service contract information needed for the main/sub switching judgment.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `HashMap<String, Object> inMap = (HashMap<String, Object>)param.getData(fixedText)` | Cast and extract the business data map keyed by fixedText — contains service contract number (svc_kei_no) and related fields for main/sub judgment |

**Block 3** — [CALL] Main/sub contract switching delegation `(L82)`

> Delegate to the static helper `JKKBpCommon.runMainSubKeijudge()` which instantiates `JKKMainSubKeiJudge` and executes the main/sub contract switching logic. This downstream component:
> - Reads service contract data to determine if a main/sub switch has occurred
> - If a change is detected (`mainSubChangeFlg = true`), applies discount processing via `runMskjWrisvcAutoAply()`
> - Writes results back into the `param` object

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `JKKBpCommon.runMainSubKeijudge(handle, param, inMap, fixedText)` | Execute main/sub service contract switching — downstream creates JKKMainSubKeiJudge instance, reads contract data, detects changes, and applies discount processing if applicable |

**Block 4** — [RETURN] Return processed parameters `(L84)`

> Return the original `param` object which has been mutated in place by the downstream processing. The result data is stored in the param under the same `fixedText` key.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | RETURN | `return param;` | Return the parameter object containing the main/sub switching results — the output data is written into param by the downstream JKKMainSubKeiJudge processing |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `runMskj` | Method | Main Sub Kei Judge — the primary method for initiating main/sub (parent-child) service contract switching processing |
| 主従切替 (Shujū Kittai) | Business term | Main/Sub Contract Switching — the operation of changing which service contract line is the primary (master) versus secondary (subordinate) within a contracted group |
| STB | Business term | Set-Top Box — a customer premises device for broadband services; the main/sub switching affects STB plan assignments |
| サービス契約番号 (Service Contract Number) | Field | `svc_kei_no` — the unique identifier for a service contract line item, used to look up and switch main/sub relationships |
| 主従 (Shujū) | Business term | Main (Master) / Sub (Subordinate) — the hierarchical relationship between service contract lines where one is primary and others are secondary |
| 割引適用 (Waribiki Tekiyou) | Business term | Discount Application — when a main/sub contract switch occurs, applicable discounts are automatically recalculated and applied to the affected contracts |
| 業務データ (Business Data) | Concept | The structured data (stored in HashMap via `param.getData()`) that carries contract information, service types, and switching results between components |
| ユーザ任意文字列 (User-Defined String) | Parameter | `fixedText` — a caller-provided string used as a namespace key for the data map stored in `param`, enabling multiple independent data exchanges in the same parameter object |
| SessionHandle | Technical | `com.fujitsu.futurity.bp.x21.bpm.db.SessionHandle` — the session manager handle carrying user session context, database connections, and transaction boundaries |
| IRequestParameterReadWrite | Technical | Interface for the request parameter object that carries model group data and control maps between business components |
| JKK_MAIN_SUB_KEI_JUDGE_CC | Constant | The fixed text key (`"JKK_MAIN_SUB_KEI_JUDGE_CC"`) used as the data map identifier in param, defined in `JKKKikiIchiranCancelCC` |
| AbstractCommonComponent | Technical | Base class extended by all common components, providing the `init()` method and core framework utilities |
| ANK-2197-00-00 | Change ticket | The change request ticket that introduced this method and its callers (KKSV0150, KKSV0612) on 2015/10/20 – 2015/11/02 |
