<commit_before>package com.litle.sdk;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;

import java.io.StringWriter;
import java.math.BigInteger;


import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import com.litle.sdk.generate.Authentication;

import com.litle.sdk.generate.LitleRequest;

public class LitleBatchFileRequest {

	private JAXBContext jc;
	private Properties properties;
	private Marshaller marshaller;
	private Communication communication;
	private LitleRequest litleRequest;
	private List<LitleBatchRequest> litleBatchRequestList;
	private String requestFileName;
	
	protected final int maxAllowedTransactionsPerFile;

	/**
	 * Construct a LitleBatchFileRequest using the configuration specified in
	 * $HOME/.litle_SDK_config.properties
	 */
	public LitleBatchFileRequest(String requestFileName) {
		intializeMembers(requestFileName);
		// initializeMembers will initialize this.config
		this.maxAllowedTransactionsPerFile = Integer.parseInt(properties.getProperty("maxAllowedTransactionsPerFile"));
	}
	
	/**
	 * Construct a LitleBatchFileRequest specifying the configuration in code. This should
	 * be used by integrations that have another way to specify their
	 * configuration settings (ofbiz, etc)
	 * 
	 * Properties that *must* be set are:
	 * 
	 * batchHost (eg https://payments.litle.com) batchPort (eg 8080) 
	 * username merchantId password version (eg
	 * 8.10) batchTcpTimeout (in seconds) batchUseSSL
	 * Optional properties are: proxyHost proxyPort
	 * printxml (possible values "true" and "false" - defaults to false)
	 * 
	 * @param config
	 */
	public LitleBatchFileRequest(String requestFileName, Properties config) {
		intializeMembers(requestFileName, config);
		// initializeMembers will initialize this.config
			
		this.maxAllowedTransactionsPerFile = Integer.parseInt(config.getProperty("maxAllowedTransactionsPerFile"));
		
	}
	
	private void intializeMembers(String requestFileName){
		intializeMembers(requestFileName, null);
	}
	
	public void intializeMembers(String requestFileName, Properties config){
		try {
			this.jc = JAXBContext.newInstance("com.litle.sdk.generate");
			this.marshaller = jc.createMarshaller();
			
			this.communication = new Communication();
			this.litleRequest = new LitleRequest();
			this.litleBatchRequestList = new ArrayList<LitleBatchRequest>();
			this.requestFileName = requestFileName;
			
			if( config == null || config.isEmpty() ){
				this.properties = new Properties();
				this.properties.load(new FileInputStream(Configuration.location()));
			} else {
				fillInMissingFieldsFromConfig(config);
				this.properties = config;
			}
			Authentication authentication = new Authentication();
			authentication.setPassword(<PASSWORD>("password"));
			authentication.setUser(this.properties.getProperty("username"));
			this.litleRequest.setAuthentication(authentication);
			this.litleRequest.setVersion(this.properties.getProperty("version"));
			
		} catch (FileNotFoundException e) {
			throw new LitleBatchException("Configuration file not found. If you are not using the .litle_SDK_config.properties file, please use the LitleOnline(Properties) constructor.  If you are using .litle_SDK_config.properties, you can generate one using java -jar litle-sdk-for-java-8.10.jar", e);
		} catch (IOException e) {
			throw new LitleBatchException(
					"Configuration file could not be loaded.  Check to see if the user running this has permission to access the file",
					e);
		} catch (JAXBException e) {
			throw new LitleBatchException("Unable to load jaxb dependencies.  Perhaps a classpath issue?", e);
		}
	}

	
	protected void setCommunication(Communication communication) {
		this.communication = communication;
	}
	
	public Properties getConfig(){
		return this.properties;
	}

	public LitleBatchRequest createBatch(String merchantId) {
		LitleBatchRequest litleBatchRequest = new LitleBatchRequest(merchantId, this);
		litleBatchRequestList.add(litleBatchRequest);
		return litleBatchRequest;
	}

	public void generateRawFile() {

	}

	public int getMaxAllowedTransactionsPerFile(){
		return this.maxAllowedTransactionsPerFile;
	}
	
	public void fillInMissingFieldsFromConfig(Properties config) {
		Properties localConfig = new Properties();
		
		try {
			localConfig.load(new FileInputStream(Configuration.location()));
			String[] allProperties = {"username","password","proxyHost","proxyPort","version","reportGroup","batchHost","batchPort","batchTcpTimeout","batchUseSSL","maxAllowedTransactionsPerFile","maxTransactionsPerBatch", "batchRequestFolder", "batchResponseFolder"};
			for(String prop : allProperties){
				if(config.getProperty(prop) == null) {
					config.setProperty(prop, localConfig.getProperty(prop));
				}
			}
		} catch (FileNotFoundException e) {
			throw new LitleBatchException("File was not found: " + Configuration.location(), e);
		} catch (IOException e) {
			throw new LitleBatchException("There was an IO exception.", e);
		}
		
	}

	public int getNumberOfBatches() {
		return this.litleBatchRequestList.size();
	}

	public int getNumberOfTransactionInFile() {
		int i = 0;
		int totalNumberOfTransactions = 0;
		for (i = 0; i < getNumberOfBatches(); i++) {
			LitleBatchRequest lbr = litleBatchRequestList.get(i);
			totalNumberOfTransactions += lbr.getBatchRequest()
					.getTransactions().size();<commit_msg>reading the properties file only if certain required properties are missing.<commit_after>package com.litle.sdk;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;

import java.io.StringWriter;
import java.math.BigInteger;


import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import com.litle.sdk.generate.Authentication;

import com.litle.sdk.generate.LitleRequest;

public class LitleBatchFileRequest {

	private JAXBContext jc;
	private Properties properties;
	private Marshaller marshaller;
	private Communication communication;
	private LitleRequest litleRequest;
	private List<LitleBatchRequest> litleBatchRequestList;
	private String requestFileName;
	
	protected final int maxAllowedTransactionsPerFile;

	/**
	 * Construct a LitleBatchFileRequest using the configuration specified in
	 * $HOME/.litle_SDK_config.properties
	 */
	public LitleBatchFileRequest(String requestFileName) {
		intializeMembers(requestFileName);
		// initializeMembers will initialize this.config
		this.maxAllowedTransactionsPerFile = Integer.parseInt(properties.getProperty("maxAllowedTransactionsPerFile"));
	}
	
	/**
	 * Construct a LitleBatchFileRequest specifying the configuration in code. This should
	 * be used by integrations that have another way to specify their
	 * configuration settings (ofbiz, etc)
	 * 
	 * Properties that *must* be set are:
	 * 
	 * batchHost (eg https://payments.litle.com) batchPort (eg 8080) 
	 * username merchantId password version (eg
	 * 8.10) batchTcpTimeout (in seconds) batchUseSSL
	 * Optional properties are: proxyHost proxyPort
	 * printxml (possible values "true" and "false" - defaults to false)
	 * 
	 * @param config
	 */
	public LitleBatchFileRequest(String requestFileName, Properties config) {
		intializeMembers(requestFileName, config);
		// initializeMembers will initialize this.config
			
		this.maxAllowedTransactionsPerFile = Integer.parseInt(config.getProperty("maxAllowedTransactionsPerFile"));
		
	}
	
	private void intializeMembers(String requestFileName){
		intializeMembers(requestFileName, null);
	}
	
	public void intializeMembers(String requestFileName, Properties config){
		try {
			this.jc = JAXBContext.newInstance("com.litle.sdk.generate");
			this.marshaller = jc.createMarshaller();
			
			this.communication = new Communication();
			this.litleRequest = new LitleRequest();
			this.litleBatchRequestList = new ArrayList<LitleBatchRequest>();
			this.requestFileName = requestFileName;
			
			if( config == null || config.isEmpty() ){
				this.properties = new Properties();
				this.properties.load(new FileInputStream(Configuration.location()));
			} else {
				fillInMissingFieldsFromConfig(config);
				this.properties = config;
			}
			Authentication authentication = new Authentication();
			authentication.setPassword(<PASSWORD>("password"));
			authentication.setUser(this.properties.getProperty("username"));
			this.litleRequest.setAuthentication(authentication);
			this.litleRequest.setVersion(this.properties.getProperty("version"));
			
		} catch (FileNotFoundException e) {
			throw new LitleBatchException("Configuration file not found. If you are not using the .litle_SDK_config.properties file, please use the LitleOnline(Properties) constructor.  If you are using .litle_SDK_config.properties, you can generate one using java -jar litle-sdk-for-java-8.10.jar", e);
		} catch (IOException e) {
			throw new LitleBatchException(
					"Configuration file could not be loaded.  Check to see if the user running this has permission to access the file",
					e);
		} catch (JAXBException e) {
			throw new LitleBatchException("Unable to load jaxb dependencies.  Perhaps a classpath issue?", e);
		}
	}

	
	protected void setCommunication(Communication communication) {
		this.communication = communication;
	}
	
	public Properties getConfig(){
		return this.properties;
	}

	public LitleBatchRequest createBatch(String merchantId) {
		LitleBatchRequest litleBatchRequest = new LitleBatchRequest(merchantId, this);
		litleBatchRequestList.add(litleBatchRequest);
		return litleBatchRequest;
	}

	public void generateRawFile() {

	}

	public int getMaxAllowedTransactionsPerFile(){
		return this.maxAllowedTransactionsPerFile;
	}
	
	public void fillInMissingFieldsFromConfig(Properties config) {
		Properties localConfig = new Properties();
		boolean propertiesReadFromFile = false;
		try {
			String[] allProperties = {"username","password","proxyHost","proxyPort","version","reportGroup","batchHost","batchPort","batchTcpTimeout","batchUseSSL","maxAllowedTransactionsPerFile","maxTransactionsPerBatch", "batchRequestFolder", "batchResponseFolder"};
			for(String prop : allProperties){
				if(config.getProperty(prop) == null) {
					if(!propertiesReadFromFile){
						localConfig.load(new FileInputStream(Configuration.location()));
						propertiesReadFromFile = true;
					}
					config.setProperty(prop, localConfig.getProperty(prop));
				}
			}
		} catch (FileNotFoundException e) {
			throw new LitleBatchException("File was not found: " + Configuration.location(), e);
		} catch (IOException e) {
			throw new LitleBatchException("There was an IO exception.", e);
		}
		
	}

	public int getNumberOfBatches() {
		return this.litleBatchRequestList.size();
	}

	public int getNumberOfTransactionInFile() {
		int i = 0;
		int totalNumberOfTransactions = 0;
		for (i = 0; i < getNumberOfBatches(); i++) {
			LitleBatchRequest lbr = litleBatchRequestList.get(i);
			totalNumberOfTransactions += lbr.getBatchRequest()
					.getTransactions().size();
{'fraction_non_alphanumeric': 0.09672657810193627, 'fraction_numerical': 0.002257532343492229, 'mean_word_length': 5.189145620634068, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '1877668', 'n_tokens_mistral': 3515, 'n_tokens_neox': 3139, 'n_words': 795}