This commit is contained in:
Gaurav Kumar
2025-03-27 12:53:49 +05:30
parent 98cdb93265
commit 00c562660f
17 changed files with 465 additions and 364 deletions

View File

@@ -3,7 +3,6 @@ package com.realnet.Payment.Paytm;
import java.net.URL;
import java.security.SecureRandom;
import java.util.Map;
import java.util.logging.Logger;
import org.json.JSONObject;
import org.springframework.http.HttpEntity;

View File

@@ -1,10 +1,5 @@
package com.realnet.rb.Controller;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,7 +10,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.realnet.CredentialDatabase.Service.SurevaultService;
import com.realnet.rb.repository.Rn_report_builder_repository;
import com.realnet.rb.service.Rn_rb_tables_service;
@@ -27,18 +21,6 @@ public class RbController {
@Autowired
private Rn_rb_tables_service rn_table_service;
// @Value("${spring.datasource.username}")
// private String userName;
//
// @Value("${spring.datasource.password}")
// private String password;
//
// @Value("${spring.datasource.url}")
// private String url;
@Autowired
private SurevaultService databaseCredentialsService;
// get all databse list available
@GetMapping("/Table_list")
@ResponseBody
@@ -68,26 +50,8 @@ public class RbController {
@GetMapping("/createdatabase/{table_schema}")
@ResponseBody
public List<Integer> createdatabase(@PathVariable String table_schema) throws JsonProcessingException {
// changes by Gyanadipta
String url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
String userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
String password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
String query = "CREATE SCHEMA " + table_schema + ";";
List<Integer> list = new ArrayList<Integer>();
try (Connection con = DriverManager.getConnection(url, userName, password); // conn.str
Statement stmt = con.createStatement()) {
int rs = stmt.executeUpdate(query);
list.add(rs);
} catch (SQLException e) {
e.printStackTrace();
} finally {
}
List<Integer> list = rn_table_service.createdatabase(table_schema);
return list;
}
@@ -96,34 +60,7 @@ public class RbController {
@GetMapping("/AllTable_list/{table_schema}")
@ResponseBody
public List<String> getallcolwithalltable(@PathVariable String table_schema, @RequestParam String str) {
ArrayList<String> tables = new ArrayList<>();
String liString = "," + str;
int i = 0;
do {
int lastIndexOf = liString.lastIndexOf(",");
String substring = liString.substring(lastIndexOf + 1);
tables.add(substring);
System.out.println(substring);
liString = liString.substring(0, lastIndexOf);
System.out.println("step " + i + " = " + liString);
i++;
} while (liString.contains(","));
ArrayList<String> arrayList = new ArrayList<>();
for (String TABLE_NAME : tables) {
List<String> list = rn_table_service.getColumnAliasList1(table_schema, TABLE_NAME);
if (!list.isEmpty()) {
list.forEach(l -> arrayList.add(l));
}
}
List<String> arrayList = rn_table_service.getallcolwithalltable(table_schema, str);
return arrayList;
}

View File

@@ -2,18 +2,21 @@ package com.realnet.rb.service;
import java.util.List;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.realnet.rb.entity.Rn_rb_Tables;
import com.realnet.rb.entity.Rn_report_builder;
public interface Rn_rb_tables_service {
Rn_report_builder save(Rn_report_builder rn_tables);
List<Rn_rb_Tables> save(List<Rn_rb_Tables> rn_tables);
List<String> getListOfTables();
List<String> getListOfColumns(int id);
List<String> getColumnList(int id);
List<String> getColumnAliasList(String name);
List<String> getListOftables();
@@ -23,8 +26,11 @@ public interface Rn_rb_tables_service {
List<String> getColumnAliasList1(String table_schema, String tABLE_NAME);
List<String> getListOftable(String table_schema);
List<String> getColumnAliasList2(String tableName);
List<Integer> createdatabase(String tableName) throws JsonProcessingException;
List<String> getallcolwithalltable(String table_schema, String str);
}

View File

@@ -8,18 +8,13 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.realnet.CredentialDatabase.Service.SurevaultService;
import com.realnet.rb.entity.RnTableListDto;
import com.realnet.rb.entity.Rn_rb_Tables;
import com.realnet.rb.entity.Rn_report_builder;
import com.realnet.rb.repository.RnTableDtoRepo;
import com.realnet.rb.repository.Rn_report_builder_repository;
import com.realnet.rb.repository.Rn_tables_Repository;
@@ -32,23 +27,14 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
@Autowired
private Rn_tables_Repository rn_repo;
@Autowired
private RnTableDtoRepo rn_repoDto;
@Value("${spring.datasource.username}")
private String userName;
// @Value("${spring.datasource.username}")
// private String userName;
//
// @Value("${spring.datasource.password}")
// private String password;
//
// @Value("${spring.datasource.url}")
// private String url;
@Autowired
private SurevaultService databaseCredentialsService;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.url}")
private String url;
@Override
public Rn_report_builder save(Rn_report_builder rn_tables) {
@@ -64,25 +50,14 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
@Override
public List<String> getListOfTables() {
String url=null;
String userName=null;
String password=null;
try {
userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = null;
String userName = null;
String password = null;
String query = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'realnet_CNSBE'";
List<String> list = new ArrayList<String>();
try (Connection con = DriverManager.getConnection(url, userName, password);
Statement stmt = con.createStatement()) {
@@ -102,19 +77,10 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
public List<String> getListOfColumns(int id) {
// Connection con = null;
// Connection con=null;
String url=null;
String userName=null;
String password=null;
try {
userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = null;
String userName = null;
String password = null;
String query = "SELECT table_allias_name FROM rn_rb_tables_t WHERE report_id=" + id + "";
List<String> list = new ArrayList<String>();
@@ -134,18 +100,10 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
@Override
public List<String> getColumnList(int id) {
String url=null;
String userName=null;
String password=null;
try {
userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = null;
String userName = null;
String password = null;
String query = "SELECT column_name FROM rn_rb_column_t WHERE report_id=" + id + "";
List<String> list = new ArrayList<String>();
@@ -165,19 +123,11 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
@Override
public List<String> getColumnAliasList(String name) {
String url=null;
String userName=null;
String password=null;
try {
userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = null;
String userName = null;
String password = null;
String query = "SELECT column_name FROM information_schema.columns WHERE TABLE_SCHEMA='realnet_CNSBE' and table_name = '"
+ name + "' ";
List<String> list = new ArrayList<String>();
@@ -198,19 +148,11 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
// get all column
@Override
public List<String> getColumnAliasList1(String table_schema, String tABLE_NAME) {
String url=null;
String userName=null;
String password=null;
try {
userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = null;
String userName = null;
String password = null;
String query = "SELECT column_name FROM information_schema.columns WHERE TABLE_SCHEMA='" + table_schema
+ "' and table_name = '" + tABLE_NAME + "' ";
List<String> list = new ArrayList<String>();
@@ -231,19 +173,11 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
// get all table list from databse
@Override
public List<String> getListOftable(String table_schema) {
String url=null;
String userName=null;
String password=null;
try {
userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = null;
String userName = null;
String password = null;
String query = "SELECT table_name FROM information_schema.tables WHERE table_schema='" + table_schema + "' ";
List<String> list = new ArrayList<String>();
@@ -264,18 +198,10 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
@Override
public List<String> getListOftables() {
String url=null;
String userName=null;
String password=null;
try {
userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = null;
String userName = null;
String password = null;
String query = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'realnet_CNSBE'";
List<String> list = new ArrayList<String>();
try (Connection con = DriverManager.getConnection(url, userName, password);
@@ -295,19 +221,10 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
@Override
public List<String> getdatabaseList() {
String url=null;
String userName=null;
String password=null;
try {
userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = null;
String userName = null;
String password = null;
String query = "select schema_name from information_schema.schemata";
List<String> list = new ArrayList<String>();
@@ -325,55 +242,105 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
}
return list;
}
@Override
public List<String> getColumnAliasList2(String tableNames) {
String url=null;
String userName=null;
String password=null;
try {
userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
String url = null;
String userName = null;
String password = null;
List<String> list = new ArrayList<>();
String[] tableArray = tableNames.split(",");
int tableIndex = 1; // Initialize the table index
for (int i = 0; i < tableArray.length; i++) {
String tableName = tableArray[i].trim();
String tableAlias = generateTableAlias(tableIndex);
String query = "SELECT CONCAT('" + tableAlias
+ "', column_name) AS full_column_name FROM information_schema.columns WHERE table_name = '"
+ tableName + "'";
try (Connection con = DriverManager.getConnection(url, userName, password);
Statement stmt = con.createStatement()) {
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String columnName = rs.getString("full_column_name");
list.add(columnName);
}
} catch (SQLException e) {
e.printStackTrace();
}
tableIndex++;
}
List<String> list = new ArrayList<>();
String[] tableArray = tableNames.split(",");
int tableIndex = 1; // Initialize the table index
for (int i = 0; i < tableArray.length; i++) {
String tableName = tableArray[i].trim();
String tableAlias = generateTableAlias(tableIndex);
String query = "SELECT CONCAT('" + tableAlias + "', column_name) AS full_column_name FROM information_schema.columns WHERE table_name = '" + tableName + "'";
try (Connection con = DriverManager.getConnection(url, userName, password);
Statement stmt = con.createStatement()) {
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String columnName = rs.getString("full_column_name");
list.add(columnName);
}
} catch (SQLException e) {
e.printStackTrace();
}
tableIndex++;
}
return list;
return list;
}
// Method to generate the table alias based on the table index
private String generateTableAlias(int tableIndex) {
StringBuilder sb = new StringBuilder();
// Calculate the suffix based on the table index
int suffixIndex = (tableIndex - 1) / 26; // e.g., 0 for table 1-26, 1 for table 27-52, etc.
// Add prefix to the table alias
sb.append((char) ('a' + (tableIndex - 1) % 26));
// Add suffix to the table alias
for (int i = 0; i < suffixIndex; i++) {
sb.append('a');
}
sb.append('.');
return sb.toString();
StringBuilder sb = new StringBuilder();
// Calculate the suffix based on the table index
int suffixIndex = (tableIndex - 1) / 26; // e.g., 0 for table 1-26, 1 for table 27-52, etc.
// Add prefix to the table alias
sb.append((char) ('a' + (tableIndex - 1) % 26));
// Add suffix to the table alias
for (int i = 0; i < suffixIndex; i++) {
sb.append('a');
}
sb.append('.');
return sb.toString();
}
@Override
public List<Integer> createdatabase(String table_schema) throws JsonProcessingException {
String query = "CREATE SCHEMA " + table_schema + ";";
List<Integer> list = new ArrayList<Integer>();
try (Connection con = DriverManager.getConnection(url, userName, password); // conn.str
Statement stmt = con.createStatement()) {
int rs = stmt.executeUpdate(query);
list.add(rs);
} catch (SQLException e) {
e.printStackTrace();
} finally {
}
return list;
}
@Override
public List<String> getallcolwithalltable(String table_schema, String str) {
ArrayList<String> tables = new ArrayList<>();
String liString = "," + str;
int i = 0;
do {
int lastIndexOf = liString.lastIndexOf(",");
String substring = liString.substring(lastIndexOf + 1);
tables.add(substring);
System.out.println(substring);
liString = liString.substring(0, lastIndexOf);
System.out.println("step " + i + " = " + liString);
i++;
} while (liString.contains(","));
ArrayList<String> arrayList = new ArrayList<>();
for (String TABLE_NAME : tables) {
List<String> list = getColumnAliasList1(table_schema, TABLE_NAME);
if (!list.isEmpty()) {
list.forEach(l -> arrayList.add(l));
}
}
return arrayList;
}
}