Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package LogBin.services.javaServices;
- import com.wm.data.*;
- import com.wm.util.Values;
- import com.wm.app.b2b.server.Service;
- import com.wm.app.b2b.server.ServiceException;
- import com.itextpdf.text.Document;
- import com.itextpdf.text.Phrase;
- import com.itextpdf.text.pdf.PdfPCell;
- import com.itextpdf.text.pdf.PdfPTable;
- import com.itextpdf.text.pdf.PdfWriter;
- import java.sql.DriverManager;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.Properties;
- import javax.mail.Authenticator;
- import javax.mail.Message;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeBodyPart;
- import javax.mail.internet.MimeMessage;
- import javax.mail.internet.MimeMultipart;
- import org.json.simple.JSONArray;
- import org.json.simple.JSONObject;
- import javax.mail.*;
- import java.io.FileOutputStream;
- import java.sql.*;
- public final class checkConfigurationDetails_SVC
- {
- /**
- * The primary method for the Java service
- *
- * @param pipeline
- * The IData pipeline
- * @throws ServiceException
- */
- public static final void checkConfigurationDetails(IData pipeline) throws ServiceException {
- IDataCursor pipelineCursor = pipeline.getCursor();
- String dbUrl = IDataUtil.getString( pipelineCursor, "dbUrl" );
- String username = IDataUtil.getString( pipelineCursor, "userName" );
- String password = IDataUtil.getString( pipelineCursor, "password" );
- String tableName = IDataUtil.getString( pipelineCursor, "tableName" );
- String colNames = IDataUtil.getString( pipelineCursor, "colNames" );
- String levelCol = IDataUtil.getString( pipelineCursor, "levelCol" );
- String sevCol = IDataUtil.getString( pipelineCursor, "sevCol" );
- String dateCol = IDataUtil.getString( pipelineCursor, "dateCol" );
- String checkStatus = "{\"result\":\"Connection Was Successfull\"}";
- String result;
- if(levelCol.matches("[a-zA-Z0-9]+")&&sevCol.matches("[a-zA-Z0-9]+")&&dateCol.matches("[a-zA-Z0-9]+")&&tableName.matches("[a-zA-Z0-9]+")){
- String driverName = "oracle.jdbc.driver.OracleDriver";
- String query = "select * from "+tableName+" where "+levelCol+"=? and "+sevCol+"=?"+" and "+dateCol+"=?";
- // checkStatus = query;
- // ArrayList<String> enteredColumnList = new ArrayList<>();
- String enteredColumnList[] = colNames.split(",");
- try{
- Class.forName(driverName);
- Connection con = DriverManager.getConnection(dbUrl,username,password);
- PreparedStatement ps = con.prepareStatement(query);
- ps.setString(1, " ");
- ps.setString(2, " ");
- ps.setString(3, " ");
- ResultSet rs = ps.executeQuery();
- ResultSetMetaData rsmd = rs.getMetaData();
- int columnCount = rsmd.getColumnCount();
- ArrayList<String> columnNamesAl = new ArrayList<>();
- // The column count starts from 1
- for (int j = 1; j <= columnCount; j++ ) {
- String name = rsmd.getColumnName(j);
- columnNamesAl.add(name);
- // Do stuff with name
- }
- for(String column: enteredColumnList){
- if(!(columnNamesAl.contains(column.toUpperCase()))){
- checkStatus = "{\"result\":\"Wrong Column Names Provided\"}";
- break;
- }
- // checkStatus = checkStatus +column;
- }
- }catch(SQLException ex){
- checkStatus = ex.getMessage();
- if(ex.getMessage().contains("ORA-12505") || ex.getMessage().contains("ORA-12504") ){
- checkStatus = "{\"result\":\"Refused Connection. Please Enter Correct Db Url\"}";
- }else if(ex.getMessage().contains("ORA-01017")){
- checkStatus = "{\"result\":\"Invalid Username/Password\"}";
- }else if(ex.getMessage().contains("ORA-00942")){
- checkStatus = "{\"result\":\"Wrong Table Name Provided\"}";
- }else if(ex.getMessage().contains("ORA-00904")){
- checkStatus = "{\"result\":\"Wrong Column Name for date or level or severity\"}";
- }
- else{
- checkStatus = ex.getMessage();
- }
- }catch(Exception ex){
- checkStatus = ex.getMessage();
- }
- // if(!(checkStatus.equals("Wrong Column Name"))){
- // checkStatus = "successful";
- // }
- }else{
- checkStatus = "{\"result\":\"Only Alphabets and Digits are allowed in Table Name and Column Names\"}";
- }
- pipelineCursor.destroy();
- // pipeline
- IDataCursor pipelineCursor_1 = pipeline.getCursor();
- IDataUtil.put( pipelineCursor_1, "checkStatus", checkStatus );
- pipelineCursor_1.destroy();
- }
- // --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---
- // --- <<IS-END-SHARED-SOURCE-AREA>> ---
- /**
- * The service implementations given below are read-only and show only the
- * method definitions and not the complete implementation.
- */
- public static final void AnalyzingFilter(IData pipeline) throws ServiceException {
- }
- public static final void generatingPDF(IData pipeline) throws ServiceException {
- }
- public static final void MonitoringFilter(IData pipeline) throws ServiceException {
- }
- public static final void sendEmailReport(IData pipeline) throws ServiceException {
- }
- final static checkConfigurationDetails_SVC _instance = new checkConfigurationDetails_SVC();
- static checkConfigurationDetails_SVC _newInstance() { return new checkConfigurationDetails_SVC(); }
- static checkConfigurationDetails_SVC _cast(Object o) { return (checkConfigurationDetails_SVC)o; }
- }
Add Comment
Please, Sign In to add comment