# Business Logic — WribSvcKeiMover.transform() [80 LOC]

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

## 1. Role

### WribSvcKeiMover.transform()

This method acts as a **discount/surcharge service contract data transformer** — it converts incoming CBS (Central Billing System) interface message data (`CAANMsg`) into a normalized `HashMap<String, String>` suitable for downstream processing by the Wrib (discount/surcharge) service chain. In the K-Opticom telecom domain, **wrib (割引)** encompasses both discount operations (**wrib**, code `"w"`) and surcharge operations (**hnsoku**, code `"d"`).

The method implements a **routing/dispatch pattern** based on the `WRIB_DCHS_HAMBET_CD` (discount/surcharge discrimination code) field extracted from the input message. When the code equals `"1"`, the method treats the record as a discount-type contract (`KeiKind.WRIB`), and applies special date arithmetic logic (v5.00.24) to compute the effective start date when the original start date is set to the sentinel value `20991231`. When the code is anything else, it treats the record as a surcharge-type contract (`KeiKind.HNSOKU`).

For surcharge-type records, if the discrimination code is `"DT0000002"` (Net/Phone/TV 3-point application — a bundled telecom service package), the method explicitly clears the start date and end date fields, as these services do not have date-bound billing periods. The method is invoked by batch processors, screen transaction CBS callers, and cross-service controllers (CIS, TRANK, MVNO), serving as a shared utility that normalizes discount/surcharge service contract data for downstream consumption.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["transform(CAANMsg in)"])
    END_NODE(["Return out"])

    START --> INIT["out = new HashMap<String, String>(DEFAULT_HASH_SIZE)"]
    INIT --> GET_KEI["String keiKind = in.getString(WRIB_DCHS_HAMBET_CD)"]
    GET_KEI --> COND_KEI{keiKind equals 1?}

    COND_KEI -->|Yes WRIB| WRIB_BR["Set KeiKind.WRIB w"]
    WRIB_BR --> WRIB_GET_S["sYmd = in.getString(SVC_CHRG_DCHSKMST_STAYMD)"]
    WRIB_BR --> WRIB_GET_E["eYmd = in.getString(SVC_CHRG_DCHSKMST_ENDYMD)"]
    WRIB_GET_S --> WRIB_DATE_COND{sYmd equals 20991231?}
    WRIB_GET_E --> WRIB_DATE_COND

    WRIB_DATE_COND -->|Yes| WRIB_END_CHECK{eYmd not blank and not 20991231?}
    WRIB_END_CHECK -->|Yes| WRIB_ADD["sYmd = JPCDateUtil.addDay(eYmd, 1)"]
    WRIB_END_CHECK -->|No| WRIB_PUTS["Populate out with 13 fields
staymd uses computed sYmd"]
    WRIB_ADD --> WRIB_PUTS

    WRIB_DATE_COND -->|No| WRIB_PUTS

    COND_KEI -->|No HNSOKU| HNSOKU_BR["Set KeiKind.HNSOKU d"]
    HNSOKU_BR --> HNS_PUTS["Populate out with 13 fields
staymd endymd from input directly"]
    HNS_PUTS --> HNS_THREE{WISVCD_DCHSKM_CD equals DT0000002?}
    HNS_THREE -->|Yes| HNS_CLEAR["Clear staymd and endymd to empty"]
    HNS_CLEAR --> END_NODE
    HNS_THREE -->|No| END_NODE

    WRIB_PUTS --> END_NODE
```

**Processing summary:**

1. Initialize an empty output HashMap with `DEFAULT_HASH_SIZE` capacity.
2. Extract the **discount/surcharge discrimination code** (`WRIB_DCHS_HAMBET_CD`) from the input message to determine the processing branch.
3. **Branch on discrimination code `"1"` (WRIB/Discount):** Set `kei_kind` to `"w"`. Extract start date and end date, then apply the v5.00.24 date computation: if the start date is the sentinel `20991231` (meaning "unspecified — compute from end date"), and the end date is valid (not blank, not `20991231`), compute the effective start date as `end date + 1 day`. Populate 13 fields in the output map using the computed start date.
4. **Branch on discrimination code != "1" (HNSOKU/Surcharge):** Set `kei_kind` to `"d"`. Populate all 13 fields directly from the input message without date computation. Then, if the discrimination code equals `"DT0000002"` (Net/Phone/TV 3-point application), clear both `staymd` and `endymd` to empty strings, as these services have no date-bound billing.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `in` | `CAANMsg` | The input CBS interface message carrying discount/surcharge service contract data. It contains fields such as the discrimination code (`WRIB_DCHS_HAMBET_CD`), service contract number, status, type code, campaign information, service name, application flag, and billing period dates (start/end). This message originates from the K-Opticom CBS system and represents a single discount or surcharge line item within a service contract. |

**Instance fields / external state read:**
- `DEFAULT_HASH_SIZE` — static constant defining the initial capacity of the output HashMap (value inferred from context as a typical Java collections default, e.g., 16).

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `in.getString(EKK0451B011CBSMsg1List.WRIB_DCHS_HAMBET_CD)` | - | - | Reads the discount/surcharge discrimination code from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.SVC_CHRG_DCHSKMST_STAYMD)` | - | - | Reads the service charge / discount item setting start date from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.SVC_CHRG_DCHSKMST_ENDYMD)` | - | - | Reads the service charge / discount item setting end date from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_NO)` | - | - | Reads the discount service contract / discount item setting number from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_STAT)` | - | - | Reads the discount service contract / discount item setting status from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_STAT_NM)` | - | - | Reads the discount service contract / discount item setting status name from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.WRIB_DCHS_TYPE_CD)` | - | - | Reads the discount / discount type code from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.WRIB_DCHS_TYPE_CD_NM)` | - | - | Reads the discount / discount type code name from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.DSP_CAMPAIGN_DCHSKM_CD)` | - | - | Reads the display-purpose campaign / discount item code from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.WRISVC_DCHSKM_CD)` | - | - | Reads the discount service / discount item code from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.WRISVC_DCHSKM_NM)` | - | - | Reads the discount service / discount item name from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.MSKM_YMD)` | - | - | Reads the application year/month/day from the input message |
| R | `in.getString(EKK0451B011CBSMsg1List.APLY_JUN_NM)` | - | - | Reads the immediate application flag name from the input message |
| C | `JPCDateUtil.addDay` | - | - | Calls `JPCDateUtil.addDay(String date, int days)` to compute `end date + 1` for the effective start date |
| C | `JKKWribSvcKeiOperateCC.KeiKind.WRIB.getKeiKind()` | - | - | Returns the constant `"w"` for discount-type contract classification |
| C | `JKKWribSvcKeiOperateCC.KeiKind.HNSOKU.getKeiKind()` | - | - | Returns the constant `"d"` for surcharge-type contract classification |
| C | `out.put(String key, String value)` | - | - | Writes key-value pairs into the output HashMap (13 puts in each branch) |

**Classification rationale:**
- All `in.getString()` calls are **Read** operations — they extract data from the incoming CBS message (no DB interaction, but data is being read from the message envelope).
- `JPCDateUtil.addDay()` is a **Compute** operation — date arithmetic utility.
- `KeiKind.getKeiKind()` is a **Compute** operation — returns a fixed enum constant string.
- `out.put()` is **Create** — builds the output HashMap structure.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JKKBatKKCashPostBase | `JKKBatKKCashPostBase.execute()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 2 | Component: Items | `Items.map()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 3 | CBS: JECNA0040001TPMA | `JECNA0040001TPMA.invoke()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 4 | CBS: JECNA0040002TPMA | `JECNA0040002TPMA.invoke()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 5 | CBS: JECNA0150001TPMA | `JECNA0150001TPMA.callPost()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 6 | CBS: JECNA0160001TPMA | `JECNA0160001TPMA.callPost()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 7 | SEC: JKKejbKKA0010002SecProc | `JKKejbKKA0010002SecProc.searchCredit()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 8 | SEC: JKKejbKKA001SecProc | `JKKejbKKA001SecProc.shokaiOsrIrai()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 9 | SEC: JKKejbKKA0110001SecProc | `JKKejbKKA0110001SecProc.execute()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 10 | Controller: JCKCtrlCisInfoImpl | `JCKCtrlCisInfoImpl.call_CIS()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 11 | Controller: JCKCtrlCisInfoStubImpl | `JCKCtrlCisInfoStubImpl.call_CIS()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 12 | Controller: JCRCtrlTnInfoImpl | `JCRCtrlTnInfoImpl.ctrlTnInfo_CRA0001()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 13 | Controller: JKKCtrlMvnoSvcKeiInfoImpl | `JKKCtrlMvnoSvcKeiInfoImpl.ctrlMvnoInfo_KKA0003()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 14 | Controller: JZMCtrlCisInfoImpl | `JZMCtrlCisInfoImpl.ctrlCisInfo_ZMA0001()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 15 | Controller: JZMCtrlTrankInfoImpl | `JZMCtrlTrankInfoImpl.call_TRANK()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |
| 16 | Utility: JFUXPathManager | `JFUXPathManager.getDomSize()` -> `WribSvcKeiMover.transform` | `getString [R] (input message fields)` |

## 6. Per-Branch Detail Blocks

**Block 1** — [PROCESS] Initialize output map (L17036)

> Creates the output HashMap that will hold the transformed discount/surcharge service contract data.

| # | Type | Code |
|---|------|------|
| 1 | SET | `HashMap<String, String> out = new HashMap<String, String>(DEFAULT_HASH_SIZE);` // Create output map with default initial capacity |

**Block 2** — [SET] Extract discrimination code (L17051)

> Reads the discount/surcharge discrimination code from the input message to determine which processing branch to take.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String keiKind = in.getString(EKK0451B011CBSMsg1List.WRIB_DCHS_HAMBET_CD);` // Read discount/surcharge discrimination code |

**Block 3** — [IF] Discrimination code equals "1" (WRIB/Discount) (L17052)

> Condition: `keiKind.equals("1")` — This branch handles discount-type service contracts. The inner enum `KeiKind.WRIB` maps to the value `"w"`, distinguishing discount operations from surcharge operations (`"d"`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `String sYmd = in.getString(EKK0451B011CBSMsg1List.SVC_CHRG_DCHSKMST_STAYMD);` // Read billing start date [v5.00.24] |
| 2 | SET | `String eYmd = in.getString(EKK0451B011CBSMsg1List.SVC_CHRG_DCHSKMST_ENDYMD);` // Read billing end date [v5.00.24] |

**Block 3.1** — [IF] Start date is sentinel value (L17057)

> v5.00.24 date computation logic: when the start date (`sYmd`) is set to `"20991231"` (a sentinel meaning "unspecified"), and the end date is valid, compute the effective start date as the day after the end date. This is a business rule for discount contracts where the start date was not explicitly set.

| # | Type | Code |
|---|------|------|
| 1 | IF | `"20991231".equals(sYmd)` // Check if start date is sentinel value |
| 2 | IF | `!JKKStringUtil.isNullBlank(eYmd) && !"20991231".equals(eYmd)` // Check if end date is valid (not blank, not sentinel) |
| 3 | SET | `sYmd = JPCDateUtil.addDay(eYmd, 1);` // Compute start date as end date + 1 day [v5.00.24] |

**Block 3.2** — [PROCESS] Populate output map for discount branch (L17061–L17075)

> Copies 13 fields from the input message into the output HashMap for discount-type contracts. The `staymd` field uses the computed `sYmd` value (which may have been updated by the v5.00.24 date logic).

| # | Type | Code |
|---|------|------|
| 1 | SET | `out.put("no", in.getString(EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_NO));` // Discount service contract number |
| 2 | SET | `out.put("kei_kind", JKKWribSvcKeiOperateCC.KeiKind.WRIB.getKeiKind());` // Set to "w" (discount) |
| 3 | SET | `out.put("stat", in.getString(EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_STAT));` // Discount service contract status |
| 4 | SET | `out.put("stat_nm", in.getString(EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_STAT_NM));` // Discount service contract status name |
| 5 | SET | `out.put("type_cd", in.getString(EKK0451B011CBSMsg1List.WRIB_DCHS_TYPE_CD));` // Discount type code |
| 6 | SET | `out.put("type_cd_nm", in.getString(EKK0451B011CBSMsg1List.WRIB_DCHS_TYPE_CD_NM));` // Discount type code name |
| 7 | SET | `out.put("campaign_cd", in.getString(EKK0451B011CBSMsg1List.DSP_CAMPAIGN_DCHSKM_CD));` // Campaign code |
| 8 | SET | `out.put("campaign_nm", in.getString(EKK0451B011CBSMsg1List.WRISVC_DCHSKM_NM));` // Campaign name (service name) |
| 9 | SET | `out.put("mskm_ymd", in.getString(EKK0451B011CBSMsg1List.MSKM_YMD));` // Application year/month/day |
| 10 | SET | `out.put("staymd", sYmd);` // Effective start date — may be computed if original was sentinel [v5.00.24] |
| 11 | SET | `out.put("endymd", in.getString(EKK0451B011CBSMsg1List.SVC_CHRG_DCHSKMST_ENDYMD));` // End date |
| 12 | SET | `out.put("wrib_svc_cd", in.getString(EKK0451B011CBSMsg1List.WRISVC_DCHSKM_CD));` // Discount service code |
| 13 | SET | `out.put("aply_jun_nm", in.getString(EKK0451B011CBSMsg1List.APLY_JUN_NM));` // Immediate application flag name |

**Block 4** — [ELSE] Not "1" (HNSOKU/Surcharge) (L17077)

> This else branch handles surcharge-type service contracts. The inner enum `KeiKind.HNSOKU` maps to the value `"d"`, distinguishing surcharge operations from discount operations (`"w"`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `out.put("no", in.getString(EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_NO));` // Discount service contract number |
| 2 | SET | `out.put("kei_kind", JKKWribSvcKeiOperateCC.KeiKind.HNSOKU.getKeiKind());` // Set to "d" (surcharge) |
| 3 | SET | `out.put("stat", in.getString(EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_STAT));` // Surcharge service contract status |
| 4 | SET | `out.put("stat_nm", in.getString(EKK0451B011CBSMsg1List.WRIBSVK_DCHSKMST_STAT_NM));` // Surcharge service contract status name |
| 5 | SET | `out.put("type_cd", in.getString(EKK0451B011CBSMsg1List.WRIB_DCHS_TYPE_CD));` // Surcharge type code |
| 6 | SET | `out.put("type_cd_nm", in.getString(EKK0451B011CBSMsg1List.WRIB_DCHS_TYPE_CD_NM));` // Surcharge type code name |
| 7 | SET | `out.put("campaign_cd", in.getString(EKK0451B011CBSMsg1List.DSP_CAMPAIGN_DCHSKM_CD));` // Campaign code |
| 8 | SET | `out.put("campaign_nm", in.getString(EKK0451B011CBSMsg1List.WRISVC_DCHSKM_NM));` // Campaign name |
| 9 | SET | `out.put("mskm_ymd", in.getString(EKK0451B011CBSMsg1List.MSKM_YMD));` // Application year/month/day |
| 10 | SET | `out.put("staymd", in.getString(EKK0451B011CBSMsg1List.SVC_CHRG_DCHSKMST_STAYMD));` // Start date from input directly (no date computation) |
| 11 | SET | `out.put("endymd", in.getString(EKK0451B011CBSMsg1List.SVC_CHRG_DCHSKMST_ENDYMD));` // End date from input directly |
| 12 | SET | `out.put("wrib_svc_cd", in.getString(EKK0451B011CBSMsg1List.WRISVC_DCHSKM_CD));` // Discount service code |
| 13 | SET | `out.put("aply_jun_nm", in.getString(EKK0451B011CBSMsg1List.APLY_JUN_NM));` // Immediate application flag name |

**Block 4.1** — [IF] Net/Phone/TV 3-point application check (L17080)

> LT-2013-0000101 response branch: For the "Net/Phone/TV 3-point application" service (bundled telecom package), both start and end dates must remain unset, as these services do not have date-bound billing periods. The discrimination code constant `DT0000002` is compared against the `WRISVC_DCHSKM_CD` field.

| # | Type | Code |
|---|------|------|
| 1 | SET | `final String TgHansoku = "DT0000002";` // Net/Phone/TV 3-point application discrimination code |
| 2 | IF | `TgHansoku.equals(in.getString(EKK0451B011CBSMsg1List.WRISVC_DCHSKM_CD))` // Check if service is the 3-point bundled package [LT-2013-0000101] |
| 3 | SET | `out.put("staymd", "");` // Clear start date |
| 4 | SET | `out.put("endymd", "");` // Clear end date |

**Block 5** — [RETURN] Return transformed data (L17090)

> Returns the fully populated output HashMap containing the normalized discount/surcharge service contract data.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return out;` // Return transformed map |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `wrib` (割引) | Field | Discount — refers to price reductions applied to telecom service contracts |
| `hnsoku` (増収) | Field | Surcharge/Revenue Increase — refers to price additions applied to telecom service contracts |
| `kei_kind` | Field | Line type classification — `"w"` for discount, `"d"` for surcharge operations |
| `WRIB_DCHS_HAMBET_CD` | Field | Discount/Surcharge discrimination code — determines whether a record is a discount (`"1"`) or surcharge type |
| `WRIBSVK_DCHSKMST_NO` | Field | Discount service contract / discount item setting number — unique identifier for the discount/surcharge line item |
| `WRIBSVK_DCHSKMST_STAT` | Field | Discount service contract / discount item setting status — operational status (e.g., active, cancelled) |
| `WRIBSVK_DCHSKMST_STAT_NM` | Field | Discount service contract / discount item setting status name — human-readable status description |
| `WRIB_DCHS_TYPE_CD` | Field | Discount / discount type code — classification of the discount or surcharge type |
| `WRIB_DCHS_TYPE_CD_NM` | Field | Discount / discount type code name — human-readable discount type description |
| `DSP_CAMPAIGN_DCHSKM_CD` | Field | Display-purpose campaign / discount item code — campaign identifier associated with the discount |
| `WRISVC_DCHSKM_CD` | Field | Discount service / discount item code — service code for the discount/surcharge offering |
| `WRISVC_DCHSKM_NM` | Field | Discount service / discount item name — human-readable name of the discount/surcharge service |
| `mskm_ymd` | Field | Application year/month/day — the date when the discount/surcharge contract application was submitted |
| `svc_chrg_dchskmst_staymd` | Field | Service charge / discount item setting start date — when billing begins |
| `svc_chrg_dchskmst_endymd` | Field | Service charge / discount item setting end date — when billing ends |
| `aply_jun_nm` | Field | Immediate application flag name — indicates whether the discount/surcharge is applied immediately |
| `DT0000002` | Constant | Net/Phone/TV 3-point application — a bundled telecom service package where start/end dates are not applicable |
| `20991231` | Constant | Sentinel date value — used as a placeholder meaning "unspecified date"; triggers date computation logic when found in start date field |
| `KeiKind` | Enum | Internal discount/surcharge classification — `WRIB("w")` for discount, `HNSOKU("d")` for surcharge, `NULL("")` for undefined |
| CAANMsg | Class | Fujitsu's message wrapper class — carries field-value pairs used across CBS interface communication |
| JPCDateUtil | Class | Date utility class — provides date arithmetic operations such as `addDay(date, offset)` |
| CBS | Acronym | Central Billing System — the core billing system in the K-Opticom telecom infrastructure |
| WRIB | Acronym | Discount (Japanese: 割引) — price reduction on telecom service contracts |
| HNSOKU | Acronym | Surcharge/Revenue Increase (Japanese: 増収) — price addition on telecom service contracts |
| v5.00.24 | Version | Software version introducing date computation logic for discount contracts where start date is the sentinel value |
| LT-2013-0000101 | Ticket | Issue tracking ID for the Net/Phone/TV 3-point application special case handling |
| WribSvcKeiMover | Class | Discount/Surcharge service contract data mover — transforms CBS messages into normalized HashMaps for downstream processing |
| DEFAULT_HASH_SIZE | Constant | Initial capacity for the output HashMap (Java collections default, typically 16) |

---
