Beispiel #1
0
  public void store(final DictionaryFile<? extends DictionaryItem> dictFile, final File file) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    getDictionaryFile(dictFile.getId())
        .ifPresent(
            currentFile -> {
              if (currentFile.getTimestamp().getTime() > dictFile.getTimestamp().getTime()) {
                throw new DictionaryException(dictFile.getPath() + " was updated.");
              }

              // TODO use stream
              try (CurlResponse response =
                  Curl.post(fessConfig.getElasticsearchUrl() + "/_configsync/file")
                      .param("path", dictFile.getPath())
                      .body(FileUtil.readUTF8(file))
                      .execute()) {
                final Map<String, Object> contentMap = response.getContentAsMap();
                if (!Constants.TRUE.equalsIgnoreCase(contentMap.get("acknowledged").toString())) {
                  throw new DictionaryException("Failed to update " + dictFile.getPath());
                }
              } catch (final IOException e) {
                throw new DictionaryException("Failed to update " + dictFile.getPath(), e);
              }
            })
        .orElse(
            () -> {
              throw new DictionaryException(dictFile.getPath() + " does not exist.");
            });
  }
Beispiel #2
0
 public InputStream getContentInputStream(
     final DictionaryFile<? extends DictionaryItem> dictFile) {
   final FessConfig fessConfig = ComponentUtil.getFessConfig();
   try {
     return Curl.get(fessConfig.getElasticsearchUrl() + "/_configsync/file")
         .param("path", dictFile.getPath())
         .execute()
         .getContentAsStream();
   } catch (final IOException e) {
     throw new DictionaryException("Failed to access " + dictFile.getPath(), e);
   }
 }