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 managing pagination of failure URL records.
25   * This class provides functionality to handle pagination of failed crawler URLs
26   * with search filters and navigation capabilities.
27   */
28  public class FailureUrlPager implements Serializable {
29  
30      /** Serial version UID for serialization compatibility. */
31      private static final long serialVersionUID = 1L;
32  
33      /**
34       * Default constructor.
35       */
36      public FailureUrlPager() {
37          // Default constructor
38      }
39  
40      /** URL filter for searching failure URLs. */
41      //@Maxbytelength(maxbytelength = 1000)
42      public String url;
43  
44      /** Minimum error count filter for searching failure URLs. */
45      //@IntRange(min = 0, max = 2147483647)
46      public String errorCountMin;
47  
48      /** Maximum error count filter for searching failure URLs. */
49      //@IntRange(min = 0, max = 2147483647)
50      public String errorCountMax;
51  
52      /** Error name filter for searching failure URLs. */
53      //@Maxbytelength(maxbytelength = 1000)
54      public String errorName;
55  
56      /** Default number of records per page. */
57      public static final int DEFAULT_PAGE_SIZE = 20;
58  
59      /** Default current page number. */
60      public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
61  
62      /** Total number of records across all pages. */
63      private int allRecordCount;
64  
65      /** Total number of pages. */
66      private int allPageCount;
67  
68      /** Flag indicating whether a previous page exists. */
69      private boolean existPrePage;
70  
71      /** Flag indicating whether a next page exists. */
72      private boolean existNextPage;
73  
74      /** List of page numbers for navigation. */
75      private List<Integer> pageNumberList;
76  
77      /** Number of records per page. */
78      private int pageSize;
79  
80      /** Current page number. */
81      private int currentPageNumber;
82  
83      /** ID of the failure URL record. */
84      public String id;
85  
86      /** Name of the thread that encountered the failure. */
87      public String threadName;
88  
89      /** Number of errors encountered for this URL. */
90      public String errorCount;
91  
92      /** Last time this URL was accessed. */
93      public String lastAccessTime;
94  
95      /**
96       * Clears all pager data and resets to default values.
97       * This method resets pagination state and search filters.
98       */
99      public void clear() {
100         allRecordCount = 0;
101         allPageCount = 0;
102         existPrePage = false;
103         existNextPage = false;
104         pageSize = getDefaultPageSize();
105         currentPageNumber = getDefaultCurrentPageNumber();
106 
107         id = null;
108         url = null;
109         threadName = null;
110         errorCount = null;
111         lastAccessTime = null;
112         errorCountMin = null;
113         errorCountMax = null;
114         errorName = null;
115 
116     }
117 
118     /**
119      * Gets the default current page number.
120      *
121      * @return the default current page number
122      */
123     protected int getDefaultCurrentPageNumber() {
124         return DEFAULT_CURRENT_PAGE_NUMBER;
125     }
126 
127     /**
128      * Gets the total number of records across all pages.
129      *
130      * @return the total record count
131      */
132     public int getAllRecordCount() {
133         return allRecordCount;
134     }
135 
136     /**
137      * Sets the total number of records across all pages.
138      *
139      * @param allRecordCount the total record count
140      */
141     public void setAllRecordCount(final int allRecordCount) {
142         this.allRecordCount = allRecordCount;
143     }
144 
145     /**
146      * Gets the total number of pages.
147      *
148      * @return the total page count
149      */
150     public int getAllPageCount() {
151         return allPageCount;
152     }
153 
154     /**
155      * Sets the total number of pages.
156      *
157      * @param allPageCount the total page count
158      */
159     public void setAllPageCount(final int allPageCount) {
160         this.allPageCount = allPageCount;
161     }
162 
163     /**
164      * Checks if a previous page exists.
165      *
166      * @return true if a previous page exists, false otherwise
167      */
168     public boolean isExistPrePage() {
169         return existPrePage;
170     }
171 
172     /**
173      * Sets whether a previous page exists.
174      *
175      * @param existPrePage true if a previous page exists, false otherwise
176      */
177     public void setExistPrePage(final boolean existPrePage) {
178         this.existPrePage = existPrePage;
179     }
180 
181     /**
182      * Checks if a next page exists.
183      *
184      * @return true if a next page exists, false otherwise
185      */
186     public boolean isExistNextPage() {
187         return existNextPage;
188     }
189 
190     /**
191      * Sets whether a next page exists.
192      *
193      * @param existNextPage true if a next page exists, false otherwise
194      */
195     public void setExistNextPage(final boolean existNextPage) {
196         this.existNextPage = existNextPage;
197     }
198 
199     /**
200      * Gets the number of records per page.
201      * If not set or invalid, returns the default page size.
202      *
203      * @return the page size
204      */
205     public int getPageSize() {
206         if (pageSize <= 0) {
207             pageSize = getDefaultPageSize();
208         }
209         return pageSize;
210     }
211 
212     /**
213      * Sets the number of records per page.
214      *
215      * @param pageSize the page size
216      */
217     public void setPageSize(final int pageSize) {
218         this.pageSize = pageSize;
219     }
220 
221     /**
222      * Gets the current page number.
223      * If not set or invalid, returns the default current page number.
224      *
225      * @return the current page number
226      */
227     public int getCurrentPageNumber() {
228         if (currentPageNumber <= 0) {
229             currentPageNumber = getDefaultCurrentPageNumber();
230         }
231         return currentPageNumber;
232     }
233 
234     /**
235      * Sets the current page number.
236      *
237      * @param currentPageNumber the current page number
238      */
239     public void setCurrentPageNumber(final int currentPageNumber) {
240         this.currentPageNumber = currentPageNumber;
241     }
242 
243     /**
244      * Gets the list of page numbers for navigation.
245      *
246      * @return the page number list
247      */
248     public List<Integer> getPageNumberList() {
249         return pageNumberList;
250     }
251 
252     /**
253      * Sets the list of page numbers for navigation.
254      *
255      * @param pageNumberList the page number list
256      */
257     public void setPageNumberList(final List<Integer> pageNumberList) {
258         this.pageNumberList = pageNumberList;
259     }
260 
261     /**
262      * Gets the default page size from the Fess configuration.
263      *
264      * @return the default page size
265      */
266     protected int getDefaultPageSize() {
267         return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
268     }
269 
270 }