Guest User

Untitled

a guest
Dec 5th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. package LogBin.services.javaServices;
  2.  
  3. import com.wm.data.*;
  4. import com.wm.util.Values;
  5. import com.wm.app.b2b.server.Service;
  6. import com.wm.app.b2b.server.ServiceException;
  7. import com.itextpdf.text.Document;
  8. import com.itextpdf.text.Phrase;
  9. import com.itextpdf.text.pdf.PdfPCell;
  10. import com.itextpdf.text.pdf.PdfPTable;
  11. import com.itextpdf.text.pdf.PdfWriter;
  12. import java.sql.DriverManager;
  13. import java.text.DateFormat;
  14. import java.text.SimpleDateFormat;
  15. import java.util.ArrayList;
  16. import java.util.Date;
  17. import java.util.Properties;
  18. import javax.mail.Authenticator;
  19. import javax.mail.Message;
  20. import javax.mail.PasswordAuthentication;
  21. import javax.mail.Session;
  22. import javax.mail.internet.InternetAddress;
  23. import javax.mail.internet.MimeBodyPart;
  24. import javax.mail.internet.MimeMessage;
  25. import javax.mail.internet.MimeMultipart;
  26. import org.json.simple.JSONArray;
  27. import org.json.simple.JSONObject;
  28. import javax.mail.*;
  29. import java.io.FileOutputStream;
  30. import java.sql.*;
  31.  
  32. public final class checkConfigurationDetails_SVC
  33.  
  34. {
  35.  
  36. /**
  37. * The primary method for the Java service
  38. *
  39. * @param pipeline
  40. * The IData pipeline
  41. * @throws ServiceException
  42. */
  43. public static final void checkConfigurationDetails(IData pipeline) throws ServiceException {
  44. IDataCursor pipelineCursor = pipeline.getCursor();
  45. String dbUrl = IDataUtil.getString( pipelineCursor, "dbUrl" );
  46. String username = IDataUtil.getString( pipelineCursor, "userName" );
  47. String password = IDataUtil.getString( pipelineCursor, "password" );
  48. String tableName = IDataUtil.getString( pipelineCursor, "tableName" );
  49. String colNames = IDataUtil.getString( pipelineCursor, "colNames" );
  50. String levelCol = IDataUtil.getString( pipelineCursor, "levelCol" );
  51. String sevCol = IDataUtil.getString( pipelineCursor, "sevCol" );
  52. String dateCol = IDataUtil.getString( pipelineCursor, "dateCol" );
  53. String checkStatus = "{\"result\":\"Connection Was Successfull\"}";
  54. String result;
  55. 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]+")){
  56.  
  57.  
  58.  
  59. String driverName = "oracle.jdbc.driver.OracleDriver";
  60. String query = "select * from "+tableName+" where "+levelCol+"=? and "+sevCol+"=?"+" and "+dateCol+"=?";
  61. // checkStatus = query;
  62. // ArrayList<String> enteredColumnList = new ArrayList<>();
  63. String enteredColumnList[] = colNames.split(",");
  64.  
  65. try{
  66.  
  67. Class.forName(driverName);
  68. Connection con = DriverManager.getConnection(dbUrl,username,password);
  69. PreparedStatement ps = con.prepareStatement(query);
  70. ps.setString(1, " ");
  71. ps.setString(2, " ");
  72. ps.setString(3, " ");
  73.  
  74. ResultSet rs = ps.executeQuery();
  75.  
  76. ResultSetMetaData rsmd = rs.getMetaData();
  77. int columnCount = rsmd.getColumnCount();
  78. ArrayList<String> columnNamesAl = new ArrayList<>();
  79.  
  80. // The column count starts from 1
  81. for (int j = 1; j <= columnCount; j++ ) {
  82. String name = rsmd.getColumnName(j);
  83. columnNamesAl.add(name);
  84.  
  85. // Do stuff with name
  86. }
  87. for(String column: enteredColumnList){
  88. if(!(columnNamesAl.contains(column.toUpperCase()))){
  89. checkStatus = "{\"result\":\"Wrong Column Names Provided\"}";
  90. break;
  91. }
  92.  
  93. // checkStatus = checkStatus +column;
  94. }
  95.  
  96.  
  97. }catch(SQLException ex){
  98. checkStatus = ex.getMessage();
  99. if(ex.getMessage().contains("ORA-12505") || ex.getMessage().contains("ORA-12504") ){
  100. checkStatus = "{\"result\":\"Refused Connection. Please Enter Correct Db Url\"}";
  101. }else if(ex.getMessage().contains("ORA-01017")){
  102. checkStatus = "{\"result\":\"Invalid Username/Password\"}";
  103.  
  104. }else if(ex.getMessage().contains("ORA-00942")){
  105. checkStatus = "{\"result\":\"Wrong Table Name Provided\"}";
  106.  
  107. }else if(ex.getMessage().contains("ORA-00904")){
  108. checkStatus = "{\"result\":\"Wrong Column Name for date or level or severity\"}";
  109. }
  110. else{
  111. checkStatus = ex.getMessage();
  112. }
  113. }catch(Exception ex){
  114. checkStatus = ex.getMessage();
  115. }
  116. // if(!(checkStatus.equals("Wrong Column Name"))){
  117. // checkStatus = "successful";
  118. // }
  119. }else{
  120. checkStatus = "{\"result\":\"Only Alphabets and Digits are allowed in Table Name and Column Names\"}";
  121. }
  122.  
  123. pipelineCursor.destroy();
  124.  
  125. // pipeline
  126. IDataCursor pipelineCursor_1 = pipeline.getCursor();
  127. IDataUtil.put( pipelineCursor_1, "checkStatus", checkStatus );
  128. pipelineCursor_1.destroy();
  129.  
  130.  
  131. }
  132.  
  133. // --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---
  134.  
  135.  
  136.  
  137. // --- <<IS-END-SHARED-SOURCE-AREA>> ---
  138.  
  139. /**
  140. * The service implementations given below are read-only and show only the
  141. * method definitions and not the complete implementation.
  142. */
  143. public static final void AnalyzingFilter(IData pipeline) throws ServiceException {
  144. }
  145. public static final void generatingPDF(IData pipeline) throws ServiceException {
  146. }
  147. public static final void MonitoringFilter(IData pipeline) throws ServiceException {
  148. }
  149. public static final void sendEmailReport(IData pipeline) throws ServiceException {
  150. }
  151.  
  152. final static checkConfigurationDetails_SVC _instance = new checkConfigurationDetails_SVC();
  153.  
  154. static checkConfigurationDetails_SVC _newInstance() { return new checkConfigurationDetails_SVC(); }
  155.  
  156. static checkConfigurationDetails_SVC _cast(Object o) { return (checkConfigurationDetails_SVC)o; }
  157.  
  158. }
Add Comment
Please, Sign In to add comment