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.util.ComponentUtil;
22
23 /**
24 * Pager class for handling user list pagination.
25 * This class manages pagination state and user search criteria for the user management interface.
26 */
27 public class UserPager implements Serializable {
28
29 /**
30 * Default constructor for UserPager.
31 */
32 public UserPager() {
33 // Default constructor
34 }
35
36 private static final long serialVersionUID = 1L;
37
38 /** Default page size for user list pagination */
39 public static final int DEFAULT_PAGE_SIZE = 20;
40
41 /**
42 * Default current page number for pagination.
43 */
44 public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
45
46 /** The total number of records */
47 private int allRecordCount;
48
49 /** The total number of pages */
50 private int allPageCount;
51
52 /** Whether there is a previous page available */
53 private boolean existPrePage;
54
55 /** Whether there is a next page available */
56 private boolean existNextPage;
57
58 /** List of page numbers for navigation */
59 private List<Integer> pageNumberList;
60
61 /** Number of records per page */
62 private int pageSize;
63
64 /** Current page number */
65 private int currentPageNumber;
66
67 /** User ID for search filtering */
68 public String id;
69
70 /** User name for search filtering */
71 public String name;
72
73 /** User roles for search filtering */
74 public String[] roles;
75
76 /** User groups for search filtering */
77 public String[] groups;
78
79 /** Version number for optimistic locking */
80 public String versionNo;
81
82 /**
83 * Clears all pagination state and search criteria.
84 * Resets the pager to its initial state with default values.
85 */
86 public void clear() {
87 allRecordCount = 0;
88 allPageCount = 0;
89 existPrePage = false;
90 existNextPage = false;
91 pageSize = getDefaultPageSize();
92 currentPageNumber = getDefaultCurrentPageNumber();
93
94 id = null;
95 roles = null;
96 groups = null;
97 versionNo = null;
98
99 }
100
101 /**
102 * Gets the default current page number.
103 *
104 * @return the default current page number
105 */
106 protected int getDefaultCurrentPageNumber() {
107 return DEFAULT_CURRENT_PAGE_NUMBER;
108 }
109
110 /**
111 * Gets the total number of records.
112 *
113 * @return the total record count
114 */
115 public int getAllRecordCount() {
116 return allRecordCount;
117 }
118
119 /**
120 * Sets the total number of records.
121 *
122 * @param allRecordCount the total record count
123 */
124 public void setAllRecordCount(final int allRecordCount) {
125 this.allRecordCount = allRecordCount;
126 }
127
128 /**
129 * Gets the total number of pages.
130 *
131 * @return the total page count
132 */
133 public int getAllPageCount() {
134 return allPageCount;
135 }
136
137 /**
138 * Sets the total number of pages.
139 *
140 * @param allPageCount the total page count
141 */
142 public void setAllPageCount(final int allPageCount) {
143 this.allPageCount = allPageCount;
144 }
145
146 /**
147 * Checks if there is a previous page available.
148 *
149 * @return true if previous page exists, false otherwise
150 */
151 public boolean isExistPrePage() {
152 return existPrePage;
153 }
154
155 /**
156 * Sets whether there is a previous page available.
157 *
158 * @param existPrePage true if previous page exists, false otherwise
159 */
160 public void setExistPrePage(final boolean existPrePage) {
161 this.existPrePage = existPrePage;
162 }
163
164 /**
165 * Checks if there is a next page available.
166 *
167 * @return true if next page exists, false otherwise
168 */
169 public boolean isExistNextPage() {
170 return existNextPage;
171 }
172
173 /**
174 * Sets whether there is a next page available.
175 *
176 * @param existNextPage true if next page exists, false otherwise
177 */
178 public void setExistNextPage(final boolean existNextPage) {
179 this.existNextPage = existNextPage;
180 }
181
182 /**
183 * Gets the number of records per page.
184 * Returns the default page size if not set or invalid.
185 *
186 * @return the page size
187 */
188 public int getPageSize() {
189 if (pageSize <= 0) {
190 pageSize = getDefaultPageSize();
191 }
192 return pageSize;
193 }
194
195 /**
196 * Sets the number of records per page.
197 *
198 * @param pageSize the page size
199 */
200 public void setPageSize(final int pageSize) {
201 this.pageSize = pageSize;
202 }
203
204 /**
205 * Gets the current page number.
206 * Returns the default page number if not set or invalid.
207 *
208 * @return the current page number
209 */
210 public int getCurrentPageNumber() {
211 if (currentPageNumber <= 0) {
212 currentPageNumber = getDefaultCurrentPageNumber();
213 }
214 return currentPageNumber;
215 }
216
217 /**
218 * Sets the current page number.
219 *
220 * @param currentPageNumber the current page number
221 */
222 public void setCurrentPageNumber(final int currentPageNumber) {
223 this.currentPageNumber = currentPageNumber;
224 }
225
226 /**
227 * Gets the list of page numbers for navigation.
228 *
229 * @return the list of page numbers
230 */
231 public List<Integer> getPageNumberList() {
232 return pageNumberList;
233 }
234
235 /**
236 * Sets the list of page numbers for navigation.
237 *
238 * @param pageNumberList the list of page numbers
239 */
240 public void setPageNumberList(final List<Integer> pageNumberList) {
241 this.pageNumberList = pageNumberList;
242 }
243
244 /**
245 * Gets the default page size from configuration.
246 *
247 * @return the default page size
248 */
249 protected int getDefaultPageSize() {
250 return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
251 }
252
253 }