---
# Business Logic — KKIFE499.execute() [12 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `local.gyomu.api.KKIFE499` |
| Layer | Controller (JAX-RS REST API) |
| Module | `api` (Package: `local.gyomu.api`) |

## 1. Role

### KKIFE499.execute()

This method is the REST API entry point for the **Referral Code Issuance (CMP/LINE) Processing Class** (紹介コード発番（CMP・LINE）受付処理クラス). It serves as a POST endpoint at `POST /KKIFE499` that receives referral code issuance requests from external systems and dispatches them to the core business processing pipeline. The method is part of the eo Customer Backbone System (eo顧客基幹システム) and handles referral code generation for both the CMP system and LINE platform integrations.

This method implements the **delegation pattern**: it acts as a thin REST controller that immediately hands off processing to its parent class `ApiServerLocalBase.exec()`. The parent's `exec()` method in turn invokes the `run()` template method (which calls `logicExecute()`), routing the request to the appropriate backend BP Service (`KKSV1013`) based on the authentication identifier (`authId`) in the request header. This three-layer delegation (`execute` → `exec` → `run` → `logicExecute`) provides a clean separation between the HTTP interface layer and the business logic layer.

In the larger system, KKIFE499 acts as an **API integration gateway** that enables both LINE (`eoforwtsn`) and the eo mobile app (`eoforeama`, added in version 72.00.00 / ANK-4629-00-00) to request referral code issuance. The method is invoked as part of an asynchronous work processing flow triggered by CMP screens.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["KKIFE499.execute()"]) --> DISPATCH["super.exec APIID, pRequest, pContext"]
    DISPATCH --> RUN["run(reqPartsBean)"]
    RUN --> LOGIC["logicExecute(reqPartsBean)"]
    LOGIC --> GET_HDR["Get authId from header"]
    GET_HDR --> COND_AUTH{"authId check"}
    COND_AUTH -->|"eoforwtsn"| SET_LINE["Set systemId = API1"]
    COND_AUTH -->|"eoforeama"| SET_EOAPP["Set systemId = EAM1"]
    COND_AUTH -->|"default"| SET_CMP["Set systemId = CMP1"]
    SET_LINE --> CALL_BP["callBpService2 KKSV1013"]
    SET_EOAPP --> CALL_BP
    SET_CMP --> CALL_BP
    CALL_BP --> BP_SVC["BP Service KKSV1013"]
    BP_SVC --> EXTRACT["Extract result from outputMap"]
    EXTRACT --> BUILD_RESP["Build ApiServerPartsBean"]
    BUILD_RESP --> RETURN["Return response"]
    DISPATCH --> RETURN
```

**Processing flow:**

1. **Entry Point (`execute`)** — Receives the HTTP POST request and delegates to `super.exec(APIID, pRequest, pContext)` in `ApiServerLocalBase`.

2. **Request Dispatch (`super.exec`)** — The parent class handles the core HTTP request processing lifecycle: parsing the request body, building an `ApiServerPartsBean` request object, invoking the `run()` template method, and constructing the final `Response` object.

3. **Business Logic Invocation (`run`)** — The overridden `run()` method calls `logicExecute(reqPartsBean)` to perform the actual business processing and returns the `ApiServerPartsBean` response.

4. **System Routing (`logicExecute`)** — The method determines which target system to route the service call to, based on the `authId` value found in the request header:
   - **LINE System** (`AUTH_ID_LINE = "eoforwtsn"`): Routes to LINE backend system (`SYSTEM_ID_LINE = "API1"`)
   - **eo Mobile App** (`AUTH_ID_EOAPP = "eoforeama"`): Routes to eo Application backend system (`SYSTEM_ID_EOAPP = "EAM1"`)
   - **Default (CMP System)**: Falls back to the CMP core system (`SYSTEM_ID_CMP = "CMP1"`)

5. **BP Service Dispatch (`callBpService2`)** — Invokes the backend processing service `KKSV1013` (the referral code issuance service) with the resolved `systemId` as the operator ID. The service ID is fixed to `KKSV1013`.

6. **Result Extraction & Response Building** — Extracts the processed result from the `outputMap` under the key `serviceId + "01CC"` (i.e., `KKSV101301CC`), wraps it in a new `ApiServerPartsBean`, and returns it.

**Constant Resolution:**

| Constant | Value | Business Meaning |
|----------|-------|-----------------|
| `APIID` | `"KKIFE499"` | API identifier used as the request key |
| `SERVICE_ID` | `"KKSV1013"` | Backend BP Service ID for referral code issuance |
| `SYSTEM_ID_CMP` | `"CMP1"` | CMP (Core Marketing Platform) backend system ID |
| `SYSTEM_ID_LINE` | `"API1"` | LINE integration backend system ID |
| `SYSTEM_ID_EOAPP` | `"EAM1"` | eo mobile application backend system ID |
| `JOB_ID` | `"KKIFE499"` | Job identifier passed to the BP service layer |
| `AUTH_ID_LINE` | `"eoforwtsn"` | Authentication identifier for LINE system requests |
| `AUTH_ID_EOAPP` | `"eoforeama"` | Authentication identifier for eo mobile app requests |
| `_01CC` | `"01CC"` | Response data key suffix used to extract results from the output map |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `pRequest` | `@Context final HttpServletRequest` | The incoming HTTP POST request carrying the referral code issuance payload. Contains request headers (including the `authId` field that determines the target system) and a JSON body with the service business data. |
| 2 | `pContext` | `@Context final ServletContext` | The servlet context providing the runtime environment. Used by the parent `exec()` method for application-level configuration and resource access. |

**Instance fields / external state:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `APIID` | `String` | Fixed API identifier `"KKIFE499"` for request dispatch |
| `SERVICE_ID` | `String` | Backend BP Service ID `"KKSV1013"` — referral code issuance service |
| `JOB_ID` | `String` | Job identifier `"KKIFE499"` passed to the BP service layer for audit tracking |
| `AUTH_ID_LINE` | `String` | Authentication ID `"eoforwtsn"` that identifies LINE platform requests |
| `AUTH_ID_EOAPP` | `String` | Authentication ID `"eoforeama"` that identifies eo mobile app requests |
| `SYSTEM_ID_CMP` | `String` | Target system ID `"CMP1"` — the CMP core system |
| `SYSTEM_ID_LINE` | `String` | Target system ID `"API1"` — the LINE integration backend |
| `SYSTEM_ID_EOAPP` | `String` | Target system ID `"EAM1"` — the eo mobile application backend |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `ApiServerLocalBase.exec` | - | - | Parent class method that handles the HTTP request dispatch, parameter parsing, and orchestrates the `run()` template method. Invoked as `super.exec(APIID, pRequest, pContext)`. |
| - | `KKIFE499.run` | - | - | Template method overridden to delegate to `logicExecute()` and return the processed response bean. |
| - | `KKIFE499.logicExecute` | - | - | Core business logic method that determines target system routing and calls the BP service. |
| - | `ApiServerLocalBase.callBpService2` | - | - | Delegates to the backend BP Service (KKSV1013) for referral code issuance processing. Wraps the request in a `HashMap` and invokes `ApiBpInterface.invokeService`. |
| - | `KKSV1013` | KKSV1013SC | Various (defined in KKSV1013) | Backend BP Service for referral code issuance. Receives the request data and processes the referral code generation logic. Specific database operations are performed within this service. |

**Note:** This method (`execute`) is a thin REST controller that does not directly perform CRUD operations. All database operations are delegated to the backend BP Service `KKSV1013` via the `callBpService2` invocation. The `logicExecute` method extracts the service result from the `outputMap` under the key `KKSV101301CC` but does not directly access any database tables.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | REST Client (LINE/eoApp/CMP) | `POST /KKIFE499` → `KKIFE499.execute(pRequest, pContext)` | `callBpService2 [C/R] KKSV1013` |

**Notes on callers:**
- KKIFE499 is accessed via HTTP POST to the JAX-RS path `/KKIFE499`.
- The `@Path("KKIFE499")` annotation registers this class as a REST resource endpoint.
- No internal Java callers were found — this is a public REST API consumed by external clients.
- The request routing within `logicExecute()` supports three client types based on the `authId` header:
  - LINE platform (`eoforwtsn`) → routed to LINE backend (`API1`)
  - eo mobile app (`eoforeama`) → routed to eo app backend (`EAM1`)
  - CMP system or any other → routed to CMP backend (`CMP1`) as default

## 6. Per-Branch Detail Blocks

### execute() Method — Public REST Entry Point (L89–100)

**Block 1** — [METHOD] `execute(HttpServletRequest pRequest, ServletContext pContext)` (L89)

> Public REST endpoint annotated with `@POST`. Delegates all processing to the parent class `exec()` method.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `super.exec(APIID, pRequest, pContext)` | Dispatches the HTTP request to the parent class for processing. Passes the API ID `KKIFE499` along with the request and servlet context. |
| 2 | RETURN | `return response` | Returns the `Response` object produced by the parent class. |

### logicExecute() Method — Business Logic Routing (L119–158)

**Block 2** — [METHOD] `logicExecute(ApiServerPartsBean reqPartsBean)` (L119)

> Core business logic that determines the target system based on the authentication ID and invokes the BP service.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `String serviceId = SERVICE_ID` | Sets the fixed service ID to `KKSV1013` for referral code issuance. |
| 2 | SET | `String systemId = null` | Initializes `systemId` to null; will be determined by authId check. |
| 3 | IF | `AUTH_ID_LINE.equals(reqPartsBean.getHeader().get("authId"))` `[AUTH_ID_LINE="eoforwtsn"]` (L128) | Checks if the request originates from the LINE platform. |

**Block 2.1** — [IF-BRANCH] LINE system identification `[AUTH_ID_LINE="eoforwtsn"]` (L130)

> When the request is authenticated as coming from LINE, route to the LINE backend system.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `systemId = SYSTEM_ID_LINE` `[SYSTEM_ID_LINE="API1"]` | Sets target system to LINE backend (`API1`). |

**Block 2.2** — [ELSE-IF] eo mobile app identification `[AUTH_ID_EOAPP="eoforeama"]` (L136)

> When the request is authenticated as coming from the eo mobile app, route to the eo application backend system. Added in version 72.00.00 (ANK-4629-00-00).

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `systemId = SYSTEM_ID_EOAPP` `[SYSTEM_ID_EOAPP="EAM1"]` | Sets target system to eo app backend (`EAM1`). |

**Block 2.3** — [ELSE] Default CMP system (L141)

> When the `authId` does not match LINE or eo app identifiers, default to the CMP core system.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `systemId = SYSTEM_ID_CMP` `[SYSTEM_ID_CMP="CMP1"]` | Sets target system to CMP core (`CMP1`) as fallback. |

**Block 3** — [AFTER IF-ELSE] BP Service Invocation (L145)

> Calls the backend BP Service with the resolved system ID.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `callBpService2(serviceId, reqPartsBean, JOB_ID, systemId)` | Invokes BP Service `KKSV1013` with request data, job ID `KKIFE499`, and the resolved target system ID as the operator identifier. Returns a result map. |
| 2 | SET | `Map<String, Object> resultMap = (Map<String, Object>)outMap.get(serviceId + _01CC)` `[serviceId + _01CC = "KKSV101301CC"]` | Extracts the service processing result from the output map using the key `KKSV101301CC`. |
| 3 | SET | `ApiServerPartsBean resPartsBean = new ApiServerPartsBean()` | Creates a new response bean to wrap the result. |
| 4 | EXEC | `resPartsBean.setBody(resultMap)` | Sets the extracted result map as the response body. |
| 5 | RETURN | `return resPartsBean` | Returns the response bean to the caller. |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `referral code` | Domain concept | A unique promotional code issued during customer referral processes. Used for marketing and customer acquisition tracking. |
| `紹介コード発番` | Japanese term | Referral Code Issuance — the process of generating and assigning a unique referral code. |
| `CMP` | Acronym | Core Marketing Platform — the central marketing and customer management system. |
| `LINE` | Business term | LINE messaging platform integration — enables customer interactions and referral code requests through the LINE app. |
| `eo` | Business term | eo — NTT Docomo's mobile brand. The "eo mobile app" (eoアプリ) is the official mobile application. |
| `eoアプリ` | Japanese term | eo Application — the mobile application for eo brand customers. |
| `AUTH_ID_LINE` | Field | Authentication identifier `"eoforwtsn"` — identifies requests originating from the LINE platform. |
| `AUTH_ID_EOAPP` | Field | Authentication identifier `"eoforeama"` — identifies requests originating from the eo mobile application. |
| `KKSV1013` | Service ID | Backend BP Service for referral code issuance processing. This is the core service that performs the actual business logic. |
| `systemId` | Field | Target system identifier (`CMP1`, `API1`, or `EAM1`) that determines which backend system processes the referral code request. |
| `authId` | Field | Authentication identifier in the request header that determines the source system of the request. |
| `_01CC` | Constant | Response data key suffix `01CC` — used as the key to extract the service result from the output map. |
| `ApiServerPartsBean` | Class | Request/response wrapper bean used throughout the API layer to carry business data between the REST layer and the BP service layer. |
| `callBpService2` | Method | Backend proxy method that invokes the BP (Business Process) service layer. Wraps request parameters and returns processed results. |
| `ApiBpInterface.invokeService` | Method | Low-level interface that performs the actual service invocation to the BP layer. |
| `JOB_ID` | Field | Job identifier `"KKIFE499"` — used for audit tracking and job logging in the BP service layer. |
| `ANK-4629-00-00` | Ticket | Feature ticket for adding eo mobile app referral code issuance support (version 72.00.00, 2024/12/10). |
| `ANK-4294-00-00` | Ticket | Feature ticket for introducing CP changes to referral CP processing (version 63.00.00, 2022/11/22). |

---
