View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.unittree.web.action;
35  
36  import fr.paris.lutece.portal.service.util.AppPropertiesService;
37  import fr.paris.lutece.portal.web.constants.Parameters;
38  
39  import org.apache.commons.lang3.StringUtils;
40  
41  import java.io.Serializable;
42  
43  import javax.servlet.http.HttpServletRequest;
44  
45  /**
46   *
47   * DefaultUnitSearchFields
48   *
49   */
50  public abstract class DefaultUnitSearchFields implements IUnitSearchFields, Serializable
51  {
52      private static final long serialVersionUID = 7400229591290783994L;
53  
54      // PROPERTIES
55      private static final String PROPERTY_ITEM_PER_PAGE = "unittree.itemsPerPage";
56  
57      // PARAMETERS
58      private static final String PARAMETER_SESSION = "session";
59      private static final String PARAMETER_IS_IN_DEPTH_SEARCH = "isInDepthSearch";
60  
61      // VARIABLES
62      private int _nItemsPerPage;
63      private int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_ITEM_PER_PAGE, 50 );
64      private String _strCurrentPageIndex;
65      private boolean _bIsInDepthSearch;
66      private String _strSortedAttributeName;
67      private boolean _bIsAscSort;
68  
69      /**
70       * {@inheritDoc}
71       */
72      @Override
73      public String getCurrentPageIndex( )
74      {
75          return _strCurrentPageIndex;
76      }
77  
78      /**
79       * {@inheritDoc}
80       */
81      @Override
82      public int getDefaultItemsPerPage( )
83      {
84          return _nDefaultItemsPerPage;
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      public void setCurrentPageIndex( String strCurrentPageIndex )
92      {
93          _strCurrentPageIndex = strCurrentPageIndex;
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     public void setDefaultItemsPerPage( int nDefaultItemsPerPage )
101     {
102         _nDefaultItemsPerPage = nDefaultItemsPerPage;
103     }
104 
105     /**
106      * {@inheritDoc}
107      */
108     @Override
109     public int getItemsPerPage( )
110     {
111         return _nItemsPerPage;
112     }
113 
114     /**
115      * {@inheritDoc}
116      */
117     @Override
118     public void setItemsPerPage( int nItemsPerPage )
119     {
120         _nItemsPerPage = nItemsPerPage;
121     }
122 
123     /**
124      * {@inheritDoc}
125      */
126     @Override
127     public void setInDepthSearch( HttpServletRequest request )
128     {
129         if ( StringUtils.isBlank( request.getParameter( PARAMETER_SESSION ) ) )
130         {
131             _bIsInDepthSearch = StringUtils.isNotBlank( request.getParameter( PARAMETER_IS_IN_DEPTH_SEARCH ) );
132         }
133     }
134 
135     /**
136      * {@inheritDoc}
137      */
138     @Override
139     public boolean isInDepthSearch( )
140     {
141         return _bIsInDepthSearch;
142     }
143 
144     /**
145      * {@inheritDoc}
146      */
147     @Override
148     public String getSortedAttributeName( )
149     {
150         return _strSortedAttributeName;
151     }
152 
153     /**
154      * {@inheritDoc}
155      */
156     @Override
157     public void setSortedAttributeName( HttpServletRequest request )
158     {
159         if ( StringUtils.isNotBlank( request.getParameter( Parameters.SORTED_ATTRIBUTE_NAME ) ) )
160         {
161             _strSortedAttributeName = request.getParameter( Parameters.SORTED_ATTRIBUTE_NAME );
162         }
163     }
164 
165     /**
166      * {@inheritDoc}
167      */
168     @Override
169     public boolean isAscSort( )
170     {
171         return _bIsAscSort;
172     }
173 
174     /**
175      * {@inheritDoc}
176      */
177     @Override
178     public void setAscSort( HttpServletRequest request )
179     {
180         if ( StringUtils.isNotBlank( request.getParameter( Parameters.SORTED_ASC ) ) )
181         {
182             _bIsAscSort = Boolean.parseBoolean( request.getParameter( Parameters.SORTED_ASC ) );
183         }
184     }
185 }