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