View Javadoc
1   /*
2    * Copyright 2012-2017 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.ds.impl;
17  
18  import java.util.Map;
19  
20  import org.codelibs.fess.Constants;
21  import org.codelibs.fess.crawler.client.CrawlerClientFactory;
22  import org.codelibs.fess.ds.IndexUpdateCallback;
23  import org.codelibs.fess.es.config.exentity.DataConfig;
24  import org.codelibs.fess.exception.DataStoreException;
25  import org.codelibs.fess.util.ComponentUtil;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  public class EsListDataStoreImpl extends EsDataStoreImpl {
30      private static final Logger logger = LoggerFactory.getLogger(EsListDataStoreImpl.class);
31  
32      @Override
33      protected void storeData(final DataConfig dataConfig, final IndexUpdateCallback callback, final Map<String, String> paramMap,
34              final Map<String, String> scriptMap, final Map<String, Object> defaultDataMap) {
35          int nThreads = 1;
36          if (paramMap.containsKey(Constants.NUM_OF_THREADS)) {
37              try {
38                  nThreads = Integer.parseInt(paramMap.get(Constants.NUM_OF_THREADS));
39              } catch (final NumberFormatException e) {
40                  logger.warn(Constants.NUM_OF_THREADS + " is not int value.", e);
41              }
42          }
43          final CrawlerClientFactory crawlerClientFactory = ComponentUtil.getCrawlerClientFactory();
44          dataConfig.initializeClientFactory(crawlerClientFactory);
45          try {
46              final FileListIndexUpdateCallbackImpl fileListIndexUpdateCallback =
47                      new FileListIndexUpdateCallbackImpl(callback, crawlerClientFactory, nThreads);
48              super.storeData(dataConfig, fileListIndexUpdateCallback, paramMap, scriptMap, defaultDataMap);
49              fileListIndexUpdateCallback.commit();
50          } catch (final Exception e) {
51              throw new DataStoreException(e);
52          }
53      }
54  
55  }