<commit_before>/*
 * Copyright 2020 Global Biodiversity Information Facility (GBIF)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.gbif.registry.directory.client.config;

import org.gbif.registry.directory.client.NodeClient;
import org.gbif.registry.directory.client.ParticipantClient;
import org.gbif.registry.directory.client.PersonClient;
import org.gbif.ws.client.ClientContract;
import org.gbif.ws.client.ClientErrorDecoder;
import org.gbif.ws.client.GbifAuthRequestInterceptor;
import org.gbif.ws.security.Md5EncodeService;
import org.gbif.ws.security.SigningService;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.databind.ObjectMapper;

import feign.Contract;
import feign.Feign;
import feign.codec.Decoder;
import feign.codec.ErrorDecoder;
import feign.jackson.JacksonDecoder;

@Configuration
public class DirectoryClientConfiguration {

  private String url;
  private GbifAuthRequestInterceptor requestInterceptor;
  private Decoder decoder;
  private ErrorDecoder errorDecoder;
  private Contract contract;

  public DirectoryClientConfiguration(
      @Value("${directory.ws.url}") String url,
      @Value("${directory.app.key}") String appKey,
      @Value("${directory.app.secret}") String secretKey,
      @Qualifier("secretKeySigningService") SigningService signingService,
      Md5EncodeService md5EncodeService,
      @Qualifier("registryObjectMapper") ObjectMapper objectMapper) {
    this.url = url;
    this.requestInterceptor =
        new GbifAuthRequestInterceptor(appKey, secretKey, signingService, md5EncodeService);
    this.decoder = new JacksonDecoder(objectMapper);
    this.errorDecoder = new ClientErrorDecoder();
    this.contract = new ClientContract();
  }

  @Bean
  public NodeClient nodeClient() {
    return Feign.builder()
        .decoder(decoder)
        .errorDecoder(errorDecoder)
        .contract(contract)
        .requestInterceptor(requestInterceptor)
        .target(NodeClient.class, url);
  }

  @Bean
  public ParticipantClient participantClient() {
    return Feign.builder()
        .decoder(decoder)
        .errorDecoder(errorDecoder)
        .contract(contract)
        .requestInterceptor(requestInterceptor)
        .target(ParticipantClient.class, url);
  }

  @Bean
  public PersonClient personClient() {
    return Feign.builder()
        .decoder(decoder)
        .errorDecoder(errorDecoder)
        .contract(contract)
        .requestInterceptor(requestInterceptor)
        .target(PersonClient.class, url);
  }
}<commit_msg>Use client factory for directory clients<commit_after>/*
 * Copyright 2020 Global Biodiversity Information Facility (GBIF)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.gbif.registry.directory.client.config;

import org.gbif.registry.directory.client.NodeClient;
import org.gbif.registry.directory.client.ParticipantClient;
import org.gbif.registry.directory.client.PersonClient;
import org.gbif.ws.client.ClientFactory;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectoryClientConfiguration {

  private ClientFactory clientFactory;

  public DirectoryClientConfiguration(
      @Value("${directory.ws.url}") String url,
      @Value("${directory.app.key}") String appKey,
      @Value("${directory.app.secret}") String secretKey) {
    this.clientFactory = new ClientFactory(appKey, url, appKey, secretKey);
  }

  @Bean
  public NodeClient nodeClient() {
    return clientFactory.newInstance(NodeClient.class);
  }

  @Bean
  public ParticipantClient participantClient() {
    return clientFactory.newInstance(ParticipantClient.class);
  }

  @Bean
  public PersonClient personClient() {
    return clientFactory.newInstance(PersonClient.class);
  }
}
{'fraction_non_alphanumeric': 0.09149940968122787, 'fraction_numerical': 0.003935458480913027, 'mean_word_length': 4.4247598719316965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '425818', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1336, 'n_words': 364}