Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.ctt.entity; import com.ctt.sshlistener.Main; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.UUID; import org.apache.commons.csv.CSVRecord; /** * * @author aleji_000 */ public class Transaction { private String client_id; private String type_id; private String code_bank; private double value_transaction; private double value_repayment; private String type_card; private int dues; private double tax; private String type_tax; private String type_repayment; private String observations = ""; private String card_number; private String isCreditCardTransaction; public Transaction(CSVRecord record) { try { System.out.println(record.get(0)); String[] rr = record.get(0).split(";"); System.out.println("0" + rr[0]); this.type_repayment = rr[0]; this.type_id = rr[1]; this.client_id = rr[2]; this.value_transaction = Double.parseDouble(rr[3]); this.value_repayment = Double.parseDouble(rr[4]); this.tax = Double.parseDouble(rr[5]); this.type_tax = rr[6]; this.code_bank = rr[7]; this.card_number = rr[8]; this.type_card = rr[9]; this.isCreditCardTransaction = rr[10]; this.dues = Integer.parseInt(rr[11]); if (rr.length >= 13) this.observations = rr[12]; } catch (NumberFormatException ex) { Main.appendLog("Error: INIT TRANSACTION " + ex.getMessage()); } } public boolean isRepayment() { if (this.type_repayment.equals("Payment")) return false; return true; } public boolean validateCanonical() throws IOException { if (this.type_repayment.equals("VALUE_ERROR") || this.type_repayment.equals("TAX_ERROR") || this.type_repayment.equals("MERCHANDISE_RETURN") || this.type_repayment.equals("FRAUD_FAULTS") || this.type_repayment.equals("") || this.type_repayment.equals("Payment") || this.type_repayment.equals("POS_ERROR")) { } else { Main.appendLog("BAD TYPE TRANSACTION: " + this.type_repayment); return false; } if (this.type_id.equals("OTHER") || this.type_id.equals("CC") || this.type_id.equals("CE") || this.type_id.equals("NIT")) { } else { Main.appendLog("BAD TYPE DOCUMENT: " + this.type_id); return false; } if (this.type_card.equals("MASTERD_CARD_DEBIT") || this.type_card.equals("VISA_DEBIT") || this.type_card.equals("AMERICAN_CREDIT") || this.type_card.equals("VISA_CREDIT") || this.type_card.equals("MASTERD_CARD_CREDIT")) { } else { Main.appendLog("BAD TYPE CARD: " + this.type_card); return false; } System.out.println("OK"); return true; } public String repaymentString() { String separator = Main.prop.getProperty("separatorCSV"); return this.type_repayment + separator + this.type_id + separator + this.client_id + separator + this.value_transaction + separator + this.value_repayment + separator + this.tax + separator + this.type_tax + separator + this.code_bank + separator + this.getCard_number() + separator + this.type_card + separator + this.isCreditCardTransaction + separator + this.dues + separator + this.observations; } public String transactionString() { String separator = Main.prop.getProperty("separatorCSV"); String today = new SimpleDateFormat("dd/mm/yyyy").format(Calendar.getInstance().getTime()).toString(); return UUID.randomUUID().toString() + separator + "REPAYMENT" + separator + this.value_repayment + separator + this.type_card + separator + this.getCard_number() + separator + "ELSUPER" + separator + today; } /** * @return the card_number */ public String getCard_number() { return card_number; } }