# Business Logic — JKKSvkeiShosaBaseCC.editMapRrks() [105 LOC]

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

## 1. Role

### JKKSvkeiShosaBaseCC.editMapRrks()

This method implements the **contact registration mapping process** (連絡先登録のマッピング処理) for the customer information update workflow. Its primary business purpose is to reconcile existing contact records (registered contacts) against customer identity data, then produce a mapped result set that determines whether new contacts need to be created or existing contacts need to be updated.

The method handles **two distinct business scenarios**: (1) **Update mode** — when existing contacts contain content (i.e., the `checkContRenSaki` guard returns true), the method routes through the *contact update* mapper (`editInMsgECK0201C010`), indicating that the customer is modifying pre-existing contact entries; (2) **Insert mode** — when existing contacts contain no content (i.e., `checkContRenSaki` returns false for all contacts), the method routes through the *contact insert* mapper (`editInMsgECK0201D010`), indicating that the customer is registering new contact entries.

The method implements a **dispatch/routing pattern** where it branches based on the presence of content in contact data, setting a `map_key` field in the result to direct downstream callers to the correct processing branch. It acts as a **shared utility** within the `JKKSvkeiShosaBaseCC` family of methods, responsible for the contact-subsystem portion of the broader customer information update screen flow.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editMapRrks(param, rsltShokai)"])
    INIT["Initialize rsltMemberStb, rslt, wkMapArray"]
    GET_CUSTOMER["Get customer data from rsltShokai using MAP_KEY_ECK0011A010"]
    GET_CONTACTS["Get contact list from rsltShokai using MAP_KEY_ECK0201B001"]
    SET_INSERT_FLG["Set renSakiInsertFlg = true"]
    CHECK_NULL["workECK0201B001Array != null?"]
    NO_CONTACTS["No contacts -- skip processing"]
    LOOP_CONTACTS["Loop: for each contact in workECK0201B001Array"]
    GET_WORK_CUST["getWorkData for customer template"]
    GET_WORK_CONT["getWorkData for contact template"]
    CHECK_TEMPLATES["Both wkTenplates1 and wkTenplates2 not null?"]
    NO_TEMPLATES["Skip iteration"]
    LOOP_CONTACTS_INNER["Loop: for each contact field j in wkTenplates2.length"]
    GET_CHILD_TEMPLATES["childTemplate1 = wkTenplates1[0], childTemplate2 = wkTenplates2[j]"]
    CHECK_CONT_REN["checkContRenSaki(childTemplate2)?"]
    NO_CONTENTS["No content contacts -- skip"]
    EDIT_CONTACT["shosaOkMapper.editInMsgECK0201C010(param, childTemplate2, childTemplate1)"]
    EDIT_IN_MSG["editInMsgCmn(param, updCustMap)"]
    ADD_RESULT["wkMapArray.add(rslt)"]
    SET_INSERT_FALSE["renSakiInsertFlg = false"]
    INNER_END["End inner loop"]
    OUTER_END["End outer loop"]
    NEW_CONTACT_FLG["renSakiInsertFlg still true?"]
    ADD_NEW_CONTACT["shosaOkMapper.editInMsgECK0201D010(param, wkTenplates1[0])"]
    ADD_NEW_IN_MSG["editInMsgCmn(param, updCustMap)"]
    ADD_NEW_RESULT["wkMapArray.add(rslt)"]
    PUT_UPDATE["rsltMemberStb.put(MAP_KEY_ECK0201C010, wkMapArray) + map_key"]
    PUT_INSERT["rsltMemberStb.put(MAP_KEY_ECK0201D010, wkMapArray) + map_key"]
    RETURN["Return rsltMemberStb"]

    START --> INIT --> GET_CUSTOMER --> GET_CONTACTS --> SET_INSERT_FLG --> CHECK_NULL
    CHECK_NULL -->|No| NO_CONTACTS
    CHECK_NULL -->|Yes| LOOP_CONTACTS
    NO_CONTACTS --> RETURN
    LOOP_CONTACTS --> GET_WORK_CUST --> GET_WORK_CONT --> CHECK_TEMPLATES
    CHECK_TEMPLATES -->|No| NO_TEMPLATES
    CHECK_TEMPLATES -->|Yes| LOOP_CONTACTS_INNER
    NO_TEMPLATES --> INNER_END
    LOOP_CONTACTS_INNER --> GET_CHILD_TEMPLATES --> CHECK_CONT_REN
    CHECK_CONT_REN -->|No| INNER_END
    CHECK_CONT_REN -->|Yes| EDIT_CONTACT --> EDIT_IN_MSG --> ADD_RESULT --> SET_INSERT_FALSE
    SET_INSERT_FALSE --> INNER_END
    INNER_END -->|next j| LOOP_CONTACTS_INNER
    INNER_END -->|Done| OUTER_END
    OUTER_END --> NEW_CONTACT_FLG
    NEW_CONTACT_FLG -->|Yes| ADD_NEW_CONTACT
    NEW_CONTACT_FLG -->|No| PUT_UPDATE
    ADD_NEW_CONTACT --> ADD_NEW_IN_MSG --> ADD_NEW_RESULT --> PUT_INSERT
    PUT_INSERT --> RETURN
    PUT_UPDATE --> RETURN
```

**Processing flow summary:**
1. **Initialization** — Create the result map (`rsltMemberStb`), and local working variables. Initialize `renSakiInsertFlg` (連絡先登録フラグ — contact registration flag) to `true`, meaning "no content contacts found yet" (i.e., default to insert mode).
2. **Retrieve customer identity data** — Fetch the customer agreement data from `rsltShokai` using `MAP_KEY_ECK0011A010`. This is always read from index `0` (the single customer record) per the OM-2014-0002974 fix.
3. **Retrieve contact list** — Fetch the contact list from `rsltShokai` using `MAP_KEY_ECK0201B001`. This is an array of contact records that the customer may register or update.
4. **Contact iteration** — For each contact in the list, retrieve both the customer template (reused from index 0, per the 2014 fix) and the specific contact template at the current loop index `j`.
5. **Content check dispatch** — For each contact field, call `checkContRenSaki` to determine if the contact contains actual content. If content exists, the record is an **existing contact** and the *update mapper* (`editInMsgECK0201C010`) is used; `renSakiInsertFlg` is set to `false`. If no content exists, the contact is skipped in the loop.
6. **Insert fallback** — If `renSakiInsertFlg` is still `true` after processing all contacts (meaning NO existing content contacts were found), execute the *insert mapper* (`editInMsgECK0201D010`) to register a new contact.
7. **Result dispatch** — Set `rsltMemberStb` with the appropriate `map_key`: `MAP_KEY_ECK0201C010` for update (existing contacts modified), or `MAP_KEY_ECK0201D010` for insert (new contacts added).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying the model group and control map for the contact registration screen. It contains form data submitted by the user (contact fields) and control metadata (e.g., screen context, operation flags). Passed to all mapper and edit methods. |
| 2 | `rsltShokai` | `HashMap<String, Object>` | The inquiry/agreement result data map (一意照会). Contains pre-fetched data from earlier inquiry processing: specifically the customer identity data under `MAP_KEY_ECK0011A010` and the contact list under `MAP_KEY_ECK0201B001`. This map carries the results from the lookup phase into the mapping phase. |

**Instance/external state read:**
| Field | Description |
|-------|-------------|
| `MAP_KEY_ECK0011A010` | Constant `"ECK0011A010"` used as the key to retrieve customer agreement data from `rsltShokai` |
| `MAP_KEY_ECK0201B001` | Constant `"ECK0201B001"` used as the key to retrieve the contact list from `rsltShokai` |
| `MAP_KEY_ECK0201D010` | Constant `"ECK0201D010"` used as the result key for insert-mode (new contact registration) |
| `MAP_KEY_ECK0201C010` | Constant `"ECK0201C010"` used as the result key for update-mode (existing contact modification) |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKSvkeiShosaBaseCC.getWorkData` | JKKSvkeiShosaBaseCC | - | Retrieves customer template data (wkTenplates1) from work map for the single customer record (ECK0011A010CBSMsg.ECK0011A010CBSMSG1LIST) |
| R | `JKKSvkeiShosaBaseCC.getWorkData` | JKKSvkeiShosaBaseCC | - | Retrieves contact template data (wkTenplates2) for each contact record in the contact list (ECK0201B001CBSMsg.ECK0201B001CBSMSG1LIST) |
| R | `JKKSvkeiShosaBaseCC.checkContRenSaki` | JKKSvkeiShosaBaseCC | - | Checks whether a contact record contains content (連絡先存在チェック — contact existence check); guards the update branch |
| U | `shosaOkMapper.editInMsgECK0201C010` | JKKSvkeiShosaShosaOkMapperCC | - | Maps and updates existing contact records (連絡先更新 — contact update) using childTemplate1 (customer) and childTemplate2 (contact) |
| U | `JKKSvkeiShosaBaseCC.editInMsgCmn` | JKKSvkeiShosaBaseCC | - | Processes common message mapping for the updated contact result |
| U | `shosaOkMapper.editInMsgECK0201D010` | JKKSvkeiShosaShosaOkMapperCC | - | Maps and inserts new contact records (連絡先登録 — contact registration) using wkTenplates1 (customer) |
| U | `JKKSvkeiShosaBaseCC.editInMsgCmn` | JKKSvkeiShosaBaseCC | - | Processes common message mapping for the inserted contact result |

**CRUD summary:**
- **Read (R):** 2 calls to `getWorkData` (customer template + contact template per iteration), 1 call to `checkContRenSaki` (content guard)
- **Update (U):** `editInMsgECK0201C010` (update existing), `editInMsgECK0201D010` (insert new), each followed by `editInMsgCmn` (common result processing)
- **No Create or Delete operations** at the direct method level

## 5. Dependency Trace

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.
Terminal operations from this method: `editInMsgCmn` [U], `editInMsgCmn` [U], `editInMsgECK0201C010` [U], `editInMsgECK0201D010` [U], `checkContRenSaki` [R], `getWorkData` [R], `getWorkData` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Component: `JKKSvkeiShosaBaseCC.updCustinfo()` | `updCustinfo()` -> `editMapRrks(param, rsltShokai)` | `editInMsgCmn` [U], `editInMsgECK0201C010` [U], `editInMsgECK0201D010` [U], `checkContRenSaki` [R], `getWorkData` [R] |

**Note:** `updCustinfo()` is the primary caller within `JKKSvkeiShosaBaseCC`. It invokes `editMapRrks` as part of the customer information update workflow — after the inquiry (search) phase populates `rsltShokai` with customer and contact data, and before the final save/commit. The method serves as a shared mapping utility used within the broader customer information update screen flow.

## 6. Per-Branch Detail Blocks

**Block 1** — VARIABLE_DECLARATION (local variable initialization) (L878-L896)

> Initialize all local working variables and set the default "insert mode" flag. The flag `renSakiInsertFlg` is pre-initialized to `true` — meaning the method defaults to "no content contacts found" (insert-new-contact mode) and will only switch to update mode if an existing contact with content is encountered.

| # | Type | Code |
|---|------|------|
| 1 | SET | `rsltMemberStb = new HashMap<>()` // Result map to be returned |
| 2 | SET | `rslt = null` // Intermediate result holder |
| 3 | SET | `wkCaanMsgList = null` // Message list (unused after OM-2014-0002974 fix) |
| 4 | SET | `wkMapArray = null` // Working map array |
| 5 | SET | `workECK0011A010Array = null` // Customer agreement data array (お客様一意照会) |
| 6 | SET | `workECK0201B001Array = null` // Contact list array (連絡先一覧照会) |
| 7 | SET | `renSakiInsertFlg = true` // Contact registration flag — default to insert mode (OM-2014-0002974) 連絡先登録フラグ |

**Block 2** — VARIABLE_ASSIGNMENT (Retrieve customer data) (L899-L901)

> Extract pre-fetched inquiry data from `rsltShokai`. The customer record is always retrieved from index 0 (single customer per contact registration). The contact list array is retrieved and will be iterated if non-null.

| # | Type | Code |
|---|------|------|
| 1 | SET | `workECK0011A010Array = (ArrayList)rsltShokai.get(MAP_KEY_ECK0011A010)` // Customer agreement data from rsltShokai [-> MAP_KEY_ECK0011A010="ECK0011A010"] (JKKSvkeiShosaBaseCC.java:74) |
| 2 | SET | `workECK0201B001Array = (ArrayList)rsltShokai.get(MAP_KEY_ECK0201B001)` // Contact list from rsltShokai [-> MAP_KEY_ECK0201B001="ECK0201B001"] (JKKSvkeiShosaBaseCC.java:105) |

**Block 3** — SET (Default insert flag — OM-2014-0002974 fix) (L903-L906)

> Set the contact registration flag to `true`. This flag determines the final behavior: if it stays `true` after processing all contacts, new contacts are registered (insert mode). If it becomes `false`, existing contacts are updated (update mode).

| # | Type | Code |
|---|------|------|
| 1 | SET | `renSakiInsertFlg = true` // Default: assume no content contacts exist (OM-2014-0002974対応) 連絡先登録フラグ |

**Block 4** — VARIABLE_ASSIGNMENT (Retrieve customer template — OM-2014-0002974 fix) (L908-L911)

> Per the OM-2014-0002974 fix (2014-09-14, Tanaka), customer data is now always read from index 0 of the customer array rather than per-contact index. This was changed because customer identity is shared across all contacts in a contact registration, not per-contact.

| # | Type | Code |
|---|------|------|
| 1 | SET | `wkTenplates1 = getWorkData(ECK0011A010CBSMsg.ECK0011A010CBSMSG1LIST, workECK0011A010Array.get(0))` // Customer data template (OM-2014-0002974対応) お客様 |
| 2 | SET | `wkTenplates2` (declared, assigned inside the loop) // Contact data template (連絡先) |

**Block 5** — IF (Contact list is not null) (L913-L980)

> This is the main conditional branch. If `workECK0201B001Array` (the contact list) is null, the method skips all contact processing and returns an empty `rsltMemberStb`. When non-null, the method iterates over each contact to map and process it.

**Block 5.1** — FOR_LOOP (Iterate over contact list) (L915-L980)

> Loop over each contact record in `workECK0201B001Array`. For each contact at index `i`:

| # | Type | Code |
|---|------|------|
| 1 | SET | `wkMapArray = new ArrayList<>()` // Fresh working array per contact |
| 2 | SET | `wkTenplates2 = getWorkData(ECK0201B001CBSMsg.ECK0201B001CBSMSG1LIST, workECK0201B001Array.get(i))` // Contact template for current index [-> ECK0201B001CBSMsg.ECK0201B001CBSMSG1LIST] 連絡先 |

**Block 5.1.1** — IF (Both templates are non-null) (L926-L980)

> Both the customer template (`wkTenplates1`) and the contact template (`wkTenplates2`) must be non-null to proceed. If either is null, the iteration is skipped.

**Block 5.1.2** — FOR_LOOP (Inner loop over contact fields) (L932-L980)

> Per the OM-2014-0002974 fix, the inner loop was changed from iterating over `wkTenplates1` (customer records) to iterating over `wkTenplates2` (contact records). This ensures each contact field is processed independently.

| # | Type | Code |
|---|------|------|
| 1 | SET | `childTemplate1 = wkTenplates1[0]` // Customer template (always index 0 per 2014 fix) |
| 2 | SET | `childTemplate2 = wkTenplates2[j]` // Contact template at index j |

**Block 5.1.2.1** — IF (Content contact check — `checkContRenSaki`) (L937-L977)

> This is the critical branching point that determines insert vs. update mode. The method calls `checkContRenSaki` on the contact template. If the contact contains content (i.e., it is an **existing** contact being modified), the update path is taken. If the contact has no content (i.e., it is a **new** contact), it is skipped and the loop continues to the next contact.

**Block 5.1.2.1.1** — CALL (Update existing contact — editInMsgECK0201C010) (L943-L949)

> Executed when `checkContRenSaki` returns true (content contact exists). This is the **update path** — the method updates an existing contact record.

| # | Type | Code |
|---|------|------|
| 1 | SET | `updCustMap = shosaOkMapper.editInMsgECK0201C010(param, childTemplate2, childTemplate1)` // Map and update existing contact (OM-2014-0002974 MOD) 連絡先の更新処理 |
| 2 | SET | `rslt = editInMsgCmn(param, updCustMap)` // Common message mapping |
| 3 | EXEC | `wkMapArray.add(rslt)` // Add result to working array |
| 4 | SET | `renSakiInsertFlg = false` // Mark: existing contacts were found, switch to update mode 変更があった場合 — 連絡先の登録処理を行わない |

> **Note:** After OM-2014-0002974, the previous call to `editInMsgECK0201D010` (insert mapper) was replaced with `editInMsgECK0201C010` (update mapper) for the content-contact branch. The comment 変更があった場合は連絡先の登録処理を行わない (If changes exist, do not perform contact registration) confirms this is the "update existing, don't register new" path.

**Block 5.1.2.1.2** — ELSE (No content — skip contact, continue loop)

> When `checkContRenSaki` returns false (no content in this contact), the contact is skipped entirely. The loop continues to the next contact index `j`.

**Block 5.1.3** — END of inner loop (L977)

**Block 5.2** — IF (Insert mode: no existing content contacts found) (L982-L992)

> After all contacts have been processed, check if `renSakiInsertFlg` is still `true`. This means NO content contacts were found in the entire contact list — all contacts are new (no content). In this case, execute the **insert mapper** to register new contacts.

| # | Type | Code |
|---|------|------|
| 1 | SET | `updCustMap = shosaOkMapper.editInMsgECK0201D010(param, wkTenplates1[0])` // Map and insert new contact (OM-2014-0002974対応) 既存の連絡先に登録 — register for existing contacts (but actually inserts new since no content contacts exist) |
| 2 | SET | `rslt = editInMsgCmn(param, updCustMap)` // Common message mapping |
| 3 | EXEC | `wkMapArray.add(rslt)` // Add result to working array |

> **Note:** The comment 既存の連絡先にコンテンツの連絡先が存在しない場合 (When no content contacts exist in existing contacts) and 既存の連絡先を登録する場合 (Register existing contacts) indicates this is the "register new contacts when none exist" path.

**Block 5.3** — IF/ELSE (Result dispatch — update vs. insert mode) (L994-L1003)

> Final dispatch based on `renSakiInsertFlg`:
> - **IF `true` (insert mode):** Put results under `MAP_KEY_ECK0201D010` with `map_key = "ECK0201D010"`. This directs downstream to the insert/new-contact processing branch.
> - **ELSE (update mode):** Put results under `MAP_KEY_ECK0201C010` with `map_key = "ECK0201C010"`. This directs downstream to the update/existing-contact processing branch.

| # | Type | Code |
|---|------|------|
| 1 | SET | `rsltMemberStb.put(MAP_KEY_ECK0201D010, wkMapArray)` // Results under insert key (OM-2014-0002974 ADD) 既存の連絡先を登録する場合 |
| 2 | SET | `rsltMemberStb.put("map_key", MAP_KEY_ECK0201D010)` // Dispatch key: ECK0201D010 [-> MAP_KEY_ECK0201D010="ECK0201D010"] (JKKSvkeiShosaBaseCC.java:107) |
| 3 | SET | `rsltMemberStb.put(MAP_KEY_ECK0201C010, wkMapArray)` // Results under update key (OM-2014-0002974 ADD) 既存の連絡先を変更する場合 |
| 4 | SET | `rsltMemberStb.put("map_key", MAP_KEY_ECK0201C010)` // Dispatch key: ECK0201C010 [-> MAP_KEY_ECK0201C010="ECK0201C010"] (JKKSvkeiShosaBaseCC.java:110) |

**Block 6** — RETURN (L1005)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return rsltMemberStb` // Returns the mapped contact data with the dispatch key |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `rsltShokai` | Field | Inquiry/agreement result data — the HashMap containing pre-fetched data from the screen's inquiry (search) phase, including customer identity and contact lists |
| `renSakiInsertFlg` | Field | Contact registration flag (連絡先登録フラグ) — internal boolean that tracks whether any existing content contacts were found; `true` = insert mode (new contacts), `false` = update mode (existing contacts modified) |
| `wkTenplates1` | Field | Customer template data — CAANMsg array representing the customer identity record used as the parent context for contact mapping |
| `wkTenplates2` | Field | Contact template data — CAANMsg array representing the contact record(s) to be processed |
| `wkMapArray` | Field | Working map array — accumulates the result mappings for contacts processed in the current invocation |
| `rsltMemberStb` | Field | Result member storage — the final HashMap returned to the caller, containing both the contact data and the dispatch key (`map_key`) |
| `MAP_KEY_ECK0011A010` | Constant | Customer agreement data key ("ECK0011A010") — used to retrieve customer identity data from rsltShokai |
| `MAP_KEY_ECK0201B001` | Constant | Contact list data key ("ECK0201B001") — used to retrieve the contact list from rsltShokai |
| `MAP_KEY_ECK0201D010` | Constant | Contact insert result key ("ECK0201D010") — used to store and dispatch insert-mode (new contact registration) results |
| `MAP_KEY_ECK0201C010` | Constant | Contact update result key ("ECK0201C010") — used to store and dispatch update-mode (existing contact modification) results |
| ECK0011A010 | Screen/CBS Code | Customer agreement inquiry screen — displays customer identity data for contact registration |
| ECK0201B001 | Screen/CBS Code | Contact list inquiry screen — displays the list of registered contacts |
| ECK0201C010 | CBS/SC Code | Contact update CBS — maps and updates existing contact records |
| ECK0201D010 | CBS/SC Code | Contact insert CBS — maps and registers new contact records |
| `checkContRenSaki` | Method | Content contact existence check (コンテンツの連絡先存在チェック) — determines whether a contact record contains actual content; guards the update branch |
| `editInMsgCmn` | Method | Common message editing (共通メッセージ編集) — processes common message mapping for contact result data |
| `getWorkData` | Method | Work data retrieval — fetches template data from the work map for a given CBS message key |
| `shosaOkMapper` | Field | Processing OK mapper — the mapper object (`JKKSvkeiShosaShosaOkMapperCC`) that performs contact update/insert mapping |
| OM-2014-0002974 | Change ticket | Change request ticket that modified the contact registration mapping logic on 2014-09-14 (Tanaka), fixing customer data retrieval to always use index 0 and introducing the content-based insert/update dispatch |
| カスタマー情報更新 | Business term | Customer information update — the broader screen/workflow in which this contact registration mapping method participates |
| CAANMsg | Type | Customer Address And Notification Message — the message object type representing structured contact/customer data records in the Fujitsu FTL framework |
