<commit_before>package net.openl10n.flies.rest.client;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import net.openl10n.flies.rest.dto.VersionInfo;

import org.jboss.resteasy.client.ClientExecutor;
import org.jboss.resteasy.client.ClientRequestFactory;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FliesClientRequestFactory implements ITranslationResourcesFactory
{
   static
   {
      ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
      RegisterBuiltin.register(instance);
   }

   private static final Logger log = LoggerFactory.getLogger(FliesClientRequestFactory.class);
   private final ClientRequestFactory crf;
   private static final String RESOURCE_PREFIX = "rest";

   public FliesClientRequestFactory(String username, String apiKey, VersionInfo ver)
   {
      this(null, username, apiKey, ver);
   }

   public FliesClientRequestFactory(URI base, String username, String apiKey, VersionInfo ver)
   {
      this(base, username, apiKey, null, ver);
   }

   public FliesClientRequestFactory(URI base, String username, String apiKey, ClientExecutor executor, VersionInfo ver)
   {
      crf = new ClientRequestFactory(executor, null, fixBase(base));
      registerPrefixInterceptor(new ApiKeyHeaderDecorator(username, apiKey, ver.getVersionNo()));
      IVersion iversion = getVersionInfo();
      VersionInfo server = iversion.get();
      log.info("Flies Server Version: {0}, Flies Client Version: {1}", server.getVersionNo(), ver.getVersionNo());
      if (!server.getBuildTimeStamp().equalsIgnoreCase(ver.getBuildTimeStamp()))
      {
         log.warn("client buildTimeStamp {} and server buildTimeStamp {} mismatch, please update your client", ver.getBuildTimeStamp(), server.getBuildTimeStamp());
      }
   }

   public <T> T createProxy(Class<T> clazz, URI baseUri)
   {
      log.debug("{} proxy uri: {}", clazz.getSimpleName(), baseUri);
      return crf.createProxy(clazz, baseUri);
   }

   private static URI fixBase(URI base)
   {
      if (base != null)
      {
         String baseString = base.toString();
         if (!baseString.endsWith("/"))
         {
            try
            {
               URI result = new URI(baseString + "/");
               log.warn("Appending '/' to Flies base URL '{}': using '{}'", baseString, result);
               return result;
            }
            catch (URISyntaxException e)<commit_msg>add more version info for the maven client<commit_after>package net.openl10n.flies.rest.client;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import net.openl10n.flies.rest.dto.VersionInfo;

import org.jboss.resteasy.client.ClientExecutor;
import org.jboss.resteasy.client.ClientRequestFactory;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FliesClientRequestFactory implements ITranslationResourcesFactory
{
   static
   {
      ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
      RegisterBuiltin.register(instance);
   }

   private static final Logger log = LoggerFactory.getLogger(FliesClientRequestFactory.class);
   private final ClientRequestFactory crf;
   private static final String RESOURCE_PREFIX = "rest";

   public FliesClientRequestFactory(String username, String apiKey, VersionInfo ver)
   {
      this(null, username, apiKey, ver);
   }

   public FliesClientRequestFactory(URI base, String username, String apiKey, VersionInfo ver)
   {
      this(base, username, apiKey, null, ver);
   }

   public FliesClientRequestFactory(URI base, String username, String apiKey, ClientExecutor executor, VersionInfo ver)
   {
      crf = new ClientRequestFactory(executor, null, fixBase(base));
      registerPrefixInterceptor(new ApiKeyHeaderDecorator(username, apiKey, ver.getVersionNo()));
      IVersion iversion = getVersionInfo();
      VersionInfo server = iversion.get();
      log.info("Flies Server Version: {}, Flies Client Version: {}", server.getVersionNo(), ver.getVersionNo());
      if (!server.getBuildTimeStamp().equalsIgnoreCase(ver.getBuildTimeStamp()))
      {
         log.warn("client buildTimeStamp {} and server buildTimeStamp {} mismatch, please update your client", ver.getBuildTimeStamp(), server.getBuildTimeStamp());
      }
   }

   public <T> T createProxy(Class<T> clazz, URI baseUri)
   {
      log.debug("{} proxy uri: {}", clazz.getSimpleName(), baseUri);
      return crf.createProxy(clazz, baseUri);
   }

   private static URI fixBase(URI base)
   {
      if (base != null)
      {
         String baseString = base.toString();
         if (!baseString.endsWith("/"))
         {
            try
            {
               URI result = new URI(baseString + "/");
               log.warn("Appending '/' to Flies base URL '{}': using '{}'", baseString, result);
               return result;
            }
            catch (URISyntaxException e)
{'fraction_non_alphanumeric': 0.105664695784856, 'fraction_numerical': 0.0026702269692923898, 'mean_word_length': 3.6325088339222615, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3233484', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1488, 'n_words': 346}