|
3 | 3 | import static org.springframework.data.relational.core.query.Criteria.where;
|
4 | 4 |
|
5 | 5 | import ca.bc.gov.api.oracle.legacy.dto.ClientPublicViewDto;
|
| 6 | +import ca.bc.gov.api.oracle.legacy.dto.SearchNumberScoreProjection; |
6 | 7 | import ca.bc.gov.api.oracle.legacy.entity.ForestClientEntity;
|
7 | 8 | import ca.bc.gov.api.oracle.legacy.repository.ForestClientRepository;
|
8 | 9 | import ca.bc.gov.api.oracle.legacy.util.ClientMapper;
|
| 10 | +import java.time.Duration; |
9 | 11 | import java.util.List;
|
10 | 12 | import lombok.RequiredArgsConstructor;
|
11 | 13 | import lombok.extern.slf4j.Slf4j;
|
12 | 14 | import org.apache.commons.lang3.StringUtils;
|
13 | 15 | import org.springframework.data.domain.PageRequest;
|
| 16 | +import org.springframework.data.domain.Pageable; |
14 | 17 | import org.springframework.data.domain.Sort;
|
15 | 18 | import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
16 | 19 | import org.springframework.data.relational.core.query.Criteria;
|
@@ -110,41 +113,49 @@ public Flux<ClientPublicViewDto> searchClientByQuery(
|
110 | 113 | }
|
111 | 114 |
|
112 | 115 | /**
|
113 |
| - * Constructs a search {@link Criteria} object based on the provided client name, acronym, or |
114 |
| - * number. |
115 |
| - * This method normalizes input values for case-insensitive searches and validates the client |
116 |
| - * number. |
| 116 | + * Constructs a search {@link Criteria} object based on the provided client name, acronym, or |
| 117 | + * number. This method normalizes input values for case-insensitive searches and validates the |
| 118 | + * client number. |
117 | 119 | *
|
118 |
| - * @param name the name of the client to search for, or null if not specified. |
| 120 | + * @param name the name of the client to search for, or null if not specified. |
119 | 121 | * @param acronym the acronym of the client to search for, or null if not specified.
|
120 |
| - * @param number the unique number of the client to search for, or null if not specified. |
| 122 | + * @param number the unique number of the client to search for, or null if not specified. |
| 123 | + * @param size the number of results to return. |
121 | 124 | * @return a {@link Mono} emitting the constructed {@link Criteria} object for the search.
|
122 |
| - * |
123 |
| - * @implNote Input values are transformed to uppercase for case-insensitivity. The client |
124 |
| - * number is validated using {@link #checkClientNumber(String)}. Repository results are |
125 |
| - * mapped to a search criteria object. |
| 125 | + * @implNote Input values are transformed to uppercase for case-insensitivity. The client number |
| 126 | + * is validated using {@link #checkClientNumber(String)}. Repository results are mapped to a |
| 127 | + * search criteria object. |
126 | 128 | */
|
127 |
| - public Mono<Criteria> searchByAcronymNameNumber(String name, String acronym, String number) { |
| 129 | + public Mono<Criteria> searchByAcronymNameNumber( |
| 130 | + String name, |
| 131 | + String acronym, |
| 132 | + String number, |
| 133 | + int page, |
| 134 | + int size) { |
128 | 135 | log.info("Searching for clients with name {}, acronym {} or number {}", name, acronym, number);
|
129 | 136 |
|
130 | 137 | String searchName = StringUtils.isNotBlank(name) ? name.toUpperCase() : null;
|
131 | 138 | String searchAcronym = StringUtils.isNotBlank(acronym) ? acronym.toUpperCase() : null;
|
132 | 139 | String searchNumber = StringUtils.isNotBlank(number) ? checkClientNumber(number) : null;
|
| 140 | + Pageable pageRequest = PageRequest.of(page, size); |
133 | 141 |
|
134 | 142 | return
|
135 |
| - forestClientRepository |
136 |
| - .searchNumberByNameAcronymNumber( |
137 |
| - searchName, |
138 |
| - searchAcronym, |
139 |
| - searchNumber |
140 |
| - ) |
141 |
| - .collectList() |
142 |
| - .map(this::searchById); |
| 143 | + forestClientRepository |
| 144 | + .searchNumberByNameAcronymNumber( |
| 145 | + searchName, |
| 146 | + searchAcronym, |
| 147 | + searchNumber, |
| 148 | + pageRequest.getOffset(), |
| 149 | + pageRequest.getPageSize() |
| 150 | + ) |
| 151 | + .map(SearchNumberScoreProjection::getClientNumber) |
| 152 | + .collectList() |
| 153 | + .map(this::searchById); |
143 | 154 |
|
144 | 155 | }
|
145 | 156 |
|
146 | 157 | private String checkClientNumber(String clientNumber) {
|
147 |
| - if(StringUtils.isBlank(clientNumber)) { |
| 158 | + if (StringUtils.isBlank(clientNumber)) { |
148 | 159 | return clientNumber;
|
149 | 160 | }
|
150 | 161 |
|
|
0 commit comments