View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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.comarquage.modules.solr.search;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  import fr.paris.lutece.plugins.comarquage.modules.solr.utils.parsers.CoMarquageSolrPublicParser;
40  import fr.paris.lutece.plugins.search.solr.business.field.Field;
41  import fr.paris.lutece.plugins.search.solr.indexer.SolrIndexer;
42  import fr.paris.lutece.plugins.search.solr.indexer.SolrIndexerService;
43  import fr.paris.lutece.plugins.search.solr.indexer.SolrItem;
44  import fr.paris.lutece.portal.service.util.AppLogService;
45  import fr.paris.lutece.portal.service.util.AppPropertiesService;
46  
47  
48  /**
49   * The Comarquage indexer for Solr search platform
50   *
51   */
52  public class SolrComarquagePublicIndexer implements SolrIndexer
53  {
54      private static final String PROPERTY_DESCRIPTION = "comarquage-solr.indexing.publicIndexer.description";
55      private static final String PROPERTY_NAME = "comarquage-solr.indexing.publicIndexer.name";
56      private static final String PROPERTY_VERSION = "comarquage-solr.indexing.publicIndexer.version";
57      private static final String PROPERTY_INDEXER_ENABLE = "comarquage-solr.indexing.publicIndexer.enable";
58  
59      private static final String COM_INDEXATION_ERROR = "[SolrComarquagePublicIndexer] An error occured during the indexation of a plublic element ";
60      
61      /**
62       * {@inheritDoc}
63       */
64      public String getDescription(  )
65      {
66          return AppPropertiesService.getProperty( PROPERTY_DESCRIPTION );
67      }
68  
69      /**
70       * {@inheritDoc}
71       */
72      public String getName(  )
73      {
74          return AppPropertiesService.getProperty( PROPERTY_NAME );
75      }
76  
77      /**
78       * {@inheritDoc}
79       */
80      public String getVersion(  )
81      {
82          return AppPropertiesService.getProperty( PROPERTY_VERSION );
83      }
84  
85      /**
86       * {@inheritDoc}
87       */
88      public List<String> indexDocuments(  )
89      {
90          // Parses the Public cards
91          CoMarquageSolrPublicParser localParser = new CoMarquageSolrPublicParser(  );
92  
93          // Gets the list of solr documents (to add to the index)
94          List<SolrItem> listDocuments = localParser.getPublicSolrItems(  );
95  
96          List<String> lstErrors = new ArrayList<String>(  );
97          
98          for ( SolrItem solrItem : listDocuments )
99          {
100         	try
101 			{
102         		SolrIndexerService.write( solrItem );
103 			}
104 			catch ( Exception e )
105 			{
106 				lstErrors.add( SolrIndexerService.buildErrorMessage( e ) );
107 				AppLogService.error( COM_INDEXATION_ERROR , e );
108 			}
109         }
110         
111         return lstErrors;
112     }
113 
114     /**
115      * {@inheritDoc}
116      */
117     public boolean isEnable(  )
118     {
119         return "true".equalsIgnoreCase( AppPropertiesService.getProperty( PROPERTY_INDEXER_ENABLE ) );
120     }
121 
122     /**
123      * {@inheritDoc}
124      */
125     public List<Field> getAdditionalFields(  )
126     {
127         // No additional fields for this indexer
128         return new ArrayList<Field>(  );
129     }
130 
131     /**
132      * {@inheritDoc}
133      */
134     public List<SolrItem> getDocuments( String strIdDocument )
135     {
136         // There is no incremental indexation
137         return null;
138     }
139 
140     /**
141      * {@inheritDoc}
142      */
143     public String getResourceUid( String strResourceId, String strResourceType )
144     {
145         // There is no incremental indexation
146         return null;
147     }
148 
149     /**
150      * {@inheritDoc}
151      */
152     public List<String> getResourcesName(  )
153     {
154         // There is no incremental indexation
155         return null;
156     }
157 }