# (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 used to render the paginated owner search results page. It takes the current page number, the Spring MVC `Model`, and a `Page<Owner>` result set, then extracts the page content and exposes all pagination metadata needed by the view layer. In business terms, it is the final response-shaping step for the owner list screen when a search returns more than one matching owner.

The method follows a simple presentation-adapter pattern: it does not execute domain rules, persist data, or branch across multiple business cases. Instead, it transforms a paged repository result into view attributes such as current page, total pages, total items, and the owner list itself. Its role in the larger system is to standardize how paginated owner search results are returned to the UI so that the `owners/ownersList` view can render navigation controls and records consistently.

There are no conditional branches in this method. Every invocation performs the same model population sequence and returns the same view name, making it a deterministic helper for pagination display.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addPaginationModel(page, model, paginated)"])
    GET_CONTENT(["Call paginated.getContent()"])
    SET_LIST(["Store owners list in listOwners"])
    ADD_CURRENT_PAGE(["Call model.addAttribute(\"currentPage\", page)"])
    ADD_TOTAL_PAGES(["Call model.addAttribute(\"totalPages\", paginated.getTotalPages())"])
    ADD_TOTAL_ITEMS(["Call model.addAttribute(\"totalItems\", paginated.getTotalElements())"])
    ADD_LIST_OWNERS(["Call model.addAttribute(\"listOwners\", listOwners)"])
    RETURN_VIEW(["Return \"owners/ownersList\""])

    START --> GET_CONTENT
    GET_CONTENT --> SET_LIST
    SET_LIST --> ADD_CURRENT_PAGE
    ADD_CURRENT_PAGE --> ADD_TOTAL_PAGES
    ADD_TOTAL_PAGES --> ADD_TOTAL_ITEMS
    ADD_TOTAL_ITEMS --> ADD_LIST_OWNERS
    ADD_LIST_OWNERS --> RETURN_VIEW
```

The method first reads the current page content from the `Page<Owner>` container, then populates the MVC model with pagination metadata and the owner list. It finishes by returning the list view name so the presentation layer can render the results page.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `page` | `int` | The user-requested page number for the owner search results. It determines which pagination position should be shown as active in the UI. |
| 2 | `model` | `Model` | The Spring MVC model used to pass page state and search results to the `owners/ownersList` view. It carries all attributes required for rendering the results screen. |
| 3 | `paginated` | `Page<Owner>` | The paginated owner search result returned from the repository layer. It contains the current slice of owner records plus total page and total item metadata. |

Instance fields and external state read by the method:
- No instance fields are read.
- The method reads the `Page<Owner>` state from `paginated`.
- The method writes four attributes into the Spring MVC `Model`.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `paginated.getContent()` | N/A | `Owner` page content | Reads the current page of owner records so the UI can display the matching owners. |
| R | `paginated.getTotalPages()` | N/A | `Owner` pagination metadata | Reads the total number of pages available for the current owner search result. |
| R | `paginated.getTotalElements()` | N/A | `Owner` pagination metadata | Reads the total number of matching owner records across all pages. |
| U | `model.addAttribute("currentPage", page)` | N/A | MVC model | Stores the active page number for view rendering. |
| U | `model.addAttribute("totalPages", paginated.getTotalPages())` | N/A | MVC model | Stores the total page count for navigation controls. |
| U | `model.addAttribute("totalItems", paginated.getTotalElements())` | N/A | MVC model | Stores the total owner count for screen-level summary display. |
| U | `model.addAttribute("listOwners", listOwners)` | N/A | MVC model | Stores the actual owner records for display in the list table. |

No SC/CBS execution occurs in this method. The method only reads the pagination result and updates the MVC model.

## 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` | `paginated.getContent() [R] Owner`, `model.addAttribute(...) [U] MVC model` |
| 2 | Controller:VetController | `VetController.showVetList` -> `VetController.addPaginationModel` | `paginated.getContent() [R] Vet`, `model.addAttribute(...) [U] MVC model` |

This method is called from the owner search flow when multiple owners match the search criteria. A similar pagination helper exists in `VetController`, but it is a different method and only shows the shared design pattern used across controllers.

## 6. Per-Branch Detail Blocks

**Block 1** — `SEQUENCE` (L121-L128)

> Main pagination model assembly for owner search results.

| # | Type | Code |
|---|------|------|
| 1 | SET | `List<Owner> listOwners = paginated.getContent();` // extract the current result page |
| 2 | EXEC | `model.addAttribute("currentPage", page);` // expose active page number to the view |
| 3 | EXEC | `model.addAttribute("totalPages", paginated.getTotalPages());` // expose total page count |
| 4 | EXEC | `model.addAttribute("totalItems", paginated.getTotalElements());` // expose total result count |
| 5 | EXEC | `model.addAttribute("listOwners", listOwners);` // expose the current owners list |
| 6 | RETURN | `return "owners/ownersList";` // return the paginated owner list view |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `page` | Field | Requested page number for the owner search results screen. |
| `model` | Technical term | Spring MVC view model used to pass data from the controller to the UI. |
| `paginated` | Technical term | A paged container of `Owner` records and pagination metadata. |
| `Owner` | Domain entity | A pet clinic customer/owner record displayed in the owner list. |
| `currentPage` | View attribute | The page number currently being displayed in the UI. |
| `totalPages` | View attribute | The total number of pages available for the current search result. |
| `totalItems` | View attribute | The total count of matching owner records. |
| `listOwners` | View attribute | The list of owner records shown in the results table. |
| `owners/ownersList` | View name | Thymeleaf/JSP view used to render the paginated owner results page. |
| MVC | Acronym | Model-View-Controller, the web presentation pattern used by Spring. |
| CRUD | Acronym | Create, Read, Update, Delete — basic data operation categories. |
| pagination | Business term | Splitting a large result set into smaller pages for easier browsing. |
| repository layer | Technical term | Data access layer that retrieves owner records and page metadata. |
| Spring `Page` | Technical term | Spring Data abstraction that carries one page of results plus paging metadata. |
