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