1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.app.pager;
17
18 import java.io.Serializable;
19 import java.util.List;
20
21 import org.codelibs.fess.Constants;
22 import org.codelibs.fess.util.ComponentUtil;
23
24 /**
25 * Pager class for related query management functionality.
26 * Provides pagination support for related query operations including
27 * search, display, and navigation through related query results.
28 */
29 public class RelatedQueryPager implements Serializable {
30 private static final long serialVersionUID = 1L;
31
32 /**
33 * Default current page number for pagination.
34 */
35 public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
36
37 /**
38 * Total number of records in the result set.
39 */
40 private int allRecordCount;
41
42 /**
43 * Total number of pages available for pagination.
44 */
45 private int allPageCount;
46
47 /**
48 * Flag indicating whether a previous page exists.
49 */
50 private boolean existPrePage;
51
52 /**
53 * Flag indicating whether a next page exists.
54 */
55 private boolean existNextPage;
56
57 /**
58 * List of page numbers for pagination navigation.
59 */
60 private List<Integer> pageNumberList;
61
62 /**
63 * Number of records to display per page.
64 */
65 private int pageSize;
66
67 /**
68 * Current page number being displayed.
69 */
70 private int currentPageNumber;
71
72 /**
73 * Unique identifier for the related query.
74 */
75 public String id;
76
77 /**
78 * Search term for the related query.
79 */
80 public String term;
81
82 /**
83 * Related queries string containing associated search queries.
84 */
85 public String queries;
86
87 /**
88 * User who created the related query entry.
89 */
90 public String createdBy;
91
92 /**
93 * Timestamp when the related query was created.
94 */
95 public String createdTime;
96
97 /**
98 * Version number for optimistic locking.
99 */
100 public String versionNo;
101
102 /**
103 * Default constructor for RelatedQueryPager.
104 * Initializes a new instance with default values for pagination
105 * and related query fields.
106 */
107 public RelatedQueryPager() {
108 // Default constructor - fields will be initialized to default values
109 }
110
111 /**
112 * Clears all pager data and resets to default values.
113 * Resets pagination state and clears all related query fields.
114 */
115 public void clear() {
116 allRecordCount = 0;
117 allPageCount = 0;
118 existPrePage = false;
119 existNextPage = false;
120 pageSize = getDefaultPageSize();
121 currentPageNumber = getDefaultCurrentPageNumber();
122
123 id = null;
124 term = null;
125 queries = null;
126 createdBy = null;
127 createdTime = null;
128 versionNo = null;
129
130 }
131
132 /**
133 * Gets the total number of records in the result set.
134 *
135 * @return the total record count
136 */
137 public int getAllRecordCount() {
138 return allRecordCount;
139 }
140
141 /**
142 * Sets the total number of records in the result set.
143 *
144 * @param allRecordCount the total record count to set
145 */
146 public void setAllRecordCount(final int allRecordCount) {
147 this.allRecordCount = allRecordCount;
148 }
149
150 /**
151 * Gets the total number of pages available for pagination.
152 *
153 * @return the total page count
154 */
155 public int getAllPageCount() {
156 return allPageCount;
157 }
158
159 /**
160 * Sets the total number of pages available for pagination.
161 *
162 * @param allPageCount the total page count to set
163 */
164 public void setAllPageCount(final int allPageCount) {
165 this.allPageCount = allPageCount;
166 }
167
168 /**
169 * Checks if a previous page exists for pagination.
170 *
171 * @return true if a previous page exists, false otherwise
172 */
173 public boolean isExistPrePage() {
174 return existPrePage;
175 }
176
177 /**
178 * Sets the flag indicating whether a previous page exists.
179 *
180 * @param existPrePage true if a previous page exists, false otherwise
181 */
182 public void setExistPrePage(final boolean existPrePage) {
183 this.existPrePage = existPrePage;
184 }
185
186 /**
187 * Checks if a next page exists for pagination.
188 *
189 * @return true if a next page exists, false otherwise
190 */
191 public boolean isExistNextPage() {
192 return existNextPage;
193 }
194
195 /**
196 * Sets the flag indicating whether a next page exists.
197 *
198 * @param existNextPage true if a next page exists, false otherwise
199 */
200 public void setExistNextPage(final boolean existNextPage) {
201 this.existNextPage = existNextPage;
202 }
203
204 /**
205 * Gets the number of records to display per page.
206 * If not set or invalid, returns the default page size.
207 *
208 * @return the page size
209 */
210 public int getPageSize() {
211 if (pageSize <= 0) {
212 pageSize = getDefaultPageSize();
213 }
214 return pageSize;
215 }
216
217 /**
218 * Sets the number of records to display per page.
219 *
220 * @param pageSize the page size to set
221 */
222 public void setPageSize(final int pageSize) {
223 this.pageSize = pageSize;
224 }
225
226 /**
227 * Gets the current page number being displayed.
228 * If not set or invalid, returns the default current page number.
229 *
230 * @return the current page number
231 */
232 public int getCurrentPageNumber() {
233 if (currentPageNumber <= 0) {
234 currentPageNumber = getDefaultCurrentPageNumber();
235 }
236 return currentPageNumber;
237 }
238
239 /**
240 * Sets the current page number being displayed.
241 *
242 * @param currentPageNumber the current page number to set
243 */
244 public void setCurrentPageNumber(final int currentPageNumber) {
245 this.currentPageNumber = currentPageNumber;
246 }
247
248 /**
249 * Gets the list of page numbers for pagination navigation.
250 *
251 * @return the list of page numbers
252 */
253 public List<Integer> getPageNumberList() {
254 return pageNumberList;
255 }
256
257 /**
258 * Sets the list of page numbers for pagination navigation.
259 *
260 * @param pageNumberList the list of page numbers to set
261 */
262 public void setPageNumberList(final List<Integer> pageNumberList) {
263 this.pageNumberList = pageNumberList;
264 }
265
266 /**
267 * Gets the default current page number from system constants.
268 *
269 * @return the default current page number
270 */
271 protected int getDefaultCurrentPageNumber() {
272 return Constants.DEFAULT_ADMIN_PAGE_NUMBER;
273 }
274
275 /**
276 * Gets the default page size from system configuration.
277 *
278 * @return the default page size
279 */
280 protected int getDefaultPageSize() {
281 return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
282 }
283
284 }