<commit_before>package com.litle.sdk;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;

import java.sql.Timestamp;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;


import com.litle.sdk.generate.Authorization;
import com.litle.sdk.generate.BatchRequest;
import com.litle.sdk.generate.ObjectFactory;
import com.litle.sdk.generate.TransactionType;

import com.litle.sdk.generate.Sale;

public class LitleBatchRequest {
	private BatchRequest batchRequest;
	private JAXBContext jc;
	private File file;
	private Marshaller marshaller;
	ObjectFactory objFac;
	TransactionType txn;
	String filePath;
	OutputStream osWrttxn;
	
	int numOfTxn;
	
	
	private final int maxTransactionsPerBatch;
	protected int litleLimit_maxTransactionsPerBatch = 100000;
	private final LitleBatchFileRequest lbfr;
	
	
	/** 
	 * This method initializes the batch level attributes of the XML and checks if the maxTransactionsPerBatch is not more than the value provided in the properties file
	 * @param merchantId
	 * @param lbfr
	 * @throws JAXBException 
	 * @throws FileNotFoundException 
	 */
	LitleBatchRequest(String merchantId, LitleBatchFileRequest lbfr) throws LitleBatchException{
		this.batchRequest = new BatchRequest();
		this.batchRequest.setMerchantId(merchantId);
		this.objFac = new ObjectFactory();
		this.lbfr = lbfr;
		File tmpFile = new File(lbfr.getConfig().getProperty("batchRequestFolder")+"/tmp");
		if(!tmpFile.exists()) {
			tmpFile.mkdir();
		}
		java.util.Date date= new java.util.Date();
		filePath = new String(lbfr.getConfig().getProperty("batchRequestFolder")+ "/tmp/Transactions" +merchantId + new Timestamp(date.getTime()));
		numOfTxn = 0;
		try {
			this.jc = JAXBContext.newInstance("com.litle.sdk.generate");
			marshaller = jc.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		} catch (JAXBException e) {
			throw new LitleBatchException("There was an exception while trying to set the marsahller object and setting the properties for it. ");
		}		
		this.maxTransactionsPerBatch = Integer.parseInt(lbfr.getConfig().getProperty("maxTransactionsPerBatch"));
		if( maxTransactionsPerBatch > litleLimit_maxTransactionsPerBatch ){
			throw new LitleBatchException("maxTransactionsPerBatch property value cannot exceed " + String.valueOf(litleLimit_maxTransactionsPerBatch));
		}
	}
	
	BatchRequest getBatchRequest(){
		return batchRequest;
	}
	
	/**
	 * This method is used to add transaction to a particular batch
	 * @param transactionType
	 * @return<commit_msg>Exception handling<commit_after>package com.litle.sdk;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;

import java.sql.Timestamp;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;


import com.litle.sdk.generate.Authorization;
import com.litle.sdk.generate.BatchRequest;
import com.litle.sdk.generate.ObjectFactory;
import com.litle.sdk.generate.TransactionType;

import com.litle.sdk.generate.Sale;

public class LitleBatchRequest {
	private BatchRequest batchRequest;
	private JAXBContext jc;
	private File file;
	private Marshaller marshaller;
	ObjectFactory objFac;
	TransactionType txn;
	String filePath;
	OutputStream osWrttxn;
	
	int numOfTxn;
	
	
	private final int maxTransactionsPerBatch;
	protected int litleLimit_maxTransactionsPerBatch = 100000;
	private final LitleBatchFileRequest lbfr;
	
	
	/** 
	 * This method initializes the batch level attributes of the XML and checks if the maxTransactionsPerBatch is not more than the value provided in the properties file
	 * @param merchantId
	 * @param lbfr
	 * @throws JAXBException 
	 * @throws FileNotFoundException 
	 */
	LitleBatchRequest(String merchantId, LitleBatchFileRequest lbfr) throws LitleBatchJAXBException, LitleBatchFileFullException{
		this.batchRequest = new BatchRequest();
		this.batchRequest.setMerchantId(merchantId);
		this.objFac = new ObjectFactory();
		this.lbfr = lbfr;
		File tmpFile = new File(lbfr.getConfig().getProperty("batchRequestFolder")+"/tmp");
		if(!tmpFile.exists()) {
			tmpFile.mkdir();
		}
		java.util.Date date= new java.util.Date();
		filePath = new String(lbfr.getConfig().getProperty("batchRequestFolder")+ "/tmp/Transactions" +merchantId + new Timestamp(date.getTime()));
		numOfTxn = 0;
		try {
			this.jc = JAXBContext.newInstance("com.litle.sdk.generate");
			marshaller = jc.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		} catch (JAXBException e) {
			throw new LitleBatchJAXBException("There was an exception while trying to set the marsahller object and setting the properties for it. ");
		}		
		this.maxTransactionsPerBatch = Integer.parseInt(lbfr.getConfig().getProperty("maxTransactionsPerBatch"));
		if( maxTransactionsPerBatch > litleLimit_maxTransactionsPerBatch ){
			throw new LitleBatchFileFullException("maxTransactionsPerBatch property value cannot exceed " + String.valueOf(litleLimit_maxTransactionsPerBatch));
		}
	}
	
	BatchRequest getBatchRequest(){
		return batchRequest;
	}
	
	/**
	 * This method is used to add transaction to a particular batch
	 * @param transactionType
	 * @return
{'fraction_non_alphanumeric': 0.09288537549407115, 'fraction_numerical': 0.0025152712899748474, 'mean_word_length': 5.376861397479955, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4541830', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1676, 'n_words': 401}