---

# (DD25) Business Logic — OwnerController.addPaginationModel() [8 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `org.springframework.samples.petclinic.owner.OwnerController` |
| Layer | Controller |
| Module | `owner` (Package: `org.springframework.samples.petclinic.owner`) |

## 1. Role

### OwnerController.addPaginationModel()

This method assembles the presentation model for the owner search results page when the application has more than one matching owner. Business-wise, it converts a paginated owner result set into the exact page-level attributes required by the UI: the current page number, the total number of pages, the total number of matching owners, and the list of owners to display. It acts as a view-model composition helper inside the controller layer, keeping pagination rendering consistent across the owner search flow.

The method does not branch into multiple business outcomes; instead, it performs a deterministic transformation from `Page<Owner>` to a Spring MVC `Model` and then returns the logical view name `owners/ownersList`. Its role in the larger system is to support the owner search and listing experience after the controller has already determined that the search result set contains multiple owners. In that sense, it is a shared rendering utility for the owner list screen and a direct counterpart to the similar pagination helper in `VetController`.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
START(["addPaginationModel(page, model, paginated)"])
GET_CONTENT["Read paginated.getContent()"]
SET_CURRENT["model.addAttribute(currentPage, page)"]
SET_TOTAL_PAGES["model.addAttribute(totalPages, paginated.getTotalPages())"]
SET_TOTAL_ITEMS["model.addAttribute(totalItems, paginated.getTotalElements())"]
SET_LIST["model.addAttribute(listOwners, listOwners)"]
RETURN_NODE(["Return owners/ownersList"])
START --> GET_CONTENT
GET_CONTENT --> SET_CURRENT
SET_CURRENT --> SET_TOTAL_PAGES
SET_TOTAL_PAGES --> SET_TOTAL_ITEMS
SET_TOTAL_ITEMS --> SET_LIST
SET_LIST --> RETURN_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `page` | `int` | The current 1-based page number selected by the user for owner search results. It determines which page indicator is exposed to the UI and is passed through unchanged to the view model. |
| 2 | `model` | `Model` | The Spring MVC presentation model used to carry pagination metadata and the owner list to the `owners/ownersList` view. The method mutates this object by adding all required page attributes. |
| 3 | `paginated` | `Page<Owner>` | The paged owner search result returned by the repository layer. It supplies the current page content, total page count, and total result count used to build the screen. |

Instance fields or external state read by the method: none. The method only reads the `Page<Owner>` parameter and writes to the provided `Model`.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `paginated.getContent()` | N/A | `Owner` | Reads the current page content from the paginated owner search result so the list can be shown in the UI. |
| R | `paginated.getTotalPages()` | N/A | `Owner` | Reads the total number of available result pages for pagination controls. |
| R | `paginated.getTotalElements()` | N/A | `Owner` | Reads the total number of matching owner records for summary display. |
| U | `model.addAttribute("currentPage", page)` | N/A | View model | Updates the MVC model with the current page number. |
| U | `model.addAttribute("totalPages", ...)` | N/A | View model | Updates the MVC model with the total page count. |
| U | `model.addAttribute("totalItems", ...)` | N/A | View model | Updates the MVC model with the total item count. |
| U | `model.addAttribute("listOwners", listOwners)` | N/A | View model | Updates the MVC model with the owner list to render. |

This method does not directly invoke any SC/CBS business service or database table operation. Its work is limited to view-model assembly based on already-fetched paging data.

## 5. Dependency Trace

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

| # | Caller (Screen/Batch) | Call Chain (Full Path to Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|----------------------------------|-------------------------------|
| 1 | Controller:OwnerController | `OwnerController.processFindForm` -> `OwnerController.addPaginationModel` | `Model.addAttribute [U] View model` |
| 2 | Controller:VetController | `VetController.showVetList` -> `OwnerController.addPaginationModel` | `Model.addAttribute [U] View model` |

Trace who calls this method and what this method ultimately calls.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Controller:OwnerController | `OwnerController.processFindForm` -> `OwnerController.addPaginationModel` | `model.addAttribute [U] View model` |
| 2 | Controller:VetController | `VetController.showVetList` -> `OwnerController.addPaginationModel` | `model.addAttribute [U] View model` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(linear pagination model assembly)` (L121-L128)

> This block builds the owner list view model from the paginated result and returns the page name to the MVC dispatcher.

| # | Type | Code |
|---|------|------|
| 1 | SET | `List<Owner> listOwners = paginated.getContent();` // copy the current page content into a view-friendly list |
| 2 | EXEC | `model.addAttribute("currentPage", page);` // expose the selected page number to the view |
| 3 | EXEC | `model.addAttribute("totalPages", paginated.getTotalPages());` // expose total page count for pagination controls |
| 4 | EXEC | `model.addAttribute("totalItems", paginated.getTotalElements());` // expose total matching owners for summary display |
| 5 | EXEC | `model.addAttribute("listOwners", listOwners);` // expose the owner records for rendering |
| 6 | RETURN | `return "owners/ownersList";` // route to the owner list view |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `page` | Field / Input | The current page number requested by the user for paginated owner search results. |
| `model` | Technical term | Spring MVC view model that carries data from the controller to the UI template. |
| `paginated` | Technical term | Spring Data `Page` wrapper containing one page of owner results plus paging metadata. |
| `Owner` | Domain entity | Pet clinic customer/owner record used to display owner search results and details. |
| `currentPage` | View attribute | UI attribute holding the page number currently being displayed. |
| `totalPages` | View attribute | UI attribute holding the number of available pages in the result set. |
| `totalItems` | View attribute | UI attribute holding the total number of owner records matched by the search. |
| `listOwners` | View attribute | UI attribute holding the owners shown in the list screen. |
| `owners/ownersList` | View name | Logical view template used to render the paginated owner list page. |
| MVC | Acronym | Model-View-Controller — the presentation pattern used by Spring web applications. |
| CRUD | Acronym | Create, Read, Update, Delete — standard data operation categories. |
| Spring MVC | Framework | Web framework used here to bind controller data into a view model. |
| `Page<Owner>` | Technical term | Spring Data pagination container for a single page of owner entities. |
| `addAttribute` | Technical term | Spring MVC method that stores data in the model for the view to consume. |
