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