View Javadoc
1   /*
2    * Copyright (c) 2002-2014, 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.gismap.utils;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  import fr.paris.lutece.plugins.directory.business.Directory;
40  import fr.paris.lutece.plugins.directory.business.DirectoryHome;
41  import fr.paris.lutece.plugins.directory.business.Entry;
42  import fr.paris.lutece.plugins.directory.business.EntryFilter;
43  import fr.paris.lutece.plugins.directory.business.EntryHome;
44  import fr.paris.lutece.plugins.directory.business.Field;
45  import fr.paris.lutece.plugins.directory.business.IEntry;
46  import fr.paris.lutece.plugins.directory.service.DirectoryPlugin;
47  import fr.paris.lutece.portal.service.plugin.Plugin;
48  import fr.paris.lutece.portal.service.plugin.PluginService;
49  import fr.paris.lutece.portal.service.util.AppPropertiesService;
50  
51  
52  // TODO: Auto-generated Javadoc
53  /**
54   * Utility class for plugin Gismap.
55   */
56  public final class GismapDirectoryUtils
57  {
58  
59      private static final Plugin _DirectoryPlugin = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
60  
61  	/** The Constant GISMAP_VIEW. */
62      public static final String GISMAP_VIEW      = "gismap.view.";
63  
64      /** The Constant GISMAP_PARAMETER. */
65      public static final String GISMAP_PARAMETER = ".parameter";
66  
67      
68      private static final String PROPERTY_ENTRY_TYPE_GEOLOCATION = "directory.entry_type.geolocation";
69  
70      /**
71       * GismapUtils.
72       */
73      private GismapDirectoryUtils( )
74      {
75      }
76  
77      /**
78       * Gets the nb view by directory id.
79       *
80       * @param directoryId the directory id
81       * @return the nb view by directory id
82       */
83      public static String getNbViewByDirectoryId( int directoryId )
84      {
85          String nbView = "";
86  
87          Directory directory = DirectoryHome.findByPrimaryKey( directoryId, _DirectoryPlugin );
88          EntryFilter filter = new EntryFilter( );
89          filter.setIdDirectory( directory.getIdDirectory( ) );
90          filter.setIsComment( EntryFilter.FILTER_FALSE );
91          filter.setIsEntryParentNull( EntryFilter.FILTER_TRUE );
92  
93          List<IEntry> listEntry = new ArrayList<>( );
94  
95          List<IEntry> listEntryFirstLevel = EntryHome.getEntryList( filter, _DirectoryPlugin );
96  
97          filter.setIsEntryParentNull( EntryFilter.ALL_INT );
98  
99          for ( IEntry entry : listEntryFirstLevel )
100         {
101             if ( !entry.getEntryType( ).getGroup( ) )
102             {
103                 listEntry.add( EntryHome.findByPrimaryKey( entry.getIdEntry( ), _DirectoryPlugin ) );
104             }
105 
106             filter.setIdEntryParent( entry.getIdEntry( ) );
107 
108             List<IEntry> listChildren = EntryHome.getEntryList( filter, _DirectoryPlugin );
109 
110             for ( IEntry entryChild : listChildren )
111             {
112                 listEntry.add( EntryHome.findByPrimaryKey( entryChild.getIdEntry( ), _DirectoryPlugin ) );
113             }
114         }
115 
116         for ( IEntry entry : listEntry )
117         {
118             if ( "fr.paris.lutece.plugins.directory.business.EntryTypeGeolocation".equals( entry.getEntryType( ).getClassName( ) ) )
119             {
120                 for ( Field field : entry.getFields( ) )
121                 {
122                     if ( "viewNumberGes".equals( field.getTitle( ) ) )
123                     {
124                         nbView = field.getValue( );
125                     }
126                 }
127             }
128         }
129         return nbView;
130     }
131 
132     
133 	/**
134 	 * Return the Identifier of the first Geolocation Entry inside a given Directory
135 	 * 
136 	 * TODO : change the output parameter to List<Integer> to handle several geolocationEntries within a directory
137 	 * 
138 	 * @param identifier of Directory
139 	 * 
140 	 * @return the geolocation entry identifier
141 	 */
142 	public static Integer getGeolocationEntry(Integer nIdDirectory) {
143 		
144 		  EntryFilter filterGeolocation = new EntryFilter( );
145           filterGeolocation.setIdDirectory( nIdDirectory );
146           filterGeolocation.setIdType( AppPropertiesService.getPropertyInt( PROPERTY_ENTRY_TYPE_GEOLOCATION, 16 ) );
147           filterGeolocation.setIsShownInResultRecord( 1 );
148 
149           List<IEntry> entriesGeolocationList = EntryHome.getEntryList( filterGeolocation, _DirectoryPlugin );
150           Entry geolocEntry = (Entry) entriesGeolocationList.get( 0 );
151           if (geolocEntry != null )
152           {
153         	  return geolocEntry.getIdEntry( );
154           }
155 
156 		return null;
157 	}
158     
159 }