# KKW02701SFLogic

## Purpose

`KKW02701SFLogic` is the business logic controller for the **reservation cancellation confirmation screen** in the KKW02701 series of the Japanese broadband ISP management system (specifically for "eo" — SoftBank/NTT Hikari internet/TV services). It handles the core workflow where a customer confirms and executes cancellation of their active service reservation, orchestrating service calls, validation checks, and screen navigation — all in a single class that bridges the web presentation layer with backend services.

## Design

This class follows the **Controller / Facade pattern** typical of the X31 framework. It extends `JCCWebBusinessLogic` and acts as the central coordination point for the KKW02701 (initial view), KKW02702 (confirmation after cancellation), and KKW02703 (confirmation update) screens. The class is stateful — it reads screen state from a `X31SDataBeanAccess` form bean, calls backend services (`KKSV0394`, `KKSV0395`, `KKSV0396`) via `invokeService()`, processes results, and delegates navigation decisions to the framework.

The class contains no persistent fields beyond static constants. All state flows through the framework's form bean and through local `HashMap` input/output maps passed to `invokeService()`.

## Key Methods

### Screen Lifecycle Methods

#### `init() -> boolean` [lines 202–209]

The entry point for the screen. Fetches the current screen information via `JCCWebCommon.getScreenInfo()`, then immediately delegates to `searchCourseRk()` to load the course history list. Returns `true` on success, `false` on error. This is the handler for the initial display of the cancellation confirmation screen.

#### `back() -> boolean` [lines 411–417]

Handles the "return" button press. Sets forward information to the current screen ID (effectively going back) and returns `true`. This is a lightweight no-op that delegates navigation to the framework.

#### `forwardFix() -> boolean` [lines 425–477]

Handles the "update" button press — i.e., when the user proceeds with the cancellation. The flow is:

1. Sets up input message parameters via `setInMsg()` with `FUNC_CODE_1`.
2. Invokes the backend service via `invokeService()`.
3. Checks for device reservation flag (`kikiOpRsvFlg`) — if set to `"1"`, shows error `EKBF750_KW` and returns `false`.
4. For eo Mobile 3G subscriptions (`PRC_GRP_CD_08`), validates the mobile course change cancellation result via `isMobileCourseChgCheckResult()` and warns with `EKB9480_KW` if inconsistent.
5. Sets a success message (`EKB9360__I`) and navigates to screen KKW02703 (update confirmation).

Returns `true` on success.

#### `forwardBack() -> boolean` [lines 485–489]

Handles the "return" button on a sub-screen. Simply re-invokes `searchCourseRk()` to refresh the course history list.

#### `forwardIdoDivChoice() -> boolean` [lines 497–517]

Handles the "diversion type selection" button press. Opens the choice screen (KKW00145) by getting screen info, populating the customer contract continuation data via `getHktgiDataMap()`, and setting forward information to the choice screen.

#### `forwardCustListShokai() -> boolean` [lines 525–531]

Handles the "customer list display" button press. Sets forward info to screen CKW00101 and returns `true`. A simple navigation handler.

#### `closeAply() -> boolean` [lines 540–570]

Handles the "set" button press added in v5.00.00. Manages the "discount automatic application target outside" flag — reading it from the service form bean and writing it into the customer data bean. Then calls `getHktgiDataMap()` to extract contract data, sets screen info for screen KKW00128, and navigates to the modular screen CCW00105.

### Core Business Logic

#### `searchCourseRk() -> boolean` [lines 589–681]

The central method that loads the course history list on screen initialization. Its processing flow:

1. Sets the operation date into the form bean.
2. Calls `KKSV0394_KKSV0394OPDBMapper.setKKSV039401CC()` to set up the service input parameters.
3. Invokes the `KKSV0394` backend service via `invokeService()`.
4. If an error result (`X31CMessageResult`) is returned, shows the message and returns `false`.
5. Maps the output results into the bean via `KKSV0394_KKSV0394OPDBMapper.getKKSV039401CC()`.
6. Determines button control flags based on popup mode (`setPopupValue()`): if popup mode is active, sets `CTRL_BUTTON_FLG` to `"0"`, otherwise computes button visibility rules based on service type, mansion flag, service status, and diversion type.
7. Sets forward info to screen KKW02701.

This method drives the entire screen's initial data population and UI configuration.

#### `setKKSV0395(X31SDataBeanAccess svcFormBean, HashMap<String, Object> inputMap, String funcCd) -> HashMap<String, String>` [lines 697–778]

Sets up the service parameters for the **net cancellation confirmation service** (`KKSV0395`). Creates a `KKSV0395_KKSV0395OPDBMapper`, then calls a large chain of mapper methods to set up input parameters — covering customer information, service codes, course history, temporary money cancellation, and various work flags. The method handles version-specific mapper calls (v4.02.00, v4.03.00, v5.00.00, v5.00.01, v5.00.02) with conditional `FUNC_CODE_1` vs `FUNC_CODE_2` routing. Sets the use case ID to `"KKSV0395"` in the parameter map and returns it.

#### `setKKSV0396(X31SDataBeanAccess svcFormBean, HashMap<String, Object> inputMap, String funcCd) -> HashMap<String, String>` [lines 794–835]

Sets up the service parameters for the **TV cancellation confirmation service** (`KKSV0396`). Structurally similar to `setKKSV0395` but for TV services. Creates a `KKSV0396_KKSV0396OPDBMapper` and calls its mapper methods. Handles version-specific additions (v5.00.02, v8.00.00, ANK-4592-00-00). Sets the use case ID to `"KKSV0396"` and returns the parameter map.

#### `setInMsg(X31SDataBeanAccess svcFormBean, HashMap<String, Object> inputMap, String funcCd) -> HashMap<String, String>` [lines 875–891]

Dispatches to either `setKKSV0395()` (for eo Net services, `SVC_CD_NET`) or `setKKSV0396()` (for eo TV services, `SVC_CD_TV`) based on the service code from the form bean. Returns `null` if neither matches. This is the central routing point that chooses which backend service to call based on the service type.

#### `setCourseRk() -> void` [lines 847–857]

Filters the course history list on the form bean to show only reservation records (`yoyaku Rekodo`). It removes all entries from index 1 onward, keeping only the first entry. Called after both `forwardRsvClCfm()` and `forwardFix()`.

### Validation / Check Methods

The following methods perform validation checks on service output maps and return `true` when the check passes (no issue) and `false` when an issue is detected:

#### `isIcjkn(HashMap<String, Object> outputMap, String kojiakKey) -> boolean` [lines 910–956]

Checks the **temporary money cancellation status**. If the work order (`kojiak`) exists in the output map, retrieves the first entry and checks its status. Only passes (`true`) if the work order status is `200` (work completed) or if the work order number doesn't match the current screen's `MSKM_DTL_KOJIAK_NO`. Returns `true` if the key is not present in the output map.

> Note: This method appears to be commented out in current code (OM-2015-0002629 DEL), but remains in the method inventory.

#### `isKktksvTkchuCheckResult(HashMap<String, Object> outputMap) -> boolean` [lines 1037–1076]

Checks whether **device provision service is active** (status `100`). Iterates through the `kktkSvKeiDelCCList` from either `KKSV039502CC` or `KKSV039604CC`. Returns `true` (pass) if no active device provision service is found; returns `false` if one is. This prevents cancellation when the customer still has an active device.

#### `isCouseRkRnkiCheckResult(HashMap<String, Object> outputMap) -> boolean` [lines 1094–1128]

Checks **course change linkage status** for eo Mobile 3G. Retrieves the `jgs_coursechg_rnk_ymd` (provider course change linkage date) from `KKSV039502SC`. Returns `true` if not present or if the date is not in the past (including today). Returns `false` only if the linkage date exists and is a past date — meaning the provider course change linkage has already occurred, which would be an issue for cancellation.

#### `isKkSonzaiCheckResult(HashMap<String, Object> outputMap) -> boolean` [lines 1147–1186]

Checks for **cloud router device presence**. Iterates through the `kktkSvKeiDelCCList` looking for `taknkiki_sbt_cd` equal to `L0` (cloud router). Returns `true` (pass) if no cloud router is found; returns `false` if a cloud router exists, blocking cancellation.

#### `isRouterSpeedCheckResult(HashMap<String, Object> outputMap, X31SDataBeanAccess svcFormBean) -> boolean` [lines 1205–1313]

The most complex validation method. Checks that the **router speed code matches the pricing course code**. For each work entry in the device provision service data, it validates a specific mapping:

| Router Type | Speed Code | Required Course Codes |
|---|---|---|
| 01 (Basic) | 10 (100M) | A05, A07, A10, A91, A92 |
| 02 (Basic Giga) | 20 (1G) | A03, A04, A06, A08, A09, A47–A57 |
| 03 (Old Wireless) | 10 (100M) | A05, A07, A10, A91, A92 |
| 04 (New Wireless) | 10 (100M) | A05, A07, A10, A91, A92 |
| 05 (New Wireless Giga) | 20 (1G) | No validation |
| All (10G) | 30 | A74, A83, A84, A89, A90, A93–A97, A99 |

Returns `true` (pass) if a valid mapping is found; `false` if the combination is invalid. Uses helper methods `isRcrs10G()`, `isRcrsRouter10()`, and `isRcrsRouter20()` for course code matching.

#### `isRcrsRouter10(String pcrsCd) -> boolean` [lines 1321–1336]

Checks if the course code corresponds to a **100M plan** (10G speed code `10`). Returns `true` for codes A05, A07, A10, A91, A92.

#### `isRcrsRouter20(String pcrsCd) -> boolean` [lines 1344–1368]

Checks if the course code corresponds to a **1G plan** (10G speed code `20`). Returns `true` for codes A03, A04, A06, A08, A09, A47–A57.

#### `isMobileCourseChgCheckResult(HashMap<String, Object> outputMap) -> boolean` [lines 1387–1417]

Checks **mobile course change cancellation**. For eo Mobile 3G, validates that the old/new course code pair is either `A26 <-> A59` (3G 7.2M standard type <-> 3G 7.2M optical hybrid type) or vice versa. Returns `true` (pass) if the change is not this specific pair (meaning no conflict), `false` if it matches the conflicting pair.

#### `isKojiRnkiCheckResult(HashMap<String, Object> outputMap) -> boolean` [lines 1434–1459]

Checks **work order linkage** for eo TV services. If `KKSV039613SC` exists and contains a `EKU0011B020CBSMsg1List` with any entries, returns `true` (meaning a work order exists — cancellation should not proceed). Returns `false` if no work order list is found.

#### `isNetKojiRnkiCheckResult(HashMap<String, Object> outputMap) -> boolean` [lines 1476–1518]

Checks **work order linkage** for eo Net services. If `KKSV039527SC` contains a `EKU0011B090CBSMsg1List`, checks each entry's `kojiak_stat`. Only permits cancellation (`true`) if all work orders have status `120` (registered), `130` (accepted), or `200` (completed). Returns `false` if any work order has a disallowed status.

#### `isRcrs10G(String pcrsCd) -> boolean` [lines 1693–1715]

Checks if the course code corresponds to a **10G plan**. Returns `true` for codes A74, A83, A84, A89, A90, A93–A99.

#### `isFatRouterExchangeCheckResult(HashMap<String, Object> outputMap, X31SDataBeanAccess svcFormBean) -> boolean` [lines 1725–1755]

Checks **multi-function router exchange compatibility** for eo Net services. Compares the current multi-function router speed code against the expected speed based on the pricing course:
- For 10G course codes, the expected speed code is `30` (10G)
- For other codes, the default is `20` (1G)
- If `other_mskm_takno_router_stat` is `110` (contract change in progress) or the current speed code is less than expected, returns `false`.

#### `isSptvStatCheckResult(HashMap<String, Object> outputMap, X31SDataBeanAccess svcFormBean) -> boolean` [lines 1765–1779]

Checks **CAS (Smart View) linkage status**. Reads `KKSV039608CC` and returns `false` (block) if `err_cd` equals `SPTV_ERR_CD_TOUROKU` (not yet registered for smart view linkage).

#### `isErrCdCheckResult(HashMap<String, Object> outputMap, X31SDataBeanAccess svcFormBean) -> boolean` [lines 1788–1802]

Checks for **system error codes**. Returns `false` if `KKSV039608CC` contains a non-blank `err_cd` that is not `SPTV_ERR_CD_TOUROKU`. This catches any unexpected error states.

#### `isCSOpCheckResult(HashMap<String, Object> outputMap, X31SDataBeanAccess svcFormBean) -> boolean` [lines 1811–1826]

Checks **CS operation status**. If `cs_option_um` in `KKSV039608CC` is `"1"`, returns `false` (blocked), indicating an active CS option prevents cancellation.

#### `isNotBlank(String arg0) -> boolean` [lines 1526–1534]

Simple utility: returns `true` if `arg0` is non-null and non-empty.

### Utility Methods

#### `getArrayListMap(HashMap<String, Object> map, String key) -> ArrayList<HashMap<String, Object>>` [lines 1544–1555]

Retrieves an `ArrayList<HashMap<String, Object>>` from a map by key. Returns `null` if the list is empty or not present, avoiding null-safety issues for callers.

#### `getValueMap(HashMap<String, Object> map, String key) -> String` [lines 1564–1574]

Retrieves a `String` value from a map by key. Returns `null` if the value is null or empty, providing null-safe value access.

#### `setForwardInfo(String next_id, String next_nm) -> void` [lines 1590–1602]

Sets navigation target information in the common info bean's `NEXT_SCREEN_ID` and `NEXT_SCREEN_NAME` fields. Called after every action handler to define where the next screen should be.

#### `getHktgiDataMap(X31SDataBeanAccess bean, String hktgiKey, String[] hktgiPrmKeys) -> HashMap<String, Object>` [lines 1613–1647]

Extracts customer contract continuation data from a service form bean into a `HashMap`. Iterates through a `X31SDataBeanAccessArray` and for each data bean, retrieves values for all keys in `hktgiPrmKeys`, handling both fixed-length and variable-length items (catching `X31SRuntimeException` and reading the count then individual elements). Returns a map containing a list of item maps.

#### `setPopupValue() -> boolean` [lines 1654–1684]

Determines button display mode based on the `HKTGI_POPUP_MODE` flag from the customer contract continuation list. Returns `true` if popup mode is empty or `"0"` (screen navigation mode — show "return" button). Returns `false` if mode is `"1"` or `"2"` (modular mode — show "close" button). Returns `false` if no customer contract list is set.

#### `setErrorInfo(String msgId, String[] repMsg, String... item) -> void` [lines 1835–1839]

Helper that iterates over an `item` array and calls `JCCWebCommon.setMessageInfo()` for each element, allowing multi-message error output in a single call.

## Relationships

```mermaid
flowchart TD
    KKW02701PJP["KKW027010PJP<br/>XML Config"]
    KKW02702PJP["KKW027020PJP<br/>XML Config"]
    KKW02703PJP["KKW027030PJP<br/>XML Config"]
    X31BizLogic["x31business_logic<br/>XML Config"]
    KKW02701SF["KKW02701SFLogic<br/>Cancellation Confirm Logic"]
    JCCWebBL["JCCWebBusinessLogic<br/>Base Class"]

    KKW02701PJP --> KKW02701SF
    KKW02702PJP --> KKW02701SF
    KKW02703PJP --> KKW02701SF
    X31BizLogic --> KKW02701SF
    KKW02701SF --> JCCWebBL
```

### Inbound (who depends on this class)

| Consumer | Relationship | Purpose |
|---|---|---|
| `WEBGAMEN_KKW027010PJP.xml` | References | Initial cancellation confirmation screen (KKW02701) |
| `WEBGAMEN_KKW027020PJP.xml` | References | Cancellation confirmation after processing (KKW02702) |
| `WEBGAMEN_KKW027030PJP.xml` | References | Update confirmation screen (KKW02703) |
| `x31business_logic_KKW02701SF.xml` | References | Business logic mapping configuration |

### Outbound (this class depends on)

| Dependency | Relationship | Purpose |
|---|---|---|
| `JCCWebBusinessLogic` | Parent class | Base framework class providing `invokeService()`, `getServiceFormBean()`, `getCommonInfoBean()` |

### Backend services called

- **KKSV0394** — Course history list retrieval (initial display)
- **KKSV0395** — Net service cancellation confirmation (eo Net/Internet)
- **KKSV0396** — TV service cancellation confirmation (eo Hikari TV)

## Usage Example

The typical lifecycle of this logic class for an eo Net cancellation:

1. **User loads the screen** → The framework calls `init()`, which calls `searchCourseRk()` to load the course history via KKSV0394, then configures button visibility based on popup mode and service conditions.

2. **User clicks the cancellation button** → The framework calls `forwardRsvClCfm()`, which:
   - Sets input parameters via `setInMsg()` → `setKKSV0395()` for Net services
   - Invokes the KKSV0395 backend service
   - Runs multiple validation checks: CAS linkage (`isSptvStatCheckResult`), system errors (`isErrCdCheckResult`), CS options (`isCSOpCheckResult`), work order status (`isKojiRnkiCheckResult` or `isNetKojiRnkiCheckResult`), device provision status (`isKktksvTkchuCheckResult`), router speed (`isRouterSpeedCheckResult`), and router exchange compatibility (`isFatRouterExchangeCheckResult`)
   - Filters the course history to show only reservation records via `setCourseRk()`
   - Navigates to KKW02702 (cancellation confirmation screen)

3. **User confirms the cancellation** → The framework calls `forwardFix()`, which follows a similar pattern, invokes the service, and navigates to KKW02703 (update confirmation screen).

## Notes for Developers

- **Service type branching**: The class branches logic based on `svcCd` (service code). `SVC_CD_NET` (eo Net) uses KKSV0395 and the Net-specific work order check (`isNetKojiRnkiCheckResult`). `SVC_CD_TV` (eo TV) uses KKSV0396 and the TV-specific work order check (`isKojiRnkiCheckResult`). The class handles both in a single code path.

- **Mobile 3G special handling**: When `prcGrpCd` equals `PRC_GRP_CD_08` (eo Mobile 3G), additional validation for course change linkage and cloud router presence is applied during cancellation.

- **Popup mode determines button behavior**: `setPopupValue()` controls whether the "return" button or "close" button is displayed. This affects how the `CTRL_BUTTON_FLG` is set — mode `"0"`/empty means screen navigation (show return), mode `"1"`/`"2"` means modular (show close).

- **Button control flags**: In v5.00.00, special logic was added for mansion-type Net services with specific diversion types (00009 — course change) that show the "discount automatic application target outside" button (`BTN_CTRL_FLG = "3"`) or hide it (`BTN_CTRL_FLG = "2"`).

- **All validation methods use the same pattern**: They return `true` when validation passes (proceed with cancellation) and `false` when an issue is detected (block or warn). However, not all failures are fatal — some (like `isCouseRkRnkiCheckResult`) only set a warning message and continue, rather than blocking.

- **Thread safety**: This class is not thread-safe. It maintains no instance state (all fields are static constants), but it reads/writes to shared form beans that are typically per-request. Each request creates a new instance.

- **Date-sensitive validation**: The `isCouseRkRnkiCheckResult()` method uses `JPCDateChecker.isPastDate()` to compare dates, so cancellation behavior can differ based on when the operation is performed relative to the provider course change linkage date.

- **The `setErrorInfo` helper** loops over items to set multiple messages, allowing composite error messages (e.g., "System Error / Target Reservation is Cancelled") to be displayed with parameter substitution.
