View Javadoc
1   /*
2    * Copyright (c) 2002-2020, 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.document.business.portlet;
35  
36  import fr.paris.lutece.portal.service.util.AppPropertiesService;
37  
38  
39  /**
40   * PortletFilter class
41   * @author merlinfe
42   *
43   */
44  public class PortletFilter
45  {
46      public static final String CONSTANTE_SPACE_STRING = " ";
47      public static final String PAGE_NAME = AppPropertiesService.getProperty( "document.filter.page_name", "page_name" );
48      public static final String PORTLET_NAME = AppPropertiesService.getProperty( "document.filter.portlet_name",
49              "portlet_name" );
50      public static final String PAGE_ID = AppPropertiesService.getProperty( "document.filter.page_id", "page_id" );
51      public static final int PROPERTY_NUMBER_OF_MAX_LATEST_PORTLETS_DISPLAY = AppPropertiesService.getPropertyInt( "document.filter.number_of_max_latest_portlets_display",
52              10 );
53      private static final String SQL_FILTER_PAGE_NAME = "  f.name like ? ";
54      private static final String SQL_FILTER_BY_PAGE_ID = "  a.id_page=? ";
55      private static final String SQL_FILTER_BY_PORTLET_NAME = " a.name like ? ";
56      private boolean _bIsDisplayLatestPortlets;
57      private String[] _tabPageName;
58      private String[] _tabPortletName;
59      private Integer _nIdPage;
60      private String _portletFilterType;
61      private String _strSearchValue;
62  
63      /**
64       * Set the page name list
65       * @param strPageTitle The list of titles of pages
66       */
67      public void setPageName( String[] strPageTitle )
68      {
69          this._tabPageName = strPageTitle;
70      }
71  
72      /**
73       * Get the page name list
74       * @return The page name list
75       */
76      public String[] getPageName(  )
77      {
78          return _tabPageName;
79      }
80  
81      /**
82       * Set the portlet title filter
83       * @param strPortletTitle The portlet title filter
84       */
85      public void setPortletName( String[] strPortletTitle )
86      {
87          this._tabPortletName = strPortletTitle;
88      }
89  
90      /**
91       * Get the portlet title filter
92       * @return The portlet title filter
93       */
94      public String[] getPortletName(  )
95      {
96          return _tabPortletName;
97      }
98  
99      /**
100      * Set the id of the page
101      * @param nIdPage The id of the page
102      */
103     public void setIdPage( Integer nIdPage )
104     {
105         this._nIdPage = nIdPage;
106     }
107 
108     /**
109      * Get the id of the page
110      * @return The id of the page
111      */
112     public Integer getIdPage(  )
113     {
114         return _nIdPage;
115     }
116 
117     /**
118      * Set the display latest portlets filter attribute
119      * @param bIsDisplayLatestPortlets the display latest portlets filter
120      *            attribute
121      */
122     public void setDisplayLatestPortlets( boolean bIsDisplayLatestPortlets )
123     {
124         this._bIsDisplayLatestPortlets = bIsDisplayLatestPortlets;
125     }
126 
127     /**
128      * Get the display latest portlets filter attribute
129      * @return The display latest portlets filter attribute
130      */
131     public boolean isDisplayLatestPortlets(  )
132     {
133         return _bIsDisplayLatestPortlets;
134     }
135 
136     /**
137      * Set the portlet type
138      * @param portletFilterType The portlet type
139      */
140     public void setPortletFilterType( String portletFilterType )
141     {
142         this._portletFilterType = portletFilterType;
143     }
144 
145     /**
146      * Get the portlet type
147      * @return The portlet type
148      */
149     public String getPortletFilterType(  )
150     {
151         return _portletFilterType;
152     }
153 
154     /**
155      * Get the SQL query for searching
156      *
157      * @return the SQL query
158      */
159     public String getSQLFilter(  )
160     {
161         if ( ( _portletFilterType != null ) && !_bIsDisplayLatestPortlets )
162         {
163             StringBuilder sbSQL = new StringBuilder(  );
164 
165             if ( _portletFilterType.equals( PAGE_NAME ) && ( _tabPageName != null ) )
166             {
167                 sbSQL.append( " ( " );
168 
169                 for ( int i = 0; i < _tabPageName.length; i++ )
170                 {
171                     sbSQL.append( SQL_FILTER_PAGE_NAME );
172 
173                     if ( i != ( _tabPageName.length - 1 ) )
174                     {
175                         sbSQL.append( " OR " );
176                     }
177                 }
178 
179                 sbSQL.append( " ) " );
180             }
181             else if ( _portletFilterType.equals( PORTLET_NAME ) && ( _tabPortletName != null ) )
182             {
183                 sbSQL.append( " ( " );
184 
185                 for ( int i = 0; i < _tabPortletName.length; i++ )
186                 {
187                     sbSQL.append( SQL_FILTER_BY_PORTLET_NAME );
188 
189                     if ( i != ( _tabPortletName.length - 1 ) )
190                     {
191                         sbSQL.append( " OR " );
192                     }
193                 }
194 
195                 sbSQL.append( " ) " );
196             }
197             else if ( _portletFilterType.equals( PAGE_ID ) && ( _nIdPage != null ) )
198             {
199                 sbSQL.append( SQL_FILTER_BY_PAGE_ID );
200             }
201 
202             return sbSQL.toString(  );
203         }
204 
205         return null;
206     }
207 
208     /**
209      * Set the search value
210      * @param strSearchValue the search value
211      */
212     public void setSearchValue( String strSearchValue )
213     {
214         this._strSearchValue = strSearchValue;
215     }
216 
217     /**
218      * Get the search value
219      * @return the search value
220      */
221     public String getSearchValue(  )
222     {
223         return _strSearchValue;
224     }
225 }