---
# (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 prepares the owner search results for presentation in the web UI after a paginated query has already been executed. It does not perform any database access itself; instead, it transforms a `Page<Owner>` into the model attributes required by the Thymeleaf view that renders the owners list screen. The method also standardizes pagination metadata by exposing the current page number, total page count, and total result count so that the front end can render paging controls consistently.

In business terms, this is a view-model assembly helper for the owner directory. Its role is to keep the controller flow simple by centralizing the formatting of paginated owner search outcomes into a single reusable rendering path. The method follows a delegation and presentation-model pattern: the caller supplies the page of owner records, and this helper maps that result into the attributes expected by the list screen. There are no conditional branches, loops, or alternate business paths inside the method; every invocation follows the same sequence and returns the same owners list view.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addPaginationModel(page, model, paginated)"])
    READ_CONTENT["Read paginated.getContent()"]
    SET_LIST["Set listOwners from page content"]
    SET_CURRENT["model.addAttribute currentPage"]
    SET_TOTAL_PAGES["model.addAttribute totalPages"]
    SET_TOTAL_ITEMS["model.addAttribute totalItems"]
    SET_LIST_OWNERS["model.addAttribute listOwners"]
    RETURN_VIEW["Return owners/ownersList"]
    END_NODE(["End"])

    START --> READ_CONTENT
    READ_CONTENT --> SET_LIST
    SET_LIST --> SET_CURRENT
    SET_CURRENT --> SET_TOTAL_PAGES
    SET_TOTAL_PAGES --> SET_TOTAL_ITEMS
    SET_TOTAL_ITEMS --> SET_LIST_OWNERS
    SET_LIST_OWNERS --> RETURN_VIEW
    RETURN_VIEW --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `page` | `int` | The 1-based page number requested by the user for the owner search result set. It determines which pagination position the UI should highlight and is copied into the model as `currentPage`. Valid values are positive integers; the method does not validate the value, so callers are expected to provide a page already resolved by the controller flow. |
| 2 | `model` | `Model` | The Spring MVC view model used to publish screen attributes for the owners list page. The method writes pagination metadata and the owner list into this object so the template can render the response. It is an imperative output dependency rather than a data source. |
| 3 | `paginated` | `Page<Owner>` | The paged owner search result returned by the repository/query layer. It carries the current page content plus pagination metadata such as total pages and total elements. The method reads it to populate the screen model; no mutation occurs. |

**Instance fields / external state read by the method:** None. The method only uses its parameters and returns a constant view name.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `paginated.getContent()` | N/A | `Owner` | Reads the current page slice of owners so the list screen can display the result rows. |
| R | `paginated.getTotalPages()` | N/A | `Owner` | Reads pagination metadata to inform the UI how many pages exist for the current search result. |
| R | `paginated.getTotalElements()` | N/A | `Owner` | Reads the total owner count to support result summary and paging controls. |
| C | `model.addAttribute("currentPage", page)` | N/A | View model | Creates a model attribute for the active page indicator. |
| C | `model.addAttribute("totalPages", paginated.getTotalPages())` | N/A | View model | Creates a model attribute for the total page count. |
| C | `model.addAttribute("totalItems", paginated.getTotalElements())` | N/A | View model | Creates a model attribute for the total result count. |
| C | `model.addAttribute("listOwners", listOwners)` | N/A | View model | Creates a model attribute containing the owners displayed on the page. |

## 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` | - |
| 2 | Controller:VetController | `VetController.showVetList` -> `OwnerController.addPaginationModel` | - |

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` | `paginated.getContent() [R] Owner`, `paginated.getTotalPages() [R] Owner`, `paginated.getTotalElements() [R] Owner` |
| 2 | Controller:VetController | `VetController.showVetList` -> `OwnerController.addPaginationModel` | `paginated.getContent() [R] Owner`, `paginated.getTotalPages() [R] Owner`, `paginated.getTotalElements() [R] Owner` |

## 6. Per-Branch Detail Blocks

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

> This block copies the already-paginated owner result into the MVC model and returns the list view.

| # | Type | Code |
|---|------|------|
| 1 | SET | `List<Owner> listOwners = paginated.getContent();` // reads the current page content |
| 2 | EXEC | `model.addAttribute("currentPage", page);` // exposes the active page number |
| 3 | EXEC | `model.addAttribute("totalPages", paginated.getTotalPages());` // exposes the total number of pages |
| 4 | EXEC | `model.addAttribute("totalItems", paginated.getTotalElements());` // exposes the total owner count |
| 5 | EXEC | `model.addAttribute("listOwners", listOwners);` // exposes the owners on the current page |
| 6 | RETURN | `return "owners/ownersList";` // routes rendering to the owners list template |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `page` | Field | Requested page number for paginated owner search results. |
| `model` | Technical term | Spring MVC view model used to pass data to the UI template. |
| `paginated` | Technical term | Paginated owner result set containing content and paging metadata. |
| `currentPage` | View attribute | The page index currently being displayed. |
| `totalPages` | View attribute | The total number of pages available for the search result. |
| `totalItems` | View attribute | The total number of owners matching the search criteria. |
| `listOwners` | View attribute | The owner records to render on the current page. |
| `Owner` | Domain entity | Customer account that owns one or more pets in PetClinic. |
| `MVC` | Acronym | Model-View-Controller, the web architecture used by Spring MVC. |
| `Page` | Technical term | Spring Data pagination container that carries page content and metadata. |
| `Thymeleaf` | Business term | Server-side HTML template engine used to render the owners list page. |
| `owners/ownersList` | View | The owners list screen rendered after pagination data is prepared. |
