JAVA Script Parser Ericsson CEDH and STRT Log
/*
* 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 strt;
import java.io.BufferedReader;
import java.sql.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author aessa
*/
public class STRT {
String dbnn;
String TT;
String locoutfile;
String usreniq;
String pwdeniq;
String ipeniq;
String porteniq;
String dbeniq;
String stsregion;
String maxrowv;
String dtt = null;
private Connection connx;
private Statement stmtx;
private ResultSet rs;
String A, B, BB, BBB, C, D, E, F, G, H, IX, J, K, L, M, N, O, P = null;
String SS1A, SS1AA, SS1AAA, SS1AAAA, SS1AAAAA, SS1AAAAAA, SS1AAAAAAA, SS1AAAAAAAA, SS1AAAAAAAAA = null;
Scanner s1, s2, s3 = null;
String DR = null;
int DRINT;
String SERVIPA = null;
String SERVIPB = null;
String SERVIPC = null;
String RNClist = null;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
final STRT ste = new STRT();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
ste.WriteDataToFile();
}
});
}
private void WriteDataToFile() {
Scanner rn = null;
try {
rn = new Scanner(new BufferedReader(new FileReader("d:/JS/rnclist.txt")));
rn.useDelimiter(";");
while (rn.hasNext()) {
DR = rn.next();
SERVIPA = rn.next();
SERVIPB = rn.next();
SERVIPC = rn.next();
RNClist = rn.next();
}
//Close the input stream
rn.close();
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
DRINT = Integer.parseInt(DR);
Calendar cal = Calendar.getInstance();
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
System.out.println("Today's date is " + dateFormat.format(cal.getTime()));
DateFormat dateFormatt = new SimpleDateFormat("yyyy-MM-dd");
cal.add(Calendar.DATE, -0);
System.out.println("Yesterday's date was " + dateFormat.format(cal.getTime()));
dtt = dateFormatt.format(cal.getTime());
File dir2 = new File("D:/STS/CEDH/" + dateFormat.format(cal.getTime()));
dir2.mkdir();
String filenamerar = "D:/STS/CEDH/" + dateFormat.format(cal.getTime()) + "/Strt_Sumbagteng_" + dateFormat.format(cal.getTime());
String filename = "D:/STS/CEDH/" + dateFormat.format(cal.getTime()) + "/Strt_Sumbagteng_" + dateFormat.format(cal.getTime()) + ".csv";
File file = new File(filename);
if (!file.exists()) {
try {
file.createNewFile();
System.out.println("File is created");
FileWriter writer = new FileWriter(file, true);
writer.write("DATE_ID,RNC,MOD,IUBLINKID,IUBLINK,CELLNAMES,NEID,TN,TNPORTS\r\n");
writer.flush();
writer.close();
} catch (Exception exc) {
System.out.println("Eror Kode : " + exc);
}
//Parser I
// String RNCS[] = {"RNBJI01","RNBJI02","RNBJI03","RNGST01","RNKBJ01","RNKBJ02","RNKIS02","RNLGS02","RNLHK02","RNLHK03","RNMAK01","RNMBO01","RNMDN01","RNMDN02","RNMDN03","RNMDN04","RNMDN05","RNMDN06","RNMDN07","RNMDN08","RNMDN09","RNMDN10","RNMDN11","RNMDN12","RNMDN13","RNMDN14","RNMDN15","RNMDN16","RNMDN17","RNMDN19","RNMDN22","RNNAD02","RNNAD03","RNNAD04","RNNAD05","RNNAD06","RNPMS02","RNPMS03","RNPMS04","RNPMS05","RNPSP01","RNPSP02","RNPYB01","RNRAP01","RNSBG01","RNSBG02","RNSGI02","RNSKL01","RNSKL02","RNTKN01"};
//57
//String RNCS[] = {"RNBKT01", "RNBKT02", "RNBKT03", "RNBKT04", "RNBLS01", "RNBLS02", "RNBTM01", "RNBTM02", "RNBTM03", "RNBTM04", "RNBTM05", "RNBTM06", "RNBTM07", "RNBTM08", "RNDUM01", "RNDUM02", "RNDUM03", "RNMSJ01", "RNPAD01", "RNPAD02", "RNPAD03", "RNPAD04", "RNPAD05","RNPAD07", "RNPAD09", "RNPBR01", "RNPBR02", "RNPBR03", "RNPBR04", "RNPBR05", "RNPBR06", "RNPBR07", "RNPBR08", "RNPBR09", "RNPBR11", "RNPPN01", "RNRGT01", "RNTAK01", "RNTBH01", "RNTBK01", "RNTBK02", "RNTBK03", "RNTPI01", "RNTPI02", "RNTPI03", "RNBLS03", "RNDUM04", "RNBTM09", "RNPBR10", "RNDUM03", "RNDUM05", "RNPBR15"};
//String RNCS[] = {"RNPPN01"};
String RNClist2 =RNClist.replaceAll("\\(|'|\\)| |;", "");
int ri = 0;
String delimsri = ",";
String[] tokensri = RNClist2.split(delimsri);
for (ri = 0; ri < tokensri.length; ri++) {
String RNCX = tokensri[ri];
String file_logn = "D:/STS/CEDH/" + RNCX + ".log";
System.out.println("Read from file = " + file_logn);
File file_log = new File(file_logn);
if (file_log.exists()) {
try {
s1 = new Scanner(new BufferedReader(new FileReader(file_log)));
s1.useDelimiter("---------------------------------------------------------------------------------------------------------------------");
while (s1.hasNext()) {
SS1A = s1.next();
SS1AA = s1.next();
SS1AAA = s1.next();
SS1AAAA = s1.next();
B = SS1AAA;
//System.out.println("Parser1 row loop" + RNCX + " = " + B);
}
s1.close();
} catch (Exception e) {
}
//Parser II
//System.out.println("Parser1B loop " + RNCX + " = " + B);
int i = 1;
String delims = "\n";
String[] tokens = B.split(delims);
for (i = 1; i < tokens.length; i++) {
C = tokens[i];
String NC = C;
String CC = " "+C;
String NCB = CC.replaceFirst("\\s+", "").replaceAll("\\s+", ",");
System.out.println("NCB=" + NCB);
int ixx = 1;
String delimsxx = ",";
String[] tokensxx = NCB.split(delimsxx);
for (ixx = 1; ixx < tokensxx.length; ixx++) {
}
try {
FileWriter writer = new FileWriter(file, true);
writer.write(dtt + "," + RNCX + "," + tokensxx[0] + "," + tokensxx[1] + "," + tokensxx[1].trim().replaceAll("%1|%2|%3| ", "") + "," + tokensxx[2] + "," + tokensxx[2].substring(0, tokensxx[2].lastIndexOf("-")).trim().replaceAll(" ", "") + "," + NC.substring(NC.lastIndexOf("I "), NC.lastIndexOf("I ") + 1).trim().replaceAll(" ", "") + "," + NC.substring(NC.lastIndexOf("I ") + 1) + "\r\n");
writer.flush();
writer.close();
} catch (Exception exc) {
System.out.println("Eror Write to file : " + exc);
}
}
}
} //loop rnc
System.out.println("cedh done");
// LOAD DATA to MYSQL BEFORERAR//
String urlC = "jdbc:mysql://Localhost:3306/eniq?allowMultiQueries=true";
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException cnfe) {
System.err.println("Class Driver tidak ditemukan : " + cnfe.getMessage());
}
String queryx = "use eniq;\n"
+ "LOAD DATA INFILE '" + filename + "' REPLACE INTO TABLE d_strt CHARACTER SET utf8 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;";
//execute
try {
System.out.println(queryx);
connx = DriverManager.getConnection(urlC, "root", "");
stmtx = connx.createStatement();
stmtx.executeUpdate(queryx);
} catch (SQLException se) {
System.err.println("Error multiple query : " + se.getMessage());
}
// RAR FILE
try {
Runtime.getRuntime().exec("C:\\Progra~1\\WinRAR\\WinRAR.exe m -ep " + filenamerar + " " + filename);
} catch (IOException ex) {
Logger.getLogger(STRT.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
System.out.println("file exist");
}
}
}
Comments
Post a Comment