# JKKHakkoSODCC

## Purpose

`JKKHakkoSODCC` is the central **Service Order Dispatch Component** in a Fujitsu Futurity-based Business Platform (BP) application. It receives service contract change requests and dispatches the appropriate order-issuance logic based on the operation type (new contract, suspension, cancellation, course change, option setup, etc.) and service category (eo light network, eo mobile, eo light phone, ADSL, etc.). It acts as a massive **facade and orchestrator**, coordinating dozens of downstream service-interface (S-IF) calls to CBS (core business system) components, and then assembling the responses back to the caller.

## Design

**Architectural role:** Facade / Command dispatcher

The class is part of the `com.fujitsu.futurity.bp.custom.common` package and is a *Business Component (BC)* in Fujitsu's Futurity framework. It does not extend any class or implement any interface — it is a plain utility/worker class instantiated by business service (BS) classes.

The entry point is the `hakkoSOD()` method, which:

1. Accepts a list of SOD (Service Order Dispatch) maps from the caller.
2. For each map, extracts the **ido_div** (operation division) and **syori_div** (processing division) from `SOD_KIHON_INFO`.
3. Dispatches to one of ~30+ specialized `_OdrCtrl()` methods based on the operation type.
4. Each `_OdrCtrl()` method may in turn query the database (via S-IF CBS calls), call `addSOD()` to register orders with the central order management system (EKK1081), and invoke further CBS components.

The class follows a **template method + strategy** pattern: `hakkoSOD()` is the template, and the `_OdrCtrl()` methods are the strategies. Each strategy method handles a single business operation end-to-end, including validation, data retrieval, CBS invocation, and error handling.

### S-IF CBS Component Registry

The class invokes the following CBS components (identified by their S-IF names). Each has a corresponding `callEKKxxxxSC()`, `mappingEKKxxxxInMsg()`, and `mappingEKKxxxxOutMsg()` pair:

| CBS Component | Purpose |
|---|---|
| **EKK1081C011** | Order condition registration |
| **EKK0081A010** | Order info creation work registration |
| **EKK0341A010** | Equipment provision details |
| **EKK0341B002** | Option service contract list (service contract number) |
| **EKK0341B008** | Option service contract (details) |
| **EKK0341B022** | Option service contract (additional/changed) |
| **EKK0341B029** | Equipment provision change |
| **EKK0341B504** | Equipment provision history |
| **EKK0351A010** | Option service contract (ISP) agreement |
| **EKK0351B002** | Option service contract list (agreement) |
| **EKK0351B003** | Option service contract (details) |
| **EKK0351B010** | Sub-option service contract list |
| **EKK0361A010** | IPv6 registration |
| **EKK0401A010** | Fee/course information |
| **EKK0411A010** | Fee/course details |
| **EKK0161A010** | Service contract details list |
| **EKK0161B003** | Service contract details (agreement) |
| **EKK0161B004** | Service contract details (list) |
| **EKK0161B008** | Service contract details (phone number) |
| **EKK0161B011** | Service contract status |
| **EKK0191A010** | Option service contract list (service contract number) |
| **EKK0191B001** | Option service contract (details) |
| **EKK0191B502** | Option service contract (additional) |
| **EKK0251B001** | Service contract agreement details |
| **EKK0251B003** | Service contract agreement (details) |
| **EKK0791A010** | PCRS (resource) reservation |
| **EKK0881A010** | Mansion service contract agreement |
| **EKK0891A010** | Mansion service contract details |
| **EKK1041A010** | Equipment provision details |
| **EKK1041B001** | Equipment provision (additional) |
| **EKK1081B001** | Order issuance condition |
| **EKK1081E010** | Order issuance condition (update) |
| **EKK1551D010** | Option service contract (ISP) |
| **EKK1681B001** | Restricted area order |
| **EKK2091A010** | Fee plan code |
| **EKK2101B001** | Fee plan code (additional) |
| **EKK2101B002** | Fee plan code (change) |
| **EKK2811A010** | Option service contract list (service contract number) |
| **EKK2811B010** | Option service contract (details) |
| **EKU0011A010** | Equipment provision (mansion) |
| **EKU0081B010** | Equipment provision (mansion) details |
| **ETU0011B010** | Equipment provision (mansion) |
| **EZM0121A010** | ENUM registration |
| **EZM0321A010** | ENUM inquiry |
| **EZM0411A010** | IPv6 configuration |
| **EDK0301B060** | Equipment provision history |

### S-IF Invocation Pattern

Every CBS call follows a consistent 3-step pattern:

```
callEKKxxxSC(param, handle, inHash, resultHash, funcCode)
    -> editInMsgCmn(param)           // Common header fields
    -> mappingEKKxxxxSCInMsg(template, inHash, funcCode)  // Set input parameters
    -> scCall.run(sIFRequest, handle) // Execute S-IF call
    -> mappingEKKxxxxSCOutMsg(resultMsgs)  // Extract results into HashMap
    -> editErrorInfo*CBS(param, templates, status)  // Map errors back to param
```

## Key Methods

### Entry Point

#### `hakkoSOD(SessionHandle handle, IRequestParameterReadWrite param, String fixedText)` → `IRequestParameterReadWrite`

**The main entry point.** Processes one or more service order dispatch (SOD) maps from the caller.

- Iterates over `TRGT_DATA_LIST` from the input parameter.
- For each SOD map, extracts `ido_div` (operation division) and `syori_div` (processing division).
- Clears instance fields (`formatClassVar()`) before processing each item — **this class is NOT thread-safe**.
- Dispatches to one of ~30+ operation-specific controllers based on `ido_div` / `syori_div`.
- Returns the populated `param` object with results and error information.

### Operation Dispatch Methods

These private methods implement the actual business logic for each type of order. They all follow the naming convention `<operationName>OdrCtrl()`:

| Method | Operation | Line Range |
|---|---|---|
| `newKeiOdrCtrl` | New contract | 6088-6169 |
| `stpUkOdrCtrl` | Suspension (acceptance) | 6295-6807 |
| `stpRlsOdrCtrl` | Suspension release | 6817-7182 |
| `kaihkOdrCtrl` | Restoration (reinstatement) | 7193-8918 |
| `dslOdrCtrl` | Cancellation | 8929-10565 |
| `ksiDslOdrCtrl` | Forced cancellation | 10576-10598 |
| `ksiDslFixOdrCtrl` | Forced cancellation confirmation | 10609-10631 |
| `cnclOdrCtrl` | Cancel | 10640-10662 |
| `courseChgeOdrCtrl` | Course change | 10673-11464 |
| `opSetOdrCtrl` | Option setup | 11476-14402 |
| `htelNoAddOdrCtrl` | Phone number addition | 14414-14514 |
| `htelNoChgeOdrCtrl` | Phone number change | 14553-14705 |
| `htelNoDslOdrCtrl` | Phone number cancellation | 14716-15320 |
| `htelNoKaihkOdrCtrl` | Phone number restoration | 15332-15861 |
| `htelItntokiOdrCtrl` | Call forwarding setup | 15870-16355 |
| `htelNoInfoChgeOdrCtrl` | Phone number info change | 16367-16910 |
| `adchgFixOdrCtrl` | Address change/registration | 16922-17035 |
| `opHktgiOdrCtrl` | Option inheritance | 17074-17465 |
| `idpwShkkaSaifuriOdrCtrl` | ID/PW initial/reissue | 17675-17837 |
| `pauseUkOdrCtrl` | Pause acceptance | 18196-18660 |
| `pauseRlsChgeOdrCtrl` | Pause change/cancellation | 18669-18968 |
| `useStpOdrCtrl` | Usage stop | 18978-19005 |
| `useStpRlsOdrCtrl` | Usage stop release | 19014-19041 |
| `wribInfoAddOdrCtrl` | Discount info registration | 19050-19133 |
| `taiikiSeigenOdrCtrl` | Area restriction | 31639-32112 |
| `bmpSwitchOdrCtrl` | Number porting switch | 34376-34479 |
| `vLanIdChgOdrCtrl` | VLAN-ID change | 32539-32808 |
| `vLanIdVaChangeOdrCtrl` | VLAN-ID change + VA equipment swap | 39065-39344 |
| `bmpSipDslOdrCtrl` | Number return (SIP cancellation) | 39455-39556 |
| `malwareBlockingDivOdrCtrl` | Malware blocking control | 40577-40771 |
| `koteiIpAd8DivOdrCtrl` | Fixed IP Address 8 control | 40851-40983 |
| `rtOpChgDivOdrCtrl` | Router option change | 41755-42013 |
| `enumAddOdrCtrl` | ENUM registration | 42097-42121 |
| `enumDelOdrCtrl` | ENUM deletion | 42132-42156 |
| `spotLoginSysidChgeOdrCtrl` | WiFi spot SYSID change | 37022-37038 |

### New Contract Orchestration

#### `newKeiOdrCtrl(SessionHandle handle, IRequestParameterReadWrite param, HashMap<String, Object> sodMap)` → `IRequestParameterReadWrite`

Handles new contract orders. Dispatches to network, phone, or mobile sub-handlers:

1. Gets the **same_trn_no** (common transaction number).
2. Determines service kind (`jdgSvcKind()`) based on price group code:
   - `NET` = eo light network/mansion
   - `MOB` = eo mobile (WiFi/eMobi/UQ WiFi)
   - `TEL` = eo light phone
   - `ADSL` = eo ADSL / FLET'S
3. For **network/ADSL**: queries option contracts, option ISP agreement, sub-options, service contract details, BBR equipment info, then calls `newNet()` for the actual new network subscription.
4. For **phone**: calls `addTensoDenwaOp()` for transfer phone SOD, then `addSODTelNew()` for phone registration.
5. For **mobile**: queries option contracts, option ISP, sub-options, service contract details, then calls `newEoMobile()`.
6. Finally, calls `addIpv6SODAft()` to register the IPv6 option.

### Option Setup

#### `opSetOdrCtrl(SessionHandle handle, IRequestParameterReadWrite param, String fixedText, HashMap<String, Object> sodMap)` → `IRequestParameterReadWrite`

The longest operation-specific controller (~3000 lines). Handles option setup for existing contracts. Supports email, homepage, mail list, dial-up connection, multi-session, IPv6, fixed global IP, number change, home pager, and many more option types.

### Core SOD Registration

#### `addSOD(SessionHandle handle, IRequestParameterReadWrite param, String orderNaiyoCd)` → `IRequestParameterReadWrite`

Core method that registers a service order with the central order management system. Takes the `orderNaiyoCd` (order content code) to determine what kind of order to register (e.g., `101` for FTTH authentication/registration).

#### `addSODTelNew(SessionHandle handle, IRequestParameterReadWrite param)` → `IRequestParameterReadWrite`

Registers a new phone service order.

#### `addSODWiFiNew(SessionHandle handle, IRequestParameterReadWrite param)` → `IRequestParameterReadWrite`

Registers a new WiFi service order.

#### `addSODTelVAChange(SessionHandle handle, IRequestParameterReadWrite param)` → `IRequestParameterReadWrite`

Registers a phone + VA (voice attachment) change order.

#### `tsuikabunAddSOD(SessionHandle handle, IRequestParameterReadWrite param, String orderNaiyoCd)` → `IRequestParameterReadWrite`

Registers an additional/sub-division service order.

#### `addTakinoSOD(SessionHandle handle, IRequestParameterReadWrite param, String orderNaiyoCd)` → `IRequestParameterReadWrite`

Registers a takino (handover/transfer) service order.

### Data Retrieval

#### `getSvcKeiInfo(SessionHandle handle, IRequestParameterReadWrite param)` → `HashMap<String, Object>`

Queries the service contract agreement S-IF to retrieve: gene_add_dtm, price group code, price code, service contract status, pause dates, pause stop code, and other service-level metadata.

#### `getOpSvcKeiList(SessionHandle handle, IRequestParameterReadWrite param, String svcKeiNo)` → `IRequestParameterReadWrite`

Retrieves the list of option service contracts for a given service contract number.

#### `getOpSvcKeiIsp(SessionHandle handle, IRequestParameterReadWrite param)` → `IRequestParameterReadWrite`

Retrieves the option service contract <ISP> agreement.

#### `getSbOpSvcKeiList(SessionHandle handle, IRequestParameterReadWrite param)` → `IRequestParameterReadWrite`

Retrieves the sub-option service contract list.

#### `getSvcKeiUtwkList(SessionHandle handle, IRequestParameterReadWrite param)` → `IRequestParameterReadWrite`

Retrieves the service contract details list.

#### `getKktkSvcKeiList(SessionHandle handle, IRequestParameterReadWrite param)` → `IRequestParameterReadWrite`

Retrieves the equipment provision service contract list.

### Service Kind Determination

#### `jdgSvcKind()` → `String`

Determines the service kind based on the `prc_grp_cd` (price group code). Returns one of:
- `NET` — eo light network (Home/Meson/Mansion types)
- `MOB` — eo mobile (WiFi/eMobi/UQ WiFi)
- `TEL` — eo light phone
- `ADSL` — eo ADSL / FLET'S
- `ELSE` — default fallback

#### `jdgOpSvcKind(String op_svc_cd)` → `String[]`

Determines whether an option is a network or phone option, and whether sub-options need to be checked. Returns `[serviceKind, checkSubOptionFlag]`.

### IPv6 Support

#### `addIpv6SODAft(SessionHandle handle, IRequestParameterReadWrite param, String ucwk_no_param, String fixedText, String opSvcKeiStatParam, HashMap<String, Object> sodMap)` → `void`

Registers the IPv6 option after the main service order. Called at the end of new contract and course change flows.

#### `jdgIpv6(...)` → `void`

Determines IPv6 eligibility based on service contract details and existing IPv6 registrations.

### CBS Call Framework Methods

Each CBS component has a standardized set of methods:

| Method Pattern | Role |
|---|---|
| `callEKKxxxxSC(param, handle, inHash, resultHash, funcCode)` | Executes the S-IF call. Sets common headers, maps input, invokes `ServiceComponentRequestInvoker`, extracts output, and maps errors. |
| `mappingEKKxxxxSCInMsg(template, inHash, funcCode)` | Populates a `CAANMsg` template with input parameters. Always starts by filling null mappings for all template fields. |
| `mappingEKKxxxxSCOutMsg(resultMsgs)` | Extracts result fields from the `CAANMsg[]` response into a `HashMap<String, Object>`. |
| `editErrorInfoEKKxxxxCBS(param, templates, returnCode)` | Maps CBS error codes and messages back into the `IRequestParameterReadWrite` control map. |

### Error Handling

#### `editErrorInfo(IRequestParameterReadWrite param, CAANMsg[] templates, int returnCode)` → `IRequestParameterReadWrite`

Base error info handler. Maps CBS return codes (e.g., 0 = success, 9000 = error) to user-readable messages using `JCMAPLConstMgr.getString()`.

#### `editErrorInfo_EKK1081D010CBS(...)` / `editErrorInfo_EKK1551D010CBS(...)` / `editErrorInfo_EKK0351B002CBS(...)` etc.

CBS-specific error handlers. Each handles the specific error codes and message templates for its corresponding CBS component.

#### `errChk(Map<?, ?> msgList)` → `void`

Generic error check that throws if the S-IF result contains errors.

### Utility Methods

| Method | Description |
|---|---|
| `getDummySvcKeiNo(handle, param)` | Gets a list of dummy service contract numbers to skip during processing |
| `getInvokeCBS(handle, param, fixedText)` | Returns a HashMap of invoked CBS components |
| `getSameTrnNo(handle, param)` / `getSame_trn_no()` | Gets the common transaction number for grouping related orders |
| `shkkaMap(HashMap<String, Object> map)` | Trims whitespace from all values in a HashMap |
| `shkkaChr(String trgtChr)` | Trims whitespace from a single string |
| `isBlank(String param)` | Checks if a string is null or empty |
| `isBlankDate(String ymd)` | Checks if a date string is null, empty, or "00000000" |
| `isAddSodTrgtStat(String stat)` | Checks if a status qualifies as "add order target" |
| `isDelSodTrgtStat(String stat)` | Checks if a status qualifies as "delete order target" |
| `chkOdrSette(handle, param)` | Validates order settings |
| `getFmtcelJgsSkbtStr(String fmtcelJgsCd)` | Formats cell judgment start string |
| `printSyslog4Err(String proId, String msgId, String msg)` | Prints error to syslog |
| `formatClassVar()` | Resets all instance variables to default values |

## Relationships

```mermaid
flowchart TD
    JFU["JFUHakkoSODCC<br/>Business Service"] --> JKK["JKKHakkoSODCC<br/>Order Dispatch Component"]

    JKK --> EKK1081["EKK1081<br/>Order Condition"]
    JKK --> EKK0081["EKK0081<br/>Order Info Creation"]
    JKK --> EKK0161["EKK0161<br/>Service Contract Details"]
    JKK --> EKK0341["EKK0341<br/>Equipment Provision"]
    JKK --> EKK0351["EKK0351<br/>Option Service"]
    JKK --> EKK0361["EKK0361<br/>IPv6 Registration"]
    JKK --> EKK0401["EKK0401<br/>Fee/Course"]
    JKK --> EKK1041["EKK1041<br/>Equipment Details"]
    JKK --> ETU0011["ETU0011<br/>Equipment Provision (Mansion)"]
    JKK --> EZM0411["EZM0411<br/>IPv6 Configuration"]
    JKK --> EKK0251["EKK0251<br/>Service Contract Agreement"]
    JKK --> EKK0191["EKK0191<br/>Option Service List"]

    style JKK fill:#f9f,stroke:#333,stroke-width:2px
    style JFU fill:#bbf,stroke:#333
    style EKK1081 fill:#ddf,stroke:#666
    style EKK0081 fill:#ddf,stroke:#666
    style EKK0161 fill:#ddf,stroke:#666
    style EKK0341 fill:#ddf,stroke:#666
    style EKK0351 fill:#ddf,stroke:#666
```

**Inbound:** `JFUHakkoSODCC` (a Business Service class) extends/depends on this class to invoke order dispatching.

**Outbound:** This class has no class-level references to other types in the codebase. All its dependencies are through dynamic S-IF invocations (`ServiceComponentRequestInvoker`) with CBS component message classes (`EKKxxxxCBSMsg`), which are imported but never held as instance variables.

## Usage Example

The typical calling pattern from a business service class:

```java
// In JFUHakkoSODCC (or similar BS class)
JKKHakkoSODCC cc = new JKKHakkoSODCC();
SessionHandle handle = new SessionHandle();

// Build the SOD map
HashMap<String, Object> sodMap = new HashMap<>();
HashMap<String, Object> sodKihonInfo = new HashMap<>();
sodKihonInfo.put("ido_div", "001");    // New contract
sodKihonInfo.put("sysid", "SYS001");
sodMap.put("SOD_KIHON_INFO", sodKihonInfo);

HashMap<String, Object> svcKeiInfo = new HashMap<>();
svcKeiInfo.put("svc_kei_no", "SVCKEI001");
sodMap.put("SVC_KEI_INFO", svcKeiInfo);

// Build the data list
ArrayList dataList = new ArrayList();
dataList.add(sodMap);

// Set parameters
param.setData("TRGT_DATA_LIST", dataList);
param.setControlMapData("FUNC_CODE_KEY", "1");

// Execute
param = cc.hakkoSOD(handle, param, "USER_DEFINED_KEY");
```

This flow would:
1. Query the service contract agreement for `SVCKEI001`
2. Determine service kind (based on price group code)
3. Query all option/sub-option/service contract details
4. Execute the appropriate `_OdrCtrl()` method (e.g., `newKeiOdrCtrl()`)
5. Register the order with EKK1081 and EKK0081
6. Return results in `param`

## Notes for Developers

1. **NOT thread-safe.** The class holds ~50+ instance fields (e.g., `ido_div`, `prc_grp_cd`, `svc_kei_stat`, `same_trn_no`, various service contract numbers) that are set during `hakkoSOD()` processing and NOT reset between items in the loop except by `formatClassVar()`. Each instance should handle one `hakkoSOD()` call at a time.

2. **Massive class.** At ~39,000+ lines and ~350 methods, this is a clear candidate for future refactoring. The strategy pattern is already in place with per-operation `_OdrCtrl()` methods, but each method is very large (some exceed 3,000 lines).

3. **Hard-coded S-IF invocations.** CBS components are invoked through `ServiceComponentRequestInvoker` with string-based message type names. There is no type-safe abstraction — mistakes in template IDs or field names only surface at runtime.

4. **Instance field side effects.** Many `_OdrCtrl()` methods modify instance fields like `mskm_dtl_no`, `prc_grp_cd`, `pcrs_cd`, `svc_kei_stat`, `ido_div`, `syori_div`, `svc_pause_ymd`, etc. Downstream calls within the same `_OdrCtrl()` chain rely on these fields being set.

5. **Japanese comments throughout.** Most inline comments and Javadoc are in Japanese. The field names are also Japanese abbreviations (e.g., `sodMap` = Service Order Dispatch map, `ido_div` = operation division, `svc_kei_no` = service contract number).

6. **Dummy service contract filtering.** The `getDummySvcKeiNo()` call at the start of `hakkoSOD()` retrieves a list of service contract numbers that should be skipped — likely for test data or special configurations.

7. **Price group driven logic.** The `prc_grp_cd` (price group code) is the primary discriminator for service type routing, not the operation type. This means the same operation (e.g., cancellation) may follow entirely different paths for network vs. phone vs. mobile services.

8. **IPv6 was added as an afterthought.** The IPv6 support (added 2012-02-29) is scattered across multiple methods and conditional branches. Look for `ANK-0046-00-01` comments marking IPv6-related changes.

9. **No outbound dependencies make it hard to test.** Since all CBS calls are done through `ServiceComponentRequestInvoker` with string-based message types, mocking CBS responses requires either framework-level testing or careful stubbing of `ServiceComponentRequestInvoker`.

10. **The class name means "Service Order Dispatch Component"** — `JKK` is a product code, `Hakko` (発行) means "issuance/distribution", `SOD` = Service Order Dispatch, `CC` = Component Class.
