<commit_before>package org.ihtsdo.otf.rest.client.snowowl;

import javax.servlet.http.Cookie;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonWriter;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.ihtsdo.otf.rest.client.RestClientException;
import org.ihtsdo.otf.rest.client.resty.HttpEntityContent;
import org.ihtsdo.otf.rest.client.resty.RestyHelper;
import org.ihtsdo.otf.rest.client.snowowl.pojo.*;
import org.ihtsdo.otf.rest.client.snowowl.pojo.MergeReviewsResults.MergeReviewStatus;
import org.ihtsdo.otf.rest.exception.BadRequestException;
import org.ihtsdo.otf.rest.exception.BusinessServiceException;
import org.ihtsdo.otf.rest.exception.ProcessingException;
import org.ihtsdo.otf.rest.exception.ResourceNotFoundException;
import org.ihtsdo.otf.utils.DateUtils;
import org.ihtsdo.sso.integration.SecurityUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import us.monoid.json.JSONArray;
import us.monoid.json.JSONException;
import us.monoid.json.JSONObject;
import us.monoid.web.BinaryResource;
import us.monoid.web.JSONResource;

import java.io.*;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;

public class SnowOwlRestClient {

	public static final String SNOWOWL_CONTENT_TYPE = "application/vnd.com.b2international.snowowl+json";
	public static final String ANY_CONTENT_TYPE = "*/*";
	public static final FastDateFormat SIMPLE_DATE_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd_HH-mm-ss");
	public static final String US_EN_LANG_REFSET = "900000000000509007";

	public enum ExportType {
		DELTA, SNAPSHOT, FULL
	}

	public enum ProcessingStatus {
		COMPLETED, SAVED
	}

	public enum ExportCategory {
		PUBLISHED, UNPUBLISHED, FEEDBACK_FIX
	}

	private final RestyHelper resty;
	private String singleSignOnCookie;
	private RestTemplate restTemplate;

	private String reasonerId;
	private boolean flatIndexExportStyle = true;
	private String logPath;
	private String rolloverLogPath;
	private final Gson gson;
	private int importTimeoutMinutes;
	private int classificationTimeoutMinutes; //Timeout of 0 means don't time out.
	private static final int INDENT = 2;
	private static final Joiner COMMA_SEPARATED_JOINER = Joiner.on(',');
	private static final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
	private final SnowOwlRestUrlHelper urlHelper;
	private final Logger logger = LoggerFactory.getLogger(getClass());

	private SnowOwlRestClient(String snowOwlUrl) {
		this.resty = new RestyHelper(ANY_CONTENT_TYPE);
		urlHelper = new SnowOwlRestUrlHelper(snowOwlUrl);
		gson = new GsonBuilder().setPrettyPrinting().create();
		restTemplate = new RestTemplate();
	}

	public SnowOwlRestClient(String snowOwlUrl, String singleSignOnCookie) {
		this(snowOwlUrl);
		this.singleSignOnCookie = singleSignOnCookie;
		resty.withHeader("Cookie", singleSignOnCookie);
	}
	
	public SnowOwlRestClient(String snowOwlUrl, Cookie[] cookies) {
		this(snowOwlUrl);
		for (Cookie cookie : cookies) {
			resty.withHeader("Cookie", cookie.getValue());
		}
	}

	public SnowOwlRestClient(String snowOwlUrl, String apiUsername, String apiPassword) {
		this(snowOwlUrl);
		resty.authenticate(snowOwlUrl, apiUsername, apiPassword.toCharArray());
	}
	
	public SnowOwlRestClient(String snowOwlUrl, String apiUsername, String apiPassword, String userName, Set<String> userRoles) {
		this(snowOwlUrl, apiUsername, apiPassword);
		resty.withHeader("X-AUTH-username", userName);<commit_msg>Removed RESTY client multi-cookie constructor.  RESTY does not support >1 header of same name, and ihtsdo-spring-sso is the better solution to recover just the 1 required cookie<commit_after>package org.ihtsdo.otf.rest.client.snowowl;

import javax.servlet.http.Cookie;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonWriter;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.ihtsdo.otf.rest.client.RestClientException;
import org.ihtsdo.otf.rest.client.resty.HttpEntityContent;
import org.ihtsdo.otf.rest.client.resty.RestyHelper;
import org.ihtsdo.otf.rest.client.snowowl.pojo.*;
import org.ihtsdo.otf.rest.client.snowowl.pojo.MergeReviewsResults.MergeReviewStatus;
import org.ihtsdo.otf.rest.exception.BadRequestException;
import org.ihtsdo.otf.rest.exception.BusinessServiceException;
import org.ihtsdo.otf.rest.exception.ProcessingException;
import org.ihtsdo.otf.rest.exception.ResourceNotFoundException;
import org.ihtsdo.otf.utils.DateUtils;
import org.ihtsdo.sso.integration.SecurityUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import us.monoid.json.JSONArray;
import us.monoid.json.JSONException;
import us.monoid.json.JSONObject;
import us.monoid.web.BinaryResource;
import us.monoid.web.JSONResource;

import java.io.*;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;

public class SnowOwlRestClient {

	public static final String SNOWOWL_CONTENT_TYPE = "application/vnd.com.b2international.snowowl+json";
	public static final String ANY_CONTENT_TYPE = "*/*";
	public static final FastDateFormat SIMPLE_DATE_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd_HH-mm-ss");
	public static final String US_EN_LANG_REFSET = "900000000000509007";

	public enum ExportType {
		DELTA, SNAPSHOT, FULL
	}

	public enum ProcessingStatus {
		COMPLETED, SAVED
	}

	public enum ExportCategory {
		PUBLISHED, UNPUBLISHED, FEEDBACK_FIX
	}

	private final RestyHelper resty;
	private String singleSignOnCookie;
	private RestTemplate restTemplate;

	private String reasonerId;
	private boolean flatIndexExportStyle = true;
	private String logPath;
	private String rolloverLogPath;
	private final Gson gson;
	private int importTimeoutMinutes;
	private int classificationTimeoutMinutes; //Timeout of 0 means don't time out.
	private static final int INDENT = 2;
	private static final Joiner COMMA_SEPARATED_JOINER = Joiner.on(',');
	private static final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
	private final SnowOwlRestUrlHelper urlHelper;
	private final Logger logger = LoggerFactory.getLogger(getClass());

	private SnowOwlRestClient(String snowOwlUrl) {
		this.resty = new RestyHelper(ANY_CONTENT_TYPE);
		urlHelper = new SnowOwlRestUrlHelper(snowOwlUrl);
		gson = new GsonBuilder().setPrettyPrinting().create();
		restTemplate = new RestTemplate();
	}

	public SnowOwlRestClient(String snowOwlUrl, String singleSignOnCookie) {
		this(snowOwlUrl);
		this.singleSignOnCookie = singleSignOnCookie;
		resty.withHeader("Cookie", singleSignOnCookie);
	}

	public SnowOwlRestClient(String snowOwlUrl, String apiUsername, String apiPassword) {
		this(snowOwlUrl);
		resty.authenticate(snowOwlUrl, apiUsername, apiPassword.toCharArray());
	}
	
	public SnowOwlRestClient(String snowOwlUrl, String apiUsername, String apiPassword, String userName, Set<String> userRoles) {
		this(snowOwlUrl, apiUsername, apiPassword);
		resty.withHeader("X-AUTH-username", userName);
{'fraction_non_alphanumeric': 0.09563978965819457, 'fraction_numerical': 0.0052585451358457495, 'mean_word_length': 6.3739903069466886, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 2, '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': '3404381', 'n_tokens_mistral': 3013, 'n_tokens_neox': 2861, 'n_words': 563}