<commit_before>package com.ampliciti.db.docussandra.javasdk.dao.impl.parent;

import com.ampliciti.db.docussandra.javasdk.Config;
import com.ampliciti.db.docussandra.javasdk.exceptions.RESTException;
import com.pearson.docussandra.domain.objects.Document;
import com.pearson.docussandra.domain.objects.Identifier;
import com.pearson.docussandra.domain.objects.Table;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.simple.JSONArray;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Parent class for all DAOs.
 *
 * @author https://github.com/JeffreyDeYoung
 */
public class DaoParent implements RESTDao {

  private static final String L_DATABASES = "/databases";
  private static final String L_TABLES = "/tables";
  private static final String L_INDEXES = "/indexes";
  private static final String L_DOCUMENTS = "/documents";
  private static final String SLASH = "/";

  /**
   * Logger for this class.
   */
  private Logger logger = LoggerFactory.getLogger(this.getClass());

  /**
   * Config needed to make a call.
   */
  private Config config;

  /**
   * Our http client.
   */
  private HttpClient client;

  /**
   * Configurations for requests
   */
  private RequestConfig rc;

  /**
   * Constructor.
   * 
   * @param config Configuration object to base this dao on.
   */
  public DaoParent(Config config) {
    this.config = config;
    client = HttpClientBuilder.create().build();
    // if (base64Encode) {
    // this.authToken = new String(Base64.encodeBase64(authToken.getBytes()));
    // } else {
    // this.authToken = authToken;
    // }
    rc = RequestConfig.custom().setConnectTimeout(60000).setSocketTimeout(3600000)
        .setConnectionRequestTimeout(60000).build();
  }

  /**
   * Config needed to make a call.
   *
   * @return the config
   */
  public Config getConfig() {
    return config;
  }

  /**
   * Gets the base URL associated with this class.
   * @return
   */
  public String getBaseURL() {
    return config.getBaseUrl();
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * @param id Identifier for what we are looking to create a URL for.
   * @return
   */
  public String createFullURL(Identifier id) {
    int size = id.components().size();
    if (size == 1) {
      return createFullURL(id.getDatabaseName(), null, null);
    } else if (size == 2) {
      return createFullURL(id.getDatabaseName(), id.getTableName(), null);
    } else { // size should == 3
      return createFullURL(id.getDatabaseName(), id.getTableName(),
          id.components().get(2).toString());
    }
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * @param tb Table to create the URL for.
   * @return A full REST url.
   */
  public String createFullURL(Table tb) {
    return createFullURL(tb.getDatabaseName(), tb.getName());
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * 
   * @param doc Document to create the URL for.
   * @return A full REST url.
   */
  public String createFullURL(Document doc) {
    return createFullURL(doc.getDatabaseName(), doc.getTableName(), doc.getUuid().toString());
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * @param db Database name to create the URL for.
   * @param tb Table name to create the URL for.
   * @return A full REST url.
   */
  public String createFullURL(String db, String tb) {
    return createFullURL(db, tb, null);
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * @param db Database name to use in the URL.
   * @param tb Table name to use in the URL.
   * @param docUUID Document UUID (as a String).
   * @return A REST URL.
   */<commit_msg>master -- code format per java standards<commit_after>package com.ampliciti.db.docussandra.javasdk.dao.impl.parent;

import com.ampliciti.db.docussandra.javasdk.Config;
import com.ampliciti.db.docussandra.javasdk.exceptions.RESTException;
import com.pearson.docussandra.domain.objects.Document;
import com.pearson.docussandra.domain.objects.Identifier;
import com.pearson.docussandra.domain.objects.Table;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.simple.JSONArray;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Parent class for all DAOs.
 *
 * @author https://github.com/JeffreyDeYoung
 */
public class DaoParent implements RESTDao {

  private static final String L_DATABASES = "/databases";
  private static final String L_TABLES = "/tables";
  private static final String L_INDEXES = "/indexes";
  private static final String L_DOCUMENTS = "/documents";
  private static final String SLASH = "/";

  /**
   * Logger for this class.
   */
  private Logger logger = LoggerFactory.getLogger(this.getClass());

  /**
   * Config needed to make a call.
   */
  private Config config;

  /**
   * Our http client.
   */
  private HttpClient client;

  /**
   * Configurations for requests
   */
  private RequestConfig rc;

  /**
   * Constructor.
   * 
   * @param config Configuration object to base this dao on.
   */
  public DaoParent(Config config) {
    this.config = config;
    client = HttpClientBuilder.create().build();
    // if (base64Encode) {
    // this.authToken = new String(Base64.encodeBase64(authToken.getBytes()));
    // } else {
    // this.authToken = authToken;
    // }
    rc = RequestConfig.custom().setConnectTimeout(60000).setSocketTimeout(3600000)
        .setConnectionRequestTimeout(60000).build();
  }

  /**
   * Config needed to make a call.
   *
   * @return the config
   */
  public Config getConfig() {
    return config;
  }

  /**
   * Gets the base URL associated with this class.
   * 
   * @return
   */
  public String getBaseURL() {
    return config.getBaseUrl();
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * 
   * @param id Identifier for what we are looking to create a URL for.
   * @return
   */
  public String createFullURL(Identifier id) {
    int size = id.components().size();
    if (size == 1) {
      return createFullURL(id.getDatabaseName(), null, null);
    } else if (size == 2) {
      return createFullURL(id.getDatabaseName(), id.getTableName(), null);
    } else { // size should == 3
      return createFullURL(id.getDatabaseName(), id.getTableName(),
          id.components().get(2).toString());
    }
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * 
   * @param tb Table to create the URL for.
   * @return A full REST url.
   */
  public String createFullURL(Table tb) {
    return createFullURL(tb.getDatabaseName(), tb.getName());
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * 
   * @param doc Document to create the URL for.
   * @return A full REST url.
   */
  public String createFullURL(Document doc) {
    return createFullURL(doc.getDatabaseName(), doc.getTableName(), doc.getUuid().toString());
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * 
   * @param db Database name to create the URL for.
   * @param tb Table name to create the URL for.
   * @return A full REST url.
   */
  public String createFullURL(String db, String tb) {
    return createFullURL(db, tb, null);
  }

  /**
   * Creates a full usable REST URL based on the passed in parameters.
   * 
   * @param db Database name to use in the URL.
   * @param tb Table name to use in the URL.
   * @param docUUID Document UUID (as a String).
   * @return A REST URL.
   */
{'fraction_non_alphanumeric': 0.11525992174399105, 'fraction_numerical': 0.0064840693124650645, 'mean_word_length': 3.26, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1698094', 'n_tokens_mistral': 2813, 'n_tokens_neox': 2711, 'n_words': 779}