View Javadoc
1   /*
2    * Copyright (c) 2002-2018, Mairie de 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.directory.modules.multiview.web.record.filter.display.impl;
35  
36  import java.util.LinkedHashMap;
37  import java.util.Locale;
38  import java.util.Map;
39  
40  import javax.servlet.http.HttpServletRequest;
41  
42  import fr.paris.lutece.plugins.directory.modules.multiview.util.DirectoryMultiviewConstants;
43  import fr.paris.lutece.plugins.directory.modules.multiview.util.RecordRecordDateCreationNameConstants;
44  import fr.paris.lutece.portal.service.i18n.I18nService;
45  import fr.paris.lutece.util.ReferenceList;
46  
47  /**
48   * Implementation of the IRecordFilterDisplay interface for the filter which manage the period of creation of records
49   */
50  public class RecordFilterDisplayRecordDateCreation extends AbstractRecordFilterDisplay
51  {
52      // Constants
53      private static final int LAST_DAY_VALUE = 1;
54      private static final int LAST_WEEK_VALUE = 7;
55      private static final int LAST_MONTH_VALUE = 31;
56      private static final String PARAMETER_SEARCH_OPEN_SINCE = "multiview_search_open_since";
57  
58      // Messages keys
59      private static final String LAST_DAY_MESSAGE_KEY = "module.directory.multiview.records_list.search_since_last_day";
60      private static final String LAST_WEEK_MESSAGE_KEY = "module.directory.multiview.records_list.search_since_last_week";
61      private static final String LAST_MONTH_MESSAGE_KEY = "module.directory.multiview.records_list.search_since_last_month";
62  
63      /**
64       * {@inheritDoc}
65       */
66      @Override
67      public String getParameterName( )
68      {
69          return PARAMETER_SEARCH_OPEN_SINCE;
70      }
71  
72      /**
73       * {@inheritDoc}
74       */
75      @Override
76      public Map<String, Object> getFilterDisplayMapValues( HttpServletRequest request )
77      {
78          String strPeriodCreationDate = request.getParameter( PARAMETER_SEARCH_OPEN_SINCE );
79          setValue( strPeriodCreationDate );
80  
81          Map<String, Object> mapFilterNameValues = new LinkedHashMap<>( );
82          mapFilterNameValues.put( RecordRecordDateCreationNameConstants.FILTER_RECORD_DATE_CREATION, strPeriodCreationDate );
83  
84          return mapFilterNameValues;
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      public void buildTemplate( HttpServletRequest request )
92      {
93          manageFilterTemplate( request, createReferenceList( request.getLocale( ) ), PARAMETER_SEARCH_OPEN_SINCE );
94      }
95  
96      /**
97       * Build the ReferenceList for the period of the record creation
98       * 
99       * @param locale
100      *            The locale to use for building the message for the list
101      * @return the ReferenceList for the period of the record creation
102      */
103     private ReferenceList createReferenceList( Locale locale )
104     {
105         ReferenceList referenceList = new ReferenceList( );
106 
107         // Default value
108         String strDefaultDayItemName = getRecordFilterDisplayLabel( );
109         referenceList.addItem( DirectoryMultiviewConstants.DEFAULT_FILTER_VALUE, strDefaultDayItemName );
110 
111         // Last day filter
112         String strLastDayItemName = I18nService.getLocalizedString( LAST_DAY_MESSAGE_KEY, locale );
113         referenceList.addItem( LAST_DAY_VALUE, strLastDayItemName );
114 
115         // Last week filter
116         String strLastWeekItemName = I18nService.getLocalizedString( LAST_WEEK_MESSAGE_KEY, locale );
117         referenceList.addItem( LAST_WEEK_VALUE, strLastWeekItemName );
118 
119         // Last month filter
120         String strLastMonthItemName = I18nService.getLocalizedString( LAST_MONTH_MESSAGE_KEY, locale );
121         referenceList.addItem( LAST_MONTH_VALUE, strLastMonthItemName );
122 
123         return referenceList;
124     }
125 }