# Business Logic — JBSbatKKDelKhChk.canDelPopId() [49 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKDelKhChk` |
| Layer | Service (Batch processing service layer) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKDelKhChk.canDelPopId()

This method performs **POP ID deletion eligibility verification** in the context of a K-Opt (koptBatch) batch job. It determines whether a given POP ID (Point of Presence identifier, used as a login credential in the system) can be safely deleted by executing a two-stage database check.

In the first stage, the method queries the **OP Service Contract table** (`KK_T_OP_SVC_KEI`) using the operation service contract number, POP ID, and operation date. If no matching record exists, this indicates there are no active service contracts referencing this POP ID — a favorable condition for deletion.

In the second stage (executed only if the first check passes), the method converts the POP ID by replacing the `%` character with `@` to produce a **mail address equivalent**, then queries the **Order Settings table** (`KK_T_ODR_SET`) for any associated cancellation Service Order Data (SOD). If a cancellation SOD record is found, the POP ID is considered still in use and deletion is denied.

The method implements a **gate pattern**: if the first check denies deletion, the method short-circuits and returns `false` immediately without performing the second check. This avoids unnecessary database queries when deletion is already ruled out. It serves as a **private utility** called by the batch job's `execute()` method, which orchestrates multiple similar deletion eligibility checks (for POP ID, ADSL authentication ID, SIP user ID, etc.) as part of a broader record cleanup routine.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["canDelPopId(inMap)"])
    START --> INIT["Initialize canDel = false"]
    INIT --> B1["Build selectWhereParam: OPSVKEI_NO, POP_ID, opeDate"]
    B1 --> Q1["executeKK_T_OP_SVC_KEI_KK_SELECT_093"]
    Q1 --> FETCH1["nextRec = db_KK_T_OP_SVC_KEI.selectNext()"]
    FETCH1 --> COND1{nextRec == null?}
    COND1 -->|true| CANDEL1["canDel = true"]
    COND1 -->|false| CANDEL2["canDel = false"]
    CANDEL1 --> EARLY_EXIT_CHECK{canDel is true?}
    CANDEL2 --> EARLY_EXIT_CHECK
    EARLY_EXIT_CHECK -->|false| EARLY_RETURN["return canDel (false)"]
    EARLY_EXIT_CHECK -->|true| POP_ID["Read POP_ID from inMap"]
    POP_ID --> MAIL_ADDR["Convert POP_ID: replace % with @"]
    MAIL_ADDR --> B2["Build kk1041SelectWhereParam: SVKEI_NO, OPSVKEI_NO, mailAddr"]
    B2 --> Q2["executeKK_T_ODR_SET_KK_SELECT_026"]
    Q2 --> FETCH2["kk1041NextRec = db_KK_T_ODR_SET.selectNext()"]
    FETCH2 --> COND2{kk1041NextRec == null?}
    COND2 -->|true| CANDEL3["canDel remains true"]
    COND2 -->|false| CANDEL4["canDel = false"]
    CANDEL3 --> FINAL_RETURN["return canDel"]
    CANDEL4 --> FINAL_RETURN
```

**Processing summary:**

1. **Initialization**: The method initializes `canDel` to `false`, meaning the default stance is "deletion is NOT allowed" until evidence proves otherwise.
2. **First Database Check (Service Contract)**: Queries the OP Service Contract table to check whether any active records exist for the given POP ID. If the query returns no records, the POP ID is considered orphaned and eligible for deletion (`canDel = true`).
3. **Short-Circuit on Denial**: If the first check determines deletion is not allowed, the method immediately returns `false` without performing the second check. This is an optimization introduced in IT1-2017-0000101.
4. **Second Database Check (Cancellation SOD)**: Converts the POP ID by replacing `%` with `@` to derive a mail address, then queries the Order Settings table for cancellation SOD records. The presence of such records indicates the POP ID is actively referenced and must not be deleted.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | Input message map carrying the batch job's input data. Contains the operation service contract number (`OPSVKEI_NO`), POP ID (`POP_ID`), and service contract number (`SVKEI_NO`) — all required for the two-stage database eligibility checks. |

**Instance fields / external state read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `opeDate` | (String/Date) | Operation date — used as a filter parameter in both database queries to ensure records match the current batch processing date. |
| `db_KK_T_OP_SVC_KEI` | `JBSbatCommonDBInterface` | Database cursor for the OP Service Contract table (`KK_T_OP_SVC_KEI`), used to fetch results from the first query. |
| `db_KK_T_ODR_SET` | `JBSbatCommonDBInterface` | Database cursor for the Order Settings table (`KK_T_ODR_SET`), used to fetch results from the second query. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKDelKhChk.executeKK_T_OP_SVC_KEI_KK_SELECT_093` | EKK093 | KK_T_OP_SVC_KEI | Queries the OP Service Contract table to check for existing records matching the POP ID, service contract number, and operation date. No records found indicates the POP ID is not in use. |
| R | `JBSbatKKDelKhChk.executeKK_T_ODR_SET_KK_SELECT_026` | EKK026 | KK_T_ODR_SET | Queries the Order Settings table using the converted mail address (POP_ID with % replaced by @), service contract number, and operation service contract number to detect cancellation SOD records. |
| R | `JBSbatServiceInterfaceMap.getString` | - | - | Reads string values from the input message map (`inMap`) — specifically `OPSVKEI_NO`, `POP_ID`, and `SVKEI_NO`. |
| R | `JBSbatCommonDBInterface.selectNext` | - | - | Advances the database cursor to the next record and returns it, used to check whether the query returned any results. |

**CRUD Classification Rationale:**

- **R (Read)**: Both `executeKK_T_OP_SVC_KEI_KK_SELECT_093` and `executeKK_T_ODR_SET_KK_SELECT_026` are SELECT-only queries — they read from the database to verify the absence or presence of records but perform no modifications. The naming convention `_SELECT_` in the method names confirms these are read operations.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `executeKK_T_ODR_SET_KK_SELECT_026` [-], `getString` [R], `getString` [R], `getString` [R], `executeKK_T_OP_SVC_KEI_KK_SELECT_093` [-], `selectNext` [R], `selectNext` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKDelKhChk.execute() | `execute()` → `canDelPopId(inMap)` | `executeKK_T_OP_SVC_KEI_KK_SELECT_093 [R] KK_T_OP_SVC_KEI`, `executeKK_T_ODR_SET_KK_SELECT_026 [R] KK_T_ODR_SET` |

**Caller details:**
- The method is called from `JBSbatKKDelKhChk.execute()` at line 435, within the same class. This is a batch processing method that orchestrates deletion eligibility checks for various identifier types (POP ID, ADSL authentication ID, SIP user ID, etc.).
- As a `private` method, it is not called from external screens or other batch classes — it is an internal helper within the deletion eligibility checker.

## 6. Per-Branch Detail Blocks

**Block 1** — [INITIALIZATION] (L1136)

> Initialize local variables. Default to "not deletable."

| # | Type | Code |
|---|------|------|
| 1 | SET | `boolean canDel = false` // "消去可否" (deletion eligibility flag) |
| 2 | SET | `JBSbatCommonDBInterface nextRec = null` // "次レコード" (next record cursor) |

**Block 2** — [ARRAY INITIALIZATION / QUERY BUILD] (L1138–1144)

> Build the WHERE clause parameters for the first database query (OP Service Contract table).

| # | Type | Code |
|---|------|------|
| 1 | SET | `Object[] selectWhereParam = {...}` // Query parameter array |
| 2 | CALL | `inMap.getString(JBSbatKKIFM160.OPSVKEI_NO)` // "オプションサービス契約番号" (Option Service Contract Number) [-> OPSVKEI_NO] |
| 3 | CALL | `inMap.getString(JBSbatKKIFM160.POP_ID)` // "POPID" (Point of Presence ID) [-> POP_ID] |
| 4 | SET | `opeDate` // "運用日" (Operation Date) — instance field |

**Block 3** — [FIRST DATABASE CHECK] (L1146–1148)

> Execute the first eligibility check: query the OP Service Contract table for records referencing the POP ID.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_OP_SVC_KEI_KK_SELECT_093(selectWhereParam)` // Query KK_T_OP_SVC_KEI |
| 2 | CALL | `nextRec = db_KK_T_OP_SVC_KEI.selectNext()` // Fetch next record from cursor |

**Block 4** — [CONDITIONAL: First Check Result] (L1149–1154)

> IF no record found (`nextRec == null`) → the POP ID is not referenced in the OP Service Contract table → deletion is allowed.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (nextRec == null)` |
| 2 | SET | `canDel = true` // POP ID not found → eligible for deletion |

**Block 5** — [SHORT-CIRCUIT CHECK] (L1156–1160)

> IT1-2017-0000101 ADD: If deletion was denied by the first check, terminate processing immediately and return `false`. This optimization avoids an unnecessary second database query.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (!canDel)` // "最初にチェックで消去"否となった場合、処理を終了する (If first check determined deletion is NOT allowed, end processing) |
| 2 | RETURN | `return canDel` // Returns `false` |

**Block 6** — [POPID TO MAIL ADDRESS CONVERSION] (L1163–1168)

> Convert the POP ID to a mail address format by replacing `%` with `@`. This is a domain-specific transformation — the POP ID uses `%` as a delimiter while the mail address equivalent in the Order Settings table uses `@`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JBSbatCommonDBInterface kk1041NextRec = null` // "次レコード" (next record cursor for second query) |
| 2 | CALL | `String popId = inMap.getString(JBSbatKKIFM160.POP_ID)` // Read POP ID [-> POP_ID] |
| 3 | SET | `String mlad = popId.replace("%", "@")` // Convert to mail address format |

**Block 7** — [SECOND QUERY BUILD] (L1170–1175)

> Build the WHERE clause parameters for the second database query (Order Settings table).

| # | Type | Code |
|---|------|------|
| 1 | SET | `Object[] kk1041SelectWhereParam = {...}` // Query parameter array for second check |
| 2 | CALL | `inMap.getString(JBSbatKKIFM160.SVKEI_NO)` // "サービス契約番号" (Service Contract Number) [-> SVKEI_NO] |
| 3 | CALL | `inMap.getString(JBSbatKKIFM160.OPSVKEI_NO)` // "オプションサービス契約番号" (Option Service Contract Number) [-> OPSVKEI_NO] |
| 4 | SET | `mailAddr` // Converted mail address (POP_ID with % replaced by @) |

**Block 8** — [SECOND DATABASE CHECK] (L1177–1179)

> Execute the second eligibility check: query the Order Settings table for cancellation SOD records associated with the converted mail address.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_ODR_SET_KK_SELECT_026(kk1041SelectWhereParam)` // Query KK_T_ODR_SET |
| 2 | CALL | `kk1041NextRec = db_KK_T_ODR_SET.selectNext()` // Fetch next record from cursor |

**Block 9** — [CONDITIONAL: Cancellation SOD Detection] (L1181–1185)

> IF a cancellation SOD record is found (`kk1041NextRec != null`) → the POP ID is actively referenced → deletion is denied. If no record is found (`kk1041NextRec == null`) → no cancellation SOD exists → `canDel` remains `true`.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (kk1041NextRec == null)` // "解約SODが発行されているか判定" (Determine whether a cancellation SOD has been issued) |
| 2 | SET | `canDel = false` // Cancellation SOD found → NOT eligible for deletion |

**Block 10** — [FINAL RETURN] (L1188)

> Return the computed deletion eligibility result.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return canDel` // `true` if POP ID can be safely deleted, `false` otherwise |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|-----------------|
| `OPSVKEI_NO` | Field | Option Service Contract Number — the unique identifier for an option service contract line item |
| `POP_ID` | Field | Point of Presence ID — a login credential identifier used by customers to access the service portal; internally represented with `%` as a delimiter |
| `SVKEI_NO` | Field | Service Contract Number — the unique identifier for a service contract |
| `opeDate` | Field | Operation Date — the business date used for batch processing; serves as a filter to ensure queries match the current processing day |
| `canDel` | Field | Deletion Eligibility Flag — internal boolean indicating whether the POP ID can be safely deleted (`true`) or not (`false`) |
| `nextRec` / `kk1041NextRec` | Field | Next Record — database cursor result used to check for the existence of matching records |
| `mailAddr` (mlad) | Variable | Mail Address — derived from the POP ID by replacing `%` with `@`; used as a lookup key in the Order Settings table |
| KK_T_OP_SVC_KEI | Entity | OP Service Contract Table — stores records of option service contracts linked to a POP ID |
| KK_T_ODR_SET | Entity | Order Settings Table — stores order-related settings records including cancellation SOD (Service Order Data) |
| SOD | Acronym | Service Order Data — internal data structure representing order fulfillment records; a "cancellation SOD" indicates a service termination has been processed |
| KK | Prefix | K-Opt — internal product line prefix for NTT East's optional telecommunications services (Fiber, Mail, etc.) |
| JBSbat | Prefix | Java Batch Service — batch processing service class naming convention |
| KKDelKhChk | Class | KK Deletion Eligibility Checker — the class containing this method; responsible for verifying whether various identifiers can be safely deleted during batch cleanup |
| executeKK_T_OP_SVC_KEI_KK_SELECT_093 | Method | SC Code EKK093 — database query method that selects records from KK_T_OP_SVC_KEI by service contract, POP ID, and operation date |
| executeKK_T_ODR_SET_KK_SELECT_026 | Method | SC Code EKK026 — database query method that selects records from KK_T_ODR_SET by service contract, option service contract, and mail address |
