Created
July 2, 2018 05:40
-
-
Save LunaticWolf/a0a94743d9c45c5a7aa7fee7069e40fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package validation; | |
import java.io.BufferedWriter; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.sql.Connection; | |
import java.sql.SQLException; | |
import java.util.TreeSet; | |
//import connection.ConnectionI; | |
//import connection.OracleConnection; | |
import daoOperation.InsertDao; | |
import daoOperation.InsertToDb; | |
import entityPojo_customer.Customer; | |
public class Rejection { | |
ValidationI vm = new ValidateMethods(); | |
public void recordLevel(String server, String str, Customer customer) { | |
InsertDao dao = new InsertToDb(); | |
TreeSet<String> set=dao.fetch_customer_code(); | |
boolean code = vm.validCustomerCode(customer, set); | |
set.add(customer.getCustomer_code()); | |
boolean name = vm.validCustomerName(customer); | |
boolean pinCode = vm.validPinCode(customer); | |
boolean record = vm.validRecordStatus(customer); | |
boolean flag = vm.validFlag(customer); | |
boolean email = vm.validEmail(customer); | |
Connection conn = dao.connection(); | |
if (code && name && record && pinCode && flag && email) { | |
int rowsAffected = dao.inputbd(server, customer, conn); | |
if (rowsAffected > 0) | |
System.out.println("done"); | |
else | |
System.out.println("Some error ocuured"); | |
try { | |
conn.commit(); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} | |
} | |
else { | |
BufferedWriter bw = null; | |
try { | |
System.out.println("nhi aa rhe "); | |
FileWriter fw = new FileWriter("d:/errorLogFil.txt"); | |
bw = new BufferedWriter(fw); | |
bw.write(str); | |
bw.newLine(); | |
bw.flush(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
public void fileLevel(String server, String str, Customer customer) { | |
InsertDao dao = new InsertToDb(); | |
TreeSet<String> set=dao.fetch_customer_code(); | |
boolean code = vm.validCustomerCode(customer, set); | |
set.add(customer.getCustomer_code()); | |
boolean name = vm.validCustomerName(customer); | |
boolean pinCode = vm.validPinCode(customer); | |
boolean record = vm.validRecordStatus(customer); | |
boolean flag = vm.validFlag(customer); | |
boolean email = vm.validEmail(customer); | |
Connection conn = dao.connection(); | |
if (code && name && record && pinCode && flag && email) { | |
int rowsAffected = dao.inputbd(server, customer, conn); | |
try { | |
conn.commit(); | |
} catch (SQLException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
if (rowsAffected > 0) | |
System.out.println("done"); | |
else | |
System.out.println("Some error ocuured"); | |
} | |
else { | |
try { | |
System.out.println("rollback"); | |
FileWriter fw = new FileWriter("//C:/Users/temp/Desktop/errorfile.txt"); | |
BufferedWriter bw = new BufferedWriter(fw); | |
bw.append(str); | |
bw.newLine(); | |
bw.flush(); | |
conn.rollback(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package validation; | |
import java.util.HashSet; | |
import java.util.TreeSet; | |
import java.util.regex.Pattern; | |
import entityPojo_customer.Customer; | |
public class ValidateMethods implements ValidationI { | |
@Override | |
public boolean validCustomerCode(Customer customer, TreeSet<String> set) { | |
if (customer.getCustomer_code().length() > 10) { | |
return false; | |
} else { | |
if (customer.getCustomer_code().equals("")) { | |
return false; | |
} | |
else if (set.contains(customer.getCustomer_code())) { | |
return false; | |
} | |
} | |
return true; | |
} | |
@Override | |
public boolean validCustomerName(Customer customer) { | |
if (customer.getCustomer_name().length() > 30) { | |
return false; | |
} else { | |
char[] arr = new char[40]; | |
// int count=0; | |
arr = customer.getCustomer_name().toCharArray(); | |
for (int i = 0; i < customer.getCustomer_name().length(); i++) { | |
int k = (int) arr[i]; | |
if ((k > 47 && k < 58) || (k > 64 && k < 91) || (k > 96 && k < 123) || k == 32) { | |
// count++; | |
} else | |
return false; | |
} | |
} | |
return true; | |
} | |
@Override | |
public boolean validPinCode(Customer customer) { | |
int length = String.valueOf(customer.getCustomer_pinCode()).length(); | |
if (length == 6) | |
return true; | |
else | |
return false; | |
} | |
@Override | |
public boolean validEmail(Customer customer) { | |
String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\." + "[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\\.)+[a-z" | |
+ "A-Z]{2,7}$"; | |
Pattern pat = Pattern.compile(emailRegex); | |
if (customer.getEmail_address().equals("")) | |
return false; | |
else | |
return pat.matcher(customer.getEmail_address()).matches(); | |
} | |
@Override | |
public boolean validRecordStatus(Customer customer) { | |
if (customer.getRecord_status().equalsIgnoreCase("N") || customer.getRecord_status().equalsIgnoreCase("M") | |
|| customer.getRecord_status().equalsIgnoreCase("D") | |
|| customer.getRecord_status().equalsIgnoreCase("A") | |
|| customer.getRecord_status().equalsIgnoreCase("R")) | |
return true; | |
else | |
return false; | |
} | |
@Override | |
public boolean validFlag(Customer customer) { | |
if (customer.getActive_inactiveFlag().equalsIgnoreCase("a") | |
|| customer.getRecord_status().equalsIgnoreCase("I")) | |
return true; | |
else | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package validation; | |
import java.util.TreeSet; | |
import entityPojo_customer.Customer; | |
public interface ValidationI { | |
public boolean validCustomerCode(Customer customer, TreeSet<String> set); | |
public boolean validCustomerName(Customer customer); | |
public boolean validPinCode(Customer customer); | |
public boolean validEmail(Customer customer); | |
public boolean validRecordStatus(Customer customer); | |
public boolean validFlag(Customer customer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment