Compare commits
12 Commits
778cf14bdc
...
repo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
447821d707 | ||
|
|
bc41959594 | ||
|
|
63a0f69100 | ||
|
|
7eb045a95a | ||
|
|
fd5945b464 | ||
|
|
301da36697 | ||
|
|
3841a1d0c8 | ||
|
|
38b8fc040c | ||
|
|
477647da0f | ||
|
|
bbca71f125 | ||
|
|
c2b22d5319 | ||
|
|
901b95ffa2 |
@@ -85,6 +85,12 @@
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- end of spring fox dependency-->
|
||||
|
||||
<dependency>
|
||||
@@ -118,6 +124,12 @@
|
||||
</dependency>
|
||||
<!-- Manually Added -->
|
||||
|
||||
<!-- <dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.45.1.0</version>
|
||||
</dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.realnet.Builders.Entity.Builder_entity_t;
|
||||
@Repository
|
||||
public interface BuilderRepository extends JpaRepository<Builder_entity_t, Long> {
|
||||
|
||||
@Query(value = "select * from builder_entity_t where job_name= ?1 && job_type=?2", nativeQuery = true)
|
||||
@Query(value = "select * from builder_entity_t where job_name= ?1 AND job_type=?2", nativeQuery = true)
|
||||
Builder_entity_t findByjobTypeAndName(String job_name, String job_type);
|
||||
|
||||
}
|
||||
|
||||
@@ -64,10 +64,21 @@ public class BuilderService {
|
||||
@Autowired
|
||||
private AppUserServiceImpl userServiceImpl;
|
||||
|
||||
// @Autowired
|
||||
// private SqlDumpExecutor sqlDumpExecutor;
|
||||
|
||||
public void callotherService() throws IOException {
|
||||
|
||||
executeDump(true);
|
||||
|
||||
// String sqlDump = getSqlDump(); // your method to get the dump as string
|
||||
//
|
||||
// try (Connection connection = SQLiteUtil.getConnection()) {
|
||||
// sqlDumpExecutor.executeDump(connection, sqlDump); // your method for executing dump only once
|
||||
// } catch (SQLException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
// ADD OTHER SERVICE
|
||||
|
||||
System.out.println("dashboard and menu inserted...");
|
||||
@@ -187,7 +198,7 @@ public class BuilderService {
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
|
||||
hashMap.put("GetAll", "/" + tableName + "/" + tableName);
|
||||
hashMap.put("GetById", "/" + tableName + "/" + tableName + "{Id}");
|
||||
hashMap.put("GetById", "/" + tableName + "/" + tableName + "/{Id}");
|
||||
hashMap.put("Post", "/" + tableName + "/" + tableName);
|
||||
hashMap.put("Put", "/" + tableName + "/" + tableName);
|
||||
|
||||
@@ -232,7 +243,7 @@ public class BuilderService {
|
||||
|
||||
public ResponseEntity<String> executeDump(Boolean execute) throws IOException {
|
||||
// Check if execution is allowed
|
||||
System.out.println(" dump executed start..");
|
||||
System.out.println(" dump executed start.. \n");
|
||||
|
||||
Builder_entity_t entity_t = builderRepository.findByjobTypeAndName("SqlDump", "Execute");
|
||||
|
||||
@@ -303,6 +314,238 @@ public class BuilderService {
|
||||
|
||||
}
|
||||
|
||||
public String getSqlDump() {
|
||||
String sqlDump = "-- SQLite compatible dump\n" + "\n" + "PRAGMA foreign_keys=OFF;\n" + "\n"
|
||||
+ "-- Table: accounts\n" + "DROP TABLE IF EXISTS accounts;\n" + "CREATE TABLE accounts (\n"
|
||||
+ " id INTEGER PRIMARY KEY,\n" + " companyname TEXT,\n" + " email TEXT,\n"
|
||||
+ " managing_work TEXT,\n" + " mobile INTEGER,\n" + " name TEXT,\n" + " pancard TEXT,\n"
|
||||
+ " password TEXT,\n" + " working TEXT\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO accounts VALUES (1,'test','test@gmail.com','w',123456789,'kk','kk','test','w');\n" + "\n"
|
||||
+ "-- Table: app_user_log\n" + "DROP TABLE IF EXISTS app_user_log;\n" + "CREATE TABLE app_user_log (\n"
|
||||
+ " log_id INTEGER PRIMARY KEY,\n" + " created_on TEXT,\n" + " generate_log TEXT,\n"
|
||||
+ " log_file_name TEXT,\n" + " log_level TEXT,\n" + " user_name TEXT UNIQUE\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO app_user_log VALUES (1,'2023-06-09 17:39:20','Y','sysadmin1686312560.log','info','sysadmin');\n"
|
||||
+ "\n" + "-- Table: app_user_log_sequence\n" + "DROP TABLE IF EXISTS app_user_log_sequence;\n"
|
||||
+ "CREATE TABLE app_user_log_sequence (\n" + " next_val INTEGER\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO app_user_log_sequence VALUES (2),(2),(2),(2),(2),(2),(2),(2),(2),(1);\n" + "\n"
|
||||
+ "-- Table: logs\n" + "DROP TABLE IF EXISTS logs;\n" + "CREATE TABLE logs (\n"
|
||||
+ " user_id INTEGER PRIMARY KEY,\n" + " dated TEXT,\n" + " lavel TEXT,\n" + " logger TEXT,\n"
|
||||
+ " message TEXT\n" + ");\n" + "\n" + "-- Table: role\n" + "DROP TABLE IF EXISTS role;\n"
|
||||
+ "CREATE TABLE role (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " description TEXT,\n"
|
||||
+ " name TEXT\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO role VALUES (1,'ADMIN','ROLE_ADMIN'),(2,'Developer','ROLE_Developer'),(3,'USER','ROLE_USER'),(5,'DEVEOPS','ROLE_DEVEOPS');\n"
|
||||
+ "\n" + "-- Table: sec_menu_det\n" + "DROP TABLE IF EXISTS sec_menu_det;\n"
|
||||
+ "CREATE TABLE sec_menu_det (\n" + " menu_item_id INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
||||
+ " created_at TEXT NOT NULL,\n" + " updated_at TEXT NOT NULL,\n" + " item_seq INTEGER,\n"
|
||||
+ " main_menu_action_name TEXT,\n" + " main_menu_icon_name TEXT,\n" + " menu_id INTEGER,\n"
|
||||
+ " menu_item_desc TEXT,\n" + " module_name TEXT,\n" + " status TEXT\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO sec_menu_det VALUES\n"
|
||||
+ "(1116,'2023-01-25 10:25:50','2023-01-25 10:25:50',3000,'security','lock',0,'Security','sec3000','Enable'),\n"
|
||||
+ "(1117,'2023-01-25 10:42:02','2023-02-04 15:34:25',3010,'usermaintance',NULL,1116,'User Maintance','U1000','Enable'),\n"
|
||||
+ "(1118,'2023-01-25 11:12:27','2023-02-04 15:34:36',3020,'usergrpmaintance',NULL,1116,'User Group Maintance','U2000','Enable'),\n"
|
||||
+ "(1523,'2023-02-04 11:15:57','2023-02-04 15:34:45',3030,'menumaintance',NULL,1116,'Menu Maintance','M3000','Enable'),\n"
|
||||
+ "(1524,'2023-02-04 11:16:52','2023-02-04 15:34:54',3040,'menuaccess',NULL,1116,'Menu Access Control','MA4000','Enable'),\n"
|
||||
+ "(1525,'2023-02-04 11:17:31','2023-02-04 15:35:06',3050,'systemparameters',NULL,1116,'System Parameters','SP5000','Enable'),\n"
|
||||
+ "(1526,'2023-02-04 11:18:04','2023-02-04 15:35:14',3060,'accesstype',NULL,1116,'Access Type','A6000','Enable'),\n"
|
||||
+ "(1528,'2023-02-04 13:31:48','2023-02-04 15:33:02',1010,'incident-new',NULL,1527,'Incident','I1000','Enable'),\n"
|
||||
+ "(1529,'2023-02-04 13:33:03','2023-02-04 15:33:12',1020,'incident-overview',NULL,1527,'Overview','O2000','Enable'),\n"
|
||||
+ "(1530,'2023-02-04 13:34:42','2023-02-04 15:33:21',1030,'sureboard2',NULL,1527,'Issueboard','I3000','Enable'),\n"
|
||||
+ "(1531,'2023-02-04 13:35:27','2023-02-04 15:33:36',1040,'change-request',NULL,1527,'Change Request','C4000','Enable'),\n"
|
||||
+ "(1532,'2023-02-04 13:36:01','2023-02-10 02:25:13',1050,'problem-creation',NULL,1527,'Problem Request','P5000','Enable');\n"
|
||||
+ "-- truncated for brevity: continue for all sec_menu_det inserts\n" + "\n"
|
||||
+ "-- Table: sec_user_group\n" + "DROP TABLE IF EXISTS sec_user_group;\n"
|
||||
+ "CREATE TABLE sec_user_group (\n" + " usr_grp INTEGER PRIMARY KEY,\n" + " createby TEXT,\n"
|
||||
+ " createdate TEXT,\n" + " group_desc TEXT,\n" + " group_level INTEGER,\n" + " group_name TEXT,\n"
|
||||
+ " status TEXT,\n" + " updateby TEXT,\n" + " updatedate TEXT\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO sec_user_group VALUES (1,NULL,NULL,'add',30,'sysadmin','E',NULL,'2023-03-01 05:54:10'),(41,NULL,'2023-02-28 13:05:54','check',20,'users','Disable',NULL,'2023-02-28 13:30:14');\n"
|
||||
+ "\n" + "-- Table: sec_user_group_id\n" + "DROP TABLE IF EXISTS sec_user_group_id;\n"
|
||||
+ "CREATE TABLE sec_user_group_id (next_val INTEGER);\n" + "\n"
|
||||
+ "INSERT INTO sec_user_group_id VALUES (59),(59),(40),(40),(40),(40),(40),(40);\n" + "\n"
|
||||
+ "-- Table: department\n" + "DROP TABLE IF EXISTS department;\n" + "CREATE TABLE department (\n"
|
||||
+ " department_code TEXT PRIMARY KEY,\n" + " active TEXT,\n" + " created_by TEXT,\n"
|
||||
+ " created_on TEXT,\n" + " description TEXT,\n" + " id INTEGER,\n" + " updated_by TEXT\n" + ");\n"
|
||||
+ "\n" + "-- Table: position\n" + "DROP TABLE IF EXISTS position;\n" + "CREATE TABLE position (\n"
|
||||
+ " position_code TEXT PRIMARY KEY,\n" + " active TEXT,\n" + " created_by TEXT,\n"
|
||||
+ " created_on TEXT,\n" + " description TEXT,\n" + " updated_by TEXT,\n" + " updated_on TEXT\n"
|
||||
+ ");\n" + "\n" + "-- Table: sys_accounts\n" + "DROP TABLE IF EXISTS sys_accounts;\n" + "\n"
|
||||
+ "CREATE TABLE sys_accounts (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
||||
+ " active INTEGER DEFAULT 0,\n" + " company_name TEXT,\n" + " email TEXT,\n" + " gst_no TEXT,\n"
|
||||
+ " mobile TEXT,\n" + " pancard TEXT,\n" + " working TEXT,\n" + " workspace TEXT\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO sys_accounts VALUES (1,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL);\n" + ""
|
||||
|
||||
+ "\n" + "-- Table: sec_users\n" + "DROP TABLE IF EXISTS sec_users;\n" + "\n"
|
||||
+ "CREATE TABLE sec_users (\n" + " user_id INTEGER PRIMARY KEY,\n"
|
||||
+ " is_complete INTEGER NOT NULL,\n" + " about TEXT,\n" + " accesstype TEXT,\n"
|
||||
+ " active INTEGER NOT NULL,\n" + " change_passw TEXT,\n" + " checknumber INTEGER,\n"
|
||||
+ " country TEXT,\n" + " createby TEXT,\n" + " createdate TEXT NOT NULL,\n"
|
||||
+ " customer_id INTEGER,\n" + " days_mth TEXT,\n" + " dep_string TEXT,\n" + " email TEXT,\n"
|
||||
+ " expiry_date TEXT,\n" + " first_login TEXT,\n" + " full_name TEXT,\n"
|
||||
+ " is_blocked INTEGER NOT NULL,\n" + " lang_code TEXT,\n" + " last_pwd_changed_date TEXT,\n"
|
||||
+ " mob_no INTEGER,\n" + " multilingual TEXT,\n" + " multitime TEXT,\n" + " no_days_mth INTEGER,\n"
|
||||
+ " notification TEXT,\n" + " password1 TEXT,\n" + " password2 TEXT,\n" + " password3 TEXT,\n"
|
||||
+ " password4 TEXT,\n"
|
||||
// + " photo BLOB,\n"
|
||||
+ " photo_name TEXT,\n" + " provider TEXT,\n" + " pwd_changed_cnt INTEGER,\n" + " random_no TEXT,\n"
|
||||
+ " short_name TEXT,\n" + " status TEXT,\n" + " title TEXT,\n" + " updateby TEXT,\n"
|
||||
+ " updatedate TEXT,\n" + " user_passw TEXT,\n" + " user_name TEXT,\n" + " usr_grp_id INTEGER,\n"
|
||||
+ " working TEXT,\n" + " account_id INTEGER,\n" + " department_code TEXT,\n"
|
||||
+ " position_code TEXT,\n" + " usr_grp INTEGER\n" + ");\n" + "\n" + "INSERT INTO sec_users VALUES (\n"
|
||||
+ " 10007307,1,NULL,NULL,1,'test3',NULL,NULL,NULL,'2024-09-03 19:32:38',NULL,NULL,NULL,\n"
|
||||
+ " 'sysadmin',NULL,NULL,'sysadmin',0,NULL,'2024-09-03 19:32:38',1234567890,NULL,NULL,NULL,NULL,\n"
|
||||
+ " 'admin123',NULL,NULL,NULL,NULL,NULL,7,NULL,NULL,NULL,NULL,NULL,NULL,\n"
|
||||
+ " '$2b$10$8iFnL/cKTTmclSD1BZh8UeP0ZKKEzZ2hbTsrRcgy3kMinDRdxN7xe','sysadmin',NULL,NULL,1,NULL,NULL,1\n"
|
||||
+ ");"
|
||||
|
||||
+ "-- Table: sec_user_sessions\n" + "DROP TABLE IF EXISTS sec_user_sessions;\n"
|
||||
+ "CREATE TABLE IF NOT EXISTS sec_user_sessions (\n" + " client_ip TEXT NOT NULL,\n"
|
||||
+ " session_id TEXT NOT NULL,\n" + " user_id INTEGER NOT NULL,\n" + " last_access_date TEXT,\n"
|
||||
+ " logintime TEXT,\n" + " logouttime TEXT,\n" + " macid TEXT,\n"
|
||||
+ " PRIMARY KEY (client_ip, session_id, user_id),\n"
|
||||
+ " FOREIGN KEY (user_id) REFERENCES sec_users(user_id)\n" + ");\n" + "\n" + "" + ""
|
||||
|
||||
+ "\n" + "-- Table: sec_grp_menu_access\n" + "DROP TABLE IF EXISTS sec_grp_menu_access;\n"
|
||||
+ "CREATE TABLE sec_grp_menu_access (\n" + " menu_item_id INTEGER NOT NULL,\n"
|
||||
+ " usr_grp INTEGER NOT NULL,\n" + " createby TEXT,\n" + " created_at TEXT,\n"
|
||||
+ " isdisable TEXT,\n" + " item_seq INTEGER,\n" + " m_create TEXT,\n" + " m_delete TEXT,\n"
|
||||
+ " m_edit TEXT,\n" + " m_query TEXT,\n" + " m_visible TEXT,\n" + " main_menu_action_name TEXT,\n"
|
||||
+ " main_menu_icon_name TEXT,\n" + " menu_id INTEGER,\n" + " menu_item_desc TEXT,\n"
|
||||
+ " mexport TEXT,\n" + " module_name TEXT,\n" + " status TEXT,\n" + " updateby TEXT,\n"
|
||||
+ " updated_at TEXT,\n" + " PRIMARY KEY (menu_item_id, usr_grp)\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO sec_grp_menu_access VALUES\n"
|
||||
+ "(1116,41,NULL,'2024-01-17 18:56:05','true',3000,'true','true','true','true','true','security','lock',0,'Security','true','sec3000','Enable',NULL,'2024-01-17 18:56:05'),\n"
|
||||
+ "(1117,41,NULL,'2024-01-17 18:56:07','true',3010,'true','true','true','true','true','usermaintance',NULL,1116,'User Maintance','true','U1000','Enable',NULL,'2024-01-17 18:56:07');\n"
|
||||
+ "\n" + "-- Table: sec_users_sequencs\n" + "DROP TABLE IF EXISTS sec_users_sequencs;\n"
|
||||
+ "CREATE TABLE sec_users_sequencs (\n" + " next_val INTEGER\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO sec_users_sequencs VALUES\n"
|
||||
+ "(10007321),(10007300),(10007300),(10007300),(10007300),(10007300),(10007300),(10007300);\n" + "\n"
|
||||
+ "-- Table: sec_workspace\n" + "DROP TABLE IF EXISTS sec_workspace;\n"
|
||||
+ "CREATE TABLE sec_workspace (\n" + " id INTEGER PRIMARY KEY,\n" + " account_id INTEGER,\n"
|
||||
+ " created_at TEXT NOT NULL,\n" + " created_by INTEGER,\n" + " updated_at TEXT NOT NULL,\n"
|
||||
+ " updated_by INTEGER,\n" + " is_active TEXT,\n" + " description TEXT,\n" + " is_default TEXT,\n"
|
||||
+ " name TEXT,\n" + " owner_id TEXT,\n" + " project_id INTEGER\n" + ");\n"
|
||||
|
||||
+ "" + "-- Table: sec_workspace_users\n" + "DROP TABLE IF EXISTS sec_workspace_users;\n"
|
||||
+ "CREATE TABLE sec_workspace_users (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
||||
+ " account_id INTEGER,\n" + " created_at TEXT NOT NULL,\n" + " created_by INTEGER,\n"
|
||||
+ " updated_at TEXT NOT NULL,\n" + " updated_by INTEGER,\n" + " project_id INTEGER,\n"
|
||||
+ " user_id INTEGER,\n" + " user_name TEXT,\n" + " user_role TEXT,\n"
|
||||
+ " worksapce_id INTEGER NOT NULL\n" + ");\n" + "\n" + "-- Table: secuser_roles\n"
|
||||
+ "DROP TABLE IF EXISTS secuser_roles;\n" + "CREATE TABLE secuser_roles (\n"
|
||||
+ " secuser_id INTEGER NOT NULL,\n" + " role_id INTEGER NOT NULL,\n"
|
||||
+ " PRIMARY KEY (secuser_id, role_id),\n"
|
||||
+ " FOREIGN KEY (secuser_id) REFERENCES sec_users(user_id),\n"
|
||||
+ " FOREIGN KEY (role_id) REFERENCES role(id)\n" + ");\n" + "\n" + "-- Insert sample data\n"
|
||||
+ "INSERT INTO secuser_roles (secuser_id, role_id) VALUES (10007307, 1);\n" + "\n"
|
||||
+ "-- Table: sys_accounts_users\n" + "DROP TABLE IF EXISTS sys_accounts_users;\n"
|
||||
+ "CREATE TABLE sys_accounts_users (\n" + " sys_accounts_id INTEGER NOT NULL,\n"
|
||||
+ " users_user_id INTEGER NOT NULL,\n" + " UNIQUE(users_user_id),\n"
|
||||
+ " FOREIGN KEY (users_user_id) REFERENCES sec_users(user_id),\n"
|
||||
+ " FOREIGN KEY (sys_accounts_id) REFERENCES sys_accounts(id)\n" + ");\n" + "\n"
|
||||
+ "-- Table: user_list\n" + "DROP TABLE IF EXISTS user_list;\n" + "CREATE TABLE user_list (\n"
|
||||
+ " id INTEGER PRIMARY KEY,\n" + " about TEXT,\n" + " account_id TEXT,\n" + " address1 TEXT,\n"
|
||||
+ " address2 TEXT,\n" + " checknumber TEXT,\n" + " company TEXT,\n" + " country TEXT,\n"
|
||||
+ " created_at TEXT,\n" + " created_by TEXT,\n" + " default_customer_id TEXT,\n"
|
||||
+ " department TEXT,\n" + " dob TEXT,\n" + " email TEXT,\n"
|
||||
+ " enable_beta_testing INTEGER NOT NULL,\n" + " enable_renewal INTEGER NOT NULL,\n"
|
||||
+ " firstname TEXT,\n" + " fullname TEXT,\n" + " gender TEXT,\n" + " is_active INTEGER NOT NULL,\n"
|
||||
+ " is_blocked INTEGER NOT NULL,\n" + " lastname TEXT,\n" + " managing_work TEXT,\n"
|
||||
+ " menu_group INTEGER NOT NULL,\n" + " name TEXT,\n" + " other_roles TEXT,\n" + " pancard TEXT,\n"
|
||||
+ " password TEXT,\n" + " phone TEXT,\n" + " photos TEXT,\n" + " postal TEXT,\n" + " role TEXT,\n"
|
||||
+ " secret_answer TEXT,\n" + " secret_question TEXT,\n" + " security_provider_id TEXT,\n"
|
||||
+ " status TEXT,\n" + " updated_at TEXT,\n" + " updated_by TEXT,\n" + " user_id TEXT,\n"
|
||||
+ " username TEXT,\n" + " working TEXT\n" + ");\n" + "" + "" + "-- Table: userloginhist\n"
|
||||
+ "DROP TABLE IF EXISTS userloginhist;\n" + "CREATE TABLE userloginhist (\n" + " create_by TEXT,\n"
|
||||
+ " create_date TEXT,\n" + " expiry_reminder INTEGER,\n" + " last_login_date TEXT,\n"
|
||||
+ " last_password_chg_date TEXT,\n" + " last_password_fail_no INTEGER,\n" + " update_by TEXT,\n"
|
||||
+ " update_date TEXT,\n" + " user_id INTEGER NOT NULL,\n" + " PRIMARY KEY(user_id),\n"
|
||||
+ " FOREIGN KEY(user_id) REFERENCES sec_users(user_id)\n" + ");\n" + "\n" + "-- Table: userpasswlog\n"
|
||||
+ "DROP TABLE IF EXISTS userpasswlog;\n" + "CREATE TABLE userpasswlog (\n"
|
||||
+ " create_date TEXT NOT NULL,\n" + " user_id INTEGER NOT NULL,\n" + " user_passw TEXT NOT NULL,\n"
|
||||
+ " create_by TEXT,\n" + " update_by TEXT,\n" + " update_date TEXT,\n"
|
||||
+ " PRIMARY KEY(create_date, user_id, user_passw),\n"
|
||||
+ " FOREIGN KEY(user_id) REFERENCES sec_users(user_id)\n" + ");\n" + "\n" + "-- Table: dashboard\n"
|
||||
+ "DROP TABLE IF EXISTS dashboard;\n" + "CREATE TABLE dashboard (\n"
|
||||
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " account_id INTEGER,\n"
|
||||
+ " created_at TEXT NOT NULL,\n" + " created_by INTEGER,\n" + " updated_at TEXT NOT NULL,\n"
|
||||
+ " updated_by INTEGER,\n" + " extn1 TEXT,\n" + " extn2 TEXT,\n" + " extn3 TEXT,\n"
|
||||
+ " extn4 TEXT,\n" + " extn5 TEXT,\n" + " extn6 TEXT,\n" + " extn7 TEXT,\n" + " extn8 TEXT,\n"
|
||||
+ " extn9 TEXT,\n" + " extn10 TEXT,\n" + " extn11 TEXT,\n" + " extn12 TEXT,\n" + " extn13 TEXT,\n"
|
||||
+ " extn14 TEXT,\n" + " extn15 TEXT,\n" + " isdashboard INTEGER NOT NULL,\n" + " model TEXT,\n"
|
||||
+ " name TEXT\n" + ");\n" + "\n" + "-- Insert sample data\n"
|
||||
+ "INSERT INTO dashboard VALUES (1,NULL,'2023-12-04 12:11:04',NULL,'2023-12-04 13:05:56',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,'[{\\\"charttitle\\\":\\\"index1\\\",\\\"type\\\":\\\"Index\\\",\\\"cols\\\":5,\\\"rows\\\":5,\\\"x\\\":0,\\\"y\\\":0,\\\"chartid\\\":3,\\\"component\\\":\\\"Index\\\",\\\"name\\\":\\\"Index\\\",\\\"slices\\\":false,\\\"donut\\\":false,\\\"chartcolor\\\":false,\\\"chartlegend\\\":false,\\\"showlabel\\\":false,\\\"Read Only\\\":false,\\\"selectedIcon\\\":\\\"IconData(U+0EE2A)\\\",\\\"charturl\\\":\\\"\\\",\\\"chartparameter\\\":\\\"\\\",\\\"datasource\\\":\\\"Default\\\"},{\\\"charttitle\\\":\\\"Index2\\\",\\\"type\\\":\\\"Index\\\",\\\"cols\\\":5,\\\"rows\\\":5,\\\"x\\\":0,\\\"y\\\":0,\\\"chartid\\\":4,\\\"component\\\":\\\"Index\\\",\\\"name\\\":\\\"Index\\\"},{\\\"charttitle\\\":\\\"Index3\\\",\\\"type\\\":\\\"Index\\\",\\\"cols\\\":5,\\\"rows\\\":5,\\\"x\\\":0,\\\"y\\\":0,\\\"chartid\\\":5,\\\"component\\\":\\\"Index\\\",\\\"name\\\":\\\"Index\\\"},{\\\"charttitle\\\":\\\"Doughnut Chart\\\",\\\"type\\\":\\\"Doughnut Chart\\\",\\\"cols\\\":5,\\\"rows\\\":5,\\\"x\\\":0,\\\"y\\\":0,\\\"chartid\\\":6,\\\"component\\\":\\\"Doughnut Chart\\\",\\\"name\\\":\\\"Doughnut Chart\\\",\\\"slices\\\":false,\\\"donut\\\":false,\\\"chartcolor\\\":false,\\\"chartlegend\\\":false,\\\"showlabel\\\":false,\\\"Read Only\\\":false,\\\"charturl\\\":\\\"http://43.205.154.152:30179/entityBuilder/Gaurav_testing/3\\\",\\\"chartparameter\\\":\\\"\\\",\\\"datasource\\\":\\\"Default\\\",\\\"selectedIcon\\\":\\\"IconData(U+0EE29)\\\"},{\\\"cols\\\": 4, \\\"rows\\\": 5, \\\"x\\\": 0, \\\"y\\\": 0, \\\"chartid\\\": 1, \\\"name\\\": \\\"Line Chart\\\", \\\"fieldName\\\": null, \\\"showlabel\\\": true, \\\"chartcolor\\\": null, \\\"chartlegend\\\": true, \\\"charturl\\\": \\\"http://43.205.154.152:30179/entityBuilder/Gaurav_testing\\\",\\\"xAxis\\\": \\\"name\\\",\\\"donut\\\": null, \\\"chartparameter\\\": null, \\\"datastore\\\": null,\\\"datasource\\\": null,\\\"id\\\": null,\\\"slices\\\": null,\\\"yAxis\\\": [\\\"pincode\\\"],\\\"charttitle\\\": \\\"Live Details\\\"}]','myfirstdashboard');\n"
|
||||
+ "\n" + "-- Table: dashboard_builder_t\n" + "DROP TABLE IF EXISTS dashboard_builder_t;\n"
|
||||
+ "CREATE TABLE dashboard_builder_t (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
||||
+ " dashboardname TEXT\n" + ");\n" + "\n" + "-- Table: dashboard_schedule_t\n"
|
||||
+ "DROP TABLE IF EXISTS dashboard_schedule_t;\n" + "CREATE TABLE dashboard_schedule_t (\n"
|
||||
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " attachment TEXT,\n" + " cc TEXT,\n"
|
||||
+ " cron TEXT,\n" + " end_time TEXT,\n" + " every TEXT,\n" + " gateway TEXT,\n"
|
||||
+ " gatewaydone TEXT,\n" + " replacement_string TEXT,\n" + " send_to TEXT,\n"
|
||||
+ " start_time TEXT,\n" + " template TEXT,\n" + " type TEXT\n" + ");\n" + "\n"
|
||||
+ "-- Table: dashboardaxis\n" + "DROP TABLE IF EXISTS dashboardaxis;\n"
|
||||
+ "CREATE TABLE dashboardaxis (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " april TEXT,\n"
|
||||
+ " feb TEXT,\n" + " jan TEXT,\n" + " march TEXT,\n" + " may TEXT\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO dashboardaxis VALUES \n" + "(1,'5','10','25','3',NULL),\n"
|
||||
+ "(3,'5000','15000','10000','30000',NULL),\n" + "(4,'5000','15000','10000','30000',NULL),\n"
|
||||
+ "(5,'5000','15000','5','30000',NULL),\n" + "(6,'5000','15000','10000','30000','2000'),\n"
|
||||
+ "(7,'23','20','25','30','20'),\n" + "(8,'23','20','25','30','99'),\n"
|
||||
+ "(9,'23','20','25','30','20');\n" + "\n" + "-- Table: dashbord_header\n"
|
||||
+ "DROP TABLE IF EXISTS dashbord_header;\n" + "CREATE TABLE dashbord_header (\n"
|
||||
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " account_id INTEGER,\n"
|
||||
+ " created_at TEXT NOT NULL,\n" + " created_by INTEGER,\n" + " updated_at TEXT NOT NULL,\n"
|
||||
+ " updated_by INTEGER,\n" + " is_build INTEGER,\n" + " dashboard_name TEXT,\n"
|
||||
+ " description TEXT,\n" + " menu_name TEXT,\n" + " module_id INTEGER NOT NULL,\n"
|
||||
+ " object_type TEXT,\n" + " secuirity_profile TEXT,\n" + " sub_object_type TEXT,\n"
|
||||
+ " tech_stack TEXT,\n" + " testing INTEGER NOT NULL,\n" + " is_updated INTEGER,\n"
|
||||
+ " add_to_home INTEGER\n" + ");\n" + "\n" + "INSERT INTO dashbord_header VALUES \n"
|
||||
+ "(1,NULL,'2023-11-23 09:06:59',NULL,'2024-02-05 17:55:17',NULL,0,'Testing Dashboard','This is dashboard for testing purpose and using chart make it dynamic.',NULL,0,NULL,'easy',NULL,NULL,0,0,0);\n"
|
||||
+ "\n" + "-- Table: dashbord_line\n" + "DROP TABLE IF EXISTS dashbord_line;\n"
|
||||
+ "CREATE TABLE dashbord_line (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " model TEXT,\n"
|
||||
+ " dashboard_name TEXT\n" + ");\n" + "\n" + "INSERT INTO dashbord_line VALUES \n" + "(1,'FF','TT'),\n"
|
||||
+ "(2,'FFhjfh','TT1'),\n"
|
||||
+ "(13,'[{\\\"cols\\\":3,\\\"rows\\\":5,\\\"x\\\":3,\\\"y\\\":5,\\\"chartid\\\":3,\\\"name\\\":\\\"Doughnut Chart\\\",\\\"component\\\":\\\"Doughnut Chart\\\"},{\\\"cols\\\":3,\\\"rows\\\":5,\\\"x\\\":3,\\\"y\\\":0,\\\"chartid\\\":3,\\\"name\\\":\\\"Line Chart\\\",\\\"component\\\":\\\"Line Chart\\\"},{\\\"cols\\\":4,\\\"rows\\\":6,\\\"x\\\":6,\\\"y\\\":0,\\\"chartid\\\":3,\\\"name\\\":\\\"Bar Chart\\\",\\\"component\\\":\\\"Bar Chart\\\"},{\\\"cols\\\":3,\\\"rows\\\":8,\\\"x\\\":0,\\\"y\\\":0,\\\"chartid\\\":3,\\\"name\\\":\\\"Grid View\\\",\\\"component\\\":\\\"Grid View\\\"}]','Dashtest'),\n"
|
||||
+ "(14,'[{\\\"cols\\\":3,\\\"rows\\\":10,\\\"x\\\":0,\\\"y\\\":0,\\\"chartid\\\":3,\\\"name\\\":\\\"Doughnut Chart\\\",\\\"component\\\":\\\"Doughnut Chart\\\"},{\\\"cols\\\":4,\\\"rows\\\":10,\\\"x\\\":3,\\\"y\\\":0,\\\"chartid\\\":2,\\\"name\\\":\\\"Line Chart\\\",\\\"component\\\":\\\"Line Chart\\\"},{\\\"cols\\\":3,\\\"rows\\\":6,\\\"x\\\":0,\\\"y\\\":10,\\\"chartid\\\":4,\\\"name\\\":\\\"Bar Chart\\\",\\\"component\\\":\\\"Bar Chart\\\"},{\\\"cols\\\":6,\\\"rows\\\":11,\\\"x\\\":7,\\\"y\\\":2,\\\"chartid\\\":11,\\\"name\\\":\\\"Grid View\\\",\\\"component\\\":\\\"Grid View\\\"}]','DashboardTesting');\n"
|
||||
+ "\n" + "-- Table: dashbord1_line\n" + "DROP TABLE IF EXISTS dashbord1_line;\n"
|
||||
+ "CREATE TABLE dashbord1_line (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " model TEXT,\n"
|
||||
+ " header_id TEXT,\n" + " account_id INTEGER,\n" + " created_at TEXT NOT NULL,\n"
|
||||
+ " created_by INTEGER,\n" + " updated_at TEXT NOT NULL,\n" + " updated_by INTEGER,\n"
|
||||
+ " dashbord_header_id INTEGER,\n"
|
||||
+ " FOREIGN KEY(dashbord_header_id) REFERENCES dashbord_header(id)\n" + ");\n" + "\n"
|
||||
+ "INSERT INTO dashbord1_line VALUES \n"
|
||||
+ "(1,'{\\\"dashboard\\\":[{\\\"cols\\\":4,\\\"rows\\\":5,\\\"x\\\":0,\\\"y\\\":0,\\\"name\\\":\\\"Radar Chart\\\",\\\"component\\\":\\\"Radar Chart\\\"},{\\\"cols\\\":5,\\\"rows\\\":6,\\\"x\\\":4,\\\"y\\\":0,\\\"chartid\\\":null,\\\"component\\\":\\\"Bubble Chart\\\",\\\"name\\\":\\\"Bubble Chart\\\"}]}',NULL,NULL,'2023-11-23 09:06:59',NULL,'2024-02-02 10:34:37',NULL,1);\n"
|
||||
+ "" + "-- Table: rp_builder\n" + "DROP TABLE IF EXISTS rp_builder;\n" + "CREATE TABLE rp_builder (\n"
|
||||
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " account_id INTEGER,\n"
|
||||
+ " created_at TEXT NOT NULL,\n" + " created_by INTEGER,\n" + " updated_at TEXT NOT NULL,\n"
|
||||
+ " updated_by INTEGER,\n" + " is_build INTEGER,\n" + " description TEXT,\n" + " menu_name TEXT,\n"
|
||||
+ " module_id INTEGER NOT NULL,\n" + " page_size TEXT,\n" + " report_builder_name TEXT,\n"
|
||||
+ " secuirity_profile TEXT,\n" + " tech_stack TEXT,\n" + " is_updated INTEGER\n" + ");\n" + "\n"
|
||||
+ "-- Table: rp_line\n" + "DROP TABLE IF EXISTS rp_line;\n" + "CREATE TABLE rp_line (\n"
|
||||
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " account_id INTEGER,\n"
|
||||
+ " created_at TEXT NOT NULL,\n" + " created_by INTEGER,\n" + " updated_at TEXT NOT NULL,\n"
|
||||
+ " updated_by INTEGER,\n" + " model TEXT,\n" + " header_id TEXT,\n" + " rp_builder_id INTEGER,\n"
|
||||
+ " FOREIGN KEY(rp_builder_id) REFERENCES rp_builder(id)\n" + ");\n" + "\n"
|
||||
+ "-- Table: rpt_builder2_t\n" + "DROP TABLE IF EXISTS rpt_builder2_t;\n"
|
||||
+ "CREATE TABLE rpt_builder2_t (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
||||
+ " active INTEGER,\n" + " description TEXT,\n" + " report_name TEXT,\n" + " is_sql INTEGER\n"
|
||||
+ ");\n" + "\n" + "-- Insert sample data\n" + "INSERT INTO rpt_builder2_t VALUES \n"
|
||||
+ "(1,1,'School Changes Reports','School Report',NULL),\n" + "(2,NULL,NULL,'Urltest1',NULL),\n"
|
||||
+ "(3,1,'test','test',1),\n" + "(4,1,'test','test',0);\n" + "\n" + "-- Table: rpt_builder_t\n"
|
||||
+ "DROP TABLE IF EXISTS rpt_builder_t;\n" + "CREATE TABLE rpt_builder_t (\n"
|
||||
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + " std_param_json TEXT,\n"
|
||||
+ " adhoc_param_flag INTEGER NOT NULL,\n" + " adhoc_param_string TEXT,\n"
|
||||
+ " date_param_flag INTEGER NOT NULL,\n" + " folder TEXT,\n" + " name TEXT,\n" + " query TEXT\n"
|
||||
+ ");\n" + "\n" + "-- Table: rpt_builder2_lines_t\n" + "DROP TABLE IF EXISTS rpt_builder2_lines_t;\n"
|
||||
+ "CREATE TABLE rpt_builder2_lines_t (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
||||
+ " header_id TEXT,\n" + " model TEXT,\n" + " rpt_builder2_t_id INTEGER,\n"
|
||||
+ " FOREIGN KEY(rpt_builder2_t_id) REFERENCES rpt_builder2_t(id)\n" + ");\n" + "\n"
|
||||
+ "-- Insert sample data\n" + "INSERT INTO rpt_builder2_lines_t VALUES\n" + "(1,NULL,'',1),\n"
|
||||
+ "(2,NULL,'[{\\\"std_param_html\\\":[\\\"name\\\",\\\"mark\\\",\\\"mark2\\\"],\\\"adhoc_param_html\\\":[\\\"name\\\",\\\"mark2\\\",\\\"id\\\",\\\"mark\\\",\\\"timestamp\\\"],\\\"date_param_req\\\":false,\\\"url\\\":\\\"http://3.109.61.114:30173/token/access_type/agyana\\\"}]',2),\n"
|
||||
+ "(3,NULL,'',3),\n" + "(4,NULL,'',4);\n" + "" + "DROP TABLE IF EXISTS builder_entity_t;\n" + "\n"
|
||||
+ "CREATE TABLE builder_entity_t (\n" + " id INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
||||
+ " job_name TEXT,\n" + " job_type TEXT\n" + ");\n" + "" + "PRAGMA foreign_keys=ON;\n" + "";
|
||||
return sqlDump;
|
||||
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
|
||||
String sql = " \n" + "DROP TABLE IF EXISTS `accounts`;\n"
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.realnet.Builders.Services;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SqlDumpExecutor {
|
||||
|
||||
/**
|
||||
* Executes a massive SQL dump safely.
|
||||
*
|
||||
* @param connection JDBC connection
|
||||
* @param sqlDump Full SQL dump string from getSql()
|
||||
*/
|
||||
public void executeDump(Connection connection, String sqlDump) {
|
||||
Statement stmt = null;
|
||||
try {
|
||||
stmt = connection.createStatement();
|
||||
connection.setAutoCommit(false);
|
||||
|
||||
// Remove MySQL backticks
|
||||
sqlDump = sqlDump.replaceAll("`", "");
|
||||
|
||||
// Remove table-level DEFAULT COLLATE or CHARSET
|
||||
sqlDump = sqlDump.replaceAll("(?i)DEFAULT\\s+CHARSET=[^;\\n]+", "");
|
||||
sqlDump = sqlDump.replaceAll("(?i)COLLATE=[^;\\n]+", "");
|
||||
|
||||
// Convert data types
|
||||
sqlDump = sqlDump.replaceAll("(?i)bigint", "INTEGER");
|
||||
sqlDump = sqlDump.replaceAll("(?i)int\\([0-9]+\\)", "INTEGER");
|
||||
sqlDump = sqlDump.replaceAll("(?i)varchar\\([0-9]+\\)", "TEXT");
|
||||
sqlDump = sqlDump.replaceAll("(?i)bit\\([0-9]+\\)", "INTEGER");
|
||||
sqlDump = sqlDump.replaceAll("(?i)longblob", "BLOB");
|
||||
|
||||
// Remove AUTO_INCREMENT (if any)
|
||||
sqlDump = sqlDump.replaceAll("(?i)AUTO_INCREMENT", "");
|
||||
|
||||
// Remove MySQL-specific directives
|
||||
sqlDump = sqlDump.replaceAll("(?i)SET\\s+[^;]+;", "");
|
||||
sqlDump = sqlDump.replaceAll("(?i)ENGINE=\\w+\\s*", "");
|
||||
sqlDump = sqlDump.replaceAll("(?i)AUTO_INCREMENT=\\d+", "");
|
||||
sqlDump = sqlDump.replaceAll("(?i)CHARSET=\\w+", "");
|
||||
|
||||
// Remove DEFAULT NULL (SQLite allows NULL by default)
|
||||
sqlDump = sqlDump.replaceAll("(?i)DEFAULT NULL", "");
|
||||
|
||||
// Convert UNIQUE KEY <name> to UNIQUE
|
||||
sqlDump = sqlDump.replaceAll("(?i)UNIQUE KEY [^\\(]+\\(", "UNIQUE(");
|
||||
|
||||
// Remove double commas in CREATE TABLE (,,)
|
||||
sqlDump = sqlDump.replaceAll(",\\s*,", ",");
|
||||
|
||||
// Remove _binary prefix in INSERT statements
|
||||
sqlDump = sqlDump.replaceAll("(?i)_binary\\s+'", "'");
|
||||
|
||||
String delimiter = ";"; // default delimiter
|
||||
StringBuilder sqlStatement = new StringBuilder();
|
||||
|
||||
String[] lines = sqlDump.split("\\r?\\n");
|
||||
for (String line : lines) {
|
||||
line = line.trim();
|
||||
|
||||
// Skip empty lines and comments
|
||||
if (line.isEmpty() || line.startsWith("--") || line.startsWith("//") || line.startsWith("/*")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Detect DELIMITER changes (optional, mostly MySQL)
|
||||
if (line.startsWith("DELIMITER ")) {
|
||||
delimiter = line.substring("DELIMITER ".length()).trim();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove MySQL-specific comments like /*! ... */
|
||||
line = line.replaceAll("/\\*!.*?\\*/", "").trim();
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
|
||||
sqlStatement.append(line).append(" ");
|
||||
|
||||
// Check if statement ends with current delimiter
|
||||
if (sqlStatement.toString().trim().endsWith(delimiter)) {
|
||||
String finalSql = sqlStatement.toString().trim();
|
||||
|
||||
// Remove the delimiter from the end
|
||||
if (delimiter.length() > 0 && finalSql.endsWith(delimiter)) {
|
||||
finalSql = finalSql.substring(0, finalSql.length() - delimiter.length()).trim();
|
||||
}
|
||||
|
||||
try {
|
||||
stmt.execute(finalSql);
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Failed SQL: " + finalSql);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
sqlStatement.setLength(0); // reset for next statement
|
||||
}
|
||||
}
|
||||
|
||||
connection.commit();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error executing SQL dump: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
try {
|
||||
connection.rollback();
|
||||
} catch (SQLException ex) {
|
||||
System.err.println("Rollback failed: " + ex.getMessage());
|
||||
}
|
||||
} finally {
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
connection.setAutoCommit(true);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.realnet.BulkUpload.Controllers;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -24,7 +22,6 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -54,7 +51,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -64,11 +60,9 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.realnet.BulkUpload.Repository.BulkUpload_Repository;
|
||||
import com.realnet.BulkUpload.Services.BulkUpload_Service;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import com.realnet.template.entity.TemplateFileUpload;
|
||||
import com.realnet.template.repository.TemplatedataRepo;
|
||||
import com.realnet.template.service.DynamicTemplateService;
|
||||
import com.realnet.template.service.FileUploadService;
|
||||
|
||||
@RestController
|
||||
@@ -78,14 +72,6 @@ public class DataImportController {
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
@Autowired
|
||||
private TemplatedataRepo temprepo;
|
||||
@Autowired
|
||||
private DynamicTemplateService dynamicTemplateService;
|
||||
|
||||
@Autowired
|
||||
private BulkUpload_Service bulkUpload_Service;
|
||||
|
||||
@Autowired
|
||||
private BulkUpload_Repository bulkUpload_Repository;
|
||||
|
||||
@Autowired
|
||||
private FileUploadService fileUploadService;
|
||||
@@ -280,175 +266,13 @@ public class DataImportController {
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
/////////// VERY IMPORTANT NOT DELETE THE BELOW///////////
|
||||
|
||||
// @PostMapping("/DownloadExcel/{id}")
|
||||
// public ResponseEntity<?> importdatadownloadexcel(@PathVariable Long id,
|
||||
// @RequestBody Map<String, List<Map<String, Object>>> jsonData) {
|
||||
//
|
||||
// TemplateFileUpload templateFileUpload = fileUploadService.getTemplatebyid(id);
|
||||
//
|
||||
// String entity_name = templateFileUpload.getEntity_name();
|
||||
//
|
||||
// BulkUpload_t bulkUpload_t = bulkUpload_Repository.getentityName(entity_name);
|
||||
// String ruleLine = bulkUpload_t.getRule_line();
|
||||
//
|
||||
// JsonParser parser = new JsonParser();
|
||||
// JsonElement element = parser.parse(ruleLine);
|
||||
// JsonArray array = element.getAsJsonArray();
|
||||
// Iterator<JsonElement> iterator = array.iterator();
|
||||
//
|
||||
// String fromsheet = null;
|
||||
// String fromColumn = null;
|
||||
// String validationTable = null;
|
||||
// String checkColumn = null;
|
||||
// String useColumn = null;
|
||||
// String replacementtable = null;
|
||||
// String replacementcolumn = null;
|
||||
//
|
||||
// while (iterator.hasNext()) {
|
||||
// JsonElement next = iterator.next();
|
||||
// JsonObject jsonObject = next.getAsJsonObject();
|
||||
//
|
||||
// fromsheet = jsonObject.get("fromsheet").getAsString();
|
||||
// fromColumn = jsonObject.get("fromColumn").getAsString();
|
||||
// validationTable = jsonObject.get("validationTable").getAsString();
|
||||
// checkColumn = jsonObject.get("checkColumn").getAsString();
|
||||
// useColumn = jsonObject.get("useColumn").getAsString();
|
||||
// replacementtable = jsonObject.get("useTable").getAsString();
|
||||
// replacementcolumn = jsonObject.get("replacementcolumn").getAsString();
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// String customerTableName = validationTable;
|
||||
// String siteTableName = replacementtable;
|
||||
//
|
||||
// try {
|
||||
// Set<String> tableNames = jsonData.keySet(); // Get all unique table names
|
||||
//
|
||||
// String siteEntityName = null;
|
||||
// for (String tableName : tableNames) {
|
||||
// List<Map<String, Object>> tableData = jsonData.get(tableName);
|
||||
//
|
||||
// // Process tableData based on the tableName (e.g., "Site" or "Customer")
|
||||
// System.out.println("Table Name: " + tableName);
|
||||
// for (Map<String, Object> row : tableData) {
|
||||
// // Process individual rows within the table data
|
||||
// System.out.println("Row Data: " + row);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// List<Map<String, Object>> processedDataList = new ArrayList<>(); // List to hold processed data rows
|
||||
//
|
||||
// // Iterate through each customer data entry
|
||||
// List<Map<String, Object>> customerData = jsonData.get("Customer");
|
||||
// for (Map<String, Object> insertCustomerData : customerData) {
|
||||
// String customerName = (String) insertCustomerData.get(checkColumn);
|
||||
//
|
||||
// // Check if the customerName is not null and iterate through "Site" data
|
||||
// List<Map<String, Object>> siteData = jsonData.get(fromsheet);
|
||||
//
|
||||
// List<Map<String, Object>> matchedSiteData = new ArrayList<>();
|
||||
// if (customerName != null) {
|
||||
// // Iterate through "Site" data and check for a matching "entity_name"
|
||||
// for (Map<String, Object> siteRow : siteData) {
|
||||
// // Specify the index as "AM" (39th column)
|
||||
//// String columnIndex = "AM";
|
||||
// String columnIndex = fromColumn;
|
||||
//
|
||||
// // Retrieve the value at the specified index
|
||||
//
|
||||
// for (Map.Entry<String, Object> entry : siteRow.entrySet()) {
|
||||
// if (entry.getKey().equals(columnIndex)) {
|
||||
// siteEntityName = (String) entry.getValue();
|
||||
// break; // Exit the loop once the value is found
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (customerName.equals(siteEntityName)) {
|
||||
// // Add the matching "Site" data to the list
|
||||
// matchedSiteData.add(siteRow);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// String insertCustomerDataJson = objectMapper.writeValueAsString(insertCustomerData);
|
||||
// String matchedSiteDataJson = objectMapper.writeValueAsString(matchedSiteData);
|
||||
//
|
||||
// String customerSql = getInsertQuery(customerTableName, insertCustomerData);
|
||||
//
|
||||
// // Insert data into the customer table
|
||||
// Object[] customerValues = new Object[insertCustomerData.size() + 5];
|
||||
// int index = 0;
|
||||
// for (Object value : insertCustomerData.values()) {
|
||||
// customerValues[index++] = value;
|
||||
// }
|
||||
// customerValues[index++] = new Timestamp(System.currentTimeMillis()); // created_at
|
||||
// customerValues[index++] = null; // created_by
|
||||
// customerValues[index++] = null; // updated_by
|
||||
// customerValues[index++] = new Timestamp(System.currentTimeMillis()); // updated_at
|
||||
// customerValues[index] = null; // account_id
|
||||
// jdbcTemplate.update(customerSql, customerValues);
|
||||
//
|
||||
// // we can use useColumn here
|
||||
// Long generatedId = jdbcTemplate.queryForObject("SELECT LAST_INSERT_ID()", Long.class);
|
||||
//
|
||||
// List<Map<String, Object>> insertMatchedSiteData = new ArrayList<>(); // List to hold processed data rows
|
||||
//
|
||||
// for (Map<String, Object> siteRow : matchedSiteData) {
|
||||
// // Replace "Customer Name" with "customer_master_id" if it exists
|
||||
// if (siteRow.containsKey(siteEntityName)) {
|
||||
// siteRow.put(replacementcolumn, generatedId);
|
||||
// siteRow.remove(siteEntityName);
|
||||
// }
|
||||
// insertMatchedSiteData.add(siteRow);
|
||||
// }
|
||||
//
|
||||
// for (Map<String, Object> siteRow : insertMatchedSiteData) {
|
||||
// Object[] siteValues = new Object[siteRow.size() + 5]; // Create a new array for each row
|
||||
//
|
||||
// int siteIndex = 0;
|
||||
// for (Object value : siteRow.values()) {
|
||||
// siteValues[siteIndex++] = value;
|
||||
// }
|
||||
//
|
||||
// siteValues[siteIndex++] = new Timestamp(System.currentTimeMillis()); // created_at
|
||||
// siteValues[siteIndex++] = null; // created_by
|
||||
// siteValues[siteIndex++] = null; // updated_by
|
||||
// siteValues[siteIndex++] = new Timestamp(System.currentTimeMillis()); // updated_at
|
||||
// siteValues[siteIndex] = null; // account_id
|
||||
//
|
||||
// String siteSql = getInsertQuery(siteTableName, siteRow);
|
||||
// jdbcTemplate.update(siteSql, siteValues);
|
||||
// }
|
||||
//
|
||||
// // Add the processed customer data to the list
|
||||
// processedDataList.add(insertCustomerData);
|
||||
// }
|
||||
//
|
||||
// // Use a LinkedHashMap to preserve insertion order in the response
|
||||
// Map<String, List<Map<String, Object>>> response = new LinkedHashMap<>();
|
||||
// response.put("result", processedDataList);
|
||||
//
|
||||
// return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// // Handle exceptions and return an appropriate response
|
||||
// return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
// }
|
||||
// }
|
||||
|
||||
@PostMapping("/DownloadExcel/{id}")
|
||||
public ResponseEntity<?> importdatadownloadexcel( @PathVariable Long id,
|
||||
public ResponseEntity<?> importdatadownloadexcel(@PathVariable Long id,
|
||||
@RequestParam(name = "jsonData") String jsonDataParam,
|
||||
@RequestParam(name = "ruleData") String ruleDataParam)
|
||||
throws JsonMappingException, JsonProcessingException, UnsupportedEncodingException {
|
||||
|
||||
|
||||
|
||||
// Inside your method
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode ruleDataNode = objectMapper.readTree(ruleDataParam);
|
||||
@@ -458,8 +282,6 @@ public class DataImportController {
|
||||
return uploadDataToTable(id, jsonDataParam);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Parse jsonDataParam to extract the JSON data
|
||||
Map<String, List<Map<String, Object>>> jsonData = objectMapper.readValue(
|
||||
URLDecoder.decode(jsonDataParam, "UTF-8"), new TypeReference<Map<String, List<Map<String, Object>>>>() {
|
||||
@@ -478,8 +300,6 @@ public class DataImportController {
|
||||
String replacementtable = null;
|
||||
String replacementcolumn = null;
|
||||
|
||||
|
||||
|
||||
if (ruleData != null && !ruleData.isEmpty()) {
|
||||
// Assuming you want to access the first element in the array
|
||||
Map<String, String> rule = ruleData.get(0);
|
||||
@@ -509,7 +329,6 @@ public class DataImportController {
|
||||
// Create a sheet for site data
|
||||
XSSFSheet siteSheet = workbook.createSheet("Site");
|
||||
|
||||
|
||||
List<Map<String, Object>> customerDataList = new ArrayList<>();
|
||||
List<Map<String, Object>> siteDataList = new ArrayList<>();
|
||||
|
||||
@@ -731,8 +550,6 @@ public class DataImportController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ResponseEntity<?> uploadDataToTable(Long id, String jsonDataParam) {
|
||||
try {
|
||||
// Get table name from TemplateFileUpload entity
|
||||
@@ -740,10 +557,12 @@ public class DataImportController {
|
||||
if (fileUploadOptional.isPresent()) {
|
||||
TemplateFileUpload fileUpload = fileUploadOptional.get();
|
||||
// String tableName = fileUpload.getTablename();
|
||||
String tableName = "aa";
|
||||
String tableName = fileUpload.getEntity_name();
|
||||
// String tableName = "aa";
|
||||
// Insert data into the specified table
|
||||
insertDataIntoTable(tableName, jsonDataParam);
|
||||
return ResponseEntity.ok().body("Data uploaded successfully to table: " + tableName);
|
||||
System.out.println("Data uploaded successfully to table...");
|
||||
return ResponseEntity.ok().body(new EntityResponse("Data uploaded successfully to table: " + tableName));
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Template file with id " + id + " not found");
|
||||
}
|
||||
@@ -754,20 +573,22 @@ public class DataImportController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void insertDataIntoTable(String tableName, String jsonDataParam) {
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
// Parse jsonDataParam to extract the JSON data
|
||||
Map<String, List<Map<String, Object>>> jsonData = objectMapper.readValue(
|
||||
URLDecoder.decode(jsonDataParam, "UTF-8"), new TypeReference<Map<String, List<Map<String, Object>>>>() {});
|
||||
URLDecoder.decode(jsonDataParam, "UTF-8"),
|
||||
new TypeReference<Map<String, List<Map<String, Object>>>>() {
|
||||
});
|
||||
|
||||
// Iterate over the entries of the jsonData map
|
||||
for (Map.Entry<String, List<Map<String, Object>>> entry : jsonData.entrySet()) {
|
||||
String sheetName = entry.getKey(); // Get the sheet name dynamically
|
||||
List<Map<String, Object>> data = entry.getValue(); // Get the list of maps dynamically
|
||||
|
||||
// Now you have the list of maps for the current sheet, you can iterate through it and perform your database insertion logic
|
||||
// Now you have the list of maps for the current sheet, you can iterate through
|
||||
// it and perform your database insertion logic
|
||||
for (Map<String, Object> rowData : data) {
|
||||
StringBuilder columns = new StringBuilder();
|
||||
StringBuilder values = new StringBuilder();
|
||||
@@ -797,8 +618,6 @@ public class DataImportController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String extractExceptionMessage(DataIntegrityViolationException e) {
|
||||
String errorMessage = e.getMessage();
|
||||
int startIndex = errorMessage.indexOf("Incorrect ");
|
||||
@@ -865,8 +684,6 @@ public class DataImportController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/downloadImportStatement/{id}")
|
||||
public ResponseEntity<?> downloadImportStatement(@PathVariable Long id) {
|
||||
// Retrieve the file data from the database based on the ID
|
||||
@@ -896,8 +713,7 @@ public class DataImportController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//get table column
|
||||
// get table column
|
||||
|
||||
@GetMapping("/columns/{tableName}")
|
||||
public List<String> getColumnNames(@PathVariable String tableName) {
|
||||
@@ -917,12 +733,8 @@ public class DataImportController {
|
||||
return new ArrayList<>(columnNamesSet);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private String getCellValue(Map<String, List<Map<String, Object>>> jsonData, String sheetName,
|
||||
String cellAddress) throws IOException {
|
||||
private String getCellValue(Map<String, List<Map<String, Object>>> jsonData, String sheetName, String cellAddress)
|
||||
throws IOException {
|
||||
if (jsonData.containsKey(sheetName)) {
|
||||
List<Map<String, Object>> sheetData = jsonData.get(sheetName);
|
||||
int size = sheetData.size();
|
||||
@@ -948,8 +760,7 @@ public class DataImportController {
|
||||
// int rowIndex = Integer.parseInt(rowPart) - 1; // Excel-style 1-based index
|
||||
System.out.println("Column Index: " + columnIndex);
|
||||
|
||||
|
||||
if (columnIndex >= 0 ) {
|
||||
if (columnIndex >= 0) {
|
||||
// Get the list of keys from the firstRowData map
|
||||
List<String> keys = new ArrayList<>(firstRowData.keySet());
|
||||
|
||||
@@ -961,15 +772,9 @@ public class DataImportController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private int getColumnIndex(String columnPart) {
|
||||
int index = 0;
|
||||
int multiplier = 1;
|
||||
@@ -984,10 +789,6 @@ public class DataImportController {
|
||||
return index - 1; // Subtract 1 to get a 0-based index
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// @PostMapping("/DownloadExcel/{entityName}")
|
||||
// public ResponseEntity<Resource> importdatadownloadexcel(@PathVariable String entityName,
|
||||
// @RequestBody List<Map<String, Object>> data) throws IOException {
|
||||
@@ -1003,8 +804,6 @@ public class DataImportController {
|
||||
// return ResponseEntity.ok().body(null);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
private List<Map<String, Object>> processData(String entityName, List<Map<String, Object>> data) {
|
||||
List<Map<String, Object>> processedData = new ArrayList<>();
|
||||
try {
|
||||
@@ -1042,8 +841,6 @@ public class DataImportController {
|
||||
return processedData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Workbook createWorkbook(List<Map<String, Object>> processedData) {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Failed Records");
|
||||
@@ -1077,6 +874,165 @@ public class DataImportController {
|
||||
return new InputStreamResource(inputStream);
|
||||
}
|
||||
|
||||
/////////// VERY IMPORTANT NOT DELETE THE BELOW///////////
|
||||
|
||||
//@PostMapping("/DownloadExcel/{id}")
|
||||
//public ResponseEntity<?> importdatadownloadexcel(@PathVariable Long id,
|
||||
// @RequestBody Map<String, List<Map<String, Object>>> jsonData) {
|
||||
//
|
||||
// TemplateFileUpload templateFileUpload = fileUploadService.getTemplatebyid(id);
|
||||
//
|
||||
// String entity_name = templateFileUpload.getEntity_name();
|
||||
//
|
||||
// BulkUpload_t bulkUpload_t = bulkUpload_Repository.getentityName(entity_name);
|
||||
// String ruleLine = bulkUpload_t.getRule_line();
|
||||
//
|
||||
// JsonParser parser = new JsonParser();
|
||||
// JsonElement element = parser.parse(ruleLine);
|
||||
// JsonArray array = element.getAsJsonArray();
|
||||
// Iterator<JsonElement> iterator = array.iterator();
|
||||
//
|
||||
// String fromsheet = null;
|
||||
// String fromColumn = null;
|
||||
// String validationTable = null;
|
||||
// String checkColumn = null;
|
||||
// String useColumn = null;
|
||||
// String replacementtable = null;
|
||||
// String replacementcolumn = null;
|
||||
//
|
||||
// while (iterator.hasNext()) {
|
||||
// JsonElement next = iterator.next();
|
||||
// JsonObject jsonObject = next.getAsJsonObject();
|
||||
//
|
||||
// fromsheet = jsonObject.get("fromsheet").getAsString();
|
||||
// fromColumn = jsonObject.get("fromColumn").getAsString();
|
||||
// validationTable = jsonObject.get("validationTable").getAsString();
|
||||
// checkColumn = jsonObject.get("checkColumn").getAsString();
|
||||
// useColumn = jsonObject.get("useColumn").getAsString();
|
||||
// replacementtable = jsonObject.get("useTable").getAsString();
|
||||
// replacementcolumn = jsonObject.get("replacementcolumn").getAsString();
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// String customerTableName = validationTable;
|
||||
// String siteTableName = replacementtable;
|
||||
//
|
||||
// try {
|
||||
// Set<String> tableNames = jsonData.keySet(); // Get all unique table names
|
||||
//
|
||||
// String siteEntityName = null;
|
||||
// for (String tableName : tableNames) {
|
||||
// List<Map<String, Object>> tableData = jsonData.get(tableName);
|
||||
//
|
||||
// // Process tableData based on the tableName (e.g., "Site" or "Customer")
|
||||
// System.out.println("Table Name: " + tableName);
|
||||
// for (Map<String, Object> row : tableData) {
|
||||
// // Process individual rows within the table data
|
||||
// System.out.println("Row Data: " + row);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// List<Map<String, Object>> processedDataList = new ArrayList<>(); // List to hold processed data rows
|
||||
//
|
||||
// // Iterate through each customer data entry
|
||||
// List<Map<String, Object>> customerData = jsonData.get("Customer");
|
||||
// for (Map<String, Object> insertCustomerData : customerData) {
|
||||
// String customerName = (String) insertCustomerData.get(checkColumn);
|
||||
//
|
||||
// // Check if the customerName is not null and iterate through "Site" data
|
||||
// List<Map<String, Object>> siteData = jsonData.get(fromsheet);
|
||||
//
|
||||
// List<Map<String, Object>> matchedSiteData = new ArrayList<>();
|
||||
// if (customerName != null) {
|
||||
// // Iterate through "Site" data and check for a matching "entity_name"
|
||||
// for (Map<String, Object> siteRow : siteData) {
|
||||
// // Specify the index as "AM" (39th column)
|
||||
//// String columnIndex = "AM";
|
||||
// String columnIndex = fromColumn;
|
||||
//
|
||||
// // Retrieve the value at the specified index
|
||||
//
|
||||
// for (Map.Entry<String, Object> entry : siteRow.entrySet()) {
|
||||
// if (entry.getKey().equals(columnIndex)) {
|
||||
// siteEntityName = (String) entry.getValue();
|
||||
// break; // Exit the loop once the value is found
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (customerName.equals(siteEntityName)) {
|
||||
// // Add the matching "Site" data to the list
|
||||
// matchedSiteData.add(siteRow);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// String insertCustomerDataJson = objectMapper.writeValueAsString(insertCustomerData);
|
||||
// String matchedSiteDataJson = objectMapper.writeValueAsString(matchedSiteData);
|
||||
//
|
||||
// String customerSql = getInsertQuery(customerTableName, insertCustomerData);
|
||||
//
|
||||
// // Insert data into the customer table
|
||||
// Object[] customerValues = new Object[insertCustomerData.size() + 5];
|
||||
// int index = 0;
|
||||
// for (Object value : insertCustomerData.values()) {
|
||||
// customerValues[index++] = value;
|
||||
// }
|
||||
// customerValues[index++] = new Timestamp(System.currentTimeMillis()); // created_at
|
||||
// customerValues[index++] = null; // created_by
|
||||
// customerValues[index++] = null; // updated_by
|
||||
// customerValues[index++] = new Timestamp(System.currentTimeMillis()); // updated_at
|
||||
// customerValues[index] = null; // account_id
|
||||
// jdbcTemplate.update(customerSql, customerValues);
|
||||
//
|
||||
// // we can use useColumn here
|
||||
// Long generatedId = jdbcTemplate.queryForObject("SELECT LAST_INSERT_ID()", Long.class);
|
||||
//
|
||||
// List<Map<String, Object>> insertMatchedSiteData = new ArrayList<>(); // List to hold processed data rows
|
||||
//
|
||||
// for (Map<String, Object> siteRow : matchedSiteData) {
|
||||
// // Replace "Customer Name" with "customer_master_id" if it exists
|
||||
// if (siteRow.containsKey(siteEntityName)) {
|
||||
// siteRow.put(replacementcolumn, generatedId);
|
||||
// siteRow.remove(siteEntityName);
|
||||
// }
|
||||
// insertMatchedSiteData.add(siteRow);
|
||||
// }
|
||||
//
|
||||
// for (Map<String, Object> siteRow : insertMatchedSiteData) {
|
||||
// Object[] siteValues = new Object[siteRow.size() + 5]; // Create a new array for each row
|
||||
//
|
||||
// int siteIndex = 0;
|
||||
// for (Object value : siteRow.values()) {
|
||||
// siteValues[siteIndex++] = value;
|
||||
// }
|
||||
//
|
||||
// siteValues[siteIndex++] = new Timestamp(System.currentTimeMillis()); // created_at
|
||||
// siteValues[siteIndex++] = null; // created_by
|
||||
// siteValues[siteIndex++] = null; // updated_by
|
||||
// siteValues[siteIndex++] = new Timestamp(System.currentTimeMillis()); // updated_at
|
||||
// siteValues[siteIndex] = null; // account_id
|
||||
//
|
||||
// String siteSql = getInsertQuery(siteTableName, siteRow);
|
||||
// jdbcTemplate.update(siteSql, siteValues);
|
||||
// }
|
||||
//
|
||||
// // Add the processed customer data to the list
|
||||
// processedDataList.add(insertCustomerData);
|
||||
// }
|
||||
//
|
||||
// // Use a LinkedHashMap to preserve insertion order in the response
|
||||
// Map<String, List<Map<String, Object>>> response = new LinkedHashMap<>();
|
||||
// response.put("result", processedDataList);
|
||||
//
|
||||
// return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// // Handle exceptions and return an appropriate response
|
||||
// return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
package com.realnet.Communication.Services;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.ResourceAccessException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.realnet.config.EmailService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.utils.Port_Constant;
|
||||
|
||||
@Service
|
||||
public class EmailNotificationService {
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
|
||||
public void sendDirectEmail(String email, String subject, String message) throws JsonProcessingException {
|
||||
// Call the sendSimpleMessage method from EmailService
|
||||
emailService.sendSimpleMessage(null, email, subject, message);
|
||||
}
|
||||
|
||||
public void sendmailViaSetu(String email, String Name, String type) {
|
||||
// Call the method from EmailCommunicationService
|
||||
|
||||
switch (type) {
|
||||
case "TeamMember":
|
||||
sendEmailTeamMember(email, Name);
|
||||
break;
|
||||
|
||||
case "WorkSpaceUser":
|
||||
sendEmailtoWorkUser(email, Name);
|
||||
break;
|
||||
case "AddProject":
|
||||
sendEmailAfterAddPrj(email, Name);
|
||||
break;
|
||||
|
||||
case "CopyProject":
|
||||
sendEmailAfterCopyPrj(email, Name);
|
||||
break;
|
||||
|
||||
case "CreateWireframe":
|
||||
sendEmailAfterCopyPrj(email, Name);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// for sending mail to team member
|
||||
public ResponseEntity<?> sendEmailTeamMember(String email, String FullName) {
|
||||
// Call the method from EmailCommunicationService
|
||||
|
||||
String subject = "Team Added to Workspace";
|
||||
String message = "Dear " + FullName + ",\n\nYou have been added to the workspace.";
|
||||
String templateName = "addproject";
|
||||
String gatewayName = "ganesh";
|
||||
|
||||
// Sending the email via Setu
|
||||
|
||||
ResponseEntity<?> responseEntity = sendEmailViaSetu(email, message, templateName, gatewayName);
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
// for sending mail to Sec workspace User
|
||||
public ResponseEntity<?> sendEmailtoWorkUser(String email, String FullName) {
|
||||
// Call the method from EmailCommunicationService
|
||||
|
||||
String subject = "Workspace Access Granted";
|
||||
String message = "Dear " + FullName + ",\n\nYou have been granted access to the workspace.";
|
||||
String templateName = "addproject"; // Replace with actual template name
|
||||
String gatewayName = "ganesh"; // Replace with actual gateway name
|
||||
|
||||
// Sending the email via Setu
|
||||
return sendEmailViaSetu(email, message, templateName, gatewayName);
|
||||
}
|
||||
|
||||
// for sending mail After Add project
|
||||
public ResponseEntity<?> sendEmailAfterAddPrj(String email, String Name) {
|
||||
// Call the method from EmailCommunicationService
|
||||
|
||||
String subject = "Add Project";
|
||||
String message = "Project " + Name + " has been created successfully.";
|
||||
String templateName = "addproject"; // Replace with actual template name
|
||||
String gatewayName = "ganesh"; // Replace with actual gateway name
|
||||
|
||||
// Sending the email via Setu
|
||||
return sendEmailViaSetu(email, message, templateName, gatewayName);
|
||||
}
|
||||
|
||||
// for sending mail After Copy project
|
||||
public ResponseEntity<?> sendEmailAfterCopyPrj(String email, String Name) {
|
||||
// Call the method from EmailCommunicationService
|
||||
|
||||
String subject = "Copy Project";
|
||||
String message = "Project " + Name + " has been Copied successfully.";
|
||||
String templateName = "addproject"; // Replace with actual template name
|
||||
String gatewayName = "ganesh"; // Replace with actual gateway name
|
||||
|
||||
// Sending the email via Setu
|
||||
return sendEmailViaSetu(email, message, templateName, gatewayName);
|
||||
}
|
||||
|
||||
// for sending mail After create Wireframe
|
||||
public ResponseEntity<?> sendEmailAfterCreateWireframe(String email, String Name) {
|
||||
// Call the method from EmailCommunicationService
|
||||
|
||||
String subject = "Create Wireframe";
|
||||
String message = "A new wireframe has been successfully added to your project.";
|
||||
|
||||
String templateName = "addproject"; // Replace with actual template name
|
||||
String gatewayName = "ganesh"; // Replace with actual gateway name
|
||||
|
||||
// Sending the email via Setu
|
||||
return sendEmailViaSetu(email, message, templateName, gatewayName);
|
||||
}
|
||||
|
||||
// send mail via setu
|
||||
public ResponseEntity<?> sendEmailViaSetu(String email, String message, String templateName, String gatewayName)
|
||||
throws ResourceAccessException {
|
||||
|
||||
// template name = notification_template, gateway name = email_gateway
|
||||
try {
|
||||
|
||||
String jsonData = "{\r\n" + " \"job_type\": \"Email\",\r\n" + " \"send_to\": \"" + email.trim()
|
||||
+ "\",\r\n" + " \"cc\": \"cc@example.com\",\r\n"
|
||||
// + " \"attachment\": \"sample-file.txt\",\r\n"
|
||||
+ " \"gatewaydone\": \"N\",\r\n" + " \"template_name\": \"" + templateName.trim() + "\",\r\n"
|
||||
+ " \"replacement_string\": \"Hello, {name} " + message + "!\",\r\n" + " \"gatewayName\": \""
|
||||
+ gatewayName.trim() + "\"\r\n" + "}\r\n";
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
// headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
|
||||
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
|
||||
queryParams.add("data", jsonData);
|
||||
|
||||
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(queryParams, headers);
|
||||
|
||||
String apiUrl2 = Port_Constant.SURE_SETU_DOMAIN
|
||||
+ "/token/Surecommunication/communication/jobtable/Com_jobTable"; // Replace with the
|
||||
// actual API URL
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(apiUrl2, requestEntity, String.class);
|
||||
|
||||
return ResponseEntity.ok(responseEntity.getBody());
|
||||
|
||||
} catch (ResourceAccessException e) {
|
||||
throw new ResourceAccessException("communication server no start..." + e);
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,6 +38,9 @@ public class Dashbord1_Line extends dashbord_Who_collumn {
|
||||
@Column(length = 5000)
|
||||
private String Model;
|
||||
|
||||
@Column(length = 5000)
|
||||
private String common_filter;
|
||||
|
||||
@JsonBackReference
|
||||
@ManyToOne
|
||||
private Dashbord_Header dashbord_Header;
|
||||
|
||||
@@ -23,44 +23,35 @@ public class HeaderService {
|
||||
return headerRepository.save(dashbord_Header);
|
||||
}
|
||||
|
||||
|
||||
public List<Dashbord_Header> getdetails() {
|
||||
// TODO Auto-generated method stub
|
||||
return (List<Dashbord_Header>) headerRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
public Dashbord_Header getdetailsbyId(int id) {
|
||||
// TODO Auto-generated method stub
|
||||
return headerRepository.findById(id);
|
||||
}
|
||||
|
||||
|
||||
public void delete_by_id(int id) {
|
||||
// TODO Auto-generated method stub
|
||||
headerRepository.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
public Dashbord_Header update_dashboard_header(Dashbord_Header dashbord_Header) {
|
||||
return headerRepository.save(dashbord_Header);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Dashbord1_Line update_Dashbord1_Line(Dashbord1_Line dashbord1_Line) {
|
||||
// TODO Auto-generated method stub
|
||||
return dashboard_lineRepository.save(dashbord1_Line);
|
||||
}
|
||||
|
||||
|
||||
public List<Dashbord_Header> get_by_module_id(int module_id) {
|
||||
// TODO Auto-generated method stub
|
||||
return (List<Dashbord_Header>) headerRepository.findbydashboardmodule(module_id);
|
||||
}
|
||||
|
||||
|
||||
public List<Dashbord1_Line> get_all_lines() {
|
||||
// TODO Auto-generated method stub
|
||||
return (List<Dashbord1_Line>) dashboard_lineRepository.findAll();
|
||||
@@ -78,22 +69,16 @@ public class HeaderService {
|
||||
|
||||
public Dashbord1_Line update_Dashbord1_Lineby_id(int id, Dashbord1_Line dashbord1_Line) {
|
||||
|
||||
|
||||
Dashbord1_Line oldline= dashboard_lineRepository.findById(id);
|
||||
Dashbord1_Line oldline = dashboard_lineRepository.findById(id);
|
||||
// .orElseThrow(() -> new ResourceNotFoundException(Constant.NOT_FOUND_EXCEPTION + " :" + id));
|
||||
|
||||
|
||||
oldline.setAccountId(dashbord1_Line.getAccountId());
|
||||
oldline.setHeader_id(dashbord1_Line.getHeader_id());
|
||||
oldline.setModel(dashbord1_Line.getModel());
|
||||
final Dashbord1_Line newline= dashboard_lineRepository.save(oldline);
|
||||
oldline.setCommon_filter(dashbord1_Line.getCommon_filter());
|
||||
|
||||
final Dashbord1_Line newline = dashboard_lineRepository.save(oldline);
|
||||
return newline;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,14 +8,23 @@ import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -24,7 +33,10 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.realnet.Payment.Paytm.PaytmPayment;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.realnet.SureConnect.Entities.Sure_Connect;
|
||||
import com.realnet.SureConnect.Service.SureService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -34,6 +46,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
public class ChartBuilder {
|
||||
|
||||
@Autowired
|
||||
private SureService sureService;
|
||||
|
||||
public List<Map<String, Object>> getAllDataFromTable(String tableName) {
|
||||
List<Map<String, Object>> tableData = new ArrayList<>();
|
||||
|
||||
@@ -101,95 +116,74 @@ public class ChartBuilder {
|
||||
return tableData;
|
||||
}
|
||||
|
||||
//...........................22.07.2023.............................//
|
||||
@GetMapping(value = "/getValue")
|
||||
public ResponseEntity<?> getValue(@RequestParam String apiUrl, @RequestParam Integer sureId,
|
||||
@RequestParam(required = false) String key) throws IOException {
|
||||
|
||||
// @GetMapping(value = "/getdashjson/{job_type}")
|
||||
// public ResponseEntity<?> jsonretun(@RequestParam String tableName, @PathVariable String job_type,
|
||||
// @RequestParam String xAxis, @RequestParam String yAxis) throws IOException {
|
||||
//
|
||||
// List<Map<String, Object>> tableData = getAllDataFromTable(tableName); // Retrieve all data from the table
|
||||
//
|
||||
// List<Object> yAxisValues = new ArrayList<>();
|
||||
// List<String> xAxisValues = new ArrayList<>();
|
||||
//
|
||||
// for (Map<String, Object> row : tableData) {
|
||||
// for (Entry<String, Object> entry : row.entrySet()) {
|
||||
// String key = entry.getKey();
|
||||
// Object value = entry.getValue();
|
||||
//
|
||||
// if (key.equalsIgnoreCase(xAxis)) {
|
||||
// xAxisValues.add(value.toString());
|
||||
// } else if (key.equalsIgnoreCase(yAxis)) {
|
||||
// yAxisValues.add(value);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// StringBuilder jsonmap = new StringBuilder();
|
||||
//
|
||||
// if (job_type.equalsIgnoreCase("Bar Chart")) {
|
||||
// jsonmap.append("[\n");
|
||||
// } else if (job_type.equalsIgnoreCase("Line Chart")) {
|
||||
// jsonmap.append(" {\r\n" + " \"chartData\": [\r\n" + " { \"data\": [");
|
||||
// } else if (job_type.equalsIgnoreCase("Doughnut Chart")) {
|
||||
// jsonmap.append("{\"chartData\": [[");
|
||||
// }
|
||||
//
|
||||
// for (int i = 0; i < xAxisValues.size(); i++) {
|
||||
// String xValue = xAxisValues.get(i);
|
||||
// Object yValue = yAxisValues.get(i);
|
||||
//
|
||||
// if (job_type.equalsIgnoreCase("Bar Chart")) {
|
||||
// jsonmap.append("{\"name\": \"" + xValue + "\", \"progress\":\"" + yValue + "\"},\n");
|
||||
// } else if (job_type.equalsIgnoreCase("Line Chart")) {
|
||||
// jsonmap.append(yValue + ",");
|
||||
// } else if (job_type.equalsIgnoreCase("Doughnut Chart")) {
|
||||
// jsonmap.append(yValue + ",");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!xAxisValues.isEmpty() && !yAxisValues.isEmpty()) {
|
||||
// jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
// }
|
||||
//
|
||||
// if (job_type.equalsIgnoreCase("Bar Chart")) {
|
||||
// jsonmap.append("]");
|
||||
// } else if (job_type.equalsIgnoreCase("Line Chart")) {
|
||||
// jsonmap.append("], \"label\": \"" + yAxis + "\" }\r\n" + " ],\r\n" + " \"chartLabels\": [ ");
|
||||
// } else if (job_type.equalsIgnoreCase("Doughnut Chart")) {
|
||||
// jsonmap.append("]],\r\n" + " \"chartLabels\": [");
|
||||
// }
|
||||
//
|
||||
// for (String xValue : xAxisValues) {
|
||||
// jsonmap.append("\"" + xValue + "\",");
|
||||
// }
|
||||
//
|
||||
// if (!xAxisValues.isEmpty()) {
|
||||
// jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
// }
|
||||
//
|
||||
// if (job_type.equalsIgnoreCase("Line Chart")) {
|
||||
// jsonmap.append("] \n }\n");
|
||||
// } else if (job_type.equalsIgnoreCase("Doughnut Chart")) {
|
||||
// jsonmap.append("]\n" + "}");
|
||||
// }
|
||||
//
|
||||
// return new ResponseEntity<>(jsonmap.toString(), HttpStatus.CREATED);
|
||||
// }
|
||||
System.out.println(" value get..");
|
||||
// Step 1: Fetch all table data from API
|
||||
List<Map<String, Object>> tableData = getAllDataFromApi(apiUrl, sureId);
|
||||
|
||||
// Step 2: Handle null or empty key
|
||||
if (key == null || key.trim().isEmpty()) {
|
||||
return ResponseEntity.badRequest().body("Key parameter is required");
|
||||
}
|
||||
|
||||
// Step 3: Extract unique values for that key
|
||||
Set<Object> uniqueValues = tableData.stream().map(row -> row.get(key)) // get value by key
|
||||
.filter(Objects::nonNull) // remove nulls
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new)); // keep unique + order
|
||||
|
||||
// Step 4: Convert to List
|
||||
List<Object> resultList = new ArrayList<>(uniqueValues);
|
||||
|
||||
// Step 5: Return as ResponseEntity
|
||||
return ResponseEntity.ok(resultList);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/getdashjson/{job_type}")
|
||||
public ResponseEntity<?> jsonretun2(@RequestParam String tableName, @PathVariable String job_type,
|
||||
@RequestParam(required = false) String xAxis, @RequestParam(required = false) List<String> yAxes)
|
||||
public ResponseEntity<?> jsonretun(@PathVariable String job_type, @RequestParam String tableName,
|
||||
@RequestParam(required = false) String xAxis, @RequestParam(required = false) List<String> yAxes,
|
||||
@RequestParam Integer sureId, @RequestParam(required = false) String parameter,
|
||||
@RequestParam(required = false) String parameterValue, @RequestParam(required = false) String filters)
|
||||
throws IOException {
|
||||
|
||||
System.out.println(" chart data getting...");
|
||||
|
||||
List<Map<String, Object>> tableData = getAllDataFromApi(tableName, sureId); // Retrieve all data from the table
|
||||
|
||||
// ✅ Filter table data if parameter and parameterValue are provided
|
||||
if (parameter != null && !parameter.trim().isEmpty() && parameterValue != null
|
||||
&& !parameterValue.trim().isEmpty()) {
|
||||
|
||||
tableData = tableData.stream().filter(row -> {
|
||||
Object paramVal = row.get(parameter);
|
||||
return paramVal != null && paramVal.toString().equalsIgnoreCase(parameterValue);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
// ✅ Parse filters JSON (supports both string and array values)
|
||||
if (filters != null && !filters.trim().isEmpty()) {
|
||||
Map<String, Object> filtersMap;
|
||||
try {
|
||||
filtersMap = mapper.readValue(filters, new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>("Invalid filters JSON format", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
// ✅ Call reusable filter method
|
||||
tableData = applyFilters(tableData, filtersMap);
|
||||
}
|
||||
|
||||
StringBuilder jsonmap = new StringBuilder();
|
||||
|
||||
if (job_type.equalsIgnoreCase("Grid View")) {
|
||||
List<Map<String, Object>> allData = getAllDataFromApi(tableName);
|
||||
if (job_type.equalsIgnoreCase("Grid")) {
|
||||
|
||||
jsonmap.append("[\n");
|
||||
|
||||
for (Map<String, Object> row : allData) {
|
||||
for (Map<String, Object> row : tableData) {
|
||||
jsonmap.append("{\n");
|
||||
|
||||
int colCount = 0;
|
||||
@@ -208,7 +202,7 @@ public class ChartBuilder {
|
||||
|
||||
jsonmap.append("}");
|
||||
|
||||
if (!row.equals(allData.get(allData.size() - 1))) {
|
||||
if (!row.equals(tableData.get(tableData.size() - 1))) {
|
||||
jsonmap.append(", ");
|
||||
}
|
||||
}
|
||||
@@ -219,12 +213,11 @@ public class ChartBuilder {
|
||||
}
|
||||
|
||||
if (job_type.equalsIgnoreCase("Todo List") && yAxes != null && !yAxes.isEmpty()) {
|
||||
List<Map<String, Object>> allData = getAllDataFromApi(tableName);
|
||||
|
||||
String listName = yAxes.get(0); // Assuming the first column in yAxes to be the list name
|
||||
List<Object> listData = new ArrayList<>();
|
||||
|
||||
for (Map<String, Object> row : allData) {
|
||||
for (Map<String, Object> row : tableData) {
|
||||
Object value = row.get(listName);
|
||||
|
||||
if (value != null) {
|
||||
@@ -239,10 +232,9 @@ public class ChartBuilder {
|
||||
return new ResponseEntity<>(response, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> tableData = getAllDataFromApi(tableName); // Retrieve all data from the table
|
||||
|
||||
List<List<Object>> yAxisValuesList = new ArrayList<>();
|
||||
List<String> xAxisValues = new ArrayList<>();
|
||||
List<String> parameterValues = new ArrayList<>();
|
||||
|
||||
// Initialize a list for each y-axis parameter
|
||||
for (int i = 0; i < yAxes.size(); i++) {
|
||||
@@ -254,7 +246,7 @@ public class ChartBuilder {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
|
||||
if (key.equalsIgnoreCase(xAxis)) {
|
||||
if (value != null && key.equalsIgnoreCase(xAxis)) {
|
||||
xAxisValues.add(value.toString());
|
||||
} else {
|
||||
int yIndex = yAxes.indexOf(key);
|
||||
@@ -262,50 +254,56 @@ public class ChartBuilder {
|
||||
yAxisValuesList.get(yIndex).add(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (job_type.equalsIgnoreCase("Bar Chart")) {
|
||||
jsonmap.append("{\n \"barChartData\": [\n");
|
||||
jsonmap = getJson(jsonmap, yAxes, xAxisValues, yAxisValuesList, parameterValues);
|
||||
|
||||
for (int j = 0; j < yAxes.size(); j++) {
|
||||
String yAxis = yAxes.get(j);
|
||||
|
||||
jsonmap.append("{");
|
||||
jsonmap.append("\"data\": [");
|
||||
|
||||
for (int i = 0; i < xAxisValues.size(); i++) {
|
||||
Object yValue = yAxisValuesList.get(j).get(i);
|
||||
jsonmap.append(yValue);
|
||||
|
||||
if (i < xAxisValues.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
return new ResponseEntity<>(jsonmap.toString(), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
jsonmap.append("],");
|
||||
jsonmap.append("\"label\": \"" + yAxis + "\"");
|
||||
jsonmap.append("}");
|
||||
/**
|
||||
* ✅ Reusable filter method Supports both single-value and multi-value filters
|
||||
*/
|
||||
private List<Map<String, Object>> applyFilters(List<Map<String, Object>> tableData,
|
||||
Map<String, Object> filtersMap) {
|
||||
if (filtersMap == null || filtersMap.isEmpty())
|
||||
return tableData;
|
||||
|
||||
if (j < yAxes.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
return tableData.stream().filter(row -> {
|
||||
for (Map.Entry<String, Object> entry : filtersMap.entrySet()) {
|
||||
Object filterValue = entry.getValue();
|
||||
Object rowValue = row.get(entry.getKey());
|
||||
|
||||
// skip empty filters
|
||||
if (filterValue == null)
|
||||
continue;
|
||||
|
||||
// ✅ Multi-value filter (List or Array)
|
||||
if (filterValue instanceof List<?>) {
|
||||
List<?> filterList = (List<?>) filterValue;
|
||||
if (filterList.isEmpty())
|
||||
continue;
|
||||
if (rowValue == null
|
||||
|| !filterList.stream().anyMatch(v -> v.toString().equalsIgnoreCase(rowValue.toString()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],\n \"barChartLabels\": [ ");
|
||||
|
||||
for (String xValue : xAxisValues) {
|
||||
jsonmap.append("\"" + xValue + "\",");
|
||||
// ✅ Single-value filter
|
||||
else {
|
||||
if (rowValue == null || !rowValue.toString().equalsIgnoreCase(filterValue.toString())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (!xAxisValues.isEmpty()) {
|
||||
jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
}
|
||||
public StringBuilder getJson(StringBuilder jsonmap, List<String> yAxes, List<String> xAxisValues,
|
||||
List<List<Object>> yAxisValuesList, List<String> parameterValues) {
|
||||
|
||||
jsonmap.append("] \n }\n");
|
||||
}
|
||||
|
||||
else if (job_type.equalsIgnoreCase("Line Chart")) {
|
||||
jsonmap.append("{\n \"chartData\": [\n");
|
||||
|
||||
for (int j = 0; j < yAxes.size(); j++) {
|
||||
@@ -314,15 +312,39 @@ public class ChartBuilder {
|
||||
jsonmap.append("{");
|
||||
jsonmap.append("\"data\": [");
|
||||
|
||||
// --- Y-Axis Data ---
|
||||
for (int i = 0; i < xAxisValues.size(); i++) {
|
||||
Object yValue = yAxisValuesList.get(j).get(i);
|
||||
List<Object> list = yAxisValuesList.get(j);
|
||||
if (list == null || list.isEmpty() || i >= list.size()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object yValue = list.get(i);
|
||||
if (yValue instanceof Number) {
|
||||
jsonmap.append(yValue);
|
||||
} else if (yValue instanceof String) {
|
||||
String yStr = ((String) yValue).trim();
|
||||
try {
|
||||
Double num = Double.parseDouble(yStr);
|
||||
jsonmap.append(num);
|
||||
} catch (NumberFormatException e) {
|
||||
continue; // skip non-numeric
|
||||
}
|
||||
} else {
|
||||
continue; // skip invalid
|
||||
}
|
||||
|
||||
if (i < xAxisValues.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
// 🧹 Remove trailing comma
|
||||
int lastIndex = jsonmap.lastIndexOf(",");
|
||||
if (lastIndex == jsonmap.length() - 1) {
|
||||
jsonmap.deleteCharAt(lastIndex);
|
||||
}
|
||||
|
||||
jsonmap.append("],");
|
||||
jsonmap.append("\"label\": \"" + yAxis + "\"");
|
||||
jsonmap.append("}");
|
||||
@@ -332,291 +354,48 @@ public class ChartBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],\n \"chartLabels\": [ ");
|
||||
|
||||
for (String xValue : xAxisValues) {
|
||||
jsonmap.append("\"" + xValue + "\",");
|
||||
}
|
||||
|
||||
if (!xAxisValues.isEmpty()) {
|
||||
jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
}
|
||||
|
||||
jsonmap.append("] \n }\n");
|
||||
} else if (job_type.equalsIgnoreCase("Doughnut Chart")) {
|
||||
jsonmap.append("{\"chartData\": [\n");
|
||||
|
||||
for (int j = 0; j < yAxes.size(); j++) {
|
||||
String yAxis = yAxes.get(j);
|
||||
|
||||
jsonmap.append("[");
|
||||
|
||||
for (int i = 0; i < xAxisValues.size(); i++) {
|
||||
Object yValue = yAxisValuesList.get(j).get(i);
|
||||
jsonmap.append(yValue);
|
||||
|
||||
if (i < xAxisValues.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("]");
|
||||
|
||||
if (j < yAxes.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
// --- Chart Labels (X-Axis) ---
|
||||
jsonmap.append("],\n \"chartLabels\": [");
|
||||
|
||||
for (String xValue : xAxisValues) {
|
||||
jsonmap.append("\"" + xValue + "\",");
|
||||
jsonmap.append("\"").append(xValue).append("\",");
|
||||
}
|
||||
|
||||
if (!xAxisValues.isEmpty()) {
|
||||
jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
}
|
||||
jsonmap.append("],");
|
||||
|
||||
// --- Parameter Values ---
|
||||
jsonmap.append("\n \"parameterValues\": [");
|
||||
if (parameterValues != null && !parameterValues.isEmpty()) {
|
||||
for (String param : parameterValues) {
|
||||
if (param != null && !param.trim().isEmpty()) {
|
||||
jsonmap.append("\"").append(param.trim()).append("\",");
|
||||
}
|
||||
}
|
||||
// Remove trailing comma
|
||||
int lastComma = jsonmap.lastIndexOf(",");
|
||||
if (lastComma == jsonmap.length() - 1) {
|
||||
jsonmap.deleteCharAt(lastComma);
|
||||
}
|
||||
}
|
||||
jsonmap.append("]\n}");
|
||||
|
||||
return jsonmap;
|
||||
}
|
||||
|
||||
else if (job_type.equalsIgnoreCase("Radar Chart")) {
|
||||
jsonmap.append("{\n \"radarChartData\": [\n");
|
||||
|
||||
for (int j = 0; j < yAxes.size(); j++) {
|
||||
String yAxis = yAxes.get(j);
|
||||
|
||||
jsonmap.append("{");
|
||||
jsonmap.append("\"data\": [");
|
||||
|
||||
for (int i = 0; i < xAxisValues.size(); i++) {
|
||||
Object yValue = yAxisValuesList.get(j).get(i);
|
||||
jsonmap.append(yValue);
|
||||
|
||||
if (i < xAxisValues.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
@GetMapping("/getAllKeys")
|
||||
public Set<String> getAllKeys(@RequestParam String apiUrl, @RequestParam Integer sureId) {
|
||||
List<Map<String, Object>> apiData = getAllKeyFromApi(apiUrl, sureId);
|
||||
return getAllKeys(apiData);
|
||||
}
|
||||
|
||||
jsonmap.append("],");
|
||||
jsonmap.append("\"label\": \"" + yAxis + "\"");
|
||||
jsonmap.append("}");
|
||||
|
||||
if (j < yAxes.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],\n \"radarChartLabels\": [ ");
|
||||
|
||||
for (String xValue : xAxisValues) {
|
||||
jsonmap.append("\"" + xValue + "\",");
|
||||
}
|
||||
|
||||
if (!xAxisValues.isEmpty()) {
|
||||
jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
}
|
||||
|
||||
jsonmap.append("] \n }\n");
|
||||
}
|
||||
|
||||
else if (job_type.equalsIgnoreCase("PolarArea Chart")) {
|
||||
jsonmap.append("{\n \"polarAreaChartData\": [\n");
|
||||
|
||||
for (int j = 0; j < yAxes.size(); j++) {
|
||||
String yAxis = yAxes.get(j);
|
||||
|
||||
jsonmap.append("{");
|
||||
jsonmap.append("\"data\": [");
|
||||
|
||||
for (int i = 0; i < xAxisValues.size(); i++) {
|
||||
Object yValue = yAxisValuesList.get(j).get(i);
|
||||
jsonmap.append(yValue);
|
||||
|
||||
if (i < xAxisValues.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],");
|
||||
jsonmap.append("\"label\": \"" + yAxis + "\"");
|
||||
jsonmap.append("}");
|
||||
|
||||
if (j < yAxes.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],\n \"polarAreaChartLabels\": [ ");
|
||||
|
||||
for (String xValue : xAxisValues) {
|
||||
jsonmap.append("\"" + xValue + "\",");
|
||||
}
|
||||
|
||||
if (!xAxisValues.isEmpty()) {
|
||||
jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
}
|
||||
|
||||
jsonmap.append("] \n }\n");
|
||||
}
|
||||
|
||||
if (job_type.equalsIgnoreCase("Pie Chart")) {
|
||||
jsonmap.append("{\n \"pieChartData\": [");
|
||||
|
||||
for (int i = 0; i < yAxisValuesList.get(0).size(); i++) { // Assuming "mark" is the first item in yAxes
|
||||
jsonmap.append(yAxisValuesList.get(0).get(i)); // Use the y-axis values
|
||||
|
||||
if (i < yAxisValuesList.get(0).size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],\n \"pieChartLabels\": [ ");
|
||||
|
||||
for (int i = 0; i < xAxisValues.size(); i++) { // Assuming "name" is the x-axis
|
||||
jsonmap.append("\"" + xAxisValues.get(i) + "\""); // Use the x-axis values
|
||||
|
||||
if (i < xAxisValues.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("] \n }\n");
|
||||
}
|
||||
|
||||
else if (job_type.equalsIgnoreCase("Bubble Chart")) {
|
||||
jsonmap.append("{\n \"bubbleChartData\": [\n");
|
||||
|
||||
for (int j = 0; j < yAxes.size(); j++) {
|
||||
String yAxis = yAxes.get(j);
|
||||
|
||||
jsonmap.append("{");
|
||||
jsonmap.append("\"data\": [");
|
||||
|
||||
for (int i = 0; i < xAxisValues.size(); i++) {
|
||||
Object xValue = xAxisValues.get(i);
|
||||
Object yValue = yAxisValuesList.get(j).get(i);
|
||||
int radius = 5 + (i % 3) * 3; // Adjust the radius as needed
|
||||
|
||||
jsonmap.append("{ \"x\": " + xValue + ", \"y\": " + yValue + ", \"r\": " + radius + "}");
|
||||
|
||||
if (i < xAxisValues.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],");
|
||||
jsonmap.append("\"label\": \"" + yAxis + "\"");
|
||||
jsonmap.append("}");
|
||||
|
||||
if (j < yAxes.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],\n \"bubbleChartLabels\": [ ");
|
||||
|
||||
for (String label : xAxisValues) {
|
||||
jsonmap.append("\"" + label + "\",");
|
||||
}
|
||||
|
||||
if (!xAxisValues.isEmpty()) {
|
||||
jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
}
|
||||
|
||||
jsonmap.append("] \n }\n");
|
||||
} else if (job_type.equalsIgnoreCase("Scatter Chart")) {
|
||||
jsonmap.append("{\n \"scatterChartData\": [\n");
|
||||
|
||||
for (int j = 0; j < yAxes.size(); j++) {
|
||||
String yAxis = yAxes.get(j);
|
||||
|
||||
jsonmap.append("{");
|
||||
jsonmap.append("\"data\": [");
|
||||
|
||||
for (int i = 0; i < xAxisValues.size(); i++) {
|
||||
Object xValue = xAxisValues.get(i);
|
||||
Object yValue = yAxisValuesList.get(j).get(i);
|
||||
|
||||
jsonmap.append("{ \"x\": " + xValue + ", \"y\": " + yValue + "}");
|
||||
|
||||
if (i < xAxisValues.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],");
|
||||
jsonmap.append("\"label\": \"" + yAxis + "\"");
|
||||
jsonmap.append("}");
|
||||
|
||||
if (j < yAxes.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],\n \"scatterChartLabels\": [ ");
|
||||
|
||||
for (String label : xAxisValues) {
|
||||
jsonmap.append("\"" + label + "\",");
|
||||
}
|
||||
|
||||
if (!xAxisValues.isEmpty()) {
|
||||
jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
}
|
||||
|
||||
jsonmap.append("] \n }\n");
|
||||
}
|
||||
|
||||
else if (job_type.equalsIgnoreCase("Dynamic Chart")) {
|
||||
jsonmap.append("{\n \"dynamicChartData\": [\n");
|
||||
|
||||
for (int j = 0; j < yAxes.size(); j++) {
|
||||
String yAxis = yAxes.get(j);
|
||||
|
||||
jsonmap.append("{");
|
||||
jsonmap.append("\"data\": [");
|
||||
|
||||
for (int i = 0; i < xAxisValues.size(); i++) {
|
||||
Object yValue = yAxisValuesList.get(j).get(i);
|
||||
jsonmap.append(yValue);
|
||||
|
||||
if (i < xAxisValues.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],");
|
||||
jsonmap.append("\"label\": \"" + yAxis + "\"");
|
||||
jsonmap.append("}");
|
||||
|
||||
if (j < yAxes.size() - 1) {
|
||||
jsonmap.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
jsonmap.append("],\n \"dynamicChartLabels\": [ ");
|
||||
|
||||
for (String xValue : xAxisValues) {
|
||||
jsonmap.append("\"" + xValue + "\",");
|
||||
}
|
||||
|
||||
if (!xAxisValues.isEmpty()) {
|
||||
jsonmap.deleteCharAt(jsonmap.lastIndexOf(","));
|
||||
}
|
||||
|
||||
jsonmap.append("] \n }\n");
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(jsonmap.toString(), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
// @GetMapping("/getKey")
|
||||
public List<Map<String, Object>> getAllKeyFromApi(String apiUrl) {
|
||||
public List<Map<String, Object>> getAllKeyFromApi(String apiUrl, Integer sureId) {
|
||||
List<Map<String, Object>> apiData = new ArrayList<>();
|
||||
|
||||
try {
|
||||
// Make a GET request using the provided URL
|
||||
ResponseEntity<Object> responseEntity = GET(apiUrl);
|
||||
ResponseEntity<Object> responseEntity = GETWithObject(apiUrl, sureId);
|
||||
|
||||
// Convert the response to a List<Map<String, Object>>
|
||||
if (responseEntity.getBody() instanceof List) {
|
||||
@@ -636,12 +415,6 @@ public class ChartBuilder {
|
||||
return apiData;
|
||||
}
|
||||
|
||||
@GetMapping("/getAllKeys")
|
||||
public Set<String> getAllKeys(@RequestParam String apiUrl) {
|
||||
List<Map<String, Object>> apiData = getAllKeyFromApi(apiUrl);
|
||||
return getAllKeys(apiData);
|
||||
}
|
||||
|
||||
private Set<String> getAllKeys(List<Map<String, Object>> apiData) {
|
||||
Set<String> allKeys = new HashSet<>();
|
||||
|
||||
@@ -652,12 +425,12 @@ public class ChartBuilder {
|
||||
return allKeys;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getAllDataFromApi(String apiUrl) {
|
||||
public List<Map<String, Object>> getAllDataFromApi(String apiUrl, Integer sureId) {
|
||||
List<Map<String, Object>> apiData = new ArrayList<>();
|
||||
|
||||
try {
|
||||
// Make a GET request using the provided URL
|
||||
ResponseEntity<Object> responseEntity = GET(apiUrl);
|
||||
ResponseEntity<Object> responseEntity = GETWithObject(apiUrl, sureId);
|
||||
|
||||
// Convert the response to a List<Map<String, Object>>
|
||||
if (responseEntity.getBody() instanceof List) {
|
||||
@@ -678,7 +451,7 @@ public class ChartBuilder {
|
||||
return apiData;
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> GET(String get) {
|
||||
public ResponseEntity<Object> GET1(String get) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
ResponseEntity<Object> u = restTemplate.getForEntity(get, Object.class);
|
||||
@@ -686,4 +459,52 @@ public class ChartBuilder {
|
||||
return u;
|
||||
|
||||
}
|
||||
|
||||
public ResponseEntity<String> GET(String url, Integer sureid) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.ALL)); // accept JSON or XML
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
// 🔹 Add your token here (you can make it dynamic)
|
||||
String token = getToken(sureid); // helper method (see below)
|
||||
if (token != null && !token.isEmpty()) {
|
||||
headers.set("Authorization", "Bearer " + token);
|
||||
}
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> GETWithObject(String url, Integer sureid) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.ALL)); // accept JSON or XML
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
// 🔹 Add your token here (you can make it dynamic)
|
||||
String token = getToken(sureid); // helper method (see below)
|
||||
if (token != null && !token.isEmpty()) {
|
||||
headers.set("Authorization", "Bearer " + token);
|
||||
}
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
|
||||
ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.GET, entity, Object.class);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private String getToken(Integer sureid) {
|
||||
Sure_Connect connect = sureService.getbyid(sureid);
|
||||
String access_token = connect.getAccess_token();
|
||||
|
||||
return access_token; // optional
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
||||
package com.realnet.Dashboard_builder.Controllers;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
public class DashboardMockController {
|
||||
|
||||
@GetMapping("/api/getDummyDashboardData")
|
||||
public ResponseEntity<List<Map<String, Object>>> getDummyDashboardData() {
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
|
||||
String[] salesReps = { "Gaurav", "Ravi", "Ankit", "Neha", "Kiran" };
|
||||
String[] partners = { "IBM", "Microsoft", "TCS", "Infosys", "Wipro" };
|
||||
String[] regions = { "Asia", "Europe", "North America", "South America", "Africa" };
|
||||
String[] channels = { "Online", "Retail", "Direct", "Distributor", "Reseller" };
|
||||
String[] products = { "Laptops", "Servers", "Networking", "Cloud", "AI" };
|
||||
|
||||
for (int i = 1; i <= 50; i++) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
|
||||
// 🧩 Fixed pattern numeric data
|
||||
row.put("leadCount", 100 + (i * 10));
|
||||
row.put("dealValue", 5000 + (i * 750));
|
||||
row.put("conversionRate", (i % 100));
|
||||
row.put("activeUsers", 50 + (i * 5));
|
||||
row.put("visits", 200 + (i * 15));
|
||||
|
||||
// 🧠 Repeated pattern text data
|
||||
row.put("salesRep", salesReps[i % salesReps.length]);
|
||||
row.put("partner", partners[i % partners.length]);
|
||||
row.put("region", regions[i % regions.length]);
|
||||
row.put("channel", channels[i % channels.length]);
|
||||
row.put("productLine", products[i % products.length]);
|
||||
|
||||
// 📅 Sequential date data
|
||||
row.put("createdDate", LocalDate.of(2024, (i % 12) + 1, ((i % 28) + 1)));
|
||||
row.put("lastUpdated", LocalDate.of(2025, ((i + 2) % 12) + 1, ((i + 3) % 28) + 1));
|
||||
|
||||
dataList.add(row);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(dataList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.realnet.DataLake.Controllers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.realnet.DataLake.Entity.Data_lake;
|
||||
import com.realnet.DataLake.Services.DataLakeActionService;
|
||||
import com.realnet.DataLake.Services.Data_lakeService;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
|
||||
@RequestMapping(value = "/Data_lake")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class Data_lakeController {
|
||||
@Autowired
|
||||
private Data_lakeService Service;
|
||||
|
||||
@Autowired
|
||||
private DataLakeActionService lakeActionService;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
@PostMapping("/Data_lake")
|
||||
public Data_lake Savedata(@RequestBody Data_lake data) {
|
||||
Data_lake save = Service.Savedata(data);
|
||||
|
||||
System.out.println("data saved..." + save);
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
@PutMapping("/Data_lake/{id}")
|
||||
public Data_lake update(@RequestBody Data_lake data, @PathVariable Integer id) {
|
||||
Data_lake update = Service.update(data, id);
|
||||
System.out.println("data update..." + update);
|
||||
return update;
|
||||
}
|
||||
|
||||
@GetMapping("/Data_lake/webhook/{id}")
|
||||
public Data_lake enableWebhook(@PathVariable Integer id) {
|
||||
Data_lake update = Service.enableWebHook(id);
|
||||
|
||||
System.out.println("webhook enabled..." + update);
|
||||
return update;
|
||||
}
|
||||
|
||||
@GetMapping("/Data_lake/keys/{lakeid}")
|
||||
public Map<String, Object> getAllKeys(@PathVariable Integer lakeid) throws JsonProcessingException {
|
||||
Map<String, Object> update = lakeActionService.getAllKeys(lakeid);
|
||||
System.out.println("get all keys and header successfully...");
|
||||
return update;
|
||||
}
|
||||
|
||||
// get all with pagination
|
||||
@GetMapping("/Data_lake/getall/page")
|
||||
public Page<Data_lake> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "size", required = false) Integer size) {
|
||||
Pageable paging = PageRequest.of(page, size);
|
||||
Page<Data_lake> get = Service.getAllWithPagination(paging);
|
||||
|
||||
return get;
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/Data_lake")
|
||||
public List<Data_lake> getdetails() {
|
||||
List<Data_lake> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
// get all without authentication
|
||||
|
||||
@GetMapping("/token/Data_lake")
|
||||
public List<Data_lake> getallwioutsec() {
|
||||
List<Data_lake> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
|
||||
@GetMapping("/Data_lake/{id}")
|
||||
public Data_lake getdetailsbyId(@PathVariable Integer id) {
|
||||
Data_lake get = Service.getdetailsbyId(id);
|
||||
return get;
|
||||
}
|
||||
|
||||
@DeleteMapping("/Data_lake/{id}")
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Integer id) {
|
||||
Service.delete_by_id(id);
|
||||
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
// json Upadted
|
||||
|
||||
@PutMapping("/Data_lake/json/{id}")
|
||||
public Data_lake update(@PathVariable Integer id) throws JsonProcessingException {
|
||||
Data_lake update = lakeActionService.applyCalculation(id);
|
||||
System.out.println("clculation applied..." + update);
|
||||
return update;
|
||||
}
|
||||
|
||||
@GetMapping("/Data_lake/merge/{id}")
|
||||
public ResponseEntity<?> mergeBatchData(@PathVariable Integer id) {
|
||||
try {
|
||||
// Get merged JSON string from service
|
||||
String mergedJson = lakeActionService.mergeBatchData(id);
|
||||
|
||||
// Parse the merged JSON string back into JSON structure
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode jsonNode = mapper.readTree(mergedJson);
|
||||
|
||||
// Return as actual JSON (not as string)
|
||||
return ResponseEntity.ok(jsonNode);
|
||||
|
||||
} catch (Exception e) {
|
||||
// Build error response manually (Map.of() not available in Java 8)
|
||||
Map<String, String> error = new HashMap<>();
|
||||
error.put("error", e.getMessage());
|
||||
return ResponseEntity.status(500).body(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.realnet.DataLake.Controllers;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
@RequestMapping("/token/api")
|
||||
public class XmlApiExample {
|
||||
|
||||
@GetMapping(value = "/getUser", produces = MediaType.APPLICATION_XML_VALUE)
|
||||
public User getUser() {
|
||||
User user = new User();
|
||||
user.setId(101);
|
||||
user.setName("John Doe");
|
||||
user.setEmail("john.doe@example.com");
|
||||
return user;
|
||||
}
|
||||
|
||||
// Dummy XML model class
|
||||
@XmlRootElement(name = "user")
|
||||
public static class User {
|
||||
private int id;
|
||||
private String name;
|
||||
private String email;
|
||||
|
||||
// Getters and setters
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.realnet.DataLake.Controllers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.realnet.DataLake.Entity.Data_lake;
|
||||
import com.realnet.DataLake.Services.DataLakeActionService;
|
||||
import com.realnet.DataLake.Services.Data_lakeService;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
|
||||
@RequestMapping(value = "/token/Data_lake")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class tokenFree_Data_lakeController {
|
||||
@Autowired
|
||||
private Data_lakeService Service;
|
||||
|
||||
@Autowired
|
||||
private DataLakeActionService lakeActionService;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
@PostMapping("/Data_lake")
|
||||
public Data_lake Savedata(@RequestBody Data_lake data) {
|
||||
Data_lake save = Service.Savedata(data);
|
||||
|
||||
System.out.println("data saved..." + save);
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
@PutMapping("/Data_lake/{id}")
|
||||
public Data_lake update(@RequestBody Data_lake data, @PathVariable Integer id) {
|
||||
Data_lake update = Service.update(data, id);
|
||||
System.out.println("data update..." + update);
|
||||
return update;
|
||||
}
|
||||
|
||||
// get all with pagination
|
||||
@GetMapping("/Data_lake/getall/page")
|
||||
public Page<Data_lake> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "size", required = false) Integer size) {
|
||||
Pageable paging = PageRequest.of(page, size);
|
||||
Page<Data_lake> get = Service.getAllWithPagination(paging);
|
||||
|
||||
return get;
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/Data_lake")
|
||||
public List<Data_lake> getdetails() {
|
||||
List<Data_lake> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
// get all without authentication
|
||||
|
||||
@GetMapping("/token/Data_lake")
|
||||
public List<Data_lake> getallwioutsec() {
|
||||
List<Data_lake> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
|
||||
@GetMapping("/Data_lake/{id}")
|
||||
public Data_lake getdetailsbyId(@PathVariable Integer id) {
|
||||
Data_lake get = Service.getdetailsbyId(id);
|
||||
return get;
|
||||
}
|
||||
|
||||
@DeleteMapping("/Data_lake/{id}")
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Integer id) {
|
||||
Service.delete_by_id(id);
|
||||
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/Data_lake/merge/{id}")
|
||||
public ResponseEntity<?> mergeBatchData(@PathVariable Integer id) {
|
||||
try {
|
||||
// Get merged JSON string from service
|
||||
String mergedJson = lakeActionService.mergeBatchData(id);
|
||||
|
||||
// Parse the merged JSON string back into JSON structure
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode jsonNode = mapper.readTree(mergedJson);
|
||||
|
||||
// Return as actual JSON (not as string)
|
||||
return ResponseEntity.ok(jsonNode);
|
||||
|
||||
} catch (Exception e) {
|
||||
// Build error response manually (Map.of() not available in Java 8)
|
||||
Map<String, String> error = new HashMap<>();
|
||||
error.put("error", e.getMessage());
|
||||
return ResponseEntity.status(500).body(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.realnet.DataLake.Entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Lob;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class BatchData {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
private Integer datalake_id;
|
||||
|
||||
@Lob
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String batchjson;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.realnet.DataLake.Entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Lob;
|
||||
|
||||
import com.realnet.WhoColumn.Entity.Extension;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Data_lake extends Extension {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
|
||||
private String schedule;
|
||||
|
||||
private String cron_job;
|
||||
|
||||
private String randomnumber;
|
||||
|
||||
private String webhook_url;
|
||||
|
||||
@Lob
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String json;
|
||||
|
||||
private Integer batch_volume;
|
||||
|
||||
private Integer sure_connect_id;
|
||||
private String sureconnect_name;
|
||||
|
||||
private String url_endpoint;
|
||||
|
||||
private Integer ref_datalake_id;
|
||||
|
||||
private String datalake_type;
|
||||
|
||||
private String blending_lakeids;
|
||||
|
||||
@Lob
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String calculated_field_json;
|
||||
|
||||
@Lob
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String groupby_json;
|
||||
|
||||
@Lob
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String sqlquery_json;
|
||||
|
||||
@Lob
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String mapping_json;
|
||||
|
||||
private Boolean iscalculatedfield;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.realnet.DataLake.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.DataLake.Entity.BatchData;
|
||||
|
||||
@Repository
|
||||
public interface BatchDataRepository extends JpaRepository<BatchData, Integer> {
|
||||
|
||||
@Query(value = "select * from batch_data where created_by=?1", nativeQuery = true)
|
||||
List<BatchData> findAll(Long creayedBy);
|
||||
|
||||
@Query(value = "select * from batch_data where created_by=?1", nativeQuery = true)
|
||||
Page<BatchData> findAll(Long creayedBy, Pageable page);
|
||||
|
||||
@Query(value = "select * from batch_data", nativeQuery = true)
|
||||
List<BatchData> findByDatalake_id(Integer datalake_id);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.realnet.DataLake.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.DataLake.Entity.Data_lake;
|
||||
|
||||
@Repository
|
||||
public interface Data_lakeRepository extends JpaRepository<Data_lake, Integer> {
|
||||
|
||||
@Query(value = "select * from data_lake where created_by=?1", nativeQuery = true)
|
||||
List<Data_lake> findAll(Long creayedBy);
|
||||
|
||||
@Query(value = "select * from data_lake where created_by=?1", nativeQuery = true)
|
||||
Page<Data_lake> findAll(Long creayedBy, Pageable page);
|
||||
|
||||
@Query(value = "select * from data_lake where created_by=?1 && ref_datalake_id=?2", nativeQuery = true)
|
||||
List<Data_lake> findAllByRefDatlakeId(Long creayedBy, Integer ref_datalake_id);
|
||||
}
|
||||
@@ -0,0 +1,963 @@
|
||||
package com.realnet.DataLake.Services;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.realnet.DataLake.Entity.BatchData;
|
||||
import com.realnet.DataLake.Entity.Data_lake;
|
||||
import com.realnet.DataLake.Repository.BatchDataRepository;
|
||||
import com.realnet.DataLake.Repository.Data_lakeRepository;
|
||||
import com.realnet.SureConnect.Entities.Sure_Connect;
|
||||
import com.realnet.SureConnect.Service.SureService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.utils.Port_Constant;
|
||||
|
||||
@Service
|
||||
public class DataLakeActionService {
|
||||
@Autowired
|
||||
private Data_lakeRepository Repository;
|
||||
|
||||
@Autowired
|
||||
private BatchDataRepository batchRepo;
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
|
||||
@Autowired
|
||||
private SureService sureService;
|
||||
|
||||
// sql to json
|
||||
public Object sqltojson(Integer lakeid) {
|
||||
Data_lake lake = Repository.findById(lakeid).get();
|
||||
String datalake_type = lake.getDatalake_type();
|
||||
|
||||
Object responseBody = null; // 👈 this is what we’ll return
|
||||
|
||||
if (datalake_type.equalsIgnoreCase("blending") && lake.getBlending_lakeids() != null
|
||||
&& lake.getSqlquery_json() != null) {
|
||||
|
||||
String blending_lakeids = lake.getBlending_lakeids(); // e.g. "12,13"
|
||||
String sqlquery_json = lake.getSqlquery_json(); // e.g. "select * from gtest, gtest2"
|
||||
|
||||
// Step 1️⃣: Collect all child lakes
|
||||
String[] lakeIds = blending_lakeids.split(",");
|
||||
Map<String, JsonNode> lakeDataMap = new HashMap<>();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
for (String idStr : lakeIds) {
|
||||
int id = Integer.parseInt(idStr.trim());
|
||||
Data_lake child = Repository.findById(id).orElse(null);
|
||||
if (child == null)
|
||||
continue;
|
||||
|
||||
String url = child.getUrl_endpoint();
|
||||
|
||||
// ResponseEntity<String> response = GETWithString(url, child.getSure_connect_id());
|
||||
ResponseEntity<Object> response = GETWithObject(url, child.getSure_connect_id());
|
||||
|
||||
Object body = response.getBody();
|
||||
|
||||
try {
|
||||
|
||||
String rawBody = mapper.writeValueAsString(body);
|
||||
JsonNode data = mapper.readTree(rawBody);
|
||||
// Normalize to array
|
||||
if (!data.isArray()) {
|
||||
ArrayNode arr = mapper.createArrayNode();
|
||||
arr.add(data);
|
||||
data = arr;
|
||||
}
|
||||
lakeDataMap.put(child.getName().toLowerCase(), data);
|
||||
System.out.println("Loaded data for: " + child.getName());
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error parsing data from " + child.getName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2️⃣: Parse SQL for table names
|
||||
List<String> tables = extractTableNames(sqlquery_json);
|
||||
System.out.println("Tables in query: " + tables);
|
||||
|
||||
// Step 3️⃣: Perform JOIN or UNION based on query type
|
||||
ArrayNode result = mapper.createArrayNode();
|
||||
|
||||
if (sqlquery_json.toLowerCase().contains("join") || sqlquery_json.toLowerCase().contains("where")) {
|
||||
// Perform naive JOIN on common field names
|
||||
result = performJoin(mapper, lakeDataMap, tables);
|
||||
} else {
|
||||
// Perform simple UNION of all tables (cross merge)
|
||||
result = performUnion(mapper, lakeDataMap, tables);
|
||||
}
|
||||
|
||||
System.out.println("✅ Final blended JSON:");
|
||||
System.out.println(result.toPrettyString());
|
||||
// Step 4️⃣: Convert ArrayNode → Object for return
|
||||
try {
|
||||
responseBody = mapper.readValue(mapper.writeValueAsString(result), Object.class);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error converting result to Object: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return responseBody;
|
||||
|
||||
}
|
||||
|
||||
/** Extract table names from SQL query like "select * from gtest, gtest2" */
|
||||
private List<String> extractTableNames(String sql) {
|
||||
List<String> tables = new ArrayList<>();
|
||||
String lower = sql.toLowerCase();
|
||||
String regex = "from\\s+([a-zA-Z0-9_,\\s]+)";
|
||||
Matcher m = Pattern.compile(regex).matcher(lower);
|
||||
if (m.find()) {
|
||||
String group = m.group(1);
|
||||
for (String name : group.split(",")) {
|
||||
tables.add(name.trim());
|
||||
}
|
||||
}
|
||||
return tables;
|
||||
}
|
||||
|
||||
/** Simple union of all tables */
|
||||
private ArrayNode performUnion(ObjectMapper mapper, Map<String, JsonNode> lakeDataMap, List<String> tables) {
|
||||
ArrayNode result = mapper.createArrayNode();
|
||||
|
||||
for (String table : tables) {
|
||||
JsonNode data = lakeDataMap.get(table.toLowerCase());
|
||||
if (data == null)
|
||||
continue;
|
||||
|
||||
for (JsonNode row : data) {
|
||||
ObjectNode newRow = mapper.createObjectNode();
|
||||
Iterator<String> fields = row.fieldNames();
|
||||
while (fields.hasNext()) {
|
||||
String field = fields.next();
|
||||
newRow.put(table + "." + field, row.get(field).asText());
|
||||
}
|
||||
result.add(newRow);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Simple JOIN based on common keys */
|
||||
private ArrayNode performJoin(ObjectMapper mapper, Map<String, JsonNode> lakeDataMap, List<String> tables) {
|
||||
ArrayNode result = mapper.createArrayNode();
|
||||
if (tables.size() < 2)
|
||||
return result;
|
||||
|
||||
JsonNode first = lakeDataMap.get(tables.get(0).toLowerCase());
|
||||
JsonNode second = lakeDataMap.get(tables.get(1).toLowerCase());
|
||||
|
||||
if (first == null || second == null)
|
||||
return result;
|
||||
|
||||
// Find common key (like "id" or "emp_id")
|
||||
String joinKey = findCommonKey(first, second);
|
||||
|
||||
for (JsonNode row1 : first) {
|
||||
for (JsonNode row2 : second) {
|
||||
if (joinKey != null && row1.has(joinKey) && row2.has(joinKey)
|
||||
&& row1.get(joinKey).asText().equals(row2.get(joinKey).asText())) {
|
||||
|
||||
ObjectNode merged = mapper.createObjectNode();
|
||||
row1.fieldNames().forEachRemaining(f -> merged.put(tables.get(0) + "." + f, row1.get(f).asText()));
|
||||
row2.fieldNames().forEachRemaining(f -> merged.put(tables.get(1) + "." + f, row2.get(f).asText()));
|
||||
result.add(merged);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Finds a likely common join key between two datasets */
|
||||
private String findCommonKey(JsonNode a, JsonNode b) {
|
||||
Set<String> aKeys = new HashSet<>();
|
||||
a.get(0).fieldNames().forEachRemaining(aKeys::add);
|
||||
|
||||
Set<String> bKeys = new HashSet<>();
|
||||
b.get(0).fieldNames().forEachRemaining(bKeys::add);
|
||||
|
||||
for (String k : aKeys) {
|
||||
if (bKeys.contains(k))
|
||||
return k;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// get all keys of url endpoint
|
||||
public Map<String, Object> getAllKeys(Integer lakeid) throws JsonProcessingException {
|
||||
Data_lake old = Repository.findById(lakeid).get();
|
||||
String url = old.getUrl_endpoint();
|
||||
|
||||
ResponseEntity<String> response = GETMethodAsString(url, old.getSure_connect_id());
|
||||
|
||||
String rawBody = response.getBody();
|
||||
|
||||
ObjectMapper jsonMapper = new ObjectMapper();
|
||||
Object responseBody;
|
||||
|
||||
// Detect and convert if XML
|
||||
if (isXml(rawBody)) {
|
||||
try {
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
JsonNode xmlNode = xmlMapper.readTree(rawBody.getBytes());
|
||||
String jsonFromXml = jsonMapper.writeValueAsString(xmlNode);
|
||||
responseBody = jsonMapper.readValue(jsonFromXml, Object.class);
|
||||
System.out.println("XML detected and converted to JSON successfully.");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to convert XML to JSON: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
responseBody = jsonMapper.readValue(rawBody, Object.class);
|
||||
System.out.println("JSON response detected.");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Invalid JSON format: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
extractTableAndHeaders(result, responseBody);
|
||||
|
||||
// Add table name from database
|
||||
result.put("tableName", old.getName());
|
||||
|
||||
System.out.println("Keys extracted successfully.");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<String, Object> extractTableAndHeaders(Map<String, Object> result, Object responseBody) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
try {
|
||||
JsonNode root = mapper.valueToTree(responseBody);
|
||||
JsonNode firstNode = root.isArray() && root.size() > 0 ? root.get(0) : root;
|
||||
|
||||
Set<String> headers = new LinkedHashSet<>();
|
||||
Iterator<String> fieldNames = firstNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String field = fieldNames.next();
|
||||
if (!field.equalsIgnoreCase("tableName")) {
|
||||
headers.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
result.put("headers", headers);
|
||||
} catch (Exception e) {
|
||||
result.put("error", "Invalid JSON: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// apply calculated json
|
||||
public Data_lake applyCalculation(Integer id) throws JsonProcessingException {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
Data_lake old = Repository.findById(id).get();
|
||||
String datalake_type = old.getDatalake_type();
|
||||
if (datalake_type != null && datalake_type.equalsIgnoreCase("blending") && old.getBlending_lakeids() != null
|
||||
&& old.getSqlquery_json() != null) {
|
||||
|
||||
Object sqltojson = sqltojson(id);
|
||||
|
||||
String jsonString = mapper.writeValueAsString(sqltojson);
|
||||
old.setJson(jsonString);
|
||||
|
||||
// Process and insert into BatchData as before
|
||||
|
||||
// Process and insert into BatchData
|
||||
processBatchData(old, sqltojson, mapper);
|
||||
|
||||
String Url = Port_Constant.LOCALHOST + ":9292" + "/Data_lake/Data_lake/merge/" + old.getId();
|
||||
old.setUrl_endpoint(Url);
|
||||
|
||||
old.setUpdatedBy(getUser().getUserId());
|
||||
|
||||
final Data_lake saved = Repository.save(old);
|
||||
return saved;
|
||||
}
|
||||
|
||||
String url = old.getUrl();
|
||||
|
||||
ResponseEntity<Object> response = GETWithObject(url, old.getSure_connect_id());
|
||||
Object data = response.getBody();
|
||||
|
||||
String rawBody = mapper.writeValueAsString(data);
|
||||
try {
|
||||
|
||||
List<Data_lake> datlakes = Repository.findAllByRefDatlakeId(getUser().getUserId(), id);
|
||||
if (datlakes != null) {
|
||||
|
||||
datlakes.forEach(lake -> {
|
||||
try {
|
||||
Updatejson(lake.getId(), rawBody);
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} catch (Exception e2) {
|
||||
System.out.println(" exception " + e2);
|
||||
// TODO: handle exception
|
||||
}
|
||||
Data_lake saved = Updatejson(id, rawBody);
|
||||
|
||||
System.out.println(" json updated..");
|
||||
return saved;
|
||||
|
||||
}
|
||||
|
||||
public Data_lake Updatejson(Integer id, String rawBody) throws JsonProcessingException {
|
||||
|
||||
Data_lake lake = Repository.findById(id).get();
|
||||
|
||||
// String url = old.getUrl();
|
||||
//
|
||||
// ResponseEntity<String> response = GETAsString(url);
|
||||
// String rawBody = response.getBody();
|
||||
|
||||
// Convert the JSON object (ArrayList, Map, etc.) to a String
|
||||
// Object responseBody = response.getBody();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
// String jsonString = mapper.writeValueAsString(rawBody);
|
||||
ObjectMapper jsonMapper = new ObjectMapper();
|
||||
Object responseBody;
|
||||
|
||||
// Detect and convert if XML
|
||||
if (isXml(rawBody)) {
|
||||
try {
|
||||
// Convert XML → JSON tree
|
||||
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
|
||||
JsonNode xmlNode = xmlMapper.readTree(rawBody.getBytes());
|
||||
// Convert to standard JSON structure
|
||||
String jsonFromXml = jsonMapper.writeValueAsString(xmlNode);
|
||||
responseBody = jsonMapper.readValue(jsonFromXml, Object.class);
|
||||
System.out.println("XML detected and converted to JSON successfully.");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to convert XML to JSON: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
// Normal JSON response
|
||||
try {
|
||||
responseBody = jsonMapper.readValue(rawBody, Object.class);
|
||||
System.out.println("JSON response detected.");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Invalid JSON format: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2️⃣: Apply mapping if available
|
||||
String mapping_json = lake.getMapping_json();
|
||||
if (mapping_json != null && !mapping_json.trim().isEmpty()) {
|
||||
try {
|
||||
Map<String, String> keyMapping = mapper.readValue(mapping_json,
|
||||
new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
responseBody = applyFieldMapping(responseBody, keyMapping);
|
||||
System.out.println("✅ Applied header mapping successfully.");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to apply mapping JSON: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
// ✅ Handle calculated fields before batch processing
|
||||
if (Boolean.TRUE.equals(lake.getIscalculatedfield()) && lake.getCalculated_field_json() != null) {
|
||||
try {
|
||||
responseBody = applyCalculatedFields(responseBody, lake.getCalculated_field_json(), mapper, lake);
|
||||
System.out.println("Calculated fields applied successfully.");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to process calculated fields: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
String jsonString = mapper.writeValueAsString(responseBody);
|
||||
lake.setJson(jsonString);
|
||||
|
||||
// Process and insert into BatchData as before
|
||||
|
||||
// Process and insert into BatchData
|
||||
processBatchData(lake, responseBody, mapper);
|
||||
|
||||
String Url = Port_Constant.LOCALHOST + ":9292" + "/Data_lake/Data_lake/merge/" + lake.getId();
|
||||
lake.setUrl_endpoint(Url);
|
||||
|
||||
lake.setUpdatedBy(getUser().getUserId());
|
||||
|
||||
final Data_lake saved = Repository.save(lake);
|
||||
|
||||
System.out.println(" json updated..");
|
||||
return saved;
|
||||
|
||||
}
|
||||
|
||||
private Object applyFieldMapping(Object input, Map<String, String> keyMapping) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
if (input instanceof List) {
|
||||
ArrayNode newArray = mapper.createArrayNode();
|
||||
for (Object obj : (List<?>) input) {
|
||||
JsonNode newNode = renameFields(mapper.valueToTree(obj), keyMapping, mapper);
|
||||
newArray.add(newNode);
|
||||
}
|
||||
return newArray;
|
||||
} else {
|
||||
return renameFields(mapper.valueToTree(input), keyMapping, mapper);
|
||||
}
|
||||
}
|
||||
|
||||
private JsonNode renameFields(JsonNode node, Map<String, String> keyMapping, ObjectMapper mapper) {
|
||||
ObjectNode updated = mapper.createObjectNode();
|
||||
|
||||
node.fieldNames().forEachRemaining(key -> {
|
||||
JsonNode value = node.get(key);
|
||||
String newKey = keyMapping.getOrDefault(key, key);
|
||||
updated.set(newKey, value);
|
||||
});
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object applyCalculatedFields(Object responseBody, String calculatedFieldJson, ObjectMapper mapper,
|
||||
Data_lake old) throws JsonProcessingException {
|
||||
|
||||
// Parse the calculated field JSON
|
||||
List<Map<String, Object>> calcFields = mapper.readValue(calculatedFieldJson, List.class);
|
||||
|
||||
// if (!(responseBody instanceof List)) {
|
||||
// responseBody = Arrays.asList(responseBody);
|
||||
// }
|
||||
|
||||
// ✅ Case 1: Already a Java List
|
||||
if (responseBody instanceof List) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
// ✅ Case 2: Jackson ArrayNode (convert to List)
|
||||
else if (responseBody instanceof com.fasterxml.jackson.databind.node.ArrayNode) {
|
||||
responseBody = mapper.convertValue(responseBody, List.class);
|
||||
}
|
||||
|
||||
// ✅ Case 3: Jackson ObjectNode (convert to single object inside list)
|
||||
else if (responseBody instanceof com.fasterxml.jackson.databind.node.ObjectNode) {
|
||||
Map<String, Object> obj = mapper.convertValue(responseBody, Map.class);
|
||||
responseBody = Collections.singletonList(obj);
|
||||
}
|
||||
|
||||
// ✅ Case 4: JSON String input
|
||||
else if (responseBody instanceof String) {
|
||||
String json = ((String) responseBody).trim();
|
||||
if (json.startsWith("[")) {
|
||||
responseBody = mapper.readValue(json, List.class);
|
||||
} else if (json.startsWith("{")) {
|
||||
Map<String, Object> singleObject = mapper.readValue(json, Map.class);
|
||||
responseBody = Collections.singletonList(singleObject);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid JSON format: " + json);
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ Case 5: Single map
|
||||
else if (responseBody instanceof Map) {
|
||||
responseBody = Collections.singletonList(responseBody);
|
||||
}
|
||||
|
||||
// ❌ Anything else — throw error
|
||||
else {
|
||||
throw new IllegalArgumentException("Unexpected response body type: " + responseBody.getClass());
|
||||
}
|
||||
List<Map<String, Object>> records = (List<Map<String, Object>>) responseBody;
|
||||
|
||||
for (Map<String, Object> calc : calcFields) {
|
||||
String type = (String) calc.get("type");
|
||||
if ("groupby".equalsIgnoreCase(type)) {
|
||||
// ✅ Handle group-by aggregation
|
||||
List<Map<String, Object>> groupbyrecords = applyGroupBy(records, calc);
|
||||
String groupByRecord = mapper.writeValueAsString(groupbyrecords);
|
||||
|
||||
old.setGroupby_json(groupByRecord);
|
||||
|
||||
} else {
|
||||
// ✅ Handle calculated / complex operations (as before)
|
||||
for (Map<String, Object> record : records) {
|
||||
String fieldName = (String) calc.get("fieldName");
|
||||
String operation = (String) calc.get("operation");
|
||||
List<Map<String, Object>> components = (List<Map<String, Object>>) calc.get("fieldComponents");
|
||||
|
||||
// Handle constant fields
|
||||
if (components != null) {
|
||||
for (Map<String, Object> comp : components) {
|
||||
String subField = (String) comp.get("field");
|
||||
Boolean isConstant = comp.get("isConstant") != null && (Boolean) comp.get("isConstant");
|
||||
Object constantValue = comp.get("constant");
|
||||
if (isConstant && subField != null) {
|
||||
record.put(subField, parseNumberOrString(constantValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle complex expression
|
||||
if ("complex".equalsIgnoreCase(operation) && calc.get("complexEquation") != null) {
|
||||
String equation = (String) calc.get("complexEquation");
|
||||
Object result = evaluateComplexExpression(equation, record);
|
||||
record.put(fieldName, result);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle normal arithmetic
|
||||
List<Object> values = new ArrayList<>();
|
||||
if (components != null) {
|
||||
for (Map<String, Object> comp : components) {
|
||||
Boolean isConstant = comp.get("isConstant") != null && (Boolean) comp.get("isConstant");
|
||||
Object val = isConstant ? comp.get("constant") : record.get(comp.get("field"));
|
||||
if (val != null) {
|
||||
values.add(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object result = performOperation(values, operation);
|
||||
record.put(fieldName, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> applyGroupBy(List<Map<String, Object>> records, Map<String, Object> groupConfig) {
|
||||
List<String> groupFields = (List<String>) groupConfig.get("groupFields");
|
||||
List<Map<String, Object>> aggregations = (List<Map<String, Object>>) groupConfig.get("aggregations");
|
||||
|
||||
// Group records by key
|
||||
Map<String, List<Map<String, Object>>> grouped = new LinkedHashMap<>();
|
||||
for (Map<String, Object> record : records) {
|
||||
String key = groupFields.stream().map(f -> String.valueOf(record.getOrDefault(f, "")))
|
||||
.collect(Collectors.joining("|"));
|
||||
grouped.computeIfAbsent(key, k -> new ArrayList<>()).add(record);
|
||||
}
|
||||
|
||||
// Aggregate results per group
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, List<Map<String, Object>>> entry : grouped.entrySet()) {
|
||||
Map<String, Object> groupRecord = new LinkedHashMap<>();
|
||||
|
||||
// Add group fields
|
||||
String[] parts = entry.getKey().split("\\|");
|
||||
for (int i = 0; i < groupFields.size(); i++) {
|
||||
groupRecord.put(groupFields.get(i), parts[i]);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> groupRows = entry.getValue();
|
||||
|
||||
// Apply each aggregation
|
||||
for (Map<String, Object> agg : aggregations) {
|
||||
String field = (String) agg.get("field");
|
||||
String operation = ((String) agg.get("operation")).toLowerCase();
|
||||
List<Double> numericValues = groupRows.stream().map(r -> toDouble(r.get(field)))
|
||||
.filter(v -> !Double.isNaN(v)).collect(Collectors.toList());
|
||||
|
||||
Object aggResult;
|
||||
switch (operation) {
|
||||
case "count":
|
||||
aggResult = groupRows.size();
|
||||
break;
|
||||
case "sum":
|
||||
aggResult = numericValues.stream().mapToDouble(Double::doubleValue).sum();
|
||||
break;
|
||||
case "avg":
|
||||
aggResult = numericValues.isEmpty() ? 0.0
|
||||
: numericValues.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
|
||||
break;
|
||||
case "min":
|
||||
aggResult = numericValues.isEmpty() ? null
|
||||
: numericValues.stream().mapToDouble(Double::doubleValue).min().orElse(0.0);
|
||||
break;
|
||||
case "max":
|
||||
aggResult = numericValues.isEmpty() ? null
|
||||
: numericValues.stream().mapToDouble(Double::doubleValue).max().orElse(0.0);
|
||||
break;
|
||||
case "median":
|
||||
aggResult = calculateMedian(numericValues);
|
||||
break;
|
||||
case "mode":
|
||||
aggResult = calculateMode(numericValues);
|
||||
break;
|
||||
case "stdev":
|
||||
aggResult = calculateStdDev(numericValues);
|
||||
break;
|
||||
default:
|
||||
aggResult = null;
|
||||
}
|
||||
|
||||
groupRecord.put(field + "_" + operation, aggResult);
|
||||
}
|
||||
|
||||
result.add(groupRecord);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// --- Statistical helpers ---
|
||||
|
||||
private Double calculateMedian(List<Double> values) {
|
||||
if (values == null || values.isEmpty())
|
||||
return null;
|
||||
List<Double> sorted = new ArrayList<>(values);
|
||||
Collections.sort(sorted);
|
||||
int n = sorted.size();
|
||||
if (n % 2 == 1) {
|
||||
return sorted.get(n / 2);
|
||||
} else {
|
||||
return (sorted.get(n / 2 - 1) + sorted.get(n / 2)) / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
private Double calculateMode(List<Double> values) {
|
||||
if (values == null || values.isEmpty())
|
||||
return null;
|
||||
Map<Double, Long> freq = values.stream().collect(Collectors.groupingBy(v -> v, Collectors.counting()));
|
||||
return freq.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null);
|
||||
}
|
||||
|
||||
private Double calculateStdDev(List<Double> values) {
|
||||
if (values == null || values.isEmpty())
|
||||
return null;
|
||||
double mean = values.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
|
||||
double variance = values.stream().mapToDouble(v -> Math.pow(v - mean, 2)).average().orElse(0.0);
|
||||
return Math.sqrt(variance);
|
||||
}
|
||||
|
||||
private Object evaluateComplexExpression(String expression, Map<String, Object> record) {
|
||||
try {
|
||||
// Replace field names with values dynamically
|
||||
for (Map.Entry<String, Object> e : record.entrySet()) {
|
||||
String field = e.getKey();
|
||||
Object val = e.getValue();
|
||||
expression = expression.replaceAll("\\b" + field + "\\b", String.valueOf(val != null ? val : 0));
|
||||
}
|
||||
|
||||
// Evaluate using ScriptEngine (works on Java 1.8)
|
||||
javax.script.ScriptEngine engine = new javax.script.ScriptEngineManager().getEngineByName("JavaScript");
|
||||
Object result = engine.eval(expression);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
System.err.println("Complex expression error: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// perform normal operation
|
||||
private Object performOperation(List<Object> values, String operation) {
|
||||
if (values.isEmpty())
|
||||
return null;
|
||||
|
||||
switch (operation.toLowerCase()) {
|
||||
case "add":
|
||||
double sum = 0;
|
||||
for (Object v : values)
|
||||
sum += toDouble(v);
|
||||
return sum;
|
||||
|
||||
case "subtract":
|
||||
double result = toDouble(values.get(0));
|
||||
for (int i = 1; i < values.size(); i++)
|
||||
result -= toDouble(values.get(i));
|
||||
return result;
|
||||
|
||||
case "multiply":
|
||||
double prod = 1;
|
||||
for (Object v : values)
|
||||
prod *= toDouble(v);
|
||||
return prod;
|
||||
|
||||
case "divide":
|
||||
double div = toDouble(values.get(0));
|
||||
for (int i = 1; i < values.size(); i++) {
|
||||
double val = toDouble(values.get(i));
|
||||
if (val != 0)
|
||||
div /= val;
|
||||
}
|
||||
return div;
|
||||
|
||||
case "percentage":
|
||||
if (values.size() < 2)
|
||||
return null;
|
||||
double num = toDouble(values.get(0));
|
||||
double den = toDouble(values.get(1));
|
||||
return den == 0 ? null : (num * den) / 100;
|
||||
|
||||
case "concat":
|
||||
return values.stream().map(Object::toString).collect(Collectors.joining("_"));
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ✅ Evaluates complex equations using JavaScript engine Supports math
|
||||
* operations, parentheses, and string concatenation.
|
||||
*/
|
||||
private Object evaluateComplexEquation(String expression, Map<String, Object> record,
|
||||
List<Map<String, Object>> fieldComponents) {
|
||||
|
||||
if (expression == null || expression.trim().isEmpty())
|
||||
return null;
|
||||
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
|
||||
try {
|
||||
// 🔹 Replace constants
|
||||
if (fieldComponents != null) {
|
||||
for (Map<String, Object> comp : fieldComponents) {
|
||||
String field = (String) comp.get("field");
|
||||
Object constant = comp.get("constant");
|
||||
Boolean isConstant = comp.get("isConstant") != null && (Boolean) comp.get("isConstant");
|
||||
|
||||
if (isConstant && constant != null) {
|
||||
String constVal = constant.toString();
|
||||
expression = expression.replaceAll("\\b" + field + "\\b", constVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 🔹 Replace field values from record
|
||||
for (Map.Entry<String, Object> entry : record.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object val = entry.getValue();
|
||||
if (val != null) {
|
||||
String safeValue = val.toString();
|
||||
|
||||
// If it's a string containing letters, wrap it in quotes for JS
|
||||
if (!safeValue.matches("^-?\\d+(\\.\\d+)?$")) {
|
||||
safeValue = "'" + safeValue.replace("'", "\\'") + "'";
|
||||
}
|
||||
|
||||
expression = expression.replaceAll("\\b" + key + "\\b", safeValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Evaluate the expression safely
|
||||
Object result = engine.eval(expression);
|
||||
System.out.println(" exoression is : " + expression + " and " + result);
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ Error evaluating complex equation: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private double toDouble(Object val) {
|
||||
if (val == null)
|
||||
return 0.0;
|
||||
try {
|
||||
return Double.parseDouble(val.toString().trim());
|
||||
} catch (NumberFormatException e) {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
private Object parseNumberOrString(Object val) {
|
||||
if (val == null)
|
||||
return null;
|
||||
String str = val.toString().trim();
|
||||
try {
|
||||
return Double.parseDouble(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isXml(String content) {
|
||||
if (content == null)
|
||||
return false;
|
||||
String trimmed = content.trim();
|
||||
// XML usually starts with '<' and ends with '>'
|
||||
return trimmed.startsWith("<") && trimmed.endsWith(">");
|
||||
}
|
||||
|
||||
private void processBatchData(Data_lake dataLake, Object responseBody, ObjectMapper mapper)
|
||||
throws JsonProcessingException {
|
||||
|
||||
int batchVolume = (dataLake.getBatch_volume() != null && dataLake.getBatch_volume() > 0)
|
||||
? dataLake.getBatch_volume()
|
||||
: 100; // default batch size if not given
|
||||
|
||||
// Convert to JsonNode
|
||||
JsonNode jsonNode = mapper.valueToTree(responseBody);
|
||||
|
||||
if (jsonNode.isArray()) {
|
||||
ArrayNode arrayNode = (ArrayNode) jsonNode;
|
||||
int total = arrayNode.size();
|
||||
System.out.println("Total records: " + total);
|
||||
|
||||
for (int i = 0; i < total; i += batchVolume) {
|
||||
int end = Math.min(i + batchVolume, total);
|
||||
|
||||
// Create a sub-array manually
|
||||
ArrayNode subArray = mapper.createArrayNode();
|
||||
for (int j = i; j < end; j++) {
|
||||
subArray.add(arrayNode.get(j));
|
||||
}
|
||||
|
||||
String subJson = mapper.writeValueAsString(subArray);
|
||||
|
||||
BatchData batch = new BatchData();
|
||||
batch.setDatalake_id(dataLake.getId());
|
||||
batch.setBatchjson(subJson);
|
||||
batchRepo.save(batch);
|
||||
}
|
||||
|
||||
System.out.println("Inserted " + (int) Math.ceil((double) total / batchVolume) + " batch records.");
|
||||
|
||||
} else {
|
||||
// Single object → one record
|
||||
BatchData batch = new BatchData();
|
||||
batch.setDatalake_id(dataLake.getId());
|
||||
batch.setBatchjson(mapper.writeValueAsString(jsonNode));
|
||||
batchRepo.save(batch);
|
||||
|
||||
System.out.println("Inserted single batch record.");
|
||||
}
|
||||
}
|
||||
|
||||
public String mergeBatchData(Integer datalakeId) throws Exception {
|
||||
List<BatchData> batchList = batchRepo.findByDatalake_id(datalakeId);
|
||||
|
||||
if (batchList.isEmpty()) {
|
||||
throw new RuntimeException("No batch data found for datalake_id: " + datalakeId);
|
||||
}
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ArrayNode mergedArray = mapper.createArrayNode();
|
||||
|
||||
for (BatchData batch : batchList) {
|
||||
String json = batch.getBatchjson();
|
||||
JsonNode node = mapper.readTree(json);
|
||||
|
||||
if (node.isArray()) {
|
||||
// Add each element to merged array
|
||||
for (JsonNode item : node) {
|
||||
mergedArray.add(item);
|
||||
}
|
||||
} else {
|
||||
// Single object, just add directly
|
||||
mergedArray.add(node);
|
||||
}
|
||||
}
|
||||
|
||||
String mergedJson = mapper.writeValueAsString(mergedArray);
|
||||
System.out.println("Merged JSON size: " + mergedArray.size());
|
||||
return mergedJson;
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> GET(String get) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
ResponseEntity<Object> u = restTemplate.getForEntity(get, Object.class);
|
||||
|
||||
return u;
|
||||
|
||||
}
|
||||
|
||||
public ResponseEntity<String> GETAsString1(String url) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
return restTemplate.getForEntity(url, String.class);
|
||||
}
|
||||
|
||||
public AppUser getUser() {
|
||||
AppUser user = userService.getLoggedInUser();
|
||||
return user;
|
||||
|
||||
}
|
||||
|
||||
public ResponseEntity<String> GETMethodAsString(String url, Integer sureid) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.ALL)); // accept JSON or XML
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
// 🔹 Add your token here (you can make it dynamic)
|
||||
String token = getToken(sureid); // helper method (see below)
|
||||
if (token != null && !token.isEmpty()) {
|
||||
headers.set("Authorization", "Bearer " + token);
|
||||
}
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> GETWithObject(String url, Integer sureid) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.ALL)); // accept JSON or XML
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
// 🔹 Add your token here (you can make it dynamic)
|
||||
String token = getToken(sureid); // helper method (see below)
|
||||
if (token != null && !token.isEmpty()) {
|
||||
headers.set("Authorization", "Bearer " + token);
|
||||
}
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
|
||||
ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.GET, entity, Object.class);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private String getToken(Integer sureid) {
|
||||
Sure_Connect connect = sureService.getbyid(sureid);
|
||||
String access_token = connect.getAccess_token();
|
||||
|
||||
return access_token; // optional
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,948 @@
|
||||
package com.realnet.DataLake.Services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.DataLake.Entity.Data_lake;
|
||||
import com.realnet.DataLake.Repository.BatchDataRepository;
|
||||
import com.realnet.DataLake.Repository.Data_lakeRepository;
|
||||
import com.realnet.SureConnect.Service.SureService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.utils.Port_Constant;
|
||||
|
||||
@Service
|
||||
public class Data_lakeService {
|
||||
@Autowired
|
||||
private Data_lakeRepository Repository;
|
||||
|
||||
@Autowired
|
||||
private BatchDataRepository batchRepo;
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
|
||||
@Autowired
|
||||
private DataLakeActionService lakeActionService;
|
||||
@Autowired
|
||||
private SureService sureService;
|
||||
|
||||
public Data_lake Savedata(Data_lake data) {
|
||||
|
||||
data.setUpdatedBy(getUser().getUserId());
|
||||
data.setCreatedBy(getUser().getUserId());
|
||||
data.setAccountId(getUser().getAccount().getAccount_id());
|
||||
|
||||
if (data.getSure_connect_id() != null) {
|
||||
|
||||
data.setSureconnect_name(sureService.getbyid(data.getSure_connect_id()).getConnection_name());
|
||||
}
|
||||
|
||||
Data_lake save = Repository.save(data);
|
||||
return save;
|
||||
}
|
||||
|
||||
// get all with pagination
|
||||
public Page<Data_lake> getAllWithPagination(Pageable page) {
|
||||
return Repository.findAll(getUser().getUserId(), page);
|
||||
}
|
||||
|
||||
public List<Data_lake> getdetails() {
|
||||
List<Data_lake> all = Repository.findAll(getUser().getUserId());
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
public Data_lake getdetailsbyId(Integer id) {
|
||||
return Repository.findById(id).get();
|
||||
}
|
||||
|
||||
public void delete_by_id(Integer id) {
|
||||
Repository.deleteById(id);
|
||||
}
|
||||
|
||||
public Data_lake enableWebHook(Integer id) {
|
||||
Data_lake old = Repository.findById(id).get();
|
||||
String Url = Port_Constant.LOCALHOST + ":9292" + "/Data_lake/Data_lake/json/" + id;
|
||||
old.setWebhook_url(Url);
|
||||
final Data_lake test = Repository.save(old);
|
||||
|
||||
return test;
|
||||
|
||||
}
|
||||
|
||||
public Data_lake update(Data_lake data, Integer id) {
|
||||
Data_lake old = Repository.findById(id).get();
|
||||
// id auto-generated hai → update nahi karenge
|
||||
|
||||
if (data.getName() != null) {
|
||||
old.setName(data.getName());
|
||||
}
|
||||
|
||||
if (data.getUrl() != null) {
|
||||
old.setUrl(data.getUrl());
|
||||
}
|
||||
|
||||
if (data.getSchedule() != null) {
|
||||
old.setSchedule(data.getSchedule());
|
||||
}
|
||||
|
||||
if (data.getCron_job() != null) {
|
||||
old.setCron_job(data.getCron_job());
|
||||
}
|
||||
|
||||
if (data.getJson() != null) {
|
||||
old.setJson(data.getJson());
|
||||
}
|
||||
|
||||
if (data.getBatch_volume() != null) {
|
||||
old.setBatch_volume(data.getBatch_volume());
|
||||
}
|
||||
|
||||
if (data.getSure_connect_id() != null) {
|
||||
old.setSure_connect_id(data.getSure_connect_id());
|
||||
|
||||
old.setSureconnect_name(sureService.getbyid(data.getSure_connect_id()).getConnection_name());
|
||||
|
||||
}
|
||||
|
||||
if (data.getUrl_endpoint() != null) {
|
||||
old.setUrl_endpoint(data.getUrl_endpoint());
|
||||
}
|
||||
|
||||
if (data.getCalculated_field_json() != null) {
|
||||
old.setCalculated_field_json(data.getCalculated_field_json());
|
||||
}
|
||||
|
||||
if (data.getIscalculatedfield() != null) {
|
||||
old.setIscalculatedfield(data.getIscalculatedfield());
|
||||
}
|
||||
|
||||
if (data.getGroupby_json() != null) {
|
||||
old.setGroupby_json(data.getGroupby_json());
|
||||
|
||||
}
|
||||
|
||||
if (data.getRef_datalake_id() != null) {
|
||||
old.setRef_datalake_id(data.getRef_datalake_id());
|
||||
|
||||
}
|
||||
|
||||
if (data.getDatalake_type() != null) {
|
||||
old.setDatalake_type(data.getDatalake_type());
|
||||
|
||||
}
|
||||
|
||||
if (data.getBlending_lakeids() != null) {
|
||||
old.setBlending_lakeids(data.getBlending_lakeids());
|
||||
|
||||
}
|
||||
if (data.getSqlquery_json() != null) {
|
||||
|
||||
old.setSqlquery_json(data.getSqlquery_json());
|
||||
|
||||
}
|
||||
if (data.getMapping_json() != null) {
|
||||
old.setMapping_json(data.getMapping_json());
|
||||
}
|
||||
|
||||
final Data_lake test = Repository.save(old);
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
// public Object sqltojson(Integer lakeid) {
|
||||
// Data_lake lake = Repository.findById(lakeid).get();
|
||||
// String datalake_type = lake.getDatalake_type();
|
||||
//
|
||||
// Object responseBody = null; // 👈 this is what we’ll return
|
||||
//
|
||||
// if (datalake_type.equalsIgnoreCase("blending") && lake.getBlending_lakeids() != null
|
||||
// && lake.getSqlquery_json() != null) {
|
||||
//
|
||||
// String blending_lakeids = lake.getBlending_lakeids(); // e.g. "12,13"
|
||||
// String sqlquery_json = lake.getSqlquery_json(); // e.g. "select * from gtest, gtest2"
|
||||
//
|
||||
// // Step 1️⃣: Collect all child lakes
|
||||
// String[] lakeIds = blending_lakeids.split(",");
|
||||
// Map<String, JsonNode> lakeDataMap = new HashMap<>();
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
//
|
||||
// for (String idStr : lakeIds) {
|
||||
// int id = Integer.parseInt(idStr.trim());
|
||||
// Data_lake child = Repository.findById(id).orElse(null);
|
||||
// if (child == null)
|
||||
// continue;
|
||||
//
|
||||
// String url = child.getUrl_endpoint();
|
||||
// ResponseEntity<String> response = GETWithString(url, child.getSure_connect_id());
|
||||
// String rawBody = response.getBody();
|
||||
//
|
||||
// try {
|
||||
// JsonNode data = mapper.readTree(rawBody);
|
||||
// // Normalize to array
|
||||
// if (!data.isArray()) {
|
||||
// ArrayNode arr = mapper.createArrayNode();
|
||||
// arr.add(data);
|
||||
// data = arr;
|
||||
// }
|
||||
// lakeDataMap.put(child.getName().toLowerCase(), data);
|
||||
// System.out.println("Loaded data for: " + child.getName());
|
||||
// } catch (Exception e) {
|
||||
// System.err.println("Error parsing data from " + child.getName() + ": " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Step 2️⃣: Parse SQL for table names
|
||||
// List<String> tables = extractTableNames(sqlquery_json);
|
||||
// System.out.println("Tables in query: " + tables);
|
||||
//
|
||||
// // Step 3️⃣: Perform JOIN or UNION based on query type
|
||||
// ArrayNode result = mapper.createArrayNode();
|
||||
//
|
||||
// if (sqlquery_json.toLowerCase().contains("join") || sqlquery_json.toLowerCase().contains("where")) {
|
||||
// // Perform naive JOIN on common field names
|
||||
// result = performJoin(mapper, lakeDataMap, tables);
|
||||
// } else {
|
||||
// // Perform simple UNION of all tables (cross merge)
|
||||
// result = performUnion(mapper, lakeDataMap, tables);
|
||||
// }
|
||||
//
|
||||
// System.out.println("✅ Final blended JSON:");
|
||||
// System.out.println(result.toPrettyString());
|
||||
// // Step 4️⃣: Convert ArrayNode → Object for return
|
||||
// try {
|
||||
// responseBody = mapper.readValue(mapper.writeValueAsString(result), Object.class);
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException("Error converting result to Object: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return responseBody;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /** Extract table names from SQL query like "select * from gtest, gtest2" */
|
||||
// private List<String> extractTableNames(String sql) {
|
||||
// List<String> tables = new ArrayList<>();
|
||||
// String lower = sql.toLowerCase();
|
||||
// String regex = "from\\s+([a-zA-Z0-9_,\\s]+)";
|
||||
// Matcher m = Pattern.compile(regex).matcher(lower);
|
||||
// if (m.find()) {
|
||||
// String group = m.group(1);
|
||||
// for (String name : group.split(",")) {
|
||||
// tables.add(name.trim());
|
||||
// }
|
||||
// }
|
||||
// return tables;
|
||||
// }
|
||||
//
|
||||
// /** Simple union of all tables */
|
||||
// private ArrayNode performUnion(ObjectMapper mapper, Map<String, JsonNode> lakeDataMap, List<String> tables) {
|
||||
// ArrayNode result = mapper.createArrayNode();
|
||||
//
|
||||
// for (String table : tables) {
|
||||
// JsonNode data = lakeDataMap.get(table.toLowerCase());
|
||||
// if (data == null)
|
||||
// continue;
|
||||
//
|
||||
// for (JsonNode row : data) {
|
||||
// ObjectNode newRow = mapper.createObjectNode();
|
||||
// Iterator<String> fields = row.fieldNames();
|
||||
// while (fields.hasNext()) {
|
||||
// String field = fields.next();
|
||||
// newRow.put(table + "." + field, row.get(field).asText());
|
||||
// }
|
||||
// result.add(newRow);
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// /** Simple JOIN based on common keys */
|
||||
// private ArrayNode performJoin(ObjectMapper mapper, Map<String, JsonNode> lakeDataMap, List<String> tables) {
|
||||
// ArrayNode result = mapper.createArrayNode();
|
||||
// if (tables.size() < 2)
|
||||
// return result;
|
||||
//
|
||||
// JsonNode first = lakeDataMap.get(tables.get(0).toLowerCase());
|
||||
// JsonNode second = lakeDataMap.get(tables.get(1).toLowerCase());
|
||||
//
|
||||
// if (first == null || second == null)
|
||||
// return result;
|
||||
//
|
||||
// // Find common key (like "id" or "emp_id")
|
||||
// String joinKey = findCommonKey(first, second);
|
||||
//
|
||||
// for (JsonNode row1 : first) {
|
||||
// for (JsonNode row2 : second) {
|
||||
// if (joinKey != null && row1.has(joinKey) && row2.has(joinKey)
|
||||
// && row1.get(joinKey).asText().equals(row2.get(joinKey).asText())) {
|
||||
//
|
||||
// ObjectNode merged = mapper.createObjectNode();
|
||||
// row1.fieldNames().forEachRemaining(f -> merged.put(tables.get(0) + "." + f, row1.get(f).asText()));
|
||||
// row2.fieldNames().forEachRemaining(f -> merged.put(tables.get(1) + "." + f, row2.get(f).asText()));
|
||||
// result.add(merged);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// /** Finds a likely common join key between two datasets */
|
||||
// private String findCommonKey(JsonNode a, JsonNode b) {
|
||||
// Set<String> aKeys = new HashSet<>();
|
||||
// a.get(0).fieldNames().forEachRemaining(aKeys::add);
|
||||
//
|
||||
// Set<String> bKeys = new HashSet<>();
|
||||
// b.get(0).fieldNames().forEachRemaining(bKeys::add);
|
||||
//
|
||||
// for (String k : aKeys) {
|
||||
// if (bKeys.contains(k))
|
||||
// return k;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// public Map<String, Object> getAllKeys(Integer lakeid) throws JsonProcessingException {
|
||||
// Data_lake old = Repository.findById(lakeid).get();
|
||||
// String url = old.getUrl_endpoint();
|
||||
//
|
||||
// ResponseEntity<String> response = GETWithString(url, old.getSure_connect_id());
|
||||
//
|
||||
// String rawBody = response.getBody();
|
||||
//
|
||||
// ObjectMapper jsonMapper = new ObjectMapper();
|
||||
// Object responseBody;
|
||||
//
|
||||
// // Detect and convert if XML
|
||||
// if (isXml(rawBody)) {
|
||||
// try {
|
||||
// XmlMapper xmlMapper = new XmlMapper();
|
||||
// JsonNode xmlNode = xmlMapper.readTree(rawBody.getBytes());
|
||||
// String jsonFromXml = jsonMapper.writeValueAsString(xmlNode);
|
||||
// responseBody = jsonMapper.readValue(jsonFromXml, Object.class);
|
||||
// System.out.println("XML detected and converted to JSON successfully.");
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException("Failed to convert XML to JSON: " + e.getMessage());
|
||||
// }
|
||||
// } else {
|
||||
// try {
|
||||
// responseBody = jsonMapper.readValue(rawBody, Object.class);
|
||||
// System.out.println("JSON response detected.");
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException("Invalid JSON format: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Map<String, Object> result = new HashMap<>();
|
||||
// extractTableAndHeaders(result, responseBody);
|
||||
//
|
||||
// // Add table name from database
|
||||
// result.put("tableName", old.getName());
|
||||
//
|
||||
// System.out.println("Keys extracted successfully.");
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// public static Map<String, Object> extractTableAndHeaders(Map<String, Object> result, Object responseBody) {
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
//
|
||||
// try {
|
||||
// JsonNode root = mapper.valueToTree(responseBody);
|
||||
// JsonNode firstNode = root.isArray() && root.size() > 0 ? root.get(0) : root;
|
||||
//
|
||||
// Set<String> headers = new LinkedHashSet<>();
|
||||
// Iterator<String> fieldNames = firstNode.fieldNames();
|
||||
// while (fieldNames.hasNext()) {
|
||||
// String field = fieldNames.next();
|
||||
// if (!field.equalsIgnoreCase("tableName")) {
|
||||
// headers.add(field);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// result.put("headers", headers);
|
||||
// } catch (Exception e) {
|
||||
// result.put("error", "Invalid JSON: " + e.getMessage());
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
//// apply calculated json
|
||||
// public Data_lake applyCalculation(Integer id) throws JsonProcessingException {
|
||||
//
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
//
|
||||
// Data_lake old = Repository.findById(id).get();
|
||||
// String datalake_type = old.getDatalake_type();
|
||||
// if (datalake_type.equalsIgnoreCase("blending") && old.getBlending_lakeids() != null
|
||||
// && old.getSqlquery_json() != null) {
|
||||
//
|
||||
// Object sqltojson = lakeActionService.sqltojson(id);
|
||||
//
|
||||
// String jsonString = mapper.writeValueAsString(sqltojson);
|
||||
// old.setJson(jsonString);
|
||||
//
|
||||
// // Process and insert into BatchData as before
|
||||
//
|
||||
// // Process and insert into BatchData
|
||||
// processBatchData(old, sqltojson, mapper);
|
||||
//
|
||||
// String Url = Port_Constant.LOCALHOST + ":9292" + "/Data_lake/Data_lake/merge/" + old.getId();
|
||||
// old.setUrl_endpoint(Url);
|
||||
//
|
||||
// old.setUpdatedBy(getUser().getUserId());
|
||||
//
|
||||
// final Data_lake saved = Repository.save(old);
|
||||
// return saved;
|
||||
// }
|
||||
//
|
||||
// String url = old.getUrl();
|
||||
//
|
||||
// ResponseEntity<String> response = GETAsString(url);
|
||||
// String rawBody = response.getBody();
|
||||
//
|
||||
// List<Data_lake> datlakes = Repository.findAllByRefDatlakeId(getUser().getUserId(), id);
|
||||
//
|
||||
// datlakes.forEach(lake -> {
|
||||
// try {
|
||||
// Updatejson(lake.getId(), rawBody);
|
||||
// } catch (JsonProcessingException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// Data_lake saved = Updatejson(id, rawBody);
|
||||
//
|
||||
// System.out.println(" json updated..");
|
||||
// return saved;
|
||||
//
|
||||
// }
|
||||
|
||||
// public Data_lake Updatejson(Integer id, String rawBody) throws JsonProcessingException {
|
||||
//
|
||||
// Data_lake old = Repository.findById(id).get();
|
||||
//
|
||||
//// String url = old.getUrl();
|
||||
////
|
||||
//// ResponseEntity<String> response = GETAsString(url);
|
||||
//// String rawBody = response.getBody();
|
||||
//
|
||||
// // Convert the JSON object (ArrayList, Map, etc.) to a String
|
||||
//// Object responseBody = response.getBody();
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
//
|
||||
//// String jsonString = mapper.writeValueAsString(rawBody);
|
||||
// ObjectMapper jsonMapper = new ObjectMapper();
|
||||
// Object responseBody;
|
||||
//
|
||||
// // Detect and convert if XML
|
||||
// if (isXml(rawBody)) {
|
||||
// try {
|
||||
// // Convert XML → JSON tree
|
||||
//
|
||||
// XmlMapper xmlMapper = new XmlMapper();
|
||||
//
|
||||
// JsonNode xmlNode = xmlMapper.readTree(rawBody.getBytes());
|
||||
// // Convert to standard JSON structure
|
||||
// String jsonFromXml = jsonMapper.writeValueAsString(xmlNode);
|
||||
// responseBody = jsonMapper.readValue(jsonFromXml, Object.class);
|
||||
// System.out.println("XML detected and converted to JSON successfully.");
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException("Failed to convert XML to JSON: " + e.getMessage());
|
||||
// }
|
||||
// } else {
|
||||
// // Normal JSON response
|
||||
// try {
|
||||
// responseBody = jsonMapper.readValue(rawBody, Object.class);
|
||||
// System.out.println("JSON response detected.");
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException("Invalid JSON format: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // ✅ Handle calculated fields before batch processing
|
||||
// if (Boolean.TRUE.equals(old.getIscalculatedfield()) && old.getCalculated_field_json() != null) {
|
||||
// try {
|
||||
// responseBody = applyCalculatedFields(responseBody, old.getCalculated_field_json(), mapper, old);
|
||||
// System.out.println("Calculated fields applied successfully.");
|
||||
// } catch (Exception e) {
|
||||
// System.err.println("Failed to process calculated fields: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// String jsonString = mapper.writeValueAsString(responseBody);
|
||||
// old.setJson(jsonString);
|
||||
//
|
||||
// // Process and insert into BatchData as before
|
||||
//
|
||||
// // Process and insert into BatchData
|
||||
// processBatchData(old, responseBody, mapper);
|
||||
//
|
||||
// String Url = Port_Constant.LOCALHOST + ":9292" + "/Data_lake/Data_lake/merge/" + old.getId();
|
||||
// old.setUrl_endpoint(Url);
|
||||
//
|
||||
// old.setUpdatedBy(getUser().getUserId());
|
||||
//
|
||||
// final Data_lake saved = Repository.save(old);
|
||||
//
|
||||
// System.out.println(" json updated..");
|
||||
// return saved;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// private Object applyCalculatedFields(Object responseBody, String calculatedFieldJson, ObjectMapper mapper,
|
||||
// Data_lake old) throws JsonProcessingException {
|
||||
//
|
||||
// // Parse the calculated field JSON
|
||||
// List<Map<String, Object>> calcFields = mapper.readValue(calculatedFieldJson, List.class);
|
||||
//
|
||||
// if (!(responseBody instanceof List)) {
|
||||
// responseBody = Arrays.asList(responseBody);
|
||||
// }
|
||||
//
|
||||
// List<Map<String, Object>> records = (List<Map<String, Object>>) responseBody;
|
||||
//
|
||||
// for (Map<String, Object> calc : calcFields) {
|
||||
// String type = (String) calc.get("type");
|
||||
// if ("groupby".equalsIgnoreCase(type)) {
|
||||
// // ✅ Handle group-by aggregation
|
||||
// List<Map<String, Object>> groupbyrecords = applyGroupBy(records, calc);
|
||||
// String groupByRecord = mapper.writeValueAsString(groupbyrecords);
|
||||
//
|
||||
// old.setGroupby_json(groupByRecord);
|
||||
//
|
||||
// } else {
|
||||
// // ✅ Handle calculated / complex operations (as before)
|
||||
// for (Map<String, Object> record : records) {
|
||||
// String fieldName = (String) calc.get("fieldName");
|
||||
// String operation = (String) calc.get("operation");
|
||||
// List<Map<String, Object>> components = (List<Map<String, Object>>) calc.get("fieldComponents");
|
||||
//
|
||||
// // Handle constant fields
|
||||
// if (components != null) {
|
||||
// for (Map<String, Object> comp : components) {
|
||||
// String subField = (String) comp.get("field");
|
||||
// Boolean isConstant = comp.get("isConstant") != null && (Boolean) comp.get("isConstant");
|
||||
// Object constantValue = comp.get("constant");
|
||||
// if (isConstant && subField != null) {
|
||||
// record.put(subField, parseNumberOrString(constantValue));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Handle complex expression
|
||||
// if ("complex".equalsIgnoreCase(operation) && calc.get("complexEquation") != null) {
|
||||
// String equation = (String) calc.get("complexEquation");
|
||||
// Object result = evaluateComplexExpression(equation, record);
|
||||
// record.put(fieldName, result);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // Handle normal arithmetic
|
||||
// List<Object> values = new ArrayList<>();
|
||||
// if (components != null) {
|
||||
// for (Map<String, Object> comp : components) {
|
||||
// Boolean isConstant = comp.get("isConstant") != null && (Boolean) comp.get("isConstant");
|
||||
// Object val = isConstant ? comp.get("constant") : record.get(comp.get("field"));
|
||||
// if (val != null) {
|
||||
// values.add(val);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Object result = performOperation(values, operation);
|
||||
// record.put(fieldName, result);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return records;
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// private List<Map<String, Object>> applyGroupBy(List<Map<String, Object>> records, Map<String, Object> groupConfig) {
|
||||
// List<String> groupFields = (List<String>) groupConfig.get("groupFields");
|
||||
// List<Map<String, Object>> aggregations = (List<Map<String, Object>>) groupConfig.get("aggregations");
|
||||
//
|
||||
// // Group records by key
|
||||
// Map<String, List<Map<String, Object>>> grouped = new LinkedHashMap<>();
|
||||
// for (Map<String, Object> record : records) {
|
||||
// String key = groupFields.stream().map(f -> String.valueOf(record.getOrDefault(f, "")))
|
||||
// .collect(Collectors.joining("|"));
|
||||
// grouped.computeIfAbsent(key, k -> new ArrayList<>()).add(record);
|
||||
// }
|
||||
//
|
||||
// // Aggregate results per group
|
||||
// List<Map<String, Object>> result = new ArrayList<>();
|
||||
//
|
||||
// for (Map.Entry<String, List<Map<String, Object>>> entry : grouped.entrySet()) {
|
||||
// Map<String, Object> groupRecord = new LinkedHashMap<>();
|
||||
//
|
||||
// // Add group fields
|
||||
// String[] parts = entry.getKey().split("\\|");
|
||||
// for (int i = 0; i < groupFields.size(); i++) {
|
||||
// groupRecord.put(groupFields.get(i), parts[i]);
|
||||
// }
|
||||
//
|
||||
// List<Map<String, Object>> groupRows = entry.getValue();
|
||||
//
|
||||
// // Apply each aggregation
|
||||
// for (Map<String, Object> agg : aggregations) {
|
||||
// String field = (String) agg.get("field");
|
||||
// String operation = ((String) agg.get("operation")).toLowerCase();
|
||||
// List<Double> numericValues = groupRows.stream().map(r -> toDouble(r.get(field)))
|
||||
// .filter(v -> !Double.isNaN(v)).collect(Collectors.toList());
|
||||
//
|
||||
// Object aggResult;
|
||||
// switch (operation) {
|
||||
// case "count":
|
||||
// aggResult = groupRows.size();
|
||||
// break;
|
||||
// case "sum":
|
||||
// aggResult = numericValues.stream().mapToDouble(Double::doubleValue).sum();
|
||||
// break;
|
||||
// case "average":
|
||||
// aggResult = numericValues.isEmpty() ? 0.0
|
||||
// : numericValues.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
|
||||
// break;
|
||||
// case "minimum":
|
||||
// aggResult = numericValues.isEmpty() ? null
|
||||
// : numericValues.stream().mapToDouble(Double::doubleValue).min().orElse(0.0);
|
||||
// break;
|
||||
// case "maximum":
|
||||
// aggResult = numericValues.isEmpty() ? null
|
||||
// : numericValues.stream().mapToDouble(Double::doubleValue).max().orElse(0.0);
|
||||
// break;
|
||||
// case "median":
|
||||
// aggResult = calculateMedian(numericValues);
|
||||
// break;
|
||||
// case "mode":
|
||||
// aggResult = calculateMode(numericValues);
|
||||
// break;
|
||||
// case "standard deviation":
|
||||
// aggResult = calculateStdDev(numericValues);
|
||||
// break;
|
||||
// default:
|
||||
// aggResult = null;
|
||||
// }
|
||||
//
|
||||
// groupRecord.put(field + "_" + operation, aggResult);
|
||||
// }
|
||||
//
|
||||
// result.add(groupRecord);
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// // --- Statistical helpers ---
|
||||
//
|
||||
// private Double calculateMedian(List<Double> values) {
|
||||
// if (values == null || values.isEmpty())
|
||||
// return null;
|
||||
// List<Double> sorted = new ArrayList<>(values);
|
||||
// Collections.sort(sorted);
|
||||
// int n = sorted.size();
|
||||
// if (n % 2 == 1) {
|
||||
// return sorted.get(n / 2);
|
||||
// } else {
|
||||
// return (sorted.get(n / 2 - 1) + sorted.get(n / 2)) / 2.0;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private Double calculateMode(List<Double> values) {
|
||||
// if (values == null || values.isEmpty())
|
||||
// return null;
|
||||
// Map<Double, Long> freq = values.stream().collect(Collectors.groupingBy(v -> v, Collectors.counting()));
|
||||
// return freq.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null);
|
||||
// }
|
||||
//
|
||||
// private Double calculateStdDev(List<Double> values) {
|
||||
// if (values == null || values.isEmpty())
|
||||
// return null;
|
||||
// double mean = values.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
|
||||
// double variance = values.stream().mapToDouble(v -> Math.pow(v - mean, 2)).average().orElse(0.0);
|
||||
// return Math.sqrt(variance);
|
||||
// }
|
||||
//
|
||||
// private Object evaluateComplexExpression(String expression, Map<String, Object> record) {
|
||||
// try {
|
||||
// // Replace field names with values dynamically
|
||||
// for (Map.Entry<String, Object> e : record.entrySet()) {
|
||||
// String field = e.getKey();
|
||||
// Object val = e.getValue();
|
||||
// expression = expression.replaceAll("\\b" + field + "\\b", String.valueOf(val != null ? val : 0));
|
||||
// }
|
||||
//
|
||||
// // Evaluate using ScriptEngine (works on Java 1.8)
|
||||
// javax.script.ScriptEngine engine = new javax.script.ScriptEngineManager().getEngineByName("JavaScript");
|
||||
// Object result = engine.eval(expression);
|
||||
// return result;
|
||||
// } catch (Exception e) {
|
||||
// System.err.println("Complex expression error: " + e.getMessage());
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//// perform normal operation
|
||||
// private Object performOperation(List<Object> values, String operation) {
|
||||
// if (values.isEmpty())
|
||||
// return null;
|
||||
//
|
||||
// switch (operation.toLowerCase()) {
|
||||
// case "add":
|
||||
// double sum = 0;
|
||||
// for (Object v : values)
|
||||
// sum += toDouble(v);
|
||||
// return sum;
|
||||
//
|
||||
// case "subtract":
|
||||
// double result = toDouble(values.get(0));
|
||||
// for (int i = 1; i < values.size(); i++)
|
||||
// result -= toDouble(values.get(i));
|
||||
// return result;
|
||||
//
|
||||
// case "multiply":
|
||||
// double prod = 1;
|
||||
// for (Object v : values)
|
||||
// prod *= toDouble(v);
|
||||
// return prod;
|
||||
//
|
||||
// case "divide":
|
||||
// double div = toDouble(values.get(0));
|
||||
// for (int i = 1; i < values.size(); i++) {
|
||||
// double val = toDouble(values.get(i));
|
||||
// if (val != 0)
|
||||
// div /= val;
|
||||
// }
|
||||
// return div;
|
||||
//
|
||||
// case "percentage":
|
||||
// if (values.size() < 2)
|
||||
// return null;
|
||||
// double num = toDouble(values.get(0));
|
||||
// double den = toDouble(values.get(1));
|
||||
// return den == 0 ? null : (num / den) * 100;
|
||||
//
|
||||
// case "concat":
|
||||
// return values.stream().map(Object::toString).collect(Collectors.joining("_"));
|
||||
//
|
||||
// default:
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * ✅ Evaluates complex equations using JavaScript engine Supports math
|
||||
// * operations, parentheses, and string concatenation.
|
||||
// */
|
||||
// private Object evaluateComplexEquation(String expression, Map<String, Object> record,
|
||||
// List<Map<String, Object>> fieldComponents) {
|
||||
//
|
||||
// if (expression == null || expression.trim().isEmpty())
|
||||
// return null;
|
||||
//
|
||||
// ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
//
|
||||
// try {
|
||||
// // 🔹 Replace constants
|
||||
// if (fieldComponents != null) {
|
||||
// for (Map<String, Object> comp : fieldComponents) {
|
||||
// String field = (String) comp.get("field");
|
||||
// Object constant = comp.get("constant");
|
||||
// Boolean isConstant = comp.get("isConstant") != null && (Boolean) comp.get("isConstant");
|
||||
//
|
||||
// if (isConstant && constant != null) {
|
||||
// String constVal = constant.toString();
|
||||
// expression = expression.replaceAll("\\b" + field + "\\b", constVal);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 🔹 Replace field values from record
|
||||
// for (Map.Entry<String, Object> entry : record.entrySet()) {
|
||||
// String key = entry.getKey();
|
||||
// Object val = entry.getValue();
|
||||
// if (val != null) {
|
||||
// String safeValue = val.toString();
|
||||
//
|
||||
// // If it's a string containing letters, wrap it in quotes for JS
|
||||
// if (!safeValue.matches("^-?\\d+(\\.\\d+)?$")) {
|
||||
// safeValue = "'" + safeValue.replace("'", "\\'") + "'";
|
||||
// }
|
||||
//
|
||||
// expression = expression.replaceAll("\\b" + key + "\\b", safeValue);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Evaluate the expression safely
|
||||
// Object result = engine.eval(expression);
|
||||
// System.out.println(" exoression is : " + expression + " and " + result);
|
||||
// return result;
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// System.err.println("❌ Error evaluating complex equation: " + e.getMessage());
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private double toDouble(Object val) {
|
||||
// if (val == null)
|
||||
// return 0.0;
|
||||
// try {
|
||||
// return Double.parseDouble(val.toString().trim());
|
||||
// } catch (NumberFormatException e) {
|
||||
// return 0.0;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private Object parseNumberOrString(Object val) {
|
||||
// if (val == null)
|
||||
// return null;
|
||||
// String str = val.toString().trim();
|
||||
// try {
|
||||
// return Double.parseDouble(str);
|
||||
// } catch (NumberFormatException e) {
|
||||
// return str;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private boolean isXml(String content) {
|
||||
// if (content == null)
|
||||
// return false;
|
||||
// String trimmed = content.trim();
|
||||
// // XML usually starts with '<' and ends with '>'
|
||||
// return trimmed.startsWith("<") && trimmed.endsWith(">");
|
||||
// }
|
||||
//
|
||||
// private void processBatchData(Data_lake dataLake, Object responseBody, ObjectMapper mapper)
|
||||
// throws JsonProcessingException {
|
||||
//
|
||||
// int batchVolume = (dataLake.getBatch_volume() != null && dataLake.getBatch_volume() > 0)
|
||||
// ? dataLake.getBatch_volume()
|
||||
// : 100; // default batch size if not given
|
||||
//
|
||||
// // Convert to JsonNode
|
||||
// JsonNode jsonNode = mapper.valueToTree(responseBody);
|
||||
//
|
||||
// if (jsonNode.isArray()) {
|
||||
// ArrayNode arrayNode = (ArrayNode) jsonNode;
|
||||
// int total = arrayNode.size();
|
||||
// System.out.println("Total records: " + total);
|
||||
//
|
||||
// for (int i = 0; i < total; i += batchVolume) {
|
||||
// int end = Math.min(i + batchVolume, total);
|
||||
//
|
||||
// // Create a sub-array manually
|
||||
// ArrayNode subArray = mapper.createArrayNode();
|
||||
// for (int j = i; j < end; j++) {
|
||||
// subArray.add(arrayNode.get(j));
|
||||
// }
|
||||
//
|
||||
// String subJson = mapper.writeValueAsString(subArray);
|
||||
//
|
||||
// BatchData batch = new BatchData();
|
||||
// batch.setDatalake_id(dataLake.getId());
|
||||
// batch.setBatchjson(subJson);
|
||||
// batchRepo.save(batch);
|
||||
// }
|
||||
//
|
||||
// System.out.println("Inserted " + (int) Math.ceil((double) total / batchVolume) + " batch records.");
|
||||
//
|
||||
// } else {
|
||||
// // Single object → one record
|
||||
// BatchData batch = new BatchData();
|
||||
// batch.setDatalake_id(dataLake.getId());
|
||||
// batch.setBatchjson(mapper.writeValueAsString(jsonNode));
|
||||
// batchRepo.save(batch);
|
||||
//
|
||||
// System.out.println("Inserted single batch record.");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public String mergeBatchData(Integer datalakeId) throws Exception {
|
||||
// List<BatchData> batchList = batchRepo.findByDatalake_id(datalakeId);
|
||||
//
|
||||
// if (batchList.isEmpty()) {
|
||||
// throw new RuntimeException("No batch data found for datalake_id: " + datalakeId);
|
||||
// }
|
||||
//
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
// ArrayNode mergedArray = mapper.createArrayNode();
|
||||
//
|
||||
// for (BatchData batch : batchList) {
|
||||
// String json = batch.getBatchjson();
|
||||
// JsonNode node = mapper.readTree(json);
|
||||
//
|
||||
// if (node.isArray()) {
|
||||
// // Add each element to merged array
|
||||
// for (JsonNode item : node) {
|
||||
// mergedArray.add(item);
|
||||
// }
|
||||
// } else {
|
||||
// // Single object, just add directly
|
||||
// mergedArray.add(node);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// String mergedJson = mapper.writeValueAsString(mergedArray);
|
||||
// System.out.println("Merged JSON size: " + mergedArray.size());
|
||||
// return mergedJson;
|
||||
// }
|
||||
//
|
||||
// public ResponseEntity<Object> GET(String get) {
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
//
|
||||
// ResponseEntity<Object> u = restTemplate.getForEntity(get, Object.class);
|
||||
//
|
||||
// return u;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public ResponseEntity<String> GETAsString(String url) {
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
// return restTemplate.getForEntity(url, String.class);
|
||||
// }
|
||||
|
||||
//
|
||||
// public ResponseEntity<String> GETWithString(String url, Integer sureid) {
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
//
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.setAccept(Collections.singletonList(MediaType.ALL)); // accept JSON or XML
|
||||
// headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
//
|
||||
// // 🔹 Add your token here (you can make it dynamic)
|
||||
// String token = getToken(sureid); // helper method (see below)
|
||||
// if (token != null && !token.isEmpty()) {
|
||||
// headers.set("Authorization", "Bearer " + token);
|
||||
// }
|
||||
//
|
||||
// HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
//
|
||||
// ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
//
|
||||
// return response;
|
||||
// }
|
||||
//
|
||||
// private String getToken(Integer sureid) {
|
||||
// Sure_Connect connect = sureService.getbyid(sureid);
|
||||
// String access_token = connect.getAccess_token();
|
||||
//
|
||||
// return access_token; // optional
|
||||
// }
|
||||
|
||||
public AppUser getUser() {
|
||||
AppUser user = userService.getLoggedInUser();
|
||||
return user;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.realnet.DynamicDashbard.controllers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartTemplate;
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.services.ChartTemplateService;
|
||||
import com.realnet.DynamicDashbard.services.ChartTypeService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/chart-templates")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class ChartTemplateController {
|
||||
|
||||
@Autowired
|
||||
private ChartTemplateService chartTemplateService;
|
||||
|
||||
@Autowired
|
||||
private ChartTypeService chartTypeService;
|
||||
|
||||
@GetMapping("/all")
|
||||
public List<ChartTemplate> getAllChartTemplates() {
|
||||
return chartTemplateService.getAllChartTemplates();
|
||||
}
|
||||
|
||||
@GetMapping("/chart-type/{chartTypeId}")
|
||||
public List<ChartTemplate> getChartTemplatesByChartType(@PathVariable Long chartTypeId) {
|
||||
return chartTemplateService.getChartTemplatesByChartType(chartTypeId);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<ChartTemplate> getChartTemplateById(@PathVariable Long id) {
|
||||
Optional<ChartTemplate> chartTemplate = chartTemplateService.getChartTemplateById(id);
|
||||
return chartTemplate.map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<ChartTemplate> createChartTemplate(@RequestParam Long chartTypeId,
|
||||
@RequestBody ChartTemplate chartTemplate) {
|
||||
try {
|
||||
// If chartType is provided as ID only, fetch the full ChartType object
|
||||
if (chartTypeId != null) {
|
||||
ChartType chartType = chartTypeService.getChartTypeById(chartTypeId)
|
||||
.orElseThrow(() -> new RuntimeException(
|
||||
"ChartType not found with id: " + chartTemplate.getChartType().getId()));
|
||||
chartTemplate.setChartType(chartType);
|
||||
}
|
||||
|
||||
ChartTemplate createdChartTemplate = chartTemplateService.saveChartTemplate(chartTemplate);
|
||||
return ResponseEntity.ok(createdChartTemplate);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<ChartTemplate> updateChartTemplate(@PathVariable Long id,
|
||||
@RequestBody ChartTemplate chartTemplateDetails) {
|
||||
try {
|
||||
ChartTemplate updatedChartTemplate = chartTemplateService.updateChartTemplate(id, chartTemplateDetails);
|
||||
return ResponseEntity.ok(updatedChartTemplate);
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteChartTemplate(@PathVariable Long id) {
|
||||
try {
|
||||
chartTemplateService.deleteChartTemplate(id);
|
||||
return ResponseEntity.ok().build();
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.realnet.DynamicDashbard.controllers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.services.ChartTypeService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/chart-types")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class ChartTypeController {
|
||||
|
||||
@Autowired
|
||||
private ChartTypeService chartTypeService;
|
||||
|
||||
@GetMapping
|
||||
public List<ChartType> getAllChartTypes() {
|
||||
return chartTypeService.getAllChartTypes();
|
||||
}
|
||||
|
||||
@GetMapping("/byname")
|
||||
public ResponseEntity<ChartType> getAllChartTypes(@RequestParam String chartName) {
|
||||
Optional<ChartType> chartType = chartTypeService.getChartTypeByName(chartName);
|
||||
|
||||
if (!chartType.isPresent()) {
|
||||
System.out.println(" chart not found");
|
||||
|
||||
}
|
||||
System.out.println(chartName + " found :\n");
|
||||
|
||||
return chartType.map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@GetMapping("/active")
|
||||
public List<ChartType> getActiveChartTypes() {
|
||||
return chartTypeService.getActiveChartTypes();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<ChartType> getChartTypeById(@PathVariable Long id) {
|
||||
Optional<ChartType> chartType = chartTypeService.getChartTypeById(id);
|
||||
return chartType.map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ChartType createChartType(@RequestBody ChartType chartType) {
|
||||
return chartTypeService.saveChartType(chartType);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<ChartType> updateChartType(@PathVariable Long id, @RequestBody ChartType chartTypeDetails) {
|
||||
try {
|
||||
ChartType updatedChartType = chartTypeService.updateChartType(id, chartTypeDetails);
|
||||
return ResponseEntity.ok(updatedChartType);
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteChartType(@PathVariable Long id) {
|
||||
try {
|
||||
chartTypeService.deleteChartType(id);
|
||||
return ResponseEntity.ok().build();
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.realnet.DynamicDashbard.controllers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ComponentProperty;
|
||||
import com.realnet.DynamicDashbard.entities.UiComponent;
|
||||
import com.realnet.DynamicDashbard.services.ComponentPropertyService;
|
||||
import com.realnet.DynamicDashbard.services.UiComponentService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/component-properties")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class ComponentPropertyController {
|
||||
|
||||
@Autowired
|
||||
private ComponentPropertyService componentPropertyService;
|
||||
|
||||
@Autowired
|
||||
private UiComponentService uiComponentService;
|
||||
|
||||
@GetMapping
|
||||
public List<ComponentProperty> getAllComponentProperties() {
|
||||
return componentPropertyService.getAllComponentProperties();
|
||||
}
|
||||
|
||||
@GetMapping("/component/{componentId}")
|
||||
public List<ComponentProperty> getComponentPropertiesByComponent(@PathVariable Long componentId) {
|
||||
return componentPropertyService.getComponentPropertiesByComponent(componentId);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<ComponentProperty> getComponentPropertyById(@PathVariable Long id) {
|
||||
Optional<ComponentProperty> componentProperty = componentPropertyService.getComponentPropertyById(id);
|
||||
return componentProperty.map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<ComponentProperty> createComponentProperty(@RequestBody ComponentProperty componentProperty) {
|
||||
try {
|
||||
// If component is provided as ID only, fetch the full UiComponent object
|
||||
if (componentProperty.getComponent() != null && componentProperty.getComponent().getId() != null
|
||||
&& (componentProperty.getComponent().getComponentName() == null
|
||||
|| componentProperty.getComponent().getComponentName().isEmpty())) {
|
||||
UiComponent component = uiComponentService.getUiComponentById(componentProperty.getComponent().getId())
|
||||
.orElseThrow(() -> new RuntimeException(
|
||||
"UiComponent not found with id: " + componentProperty.getComponent().getId()));
|
||||
componentProperty.setComponent(component);
|
||||
}
|
||||
|
||||
ComponentProperty createdComponentProperty = componentPropertyService
|
||||
.saveComponentProperty(componentProperty);
|
||||
return ResponseEntity.ok(createdComponentProperty);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<ComponentProperty> updateComponentProperty(@PathVariable Long id,
|
||||
@RequestBody ComponentProperty componentPropertyDetails) {
|
||||
try {
|
||||
ComponentProperty updatedComponentProperty = componentPropertyService.updateComponentProperty(id,
|
||||
componentPropertyDetails);
|
||||
return ResponseEntity.ok(updatedComponentProperty);
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteComponentProperty(@PathVariable Long id) {
|
||||
try {
|
||||
componentPropertyService.deleteComponentProperty(id);
|
||||
return ResponseEntity.ok().build();
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.realnet.DynamicDashbard.controllers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.entities.DynamicField;
|
||||
import com.realnet.DynamicDashbard.services.ChartTypeService;
|
||||
import com.realnet.DynamicDashbard.services.DynamicFieldService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/dynamic-fields")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class DynamicFieldController {
|
||||
|
||||
@Autowired
|
||||
private DynamicFieldService dynamicFieldService;
|
||||
|
||||
@Autowired
|
||||
private ChartTypeService chartTypeService;
|
||||
|
||||
@GetMapping
|
||||
public List<DynamicField> getAllDynamicFields() {
|
||||
return dynamicFieldService.getAllDynamicFields();
|
||||
}
|
||||
|
||||
@GetMapping("/chart-type/{chartTypeId}")
|
||||
public List<DynamicField> getDynamicFieldsByChartType(@PathVariable Long chartTypeId) {
|
||||
return dynamicFieldService.getDynamicFieldsByChartType(chartTypeId);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<DynamicField> getDynamicFieldById(@PathVariable Long id) {
|
||||
Optional<DynamicField> dynamicField = dynamicFieldService.getDynamicFieldById(id);
|
||||
return dynamicField.map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<DynamicField> createDynamicField(@RequestParam Long chartTypeId,
|
||||
@RequestBody DynamicField dynamicField) {
|
||||
try {
|
||||
// If chartType is provided as ID only, fetch the full ChartType object
|
||||
if (chartTypeId != null) {
|
||||
ChartType chartType = chartTypeService.getChartTypeById(chartTypeId)
|
||||
.orElseThrow(() -> new RuntimeException(
|
||||
"ChartType not found with id: " + dynamicField.getChartType().getId()));
|
||||
dynamicField.setChartType(chartType);
|
||||
}
|
||||
|
||||
DynamicField createdDynamicField = dynamicFieldService.saveDynamicField(dynamicField);
|
||||
return ResponseEntity.ok(createdDynamicField);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<DynamicField> updateDynamicField(@PathVariable Long id,
|
||||
@RequestBody DynamicField dynamicFieldDetails) {
|
||||
try {
|
||||
DynamicField updatedDynamicField = dynamicFieldService.updateDynamicField(id, dynamicFieldDetails);
|
||||
return ResponseEntity.ok(updatedDynamicField);
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteDynamicField(@PathVariable Long id) {
|
||||
try {
|
||||
dynamicFieldService.deleteDynamicField(id);
|
||||
return ResponseEntity.ok().build();
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.realnet.DynamicDashbard.controllers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.entities.UiComponent;
|
||||
import com.realnet.DynamicDashbard.services.ChartTypeService;
|
||||
import com.realnet.DynamicDashbard.services.UiComponentService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/ui-components")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class UiComponentController {
|
||||
|
||||
@Autowired
|
||||
private UiComponentService uiComponentService;
|
||||
|
||||
@Autowired
|
||||
private ChartTypeService chartTypeService;
|
||||
|
||||
@GetMapping
|
||||
public List<UiComponent> getAllUiComponents() {
|
||||
return uiComponentService.getAllUiComponents();
|
||||
}
|
||||
|
||||
@GetMapping("/chart-type/{chartTypeId}")
|
||||
public List<UiComponent> getUiComponentsByChartType(@PathVariable Long chartTypeId) {
|
||||
return uiComponentService.getUiComponentsByChartType(chartTypeId);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<UiComponent> getUiComponentById(@PathVariable Long id) {
|
||||
Optional<UiComponent> uiComponent = uiComponentService.getUiComponentById(id);
|
||||
return uiComponent.map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<UiComponent> createUiComponent(@RequestBody UiComponent uiComponent) {
|
||||
try {
|
||||
// If chartType is provided as ID only, fetch the full ChartType object
|
||||
if (uiComponent.getChartType() != null && uiComponent.getChartType().getId() != null
|
||||
&& (uiComponent.getChartType().getName() == null
|
||||
|| uiComponent.getChartType().getName().isEmpty())) {
|
||||
ChartType chartType = chartTypeService.getChartTypeById(uiComponent.getChartType().getId())
|
||||
.orElseThrow(() -> new RuntimeException(
|
||||
"ChartType not found with id: " + uiComponent.getChartType().getId()));
|
||||
uiComponent.setChartType(chartType);
|
||||
}
|
||||
|
||||
UiComponent createdUiComponent = uiComponentService.saveUiComponent(uiComponent);
|
||||
System.out.println(createdUiComponent.getComponentName() + " ui component created successfully..");
|
||||
return ResponseEntity.ok(createdUiComponent);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<UiComponent> updateUiComponent(@PathVariable Long id,
|
||||
@RequestBody UiComponent uiComponentDetails) {
|
||||
try {
|
||||
UiComponent updatedUiComponent = uiComponentService.updateUiComponent(id, uiComponentDetails);
|
||||
return ResponseEntity.ok(updatedUiComponent);
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteUiComponent(@PathVariable Long id) {
|
||||
try {
|
||||
uiComponentService.deleteUiComponent(id);
|
||||
return ResponseEntity.ok().build();
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.realnet.DynamicDashbard.entities;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.PrePersist;
|
||||
import javax.persistence.PreUpdate;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "chart_templates")
|
||||
public class ChartTemplate {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "chart_type_id", nullable = false)
|
||||
@JsonBackReference
|
||||
private ChartType chartType;
|
||||
|
||||
@Column(name = "template_name", nullable = false, length = 100)
|
||||
private String templateName;
|
||||
|
||||
@Column(name = "template_html", columnDefinition = "TEXT")
|
||||
private String templateHtml;
|
||||
|
||||
@Column(name = "template_css", columnDefinition = "TEXT")
|
||||
private String templateCss;
|
||||
|
||||
@Column(name = "is_default")
|
||||
private Boolean isDefault = false;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "created_at")
|
||||
@CreatedDate
|
||||
private Date createdAt;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "updated_at")
|
||||
@LastModifiedDate
|
||||
private Date updatedAt;
|
||||
|
||||
//
|
||||
// @PrePersist
|
||||
// protected void onCreate() {
|
||||
// createdAt = LocalDateTime.now();
|
||||
// updatedAt = LocalDateTime.now();
|
||||
// }
|
||||
//
|
||||
// @PreUpdate
|
||||
// protected void onUpdate() {
|
||||
// updatedAt = LocalDateTime.now();
|
||||
// }
|
||||
//
|
||||
// // Constructors
|
||||
// public ChartTemplate() {
|
||||
// }
|
||||
//
|
||||
// public ChartTemplate(ChartType chartType, String templateName, String templateHtml, String templateCss) {
|
||||
// this.chartType = chartType;
|
||||
// this.templateName = templateName;
|
||||
// this.templateHtml = templateHtml;
|
||||
// this.templateCss = templateCss;
|
||||
// }
|
||||
//
|
||||
// // Getters and Setters
|
||||
// public Long getId() {
|
||||
// return id;
|
||||
// }
|
||||
//
|
||||
// public void setId(Long id) {
|
||||
// this.id = id;
|
||||
// }
|
||||
//
|
||||
// public ChartType getChartType() {
|
||||
// return chartType;
|
||||
// }
|
||||
//
|
||||
// public void setChartType(ChartType chartType) {
|
||||
// this.chartType = chartType;
|
||||
// }
|
||||
//
|
||||
// public String getTemplateName() {
|
||||
// return templateName;
|
||||
// }
|
||||
//
|
||||
// public void setTemplateName(String templateName) {
|
||||
// this.templateName = templateName;
|
||||
// }
|
||||
//
|
||||
// public String getTemplateHtml() {
|
||||
// return templateHtml;
|
||||
// }
|
||||
//
|
||||
// public void setTemplateHtml(String templateHtml) {
|
||||
// this.templateHtml = templateHtml;
|
||||
// }
|
||||
//
|
||||
// public String getTemplateCss() {
|
||||
// return templateCss;
|
||||
// }
|
||||
//
|
||||
// public void setTemplateCss(String templateCss) {
|
||||
// this.templateCss = templateCss;
|
||||
// }
|
||||
//
|
||||
// public Boolean getIsDefault() {
|
||||
// return isDefault;
|
||||
// }
|
||||
//
|
||||
// public void setIsDefault(Boolean isDefault) {
|
||||
// this.isDefault = isDefault;
|
||||
// }
|
||||
//
|
||||
// public LocalDateTime getCreatedAt() {
|
||||
// return createdAt;
|
||||
// }
|
||||
//
|
||||
// public void setCreatedAt(LocalDateTime createdAt) {
|
||||
// this.createdAt = createdAt;
|
||||
// }
|
||||
//
|
||||
// public LocalDateTime getUpdatedAt() {
|
||||
// return updatedAt;
|
||||
// }
|
||||
//
|
||||
// public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
// this.updatedAt = updatedAt;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.realnet.DynamicDashbard.entities;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "chart_types")
|
||||
public class ChartType {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "name", nullable = false, length = 50)
|
||||
private String name;
|
||||
|
||||
@Column(name = "display_name", length = 100)
|
||||
private String displayName;
|
||||
|
||||
@Column(name = "description", columnDefinition = "TEXT")
|
||||
private String description;
|
||||
|
||||
@Column(name = "is_active")
|
||||
private Boolean isActive = true;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "created_at")
|
||||
@CreatedDate
|
||||
private Date createdAt;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "updated_at")
|
||||
@LastModifiedDate
|
||||
private Date updatedAt;
|
||||
|
||||
@OneToMany(mappedBy = "chartType", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JsonManagedReference
|
||||
private List<UiComponent> uiComponents;
|
||||
|
||||
@OneToMany(mappedBy = "chartType", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JsonManagedReference
|
||||
private List<ChartTemplate> chartTemplates;
|
||||
|
||||
@OneToMany(mappedBy = "chartType", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JsonManagedReference
|
||||
private List<DynamicField> dynamicFields;
|
||||
|
||||
// @PrePersist
|
||||
// protected void onCreate() {
|
||||
// createdAt = LocalDateTime.now();
|
||||
// updatedAt = LocalDateTime.now();
|
||||
// }
|
||||
//
|
||||
// @PreUpdate
|
||||
// protected void onUpdate() {
|
||||
// updatedAt = LocalDateTime.now();
|
||||
// }
|
||||
//
|
||||
// // Constructors
|
||||
// public ChartType() {
|
||||
// }
|
||||
//
|
||||
// public ChartType(String name, String displayName, String description) {
|
||||
// this.name = name;
|
||||
// this.displayName = displayName;
|
||||
// this.description = description;
|
||||
// }
|
||||
//
|
||||
// // Getters and Setters
|
||||
// public Long getId() {
|
||||
// return id;
|
||||
// }
|
||||
//
|
||||
// public void setId(Long id) {
|
||||
// this.id = id;
|
||||
// }
|
||||
//
|
||||
// public String getName() {
|
||||
// return name;
|
||||
// }
|
||||
//
|
||||
// public void setName(String name) {
|
||||
// this.name = name;
|
||||
// }
|
||||
//
|
||||
// public String getDisplayName() {
|
||||
// return displayName;
|
||||
// }
|
||||
//
|
||||
// public void setDisplayName(String displayName) {
|
||||
// this.displayName = displayName;
|
||||
// }
|
||||
//
|
||||
// public String getDescription() {
|
||||
// return description;
|
||||
// }
|
||||
//
|
||||
// public void setDescription(String description) {
|
||||
// this.description = description;
|
||||
// }
|
||||
//
|
||||
// public Boolean getIsActive() {
|
||||
// return isActive;
|
||||
// }
|
||||
//
|
||||
// public void setIsActive(Boolean isActive) {
|
||||
// this.isActive = isActive;
|
||||
// }
|
||||
//
|
||||
// public LocalDateTime getCreatedAt() {
|
||||
// return createdAt;
|
||||
// }
|
||||
//
|
||||
// public void setCreatedAt(LocalDateTime createdAt) {
|
||||
// this.createdAt = createdAt;
|
||||
// }
|
||||
//
|
||||
// public LocalDateTime getUpdatedAt() {
|
||||
// return updatedAt;
|
||||
// }
|
||||
//
|
||||
// public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
// this.updatedAt = updatedAt;
|
||||
// }
|
||||
//
|
||||
// public List<UiComponent> getUiComponents() {
|
||||
// return uiComponents;
|
||||
// }
|
||||
//
|
||||
// public void setUiComponents(List<UiComponent> uiComponents) {
|
||||
// this.uiComponents = uiComponents;
|
||||
// }
|
||||
//
|
||||
// public List<ChartTemplate> getChartTemplates() {
|
||||
// return chartTemplates;
|
||||
// }
|
||||
//
|
||||
// public void setChartTemplates(List<ChartTemplate> chartTemplates) {
|
||||
// this.chartTemplates = chartTemplates;
|
||||
// }
|
||||
//
|
||||
// public List<DynamicField> getDynamicFields() {
|
||||
// return dynamicFields;
|
||||
// }
|
||||
//
|
||||
// public void setDynamicFields(List<DynamicField> dynamicFields) {
|
||||
// this.dynamicFields = dynamicFields;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.realnet.DynamicDashbard.entities;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "component_properties")
|
||||
public class ComponentProperty {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "component_id", nullable = false)
|
||||
@JsonBackReference
|
||||
private UiComponent component;
|
||||
|
||||
@Column(name = "property_name", nullable = false, length = 100)
|
||||
private String propertyName;
|
||||
|
||||
@Column(name = "property_value", columnDefinition = "TEXT")
|
||||
private String propertyValue;
|
||||
|
||||
@Column(name = "property_type", length = 50)
|
||||
private String propertyType;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "created_at")
|
||||
@CreatedDate
|
||||
private Date createdAt;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "updated_at")
|
||||
@LastModifiedDate
|
||||
private Date updatedAt;
|
||||
|
||||
//
|
||||
// @PrePersist
|
||||
// protected void onCreate() {
|
||||
// createdAt = LocalDateTime.now();
|
||||
// updatedAt = LocalDateTime.now();
|
||||
// }
|
||||
//
|
||||
// @PreUpdate
|
||||
// protected void onUpdate() {
|
||||
// updatedAt = LocalDateTime.now();
|
||||
// }
|
||||
//
|
||||
// // Constructors
|
||||
// public ComponentProperty() {}
|
||||
//
|
||||
// public ComponentProperty(UiComponent component, String propertyName, String propertyValue, String propertyType) {
|
||||
// this.component = component;
|
||||
// this.propertyName = propertyName;
|
||||
// this.propertyValue = propertyValue;
|
||||
// this.propertyType = propertyType;
|
||||
// }
|
||||
//
|
||||
// // Getters and Setters
|
||||
// public Long getId() {
|
||||
// return id;
|
||||
// }
|
||||
//
|
||||
// public void setId(Long id) {
|
||||
// this.id = id;
|
||||
// }
|
||||
//
|
||||
// public UiComponent getComponent() {
|
||||
// return component;
|
||||
// }
|
||||
//
|
||||
// public void setComponent(UiComponent component) {
|
||||
// this.component = component;
|
||||
// }
|
||||
//
|
||||
// public String getPropertyName() {
|
||||
// return propertyName;
|
||||
// }
|
||||
//
|
||||
// public void setPropertyName(String propertyName) {
|
||||
// this.propertyName = propertyName;
|
||||
// }
|
||||
//
|
||||
// public String getPropertyValue() {
|
||||
// return propertyValue;
|
||||
// }
|
||||
//
|
||||
// public void setPropertyValue(String propertyValue) {
|
||||
// this.propertyValue = propertyValue;
|
||||
// }
|
||||
//
|
||||
// public String getPropertyType() {
|
||||
// return propertyType;
|
||||
// }
|
||||
//
|
||||
// public void setPropertyType(String propertyType) {
|
||||
// this.propertyType = propertyType;
|
||||
// }
|
||||
//
|
||||
// public LocalDateTime getCreatedAt() {
|
||||
// return createdAt;
|
||||
// }
|
||||
//
|
||||
// public void setCreatedAt(LocalDateTime createdAt) {
|
||||
// this.createdAt = createdAt;
|
||||
// }
|
||||
//
|
||||
// public LocalDateTime getUpdatedAt() {
|
||||
// return updatedAt;
|
||||
// }
|
||||
//
|
||||
// public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
// this.updatedAt = updatedAt;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.realnet.DynamicDashbard.entities;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.PrePersist;
|
||||
import javax.persistence.PreUpdate;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
|
||||
@Entity
|
||||
@Table(name = "dynamic_fields")
|
||||
public class DynamicField {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "chart_type_id", nullable = false)
|
||||
@JsonBackReference
|
||||
private ChartType chartType;
|
||||
|
||||
@Column(name = "field_name", nullable = false, length = 100)
|
||||
private String fieldName;
|
||||
|
||||
@Column(name = "field_label", length = 100)
|
||||
private String fieldLabel;
|
||||
|
||||
@Column(name = "field_type", length = 50)
|
||||
private String fieldType;
|
||||
|
||||
@Column(name = "field_options", columnDefinition = "TEXT")
|
||||
private String fieldOptions;
|
||||
|
||||
@Column(name = "is_required")
|
||||
private Boolean isRequired = false;
|
||||
|
||||
@Column(name = "show_in_ui")
|
||||
private Boolean showInUi = true;
|
||||
|
||||
@Column(name = "sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
@Column(name = "created_at")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
createdAt = LocalDateTime.now();
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void onUpdate() {
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
// Constructors
|
||||
public DynamicField() {
|
||||
}
|
||||
|
||||
public DynamicField(ChartType chartType, String fieldName, String fieldLabel, String fieldType) {
|
||||
this.chartType = chartType;
|
||||
this.fieldName = fieldName;
|
||||
this.fieldLabel = fieldLabel;
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ChartType getChartType() {
|
||||
return chartType;
|
||||
}
|
||||
|
||||
public void setChartType(ChartType chartType) {
|
||||
this.chartType = chartType;
|
||||
}
|
||||
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
public void setFieldName(String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
public String getFieldLabel() {
|
||||
return fieldLabel;
|
||||
}
|
||||
|
||||
public void setFieldLabel(String fieldLabel) {
|
||||
this.fieldLabel = fieldLabel;
|
||||
}
|
||||
|
||||
public String getFieldType() {
|
||||
return fieldType;
|
||||
}
|
||||
|
||||
public void setFieldType(String fieldType) {
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
|
||||
public String getFieldOptions() {
|
||||
return fieldOptions;
|
||||
}
|
||||
|
||||
public void setFieldOptions(String fieldOptions) {
|
||||
this.fieldOptions = fieldOptions;
|
||||
}
|
||||
|
||||
public Boolean getIsRequired() {
|
||||
return isRequired;
|
||||
}
|
||||
|
||||
public void setIsRequired(Boolean isRequired) {
|
||||
this.isRequired = isRequired;
|
||||
}
|
||||
|
||||
public Boolean getShowInUi() {
|
||||
return showInUi;
|
||||
}
|
||||
|
||||
public void setShowInUi(Boolean showInUi) {
|
||||
this.showInUi = showInUi;
|
||||
}
|
||||
|
||||
public Integer getSortOrder() {
|
||||
return sortOrder;
|
||||
}
|
||||
|
||||
public void setSortOrder(Integer sortOrder) {
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.realnet.DynamicDashbard.entities;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "ui_components")
|
||||
public class UiComponent {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "chart_type_id", nullable = false)
|
||||
@JsonBackReference
|
||||
private ChartType chartType;
|
||||
|
||||
@Column(name = "component_name", nullable = false, length = 100)
|
||||
private String componentName;
|
||||
|
||||
@Column(name = "component_type", length = 50)
|
||||
private String componentType;
|
||||
|
||||
@Column(name = "display_label", length = 100)
|
||||
private String displayLabel;
|
||||
|
||||
@Column(name = "placeholder", columnDefinition = "TEXT")
|
||||
private String placeholder;
|
||||
|
||||
@Column(name = "is_required")
|
||||
private Boolean isRequired = false;
|
||||
|
||||
@Column(name = "sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "created_at")
|
||||
@CreatedDate
|
||||
private Date createdAt;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name = "updated_at")
|
||||
@LastModifiedDate
|
||||
private Date updatedAt;
|
||||
|
||||
@OneToMany(mappedBy = "component", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JsonManagedReference
|
||||
private List<ComponentProperty> componentProperties;
|
||||
|
||||
// @PrePersist
|
||||
// protected void onCreate() {
|
||||
// createdAt = LocalDateTime.now();
|
||||
// updatedAt = LocalDateTime.now();
|
||||
// }
|
||||
//
|
||||
// @PreUpdate
|
||||
// protected void onUpdate() {
|
||||
// updatedAt = LocalDateTime.now();
|
||||
// }
|
||||
|
||||
// Constructors
|
||||
public UiComponent() {
|
||||
}
|
||||
|
||||
public UiComponent(ChartType chartType, String componentName, String componentType) {
|
||||
this.chartType = chartType;
|
||||
this.componentName = componentName;
|
||||
this.componentType = componentType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.realnet.DynamicDashbard.repositories;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartTemplate;
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
|
||||
@Repository
|
||||
public interface ChartTemplateRepository extends JpaRepository<ChartTemplate, Long> {
|
||||
List<ChartTemplate> findByChartType(ChartType chartType);
|
||||
|
||||
Optional<ChartTemplate> findByChartTypeAndIsDefaultTrue(ChartType chartType);
|
||||
|
||||
List<ChartTemplate> findByChartTypeAndTemplateNameContainingIgnoreCase(ChartType chartType, String templateName);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.realnet.DynamicDashbard.repositories;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
|
||||
@Repository
|
||||
public interface ChartTypeRepository extends JpaRepository<ChartType, Long> {
|
||||
|
||||
List<ChartType> findByIsActiveTrue();
|
||||
|
||||
Optional<ChartType> findByName(String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.realnet.DynamicDashbard.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ComponentProperty;
|
||||
import com.realnet.DynamicDashbard.entities.UiComponent;
|
||||
|
||||
@Repository
|
||||
public interface ComponentPropertyRepository extends JpaRepository<ComponentProperty, Long> {
|
||||
List<ComponentProperty> findByComponent(UiComponent component);
|
||||
List<ComponentProperty> findByComponentAndPropertyName(UiComponent component, String propertyName);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
package com.realnet.DynamicDashbard.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.entities.DynamicField;
|
||||
|
||||
@Repository
|
||||
public interface DynamicFieldRepository extends JpaRepository<DynamicField, Long> {
|
||||
List<DynamicField> findByChartType(ChartType chartType);
|
||||
List<DynamicField> findByChartTypeAndIsRequiredTrue(ChartType chartType);
|
||||
List<DynamicField> findByChartTypeAndShowInUiTrueOrderBySortOrder(ChartType chartType);
|
||||
List<DynamicField> findByChartTypeOrderBySortOrder(ChartType chartType);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.realnet.DynamicDashbard.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.entities.UiComponent;
|
||||
|
||||
@Repository
|
||||
public interface UiComponentRepository extends JpaRepository<UiComponent, Long> {
|
||||
List<UiComponent> findByChartType(ChartType chartType);
|
||||
|
||||
List<UiComponent> findByChartTypeAndIsRequiredTrue(ChartType chartType);
|
||||
|
||||
List<UiComponent> findByChartTypeOrderBySortOrder(ChartType chartType);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.realnet.DynamicDashbard.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartTemplate;
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.repositories.ChartTemplateRepository;
|
||||
import com.realnet.DynamicDashbard.repositories.ChartTypeRepository;
|
||||
|
||||
@Service
|
||||
public class ChartTemplateService {
|
||||
|
||||
@Autowired
|
||||
private ChartTemplateRepository chartTemplateRepository;
|
||||
|
||||
@Autowired
|
||||
private ChartTypeRepository chartTypeRepository;
|
||||
|
||||
public List<ChartTemplate> getAllChartTemplates() {
|
||||
return chartTemplateRepository.findAll();
|
||||
}
|
||||
|
||||
public List<ChartTemplate> getChartTemplatesByChartType(Long chartTypeId) {
|
||||
ChartType chartType = chartTypeRepository.findById(chartTypeId)
|
||||
.orElseThrow(() -> new RuntimeException("ChartType not found with id: " + chartTypeId));
|
||||
return chartTemplateRepository.findByChartType(chartType);
|
||||
}
|
||||
|
||||
public Optional<ChartTemplate> getChartTemplateById(Long id) {
|
||||
return chartTemplateRepository.findById(id);
|
||||
}
|
||||
|
||||
public ChartTemplate saveChartTemplate(ChartTemplate chartTemplate) {
|
||||
return chartTemplateRepository.save(chartTemplate);
|
||||
}
|
||||
|
||||
public ChartTemplate updateChartTemplate(Long id, ChartTemplate chartTemplateDetails) {
|
||||
ChartTemplate chartTemplate = chartTemplateRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("ChartTemplate not found with id: " + id));
|
||||
|
||||
chartTemplate.setTemplateName(chartTemplateDetails.getTemplateName());
|
||||
chartTemplate.setTemplateHtml(chartTemplateDetails.getTemplateHtml());
|
||||
chartTemplate.setTemplateCss(chartTemplateDetails.getTemplateCss());
|
||||
chartTemplate.setIsDefault(chartTemplateDetails.getIsDefault());
|
||||
|
||||
return chartTemplateRepository.save(chartTemplate);
|
||||
}
|
||||
|
||||
public void deleteChartTemplate(Long id) {
|
||||
ChartTemplate chartTemplate = chartTemplateRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("ChartTemplate not found with id: " + id));
|
||||
chartTemplateRepository.delete(chartTemplate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.realnet.DynamicDashbard.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.repositories.ChartTypeRepository;
|
||||
|
||||
@Service
|
||||
public class ChartTypeService {
|
||||
|
||||
@Autowired
|
||||
private ChartTypeRepository chartTypeRepository;
|
||||
|
||||
public List<ChartType> getAllChartTypes() {
|
||||
return chartTypeRepository.findAll();
|
||||
}
|
||||
|
||||
public List<ChartType> getActiveChartTypes() {
|
||||
return chartTypeRepository.findByIsActiveTrue();
|
||||
}
|
||||
|
||||
public Optional<ChartType> getChartTypeById(Long id) {
|
||||
return chartTypeRepository.findById(id);
|
||||
}
|
||||
|
||||
public Optional<ChartType> getChartTypeByName(String name) {
|
||||
return chartTypeRepository.findByName(name);
|
||||
}
|
||||
|
||||
public ChartType saveChartType(ChartType chartType) {
|
||||
return chartTypeRepository.save(chartType);
|
||||
}
|
||||
|
||||
public ChartType updateChartType(Long id, ChartType chartTypeDetails) {
|
||||
ChartType chartType = chartTypeRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("ChartType not found with id: " + id));
|
||||
|
||||
chartType.setName(chartTypeDetails.getName());
|
||||
chartType.setDisplayName(chartTypeDetails.getDisplayName());
|
||||
chartType.setDescription(chartTypeDetails.getDescription());
|
||||
chartType.setIsActive(chartTypeDetails.getIsActive());
|
||||
|
||||
return chartTypeRepository.save(chartType);
|
||||
}
|
||||
|
||||
public void deleteChartType(Long id) {
|
||||
ChartType chartType = chartTypeRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("ChartType not found with id: " + id));
|
||||
chartTypeRepository.delete(chartType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.realnet.DynamicDashbard.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ComponentProperty;
|
||||
import com.realnet.DynamicDashbard.entities.UiComponent;
|
||||
import com.realnet.DynamicDashbard.repositories.ComponentPropertyRepository;
|
||||
import com.realnet.DynamicDashbard.repositories.UiComponentRepository;
|
||||
|
||||
@Service
|
||||
public class ComponentPropertyService {
|
||||
|
||||
@Autowired
|
||||
private ComponentPropertyRepository componentPropertyRepository;
|
||||
|
||||
@Autowired
|
||||
private UiComponentRepository uiComponentRepository;
|
||||
|
||||
public List<ComponentProperty> getAllComponentProperties() {
|
||||
return componentPropertyRepository.findAll();
|
||||
}
|
||||
|
||||
public List<ComponentProperty> getComponentPropertiesByComponent(Long componentId) {
|
||||
UiComponent component = uiComponentRepository.findById(componentId)
|
||||
.orElseThrow(() -> new RuntimeException("UiComponent not found with id: " + componentId));
|
||||
return componentPropertyRepository.findByComponent(component);
|
||||
}
|
||||
|
||||
public Optional<ComponentProperty> getComponentPropertyById(Long id) {
|
||||
return componentPropertyRepository.findById(id);
|
||||
}
|
||||
|
||||
public ComponentProperty saveComponentProperty(ComponentProperty componentProperty) {
|
||||
return componentPropertyRepository.save(componentProperty);
|
||||
}
|
||||
|
||||
public ComponentProperty updateComponentProperty(Long id, ComponentProperty componentPropertyDetails) {
|
||||
ComponentProperty componentProperty = componentPropertyRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("ComponentProperty not found with id: " + id));
|
||||
|
||||
componentProperty.setPropertyName(componentPropertyDetails.getPropertyName());
|
||||
componentProperty.setPropertyValue(componentPropertyDetails.getPropertyValue());
|
||||
componentProperty.setPropertyType(componentPropertyDetails.getPropertyType());
|
||||
|
||||
return componentPropertyRepository.save(componentProperty);
|
||||
}
|
||||
|
||||
public void deleteComponentProperty(Long id) {
|
||||
ComponentProperty componentProperty = componentPropertyRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("ComponentProperty not found with id: " + id));
|
||||
componentPropertyRepository.delete(componentProperty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.realnet.DynamicDashbard.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.entities.DynamicField;
|
||||
import com.realnet.DynamicDashbard.repositories.ChartTypeRepository;
|
||||
import com.realnet.DynamicDashbard.repositories.DynamicFieldRepository;
|
||||
|
||||
@Service
|
||||
public class DynamicFieldService {
|
||||
|
||||
@Autowired
|
||||
private DynamicFieldRepository dynamicFieldRepository;
|
||||
|
||||
@Autowired
|
||||
private ChartTypeRepository chartTypeRepository;
|
||||
|
||||
public List<DynamicField> getAllDynamicFields() {
|
||||
return dynamicFieldRepository.findAll();
|
||||
}
|
||||
|
||||
public List<DynamicField> getDynamicFieldsByChartType(Long chartTypeId) {
|
||||
ChartType chartType = chartTypeRepository.findById(chartTypeId)
|
||||
.orElseThrow(() -> new RuntimeException("ChartType not found with id: " + chartTypeId));
|
||||
return dynamicFieldRepository.findByChartType(chartType);
|
||||
}
|
||||
|
||||
public Optional<DynamicField> getDynamicFieldById(Long id) {
|
||||
return dynamicFieldRepository.findById(id);
|
||||
}
|
||||
|
||||
public DynamicField saveDynamicField(DynamicField dynamicField) {
|
||||
return dynamicFieldRepository.save(dynamicField);
|
||||
}
|
||||
|
||||
public DynamicField updateDynamicField(Long id, DynamicField dynamicFieldDetails) {
|
||||
DynamicField dynamicField = dynamicFieldRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("DynamicField not found with id: " + id));
|
||||
|
||||
dynamicField.setFieldName(dynamicFieldDetails.getFieldName());
|
||||
dynamicField.setFieldLabel(dynamicFieldDetails.getFieldLabel());
|
||||
dynamicField.setFieldType(dynamicFieldDetails.getFieldType());
|
||||
dynamicField.setFieldOptions(dynamicFieldDetails.getFieldOptions());
|
||||
dynamicField.setIsRequired(dynamicFieldDetails.getIsRequired());
|
||||
dynamicField.setShowInUi(dynamicFieldDetails.getShowInUi());
|
||||
dynamicField.setSortOrder(dynamicFieldDetails.getSortOrder());
|
||||
|
||||
return dynamicFieldRepository.save(dynamicField);
|
||||
}
|
||||
|
||||
public void deleteDynamicField(Long id) {
|
||||
DynamicField dynamicField = dynamicFieldRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("DynamicField not found with id: " + id));
|
||||
dynamicFieldRepository.delete(dynamicField);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.realnet.DynamicDashbard.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.DynamicDashbard.entities.ChartType;
|
||||
import com.realnet.DynamicDashbard.entities.UiComponent;
|
||||
import com.realnet.DynamicDashbard.repositories.ChartTypeRepository;
|
||||
import com.realnet.DynamicDashbard.repositories.UiComponentRepository;
|
||||
|
||||
@Service
|
||||
public class UiComponentService {
|
||||
|
||||
@Autowired
|
||||
private UiComponentRepository uiComponentRepository;
|
||||
|
||||
@Autowired
|
||||
private ChartTypeRepository chartTypeRepository;
|
||||
|
||||
public List<UiComponent> getAllUiComponents() {
|
||||
return uiComponentRepository.findAll();
|
||||
}
|
||||
|
||||
public List<UiComponent> getUiComponentsByChartType(Long chartTypeId) {
|
||||
ChartType chartType = chartTypeRepository.findById(chartTypeId)
|
||||
.orElseThrow(() -> new RuntimeException("ChartType not found with id: " + chartTypeId));
|
||||
return uiComponentRepository.findByChartType(chartType);
|
||||
}
|
||||
|
||||
public Optional<UiComponent> getUiComponentById(Long id) {
|
||||
return uiComponentRepository.findById(id);
|
||||
}
|
||||
|
||||
public UiComponent saveUiComponent(UiComponent uiComponent) {
|
||||
return uiComponentRepository.save(uiComponent);
|
||||
}
|
||||
|
||||
public UiComponent updateUiComponent(Long id, UiComponent uiComponentDetails) {
|
||||
UiComponent uiComponent = uiComponentRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("UiComponent not found with id: " + id));
|
||||
|
||||
uiComponent.setComponentName(uiComponentDetails.getComponentName());
|
||||
uiComponent.setComponentType(uiComponentDetails.getComponentType());
|
||||
uiComponent.setDisplayLabel(uiComponentDetails.getDisplayLabel());
|
||||
uiComponent.setPlaceholder(uiComponentDetails.getPlaceholder());
|
||||
uiComponent.setIsRequired(uiComponentDetails.getIsRequired());
|
||||
uiComponent.setSortOrder(uiComponentDetails.getSortOrder());
|
||||
|
||||
return uiComponentRepository.save(uiComponent);
|
||||
}
|
||||
|
||||
public void deleteUiComponent(Long id) {
|
||||
UiComponent uiComponent = uiComponentRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("UiComponent not found with id: " + id));
|
||||
uiComponentRepository.delete(uiComponent);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class FileuploadService {
|
||||
File projectdir = new File(Path1);
|
||||
if (!projectdir.exists()) {
|
||||
boolean mkdir = projectdir.mkdirs();
|
||||
System.out.println(Path1 + " folder create = " + mkdir);
|
||||
System.out.println(Path1 + " folder created = " + mkdir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -25,12 +23,10 @@ public class NotController {
|
||||
// return dash;
|
||||
// }
|
||||
|
||||
|
||||
@GetMapping("/get_notification")
|
||||
public List<NotEntity> getdetails() {
|
||||
List<NotEntity> dash = notRepo.findTopByOrderByd();
|
||||
return dash;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
@@ -28,10 +29,12 @@ public class Rpt_builder2_t {
|
||||
private Boolean active;
|
||||
private Boolean isSql;
|
||||
|
||||
@Column(name = "sure_connect_id")
|
||||
private Integer sureConnectId;
|
||||
private String sureconnect_name;
|
||||
|
||||
@JsonManagedReference
|
||||
@OneToMany(cascade = CascadeType.ALL,mappedBy = "rpt_builder2_t")
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "rpt_builder2_t")
|
||||
private List<Rpt_builder2_lines_t> Rpt_builder2_lines = new ArrayList<>();
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.realnet.Rpt_builder2.Services;
|
||||
|
||||
import com.realnet.Rpt_builder2.Repository.Rpt_builder2_Repository;
|
||||
import com.realnet.SureConnect.Entities.Sure_Connect;
|
||||
import com.realnet.SureConnect.Service.SureService;
|
||||
import com.realnet.Rpt_builder2.Entity.Rpt_builder2_t;
|
||||
import java.util.List;
|
||||
|
||||
@@ -12,7 +14,17 @@ public class Rpt_builder2_Service {
|
||||
@Autowired
|
||||
private Rpt_builder2_Repository Repository;
|
||||
|
||||
@Autowired
|
||||
private SureService sureService;
|
||||
|
||||
public Rpt_builder2_t Savedata(Rpt_builder2_t data) {
|
||||
|
||||
if (data.getSureConnectId() != null) {
|
||||
|
||||
Sure_Connect sureconnect = sureService.getbyid(data.getSureConnectId());
|
||||
|
||||
data.setSureconnect_name(sureconnect.getConnection_name());
|
||||
}
|
||||
return Repository.save(data);
|
||||
}
|
||||
|
||||
@@ -40,8 +52,15 @@ public class Rpt_builder2_Service {
|
||||
old.setReportName(data.getReportName());
|
||||
old.setDescription(data.getDescription());
|
||||
old.setActive(data.getActive());
|
||||
// old.setFolderName(data.getFolderName());
|
||||
|
||||
if (data.getSureConnectId() != null) {
|
||||
|
||||
Sure_Connect sureconnect = sureService.getbyid(data.getSureConnectId());
|
||||
|
||||
old.setSureConnectId(data.getSureConnectId());
|
||||
old.setSureconnect_name(sureconnect.getConnection_name());
|
||||
}
|
||||
// old.setFolderName(data.getFolderName());
|
||||
|
||||
final Rpt_builder2_t test = Repository.save(old);
|
||||
return test;
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
package com.realnet.Rpt_builder2_lines.Controllers;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.realnet.Rpt_builder2_lines.Entity.Rpt_builder2_lines_t;
|
||||
@@ -71,28 +80,65 @@ public class Rpt_builder2_lines_Controller {
|
||||
public Set<String> getKeysById(@RequestParam String url) {
|
||||
ResponseEntity<Object> response = GET(url);
|
||||
System.out.println("Response status code: " + response.getStatusCodeValue());
|
||||
// Check the class of the response body
|
||||
if (response.getBody() != null) {
|
||||
System.out.println("Response body class: " + response.getBody().getClass());
|
||||
|
||||
Object body = response.getBody();
|
||||
if (body == null) {
|
||||
System.out.println("Response body is null");
|
||||
return Collections.emptySet();
|
||||
}
|
||||
// Check if the response body is an ArrayList
|
||||
if (response.getBody() instanceof ArrayList) {
|
||||
ArrayList<Object> responseBody = (ArrayList<Object>) response.getBody();
|
||||
// Assuming you want to extract keys from elements inside the ArrayList,
|
||||
// you might need to iterate through the list and extract keys from each element.
|
||||
|
||||
System.out.println("Response body class: " + body.getClass());
|
||||
|
||||
Set<String> keys = new HashSet<>();
|
||||
for (Object element : responseBody) {
|
||||
if (element instanceof LinkedHashMap) {
|
||||
LinkedHashMap<String, Object> elementMap = (LinkedHashMap<String, Object>) element;
|
||||
keys.addAll(elementMap.keySet());
|
||||
|
||||
// ✅ Case 1: Response is a JSON array → List of LinkedHashMap
|
||||
if (body instanceof List) {
|
||||
List<?> list = (List<?>) body;
|
||||
for (Object element : list) {
|
||||
if (element instanceof Map) {
|
||||
keys.addAll(
|
||||
((Map<?, ?>) element).keySet().stream().map(Object::toString).collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
}
|
||||
// ✅ Case 2: Response is a single JSON object → LinkedHashMap
|
||||
else if (body instanceof Map) {
|
||||
keys.addAll(((Map<?, ?>) body).keySet().stream().map(Object::toString).collect(Collectors.toSet()));
|
||||
}
|
||||
// ✅ Case 3: Response is some other type (String, primitive, etc.)
|
||||
else {
|
||||
System.out.println("Unhandled response type: " + body.getClass());
|
||||
}
|
||||
|
||||
return keys;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// @GetMapping("/geturlkeybyurl")
|
||||
// public Set<String> getKeysById(@RequestParam String url) {
|
||||
// ResponseEntity<Object> response = GET(url);
|
||||
// System.out.println("Response status code: " + response.getStatusCodeValue());
|
||||
// // Check the class of the response body
|
||||
// if (response.getBody() != null) {
|
||||
// System.out.println("Response body class: " + response.getBody().getClass());
|
||||
// }
|
||||
// // Check if the response body is an ArrayList
|
||||
// if (response.getBody() instanceof ArrayList) {
|
||||
// ArrayList<Object> responseBody = (ArrayList<Object>) response.getBody();
|
||||
// // Assuming you want to extract keys from elements inside the ArrayList,
|
||||
// // you might need to iterate through the list and extract keys from each element.
|
||||
// Set<String> keys = new HashSet<>();
|
||||
// for (Object element : responseBody) {
|
||||
// if (element instanceof LinkedHashMap) {
|
||||
// LinkedHashMap<String, Object> elementMap = (LinkedHashMap<String, Object>) element;
|
||||
// keys.addAll(elementMap.keySet());
|
||||
// }
|
||||
// }
|
||||
// return keys;
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
public ResponseEntity<Object> GET(String get) {
|
||||
org.springframework.web.client.RestTemplate restTemplate = new org.springframework.web.client.RestTemplate();
|
||||
ResponseEntity<Object> u = restTemplate.getForEntity(get, Object.class);
|
||||
@@ -105,7 +151,8 @@ public class Rpt_builder2_lines_Controller {
|
||||
// Create an instance of RestTemplate
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
// Send an HTTP GET request to the provided URL and retrieve the response body as a String
|
||||
// Send an HTTP GET request to the provided URL and retrieve the response body
|
||||
// as a String
|
||||
String responseBody = restTemplate.getForObject(url, String.class);
|
||||
|
||||
// Create a Map to hold the URL and body data
|
||||
@@ -123,6 +170,4 @@ public class Rpt_builder2_lines_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.realnet.SureConnect.Controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.realnet.SureConnect.Entities.Sure_Connect;
|
||||
import com.realnet.SureConnect.Service.SureService;
|
||||
|
||||
@RestController
|
||||
public class SureController {
|
||||
|
||||
@Autowired
|
||||
private SureService sureService;
|
||||
|
||||
// CREATE DATA
|
||||
@PostMapping("/Sure_Connect")
|
||||
public ResponseEntity<?> add(@RequestBody Sure_Connect sure_Connect) {
|
||||
Sure_Connect order = sureService.create(sure_Connect);
|
||||
|
||||
return new ResponseEntity<>(order, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
// update data
|
||||
@PutMapping("/Sure_Connect/{id}")
|
||||
public ResponseEntity<?> update(@RequestBody Sure_Connect sure_Connect, @PathVariable Integer id) {
|
||||
|
||||
Sure_Connect order = sureService.update(sure_Connect, id);
|
||||
|
||||
return new ResponseEntity<>(order, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// Get all
|
||||
@GetMapping("/Sure_Connect")
|
||||
public ResponseEntity<?> getall() {
|
||||
List<Sure_Connect> pm = sureService.getall();
|
||||
return new ResponseEntity<>(pm, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// get by id
|
||||
@GetMapping("/Sure_Connect/{id}")
|
||||
public ResponseEntity<?> getbyid(@PathVariable int id) {
|
||||
Sure_Connect pm = sureService.getbyid(id);
|
||||
|
||||
return new ResponseEntity<>(pm, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// delete by id
|
||||
@DeleteMapping("/Sure_Connect/{id}")
|
||||
public ResponseEntity<?> deleteOne(@PathVariable int id) {
|
||||
|
||||
sureService.deletebyid(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
// get by name
|
||||
@GetMapping("/token/Sure_Connectbyname/{connection_name}")
|
||||
public ResponseEntity<?> getbyname(@PathVariable String connection_name) {
|
||||
Sure_Connect pm = sureService.getbyname(connection_name);
|
||||
|
||||
return new ResponseEntity<>(pm, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.realnet.SureConnect.Controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sure_connect/sure_postman")
|
||||
public class Sure_Postman_Api {
|
||||
|
||||
Logger log = org.slf4j.LoggerFactory.getLogger(Sure_Postman_Api.class);
|
||||
|
||||
@PostMapping("/call_api")
|
||||
public ResponseEntity<?> calldifferentmethod(@RequestBody String json_body,
|
||||
@RequestParam String api_url,
|
||||
//@RequestParam String json_body,
|
||||
@RequestParam String method, @RequestParam String token) {
|
||||
|
||||
|
||||
log.info("executing no json_bodyeters");
|
||||
|
||||
if (method.equalsIgnoreCase("DELETE")) {
|
||||
Object body = DELETE(api_url,token);
|
||||
|
||||
return new ResponseEntity<>(body, HttpStatus.OK);
|
||||
} else {
|
||||
Object object = callmethod(api_url, json_body, method, token);
|
||||
|
||||
System.out.println(object);
|
||||
return new ResponseEntity<>(object, HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// CALL METHOD
|
||||
public Object callmethod(String urll, String json_body, String method, String token) {
|
||||
|
||||
|
||||
|
||||
if (method.equalsIgnoreCase("GET")) {
|
||||
ResponseEntity<Object> get = GET(urll,token);
|
||||
Object body = get.getBody();
|
||||
System.out.println(body);
|
||||
return get.getBody();
|
||||
}
|
||||
|
||||
else if (method.equalsIgnoreCase("POST")) {
|
||||
ResponseEntity<Object> post = POST(urll, json_body, token);
|
||||
Object body = post.getBody();
|
||||
System.out.println(body);
|
||||
|
||||
return post.getBody();
|
||||
|
||||
} else if (method.equalsIgnoreCase("PUT")) {
|
||||
ResponseEntity<Object> put = PUT(urll, json_body, token);
|
||||
Object body = put.getBody();
|
||||
System.out.println(body);
|
||||
|
||||
return put.getBody();
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private HttpHeaders getHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
return headers;
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> GET(String url,String token) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String resourceUrl = url;
|
||||
String token1 = "Bearer " + token;
|
||||
HttpHeaders headers = getHeaders();
|
||||
headers.set("Authorization", token1);
|
||||
HttpEntity<Object> request = new HttpEntity<Object>( headers);
|
||||
// ResponseEntity<Object> u = restTemplate.getForEntity(url, Object.class);
|
||||
ResponseEntity<Object> u = restTemplate.exchange(resourceUrl, HttpMethod.GET, request, Object.class);
|
||||
|
||||
return u;
|
||||
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> POST(String jobinfo, Object user, String token) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String resourceUrl = jobinfo;
|
||||
String token1 = "Bearer " + token;
|
||||
HttpHeaders headers = getHeaders();
|
||||
headers.set("Authorization", token1);
|
||||
HttpEntity<Object> request = new HttpEntity<Object>(user, headers);
|
||||
ResponseEntity<Object> res = restTemplate.postForEntity(resourceUrl, request, Object.class);
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> PUT(String jobinfo, Object user, String token) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String resourceUrl = jobinfo;
|
||||
String token1 = "Bearer " + token;
|
||||
HttpHeaders headers = getHeaders();
|
||||
headers.set("Authorization", token1);
|
||||
HttpEntity<Object> request = new HttpEntity<Object>(user, headers);
|
||||
// ResponseEntity<Object> res = restTemplate.put(resourceUrl, request, Object.class);
|
||||
ResponseEntity<Object> res = restTemplate.exchange(resourceUrl, HttpMethod.PUT, request, Object.class);
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
public Object DELETE(String url, String token) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String resourceUrl = url;
|
||||
String token1 = "Bearer " + token;
|
||||
HttpHeaders headers = getHeaders();
|
||||
headers.set("Authorization", token1);
|
||||
HttpEntity<Object> request = new HttpEntity<Object>(headers);
|
||||
// ResponseEntity<Object> u = restTemplate.getForEntity(url, Object.class);
|
||||
ResponseEntity<Object> u = restTemplate.exchange(resourceUrl, HttpMethod.DELETE, request, Object.class);
|
||||
return u;
|
||||
// restTemplate.delete(url, Object.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.realnet.SureConnect.Entities;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Sure_Connect {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy =GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
private String connection_name;
|
||||
|
||||
@Column(length = 10000)
|
||||
private String description;
|
||||
|
||||
private String type;
|
||||
private String access_token;
|
||||
private int client_id;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.realnet.SureConnect.Repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.SureConnect.Entities.Sure_Connect;
|
||||
|
||||
@Repository
|
||||
public interface SureRepository extends JpaRepository<Sure_Connect, Integer>{
|
||||
|
||||
Sure_Connect findById(int id);
|
||||
|
||||
@Query(value = "select * from sure_connect where connection_name=?1 ", nativeQuery = true)
|
||||
Sure_Connect findByConnection_name(String connection_name);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.realnet.SureConnect.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.SureConnect.Entities.Sure_Connect;
|
||||
import com.realnet.SureConnect.Repository.SureRepository;
|
||||
import com.realnet.exceptions.ResourceNotFoundException;
|
||||
|
||||
@Service
|
||||
public class SureService {
|
||||
|
||||
@Autowired
|
||||
private SureRepository sureRepository;
|
||||
|
||||
public Sure_Connect create(Sure_Connect sure_Connect) {
|
||||
return sureRepository.save(sure_Connect);
|
||||
}
|
||||
|
||||
|
||||
public List<Sure_Connect> getall() {
|
||||
return (List<Sure_Connect>) sureRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
public Sure_Connect getbyid(int id) {
|
||||
return sureRepository.findById(id);
|
||||
}
|
||||
|
||||
public Sure_Connect getbyname(String connection_name) {
|
||||
return sureRepository.findByConnection_name(connection_name);
|
||||
}
|
||||
|
||||
|
||||
public Sure_Connect update(Sure_Connect sure, int id) {
|
||||
Sure_Connect pm = sureRepository.findById(id);
|
||||
// .orElseThrow(()->new ResourceNotFoundException("not found"));
|
||||
|
||||
pm.setAccess_token(sure.getAccess_token());
|
||||
pm.setClient_id(sure.getClient_id());
|
||||
pm.setConnection_name(sure.getConnection_name());
|
||||
pm.setDescription(sure.getDescription());
|
||||
pm.setPassword(sure.getPassword());
|
||||
pm.setType(sure.getType());
|
||||
pm.setUsername(sure.getUsername());
|
||||
return sureRepository.save(pm);
|
||||
}
|
||||
|
||||
|
||||
public void deletebyid(int id) {
|
||||
sureRepository.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.realnet.Workspaceuser.Controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.Workspaceuser.Entity.DDTable;
|
||||
import com.realnet.Workspaceuser.Entity.SecUsedDd;
|
||||
import com.realnet.Workspaceuser.Entity.Sec_teams;
|
||||
import com.realnet.Workspaceuser.Repository.Sec_teams_Repository;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.repository1.AppUserRepository;
|
||||
//@RequestMapping("/Workspace_Dd")
|
||||
@RestController
|
||||
public class DDController {
|
||||
|
||||
@Autowired
|
||||
private Sec_teams_Repository sec_teams_Repository;
|
||||
|
||||
@Autowired
|
||||
private AppUserRepository appUserRepository;
|
||||
|
||||
// SEC TEAM DD
|
||||
|
||||
@GetMapping("/Sec_team")
|
||||
public ResponseEntity<?> getteam(){
|
||||
List<Sec_teams> sec = (List<Sec_teams>) sec_teams_Repository.findAll();
|
||||
ArrayList<DDTable> dd = new ArrayList<DDTable>();
|
||||
for(Sec_teams s:sec) {
|
||||
DDTable d = new DDTable();
|
||||
d.setId(s.getId());
|
||||
d.setName(s.getName());
|
||||
dd.add(d);
|
||||
}
|
||||
return new ResponseEntity<>(dd, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
// Report To
|
||||
@GetMapping("/Report_to")
|
||||
public ResponseEntity<?> reportto(){
|
||||
List<AppUser> sec = (List<AppUser>) appUserRepository.findAll();
|
||||
ArrayList<SecUsedDd> dd = new ArrayList<SecUsedDd>();
|
||||
for(AppUser s:sec) {
|
||||
SecUsedDd d = new SecUsedDd();
|
||||
d.setUserId(s.getUserId());
|
||||
d.setFullName(s.getFullName());
|
||||
|
||||
dd.add(d);
|
||||
}
|
||||
return new ResponseEntity<>(dd, HttpStatus.OK);
|
||||
|
||||
}
|
||||
// assign To
|
||||
@GetMapping("/Assign")
|
||||
public ResponseEntity<?> Assign(){
|
||||
List<AppUser> sec = (List<AppUser>) appUserRepository.findAll();
|
||||
ArrayList<SecUsedDd> dd = new ArrayList<SecUsedDd>();
|
||||
for(AppUser s:sec) {
|
||||
SecUsedDd d = new SecUsedDd();
|
||||
d.setUserId(s.getUserId());
|
||||
d.setFullName(s.getFullName());
|
||||
|
||||
dd.add(d);
|
||||
}
|
||||
return new ResponseEntity<>(dd, HttpStatus.OK);
|
||||
|
||||
}
|
||||
// Requestor To
|
||||
@GetMapping("/Requestor")
|
||||
public ResponseEntity<?> Requestor(){
|
||||
List<AppUser> sec = (List<AppUser>) appUserRepository.findAll();
|
||||
ArrayList<SecUsedDd> dd = new ArrayList<SecUsedDd>();
|
||||
for(AppUser s:sec) {
|
||||
SecUsedDd d = new SecUsedDd();
|
||||
d.setUserId(s.getUserId());
|
||||
d.setFullName(s.getFullName());
|
||||
|
||||
dd.add(d);
|
||||
}
|
||||
return new ResponseEntity<>(dd, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
// owner To
|
||||
@GetMapping("/Owner")
|
||||
public ResponseEntity<?> Owner(){
|
||||
List<AppUser> sec = (List<AppUser>) appUserRepository.findAll();
|
||||
ArrayList<SecUsedDd> dd = new ArrayList<SecUsedDd>();
|
||||
for(AppUser s:sec) {
|
||||
SecUsedDd d = new SecUsedDd();
|
||||
d.setUserId(s.getUserId());
|
||||
d.setFullName(s.getFullName());
|
||||
|
||||
dd.add(d);
|
||||
}
|
||||
return new ResponseEntity<>(dd, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.realnet.Workspaceuser.Controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.Workspaceuser.Entity.Sec_teams;
|
||||
import com.realnet.Workspaceuser.Service.Sec_teamService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
|
||||
@RequestMapping("/Workspace_team")
|
||||
@RestController
|
||||
public class SecTeamController {
|
||||
|
||||
@Autowired
|
||||
private Sec_teamService sec_teamService;
|
||||
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
|
||||
// create
|
||||
@PostMapping("/SecTeam")
|
||||
public Sec_teams create(@RequestBody Sec_teams rnrule) {
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
|
||||
long accountId = loggedInUser.getAccount().getAccount_id();
|
||||
Long l = accountId;
|
||||
if (l != null) {
|
||||
rnrule.setAccountId(accountId);
|
||||
|
||||
}
|
||||
|
||||
Sec_teams rn = sec_teamService.create(rnrule);
|
||||
return rn;
|
||||
}
|
||||
|
||||
// get all
|
||||
@GetMapping("/SecTeam")
|
||||
public ResponseEntity<?> getall() {
|
||||
List<Sec_teams> li = sec_teamService.getall();
|
||||
return new ResponseEntity<>(li, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// get all by accountId
|
||||
@GetMapping("/SecTeam/AccountId")
|
||||
public ResponseEntity<?> getallByAccountId() {
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
|
||||
long accountId = loggedInUser.getAccount().getAccount_id();
|
||||
|
||||
List<Sec_teams> li = sec_teamService.getallbyAccountId(accountId);
|
||||
return new ResponseEntity<>(li, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// get by id
|
||||
@GetMapping("/SecTeam/{id}")
|
||||
public ResponseEntity<?> getbyid(@PathVariable int id) {
|
||||
Sec_teams rn = sec_teamService.getbyid(id);
|
||||
return new ResponseEntity<>(rn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// update by id
|
||||
@PutMapping("/SecTeam/{id}")
|
||||
public ResponseEntity<?> update(@RequestBody Sec_teams project, @PathVariable int id) {
|
||||
Sec_teams rule_t = sec_teamService.updatebyid(project, id);
|
||||
return new ResponseEntity<>(rule_t, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
// Delete by id
|
||||
@DeleteMapping("/SecTeam/{id}")
|
||||
public void deletebyid(@PathVariable int id) {
|
||||
sec_teamService.deletebyid(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package com.realnet.Workspaceuser.Controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.Communication.Services.EmailNotificationService;
|
||||
import com.realnet.Workspaceuser.Entity.Sec_team_members;
|
||||
import com.realnet.Workspaceuser.Entity.Sec_workspace_users;
|
||||
import com.realnet.Workspaceuser.Repository.SecWorkspaceUserRepo;
|
||||
import com.realnet.Workspaceuser.Repository.Sec_team_MemberRepository;
|
||||
|
||||
import com.realnet.users.entity.Role;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.repository.RoleRepo;
|
||||
import com.realnet.users.repository1.AppUserRepository;
|
||||
import com.realnet.users.response.MessageResponse;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/workspace/secworkspaceuser")
|
||||
@EnableCaching
|
||||
public class SecWorkSpaceUSerController {
|
||||
|
||||
@Autowired
|
||||
private SecWorkspaceUserRepo secWorkspaceUserRepo;
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private Sec_team_MemberRepository memberRepository;
|
||||
@Autowired
|
||||
private AppUserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private RoleRepo roleRepo;
|
||||
|
||||
@Autowired
|
||||
private EmailNotificationService emailNotificationService;
|
||||
|
||||
|
||||
|
||||
// ADD WHOLE TEAM TO SECWORKSPACE USER BY TEAM_ID
|
||||
@PostMapping("/addteam/{project_id}/{team_id}")
|
||||
public ResponseEntity<?> addwholeteam(@PathVariable Integer project_id, @PathVariable int team_id,
|
||||
@RequestBody Sec_workspace_users users) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
List<Sec_team_members> members = memberRepository.getallteam(team_id);
|
||||
for (Sec_team_members mem : members) {
|
||||
Sec_workspace_users secuser = secWorkspaceUserRepo.getallsecworkspcceuser(mem.getMember_id(), project_id);
|
||||
if (secuser == null) {
|
||||
Sec_workspace_users user = new Sec_workspace_users();
|
||||
Optional<AppUser> us = userRepository.findById(mem.getMember_id());
|
||||
user.setAccountId(us.get().getAccount().getAccount_id());
|
||||
user.setUser_id(mem.getMember_id());
|
||||
user.setWorksapce_id(project_id);
|
||||
user.setProject_id(project_id);
|
||||
user.setUser_name(mem.getMember_name());
|
||||
// Set<Role> roles = new HashSet<>();
|
||||
// String role1 = "ROLE_Developer";
|
||||
// Role userRole = roleRepo.findByName(role1);
|
||||
// roles.add(userRole);
|
||||
// users.setUser_role(roles);
|
||||
Sec_workspace_users save = secWorkspaceUserRepo.save(user);
|
||||
|
||||
list.add(save);
|
||||
|
||||
// send mail to team member
|
||||
try {
|
||||
emailNotificationService.sendmailViaSetu(us.get().getEmail(), us.get().getFullName(), "TeamMember");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("email sending error ..." + e);
|
||||
// TODO: handle exception
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return new ResponseEntity<>(list, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// GET ALL SEC_WORKSPACE_USER
|
||||
@GetMapping("/sec_workspace_users")
|
||||
public ResponseEntity<?> getallusers() {
|
||||
List<Sec_workspace_users> list = secWorkspaceUserRepo.findAll();
|
||||
return new ResponseEntity<>(list, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// GET ALL SEC_WORKSPACE_USER by PROJECT ID
|
||||
@GetMapping("/get_by_projectid/{project_id}")
|
||||
public ResponseEntity<?> getallusers(@PathVariable Integer project_id) {
|
||||
List<Sec_workspace_users> list = secWorkspaceUserRepo.getallproject(project_id);
|
||||
return new ResponseEntity<>(list, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// ADD SEC WORKSPACE USER
|
||||
@PostMapping("/add_workspace/users/{userid}/{project_id}/{access_duration}")
|
||||
public ResponseEntity<?> addsecusers(@RequestBody Sec_workspace_users users, @PathVariable Long userid,
|
||||
@PathVariable Integer project_id, @PathVariable Integer access_duration, @RequestParam String role) {
|
||||
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
Long fromuserid = loggedInUser.getUserId();
|
||||
// Long account_id = loggedInUser.getAccount().getAccount_id();
|
||||
|
||||
Sec_workspace_users workspace_users = secWorkspaceUserRepo.getallsecworkspcceuser(userid, project_id);
|
||||
if (workspace_users == null) {
|
||||
Optional<AppUser> us = userRepository.findById(userid);
|
||||
users.setAccountId(us.get().getAccount().getAccount_id());
|
||||
users.setFromuserId(fromuserid);
|
||||
users.setUser_id(userid);
|
||||
users.setUser_name(us.get().getFullName());
|
||||
users.setWorksapce_id(project_id);
|
||||
users.setProject_id(project_id);
|
||||
|
||||
users.setAccess_duration(access_duration);
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(new Date());
|
||||
c.add(Calendar.DATE, access_duration);
|
||||
|
||||
// SimpleDateFormat dateFormat = new SimpleDateFormat();
|
||||
// String format = dateFormat.format(c.getTime());
|
||||
|
||||
users.setAccess_till_date(c.getTime());
|
||||
|
||||
Set<Role> roles = new HashSet<>();
|
||||
// String role1 = "ROLE_Developer";
|
||||
Role userRole = roleRepo.findByName(role);
|
||||
// roles.add(userRole);
|
||||
if (userRole != null) {
|
||||
users.setUser_role(role);
|
||||
}
|
||||
|
||||
Sec_workspace_users save = secWorkspaceUserRepo.save(users);
|
||||
|
||||
// send mail to team member
|
||||
|
||||
try {
|
||||
|
||||
emailNotificationService.sendmailViaSetu(us.get().getEmail(), us.get().getFullName(), "WorkSpaceUser");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("email sending error ..." + e);
|
||||
// TODO: handle exception
|
||||
}
|
||||
return new ResponseEntity<>(save, HttpStatus.OK);
|
||||
} else
|
||||
return ResponseEntity.badRequest().body(new MessageResponse("user already added"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.realnet.Workspaceuser.Controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.realnet.Workspaceuser.Service.SecTeam_MemberService;
|
||||
import com.realnet.Workspaceuser.Entity.Sec_team_members;
|
||||
@RequestMapping("/Workspace_team_member")
|
||||
@RestController
|
||||
public class Sec_team_members_Controller {
|
||||
|
||||
@Autowired
|
||||
private SecTeam_MemberService secTeam_MemberService;
|
||||
|
||||
// create
|
||||
@PostMapping("/Teammember")
|
||||
public Sec_team_members create(@RequestBody Sec_team_members rnrule){
|
||||
Sec_team_members rn = secTeam_MemberService.create(rnrule);
|
||||
return rn;
|
||||
}
|
||||
|
||||
// get all
|
||||
|
||||
@GetMapping("/Teammember")
|
||||
public ResponseEntity<?> getall(){
|
||||
List<Sec_team_members> li = secTeam_MemberService.getall();
|
||||
return new ResponseEntity<>(li,HttpStatus.OK);
|
||||
}
|
||||
|
||||
// get by id
|
||||
@GetMapping("/Teammember/{id}")
|
||||
public ResponseEntity<?> getbyid(@PathVariable int id){
|
||||
Sec_team_members rn= secTeam_MemberService.getbyid(id);
|
||||
return new ResponseEntity<>(rn,HttpStatus.OK);
|
||||
}
|
||||
|
||||
// update by id
|
||||
@PutMapping("/Teammember/{id}")
|
||||
public ResponseEntity<?> update(@RequestBody Sec_team_members project, @PathVariable int id){
|
||||
Sec_team_members rule_t= secTeam_MemberService.updatebyid(project,id);
|
||||
return new ResponseEntity<>(rule_t,HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
// Delete by id
|
||||
@DeleteMapping("/Teammember/{id}")
|
||||
public void deletebyid(@PathVariable int id){
|
||||
secTeam_MemberService.deletebyid(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.realnet.Workspaceuser.Controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.realnet.Workspaceuser.Entity.Sec_workspace;
|
||||
import com.realnet.Workspaceuser.Repository.WorkspaceRepository;
|
||||
import com.realnet.Workspaceuser.Service.WorkspaceService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
|
||||
@RequestMapping("/Workspace_workspace")
|
||||
@RestController
|
||||
public class WorkspaceController {
|
||||
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
|
||||
@Autowired
|
||||
private WorkspaceService workspaceService;
|
||||
@Autowired
|
||||
private WorkspaceRepository workspaceRepository;
|
||||
|
||||
// create
|
||||
@PostMapping("/workspace")
|
||||
public Sec_workspace create(@RequestBody Sec_workspace rnrule) {
|
||||
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
Long userId = loggedInUser.getUserId();
|
||||
rnrule.setOwner_id(userId);
|
||||
|
||||
long accountId = loggedInUser.getAccount().getAccount_id();
|
||||
Long l = accountId;
|
||||
if (l != null) {
|
||||
rnrule.setAccountId(accountId);
|
||||
|
||||
}
|
||||
Sec_workspace rn = workspaceService.create(rnrule);
|
||||
return rn;
|
||||
}
|
||||
|
||||
// get all
|
||||
|
||||
@GetMapping("/workspace")
|
||||
public ResponseEntity<?> getall() {
|
||||
|
||||
List<Sec_workspace> li = workspaceService.getall();
|
||||
|
||||
return new ResponseEntity<>(li, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// get all BY ACCOUNT ID
|
||||
@GetMapping("/FindByaccount")
|
||||
public ResponseEntity<?> getallbyaccount() {
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
long accountId = loggedInUser.getAccount().getAccount_id();
|
||||
List<Sec_workspace> li = workspaceRepository.findByAccountId(accountId);
|
||||
return new ResponseEntity<>(li, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// get by id
|
||||
@GetMapping("/workspace/{id}")
|
||||
public ResponseEntity<?> getbyid(@PathVariable int id) {
|
||||
Sec_workspace rn = workspaceService.getbyid(id);
|
||||
return new ResponseEntity<>(rn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// update by id
|
||||
@PutMapping("/workspace/{id}")
|
||||
public ResponseEntity<?> update(@RequestBody Sec_workspace project, @PathVariable int id) {
|
||||
Sec_workspace rule_t = workspaceService.updatebyid(project, id);
|
||||
return new ResponseEntity<>(rule_t, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
// Delete by id
|
||||
@DeleteMapping("/workspace/{id}")
|
||||
public void deletebyid(@PathVariable int id) {
|
||||
workspaceService.deletebyid(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.realnet.Workspaceuser.Entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DDTable {
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.realnet.Workspaceuser.Entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SecUsedDd {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String fullName;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.realnet.Workspaceuser.Entity;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import lombok.Data;
|
||||
@Data
|
||||
@Entity
|
||||
public class Sec_team_members {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
private int id;
|
||||
|
||||
private int team_id;
|
||||
private Long member_id;
|
||||
private boolean member_type;
|
||||
private String access_days;
|
||||
private Date access_start_date;
|
||||
private String member_name;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.realnet.Workspaceuser.Entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import com.realnet.fnd.entity.Rn_Who_AccId_Column;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Sec_teams extends Rn_Who_AccId_Column{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
private int id;
|
||||
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String Is_active;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.realnet.Workspaceuser.Entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import com.realnet.fnd.entity.Rn_Who_AccId_Column;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Sec_workspace extends Rn_Who_AccId_Column {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private int id;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String is_default;
|
||||
private String Is_active;
|
||||
private Long owner_id;
|
||||
private Integer project_id;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.realnet.Workspaceuser.Entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.realnet.WhoColumn.Entity.Who_column;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Sec_workspace_users extends Who_column {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private int worksapce_id;
|
||||
private Long user_id;
|
||||
private String user_name;
|
||||
private Integer project_id;
|
||||
private String user_role;
|
||||
|
||||
private String project_name;
|
||||
private Long fromuserId;
|
||||
|
||||
private Integer access_duration;
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-mm-yyyy")
|
||||
private Date access_till_date;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.realnet.Workspaceuser.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.Workspaceuser.Entity.Sec_workspace_users;
|
||||
|
||||
@Repository
|
||||
public interface SecWorkspaceUserRepo extends JpaRepository<Sec_workspace_users, Long> {
|
||||
|
||||
@Query(value = "SELECT * FROM sec_workspace_users WHERE user_id=?1 && access_till_date >= NOW();", nativeQuery = true)
|
||||
List<Sec_workspace_users> getallbyuserid(Long userId);
|
||||
|
||||
@Query(value = "SELECT * FROM sec_workspace_users WHERE user_id=?1 and project_id=?2", nativeQuery = true)
|
||||
Sec_workspace_users getallsecworkspcceuser(Long userid, Integer project_id);
|
||||
|
||||
@Query(value = "SELECT * FROM sec_workspace_users WHERE project_id=?1", nativeQuery = true)
|
||||
List<Sec_workspace_users> getallproject(Integer project_id);
|
||||
|
||||
@Query(value = "SELECT count(*) FROM sec_workspace_users WHERE user_id=?1", nativeQuery = true)
|
||||
Object countSharewithme(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.realnet.Workspaceuser.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.Workspaceuser.Entity.Sec_team_members;
|
||||
|
||||
@Repository
|
||||
public interface Sec_team_MemberRepository extends CrudRepository<Sec_team_members, Integer> {
|
||||
Sec_team_members findById(int id);
|
||||
|
||||
@Query(value = "SELECT * FROM sec_team_members a where a.team_id =?1", nativeQuery = true)
|
||||
List<Sec_team_members> getallteam(int team_id);
|
||||
@Query(value = "SELECT * FROM sec_team_members a where a.team_id =?1 and a.member_id=?2", nativeQuery = true)
|
||||
Sec_team_members findteammember(int id, Long userId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.realnet.Workspaceuser.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.Workspaceuser.Entity.Sec_teams;
|
||||
|
||||
@Repository
|
||||
public interface Sec_teams_Repository extends CrudRepository<Sec_teams, Integer> {
|
||||
|
||||
Sec_teams findById(int id);
|
||||
|
||||
@Query(value = "SELECT * FROM sec_teams where account_id=?1", nativeQuery = true)
|
||||
List<Sec_teams> findAllByAccountid(Long accountId);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.realnet.Workspaceuser.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.Workspaceuser.Entity.Sec_workspace;
|
||||
|
||||
@Repository
|
||||
public interface WorkspaceRepository extends CrudRepository<Sec_workspace, Integer> {
|
||||
|
||||
Sec_workspace findById(int id);
|
||||
|
||||
List<Sec_workspace> findByAccountId(Long accountId);
|
||||
|
||||
// List<Sec_workspace> findByProject_id(Integer project_id);
|
||||
|
||||
@Query(value = "SELECT * FROM sec_workspace WHERE project_id=?1", nativeQuery = true)
|
||||
List<Sec_workspace> findByProject_id(Integer project_id);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.realnet.Workspaceuser.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.Workspaceuser.Entity.Sec_team_members;
|
||||
import com.realnet.Workspaceuser.Entity.Sec_teams;
|
||||
import com.realnet.Workspaceuser.Repository.Sec_team_MemberRepository;
|
||||
|
||||
@Service
|
||||
public class SecTeam_MemberService {
|
||||
|
||||
@Autowired
|
||||
private Sec_team_MemberRepository sec_team_MemberRepository;
|
||||
|
||||
public Sec_team_members create(Sec_team_members rnrule) {
|
||||
return sec_team_MemberRepository.save(rnrule);
|
||||
}
|
||||
|
||||
|
||||
public List<Sec_team_members> getall() {
|
||||
return (List<Sec_team_members>) sec_team_MemberRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
public Sec_team_members getbyid(int id) {
|
||||
return sec_team_MemberRepository.findById(id);
|
||||
}
|
||||
|
||||
|
||||
public Sec_team_members updatebyid(Sec_team_members project, int id) {
|
||||
Sec_team_members rule = sec_team_MemberRepository.findById(id);
|
||||
|
||||
// .orElseThrow(()-> ResourceNotFoundException("rueboard","id",id));
|
||||
rule.setAccess_days(project.getAccess_days());
|
||||
rule.setAccess_start_date(project.getAccess_start_date());
|
||||
rule.setMember_id(project.getMember_id());
|
||||
rule.setTeam_id(project.getTeam_id());
|
||||
|
||||
return sec_team_MemberRepository.save(rule);
|
||||
}
|
||||
|
||||
|
||||
public void deletebyid(int id) {
|
||||
sec_team_MemberRepository.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.realnet.Workspaceuser.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.Workspaceuser.Entity.Sec_teams;
|
||||
import com.realnet.Workspaceuser.Repository.Sec_teams_Repository;
|
||||
|
||||
@Service
|
||||
public class Sec_teamService {
|
||||
|
||||
@Autowired
|
||||
private Sec_teams_Repository sec_teams_Repository;
|
||||
|
||||
public Sec_teams create(Sec_teams rnrule) {
|
||||
return sec_teams_Repository.save(rnrule);
|
||||
}
|
||||
|
||||
public List<Sec_teams> getall() {
|
||||
return (List<Sec_teams>) sec_teams_Repository.findAll();
|
||||
}
|
||||
|
||||
// get all by accountId
|
||||
public List<Sec_teams> getallbyAccountId(Long accountId) {
|
||||
return (List<Sec_teams>) sec_teams_Repository.findAllByAccountid(accountId);
|
||||
}
|
||||
|
||||
public Sec_teams getbyid(int id) {
|
||||
return sec_teams_Repository.findById(id);
|
||||
}
|
||||
|
||||
public Sec_teams updatebyid(Sec_teams project, int id) {
|
||||
Sec_teams rule = sec_teams_Repository.findById(id);
|
||||
|
||||
// .orElseThrow(()-> ResourceNotFoundException("rueboard","id",id));
|
||||
rule.setAccountId(project.getAccountId());
|
||||
rule.setDescription(project.getDescription());
|
||||
rule.setIs_active(project.getIs_active());
|
||||
rule.setName(project.getName());
|
||||
|
||||
return sec_teams_Repository.save(rule);
|
||||
}
|
||||
|
||||
public void deletebyid(int id) {
|
||||
sec_teams_Repository.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.realnet.Workspaceuser.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.realnet.Workspaceuser.Entity.Sec_workspace;
|
||||
import com.realnet.Workspaceuser.Repository.WorkspaceRepository;
|
||||
|
||||
@Service
|
||||
public class WorkspaceService {
|
||||
|
||||
@Autowired
|
||||
private WorkspaceRepository workspaceRepository;
|
||||
|
||||
public Sec_workspace create(Sec_workspace rnrule) {
|
||||
return workspaceRepository.save(rnrule);
|
||||
}
|
||||
|
||||
|
||||
public List<Sec_workspace> getall() {
|
||||
return (List<Sec_workspace>) workspaceRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
public Sec_workspace getbyid(int id) {
|
||||
return workspaceRepository.findById(id);
|
||||
}
|
||||
|
||||
|
||||
public Sec_workspace updatebyid(Sec_workspace project, int id) {
|
||||
Sec_workspace rule = workspaceRepository.findById(id);
|
||||
|
||||
// .orElseThrow(()-> ResourceNotFoundException("rueboard","id",id));
|
||||
rule.setAccountId(project.getAccountId());
|
||||
// rule.setDefault_team_id(project.getDefault_team_id());
|
||||
rule.setDescription(project.getDescription());
|
||||
rule.setIs_active(project.getIs_active());
|
||||
rule.setIs_default(project.getIs_default());
|
||||
rule.setName(project.getName());
|
||||
rule.setOwner_id(project.getOwner_id());
|
||||
|
||||
return workspaceRepository.save(rule);
|
||||
}
|
||||
|
||||
|
||||
public void deletebyid(int id) {
|
||||
Sec_workspace save = workspaceRepository.findById(id);
|
||||
workspaceRepository.delete(save);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -23,9 +24,10 @@ public class GeneratetokenController {
|
||||
private GeneratetokenService generatetokenService;
|
||||
|
||||
@PostMapping("/generateToken")
|
||||
public String generatetoken(@RequestParam String token_name) throws JsonProcessingException {
|
||||
public Token_registery generatetoken(@RequestBody Token_registery reg) throws JsonProcessingException {
|
||||
|
||||
String token = generatetokenService.generatetoken(token_name);
|
||||
String token_name = reg.getToken_name();
|
||||
Token_registery token = generatetokenService.generatetoken(token_name);
|
||||
|
||||
return token;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@@ -29,13 +30,16 @@ public class GeneratetokenService {
|
||||
@Autowired
|
||||
private Token_registery_Repository token_registery_Repository;
|
||||
|
||||
public String generatetoken(String toekn_name) throws JsonProcessingException {
|
||||
@Autowired
|
||||
private BCryptPasswordEncoder bcryptEncoder;
|
||||
|
||||
public Token_registery generatetoken(String toekn_name) throws JsonProcessingException {
|
||||
|
||||
AppUser loggedInUser = userServiceImpl.getLoggedInUser();
|
||||
|
||||
String username = loggedInUser.getUsername();
|
||||
|
||||
String userPassw = loggedInUser.getUserPassw();
|
||||
String userPassw = loggedInUser.getChangePassw();
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
@@ -56,13 +60,13 @@ public class GeneratetokenService {
|
||||
HttpEntity<Object> request = new HttpEntity<Object>(builder.toString(), headers);
|
||||
|
||||
ResponseEntity<String> res = restTemplate.postForEntity(resourceUrl, request, String.class);
|
||||
Object object = res.getBody();
|
||||
String object = res.getBody();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(object);
|
||||
// String str = mapper.writeValueAsString(object);
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
JsonElement element = parser.parse(object);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
JsonObject item = obj.get("item").getAsJsonObject();
|
||||
@@ -74,9 +78,11 @@ public class GeneratetokenService {
|
||||
token_registery.setToken_name(toekn_name);
|
||||
token_registery.setCreatedBy(loggedInUser.getUserId());
|
||||
|
||||
Token_registery save = token_registery_Repository.save(token_registery);
|
||||
|
||||
System.out.println("token is == " + token);
|
||||
|
||||
return token;
|
||||
return save;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
//package com.realnet.config.sqlite;
|
||||
//
|
||||
//import java.sql.Types;
|
||||
//import org.hibernate.dialect.Dialect;
|
||||
//import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
//
|
||||
//public class SQLiteDialect extends Dialect {
|
||||
//
|
||||
// public SQLiteDialect() {
|
||||
// registerColumnType(Types.INTEGER, "integer");
|
||||
// registerColumnType(Types.VARCHAR, "text");
|
||||
// registerColumnType(Types.BLOB, "blob");
|
||||
// registerColumnType(Types.REAL, "real");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
// return new SQLiteIdentityColumnSupport();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean hasAlterTable() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean dropConstraints() {
|
||||
// return false;
|
||||
// }
|
||||
// @Override
|
||||
// public boolean supportsUnionAll() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -0,0 +1,22 @@
|
||||
//package com.realnet.config.sqlite;
|
||||
//
|
||||
//import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
|
||||
//
|
||||
//public class SQLiteIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
//
|
||||
// @Override
|
||||
// public boolean supportsIdentityColumns() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getIdentitySelectString(String table, String column, int type) {
|
||||
// return "select last_insert_rowid()";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getIdentityColumnString(int type) {
|
||||
// // SQLite mein sirf "integer" + auto increment hota hai
|
||||
// return "integer";
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,15 @@
|
||||
//package com.realnet.config.sqlite;
|
||||
//
|
||||
//import java.sql.Connection;
|
||||
//import java.sql.DriverManager;
|
||||
//import java.sql.SQLException;
|
||||
//
|
||||
//public class SQLiteUtil {
|
||||
//
|
||||
// private static final String DB_FILE = "realtest1.db"; // SQLite file
|
||||
//
|
||||
// public static Connection getConnection() throws SQLException {
|
||||
// String url = "jdbc:sqlite:" + DB_FILE;
|
||||
// return DriverManager.getConnection(url);
|
||||
// }
|
||||
//}
|
||||
@@ -1,28 +1,16 @@
|
||||
package com.realnet.fnd.entity1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
222
backend/src/main/java/com/realnet/helper/CnsHelper.java
Normal file
222
backend/src/main/java/com/realnet/helper/CnsHelper.java
Normal file
@@ -0,0 +1,222 @@
|
||||
package com.realnet.helper;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.realnet.utils.Port_Constant;
|
||||
|
||||
public class CnsHelper {
|
||||
|
||||
static Logger log = org.slf4j.LoggerFactory.getLogger(CnsHelper.class);
|
||||
|
||||
// CONNECTOR CALL
|
||||
public static String callconnector(String name) throws JsonProcessingException {
|
||||
|
||||
String token = null;
|
||||
ResponseEntity<Object> u = null;
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = Port_Constant.BACKEND_PORTAL_DOMAIN + "/token/Sure_Connectbyname/" + name;
|
||||
|
||||
//
|
||||
try {
|
||||
|
||||
u = restTemplate.getForEntity(url, Object.class);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
System.out.println(" token get error " + e);
|
||||
|
||||
// TODO: handle exception
|
||||
}
|
||||
Object object = u.getBody();
|
||||
|
||||
if (object != null) {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(object);
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
JsonElement tok = obj.get("access_token");
|
||||
System.out.println("token is == " + token);
|
||||
token = tok.getAsString();
|
||||
} else {
|
||||
System.out.println(" empty totek get ...");
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
public static ResponseEntity<?> run(String urll, String param, String method, String token, String username,
|
||||
String password) {
|
||||
|
||||
log.info("executing no parameters");
|
||||
|
||||
if (method.equalsIgnoreCase("DELETE")) {
|
||||
Object body = DELETE(urll);
|
||||
|
||||
return new ResponseEntity<>(body, HttpStatus.OK);
|
||||
} else {
|
||||
Object object = callmethod(urll, param, method, token, username, password);
|
||||
|
||||
System.out.println(object);
|
||||
return new ResponseEntity<>(object, HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean DELETE(String url) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
restTemplate.delete(url, Object.class);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// CALL METHOD
|
||||
public static Object callmethod(String url, String param, String method, String token, String username,
|
||||
String password) {
|
||||
|
||||
if (method.equalsIgnoreCase("GET")) {
|
||||
ResponseEntity<Object> get = GET(url);
|
||||
Object body = get.getBody();
|
||||
System.out.println(body);
|
||||
return get.getBody();
|
||||
}
|
||||
|
||||
else if (method.equalsIgnoreCase("POST")) {
|
||||
|
||||
ResponseEntity<Object> post;
|
||||
if (username != null && password != null) {
|
||||
post = POSTForBasicAuth(url, param, username, password);
|
||||
|
||||
} else {
|
||||
|
||||
post = POST(url, param, token);
|
||||
}
|
||||
Object body = post.getBody();
|
||||
System.out.println(body);
|
||||
|
||||
return post.getBody();
|
||||
|
||||
} else if (method.equalsIgnoreCase("PUT")) {
|
||||
ResponseEntity<Object> put = PUT(url, param, token);
|
||||
Object body = put.getBody();
|
||||
System.out.println(body);
|
||||
|
||||
return put.getBody();
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static ResponseEntity<Object> GET(String get) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
ResponseEntity<Object> u = restTemplate.getForEntity(get, Object.class);
|
||||
int statusCodeValue = u.getStatusCodeValue();
|
||||
System.out.println(statusCodeValue);
|
||||
|
||||
return u;
|
||||
|
||||
}
|
||||
|
||||
public static ResponseEntity<Object> GET(String get, String token) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String resourceUrl = get;
|
||||
String token1 = "Bearer " + token;
|
||||
HttpHeaders headers = getHeaders();
|
||||
headers.set("Authorization", token1);
|
||||
HttpEntity<Object> request = new HttpEntity<Object>(headers);
|
||||
ResponseEntity<Object> u = restTemplate.exchange(resourceUrl, HttpMethod.GET, request, Object.class);
|
||||
|
||||
int statusCodeValue = u.getStatusCodeValue();
|
||||
System.out.println(statusCodeValue);
|
||||
|
||||
return u;
|
||||
|
||||
}
|
||||
|
||||
public static ResponseEntity<Object> POST(String jobinfo, Object user, String token) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String resourceUrl = jobinfo;
|
||||
String token1 = "Bearer " + token;
|
||||
HttpHeaders headers = getHeaders();
|
||||
headers.set("Authorization", token1);
|
||||
HttpEntity<Object> request = new HttpEntity<Object>(user, headers);
|
||||
ResponseEntity<Object> res = restTemplate.postForEntity(resourceUrl, request, Object.class);
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
public static ResponseEntity<Object> POSTForBasicAuth(String jobinfo, Object user, String username,
|
||||
String password) {
|
||||
|
||||
System.out.println(" call basic auth..");
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String resourceUrl = jobinfo;
|
||||
|
||||
String auth = username + ":" + password;
|
||||
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.US_ASCII));
|
||||
String authHeader = "Basic " + new String(encodedAuth);
|
||||
|
||||
HttpHeaders headers = getHeaders();
|
||||
|
||||
headers.set("Authorization", authHeader);
|
||||
|
||||
HttpEntity<Object> request = new HttpEntity<>(user.toString(), headers);
|
||||
ResponseEntity<Object> res = null;
|
||||
try {
|
||||
|
||||
res = restTemplate.postForEntity(resourceUrl, request, Object.class);
|
||||
} catch (Exception e) {
|
||||
|
||||
System.out.println(" call basic auth error " + e);
|
||||
// TODO: handle exception
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
public static ResponseEntity<Object> PUT(String jobinfo, Object user, String token) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String resourceUrl = jobinfo;
|
||||
String token1 = "Bearer " + token;
|
||||
HttpHeaders headers = getHeaders();
|
||||
headers.set("Authorization", token1);
|
||||
HttpEntity<Object> request = new HttpEntity<Object>(user, headers);
|
||||
// ResponseEntity<Object> res = restTemplate.put(resourceUrl, request, Object.class);
|
||||
ResponseEntity<Object> res = restTemplate.exchange(resourceUrl, HttpMethod.PUT, request, Object.class);
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
private static HttpHeaders getHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
return headers;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,14 +24,6 @@ public class Rn_report_builder extends Rn_Who_Columns {
|
||||
@Column(name = "ID")
|
||||
private int id;
|
||||
|
||||
//
|
||||
// @ManyToOne(fetch = FetchType.LAZY,cascade=CascadeType.ALL)
|
||||
// @JoinColumn(name = "MODULE_ID",insertable = false, updatable = false)
|
||||
// @JsonBackReference
|
||||
// private Rn_Module_Setup module;
|
||||
//
|
||||
//
|
||||
|
||||
@Column(name = "REPORT_NAME")
|
||||
private String report_name;
|
||||
|
||||
|
||||
@@ -246,9 +246,7 @@ public class Rn_rb_tables_serviceImpl implements Rn_rb_tables_service {
|
||||
@Override
|
||||
public List<String> getColumnAliasList2(String tableNames) {
|
||||
|
||||
String url = null;
|
||||
String userName = null;
|
||||
String password = null;
|
||||
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
String[] tableArray = tableNames.split(",");
|
||||
|
||||
@@ -10,16 +10,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.realnet.CredentialDatabase.Service.SurevaultService;
|
||||
import com.realnet.exceptions.ResourceNotFoundException;
|
||||
import com.realnet.rb.entity.Rn_Rb_Where_Param;
|
||||
@@ -36,7 +32,7 @@ import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.utils.Constant;
|
||||
|
||||
@Service
|
||||
public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
public class Rn_report_builder_serviceIpml implements Rn_report_builder_service {
|
||||
@Autowired
|
||||
private Rn_report_builder_repository rn_report_builder_repository;
|
||||
|
||||
@@ -52,19 +48,18 @@ public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
@Autowired
|
||||
private Rn_rb_where_param_repository whereRepo;
|
||||
|
||||
// @Value("${spring.datasource.username}")
|
||||
// private String userName;
|
||||
//
|
||||
// @Value("${spring.datasource.password}")
|
||||
// private String password;
|
||||
//
|
||||
// @Value("${spring.datasource.url}")
|
||||
// private String url;
|
||||
@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;
|
||||
|
||||
|
||||
@Override
|
||||
public Page<Rn_report_builder> getAll(Pageable page) {
|
||||
return rn_report_builder_repository.findAll(page);
|
||||
@@ -93,14 +88,13 @@ public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
public boolean saveReport(Rn_reportDTO report, int moduleId) {
|
||||
AppUser user = userService.getLoggedInUser();
|
||||
Long userId = user.getUserId();
|
||||
//Long accountId = user.getSys_account().getId();
|
||||
// Long accountId = user.getSys_account().getId();
|
||||
|
||||
String report_name = report.getReport_name();
|
||||
String desc = report.getDescription();
|
||||
String tags=report.getReport_tags();
|
||||
String tags = report.getReport_tags();
|
||||
|
||||
|
||||
Rn_report_builder reportBuilder=new Rn_report_builder();
|
||||
Rn_report_builder reportBuilder = new Rn_report_builder();
|
||||
reportBuilder.setReport_name(report_name);
|
||||
reportBuilder.setDescription(desc);
|
||||
reportBuilder.setReport_tags(tags);
|
||||
@@ -113,14 +107,13 @@ public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
public Rn_report_builder saveReport(Rn_report_builder report, int moduleId) {
|
||||
AppUser user = userService.getLoggedInUser();
|
||||
Long userId = user.getUserId();
|
||||
//Long accountId = user.getSys_account().getId();
|
||||
// Long accountId = user.getSys_account().getId();
|
||||
|
||||
String report_name = report.getReport_name();
|
||||
String desc = report.getDescription();
|
||||
String tags=report.getReport_tags();
|
||||
String tags = report.getReport_tags();
|
||||
|
||||
|
||||
Rn_report_builder reportBuilder=new Rn_report_builder();
|
||||
Rn_report_builder reportBuilder = new Rn_report_builder();
|
||||
reportBuilder.setReport_name(report_name);
|
||||
reportBuilder.setDescription(desc);
|
||||
reportBuilder.setReport_tags(tags);
|
||||
@@ -128,11 +121,9 @@ public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
reportBuilder.setIs_build("N");
|
||||
reportBuilder.setIs_updated("N");
|
||||
|
||||
|
||||
return save(reportBuilder);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rn_report_builder updateById(int id, String date_string) {
|
||||
|
||||
@@ -173,81 +164,72 @@ public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
Rn_report_builder rn_builder = rn_report_builder_repository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Constant.NOT_FOUND_EXCEPTION + " :" + id));
|
||||
|
||||
StringBuilder sb=new StringBuilder();
|
||||
StringBuilder sb2=new StringBuilder();
|
||||
StringBuilder sb3=new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb2 = new StringBuilder();
|
||||
StringBuilder sb3 = new StringBuilder();
|
||||
|
||||
//get tables
|
||||
List<Rn_rb_Tables> tableList=tableRepo.getTablesByReport(id);
|
||||
// get tables
|
||||
List<Rn_rb_Tables> tableList = tableRepo.getTablesByReport(id);
|
||||
for (int i = 0; i < tableList.size(); i++) {
|
||||
String table_name=tableList.get(i).getTable_name();
|
||||
String table_allias_name=tableList.get(i).getTable_allias_name();
|
||||
if(i ==0)
|
||||
{
|
||||
sb.append(table_name+" "+table_allias_name);
|
||||
}else{
|
||||
sb.append(","+table_name+" "+table_allias_name);
|
||||
String table_name = tableList.get(i).getTable_name();
|
||||
String table_allias_name = tableList.get(i).getTable_allias_name();
|
||||
if (i == 0) {
|
||||
sb.append(table_name + " " + table_allias_name);
|
||||
} else {
|
||||
sb.append("," + table_name + " " + table_allias_name);
|
||||
}
|
||||
}
|
||||
|
||||
//get columns
|
||||
List<Rn_rb_Column> columnList=columnRepo.getColumnByReport(id);
|
||||
// get columns
|
||||
List<Rn_rb_Column> columnList = columnRepo.getColumnByReport(id);
|
||||
for (int i = 0; i < columnList.size(); i++) {
|
||||
String column_name=columnList.get(i).getColumn_name();
|
||||
String table_allies_name=columnList.get(i).getTable_allies_name();
|
||||
String column_allias_name=columnList.get(i).getColumn_allias_name();
|
||||
String asc_desc=columnList.get(i).getAsc_desc();
|
||||
String function=columnList.get(i).getFunctions();
|
||||
if(function != null && !function.isEmpty())
|
||||
{
|
||||
sb2.append(function+"("+table_allies_name+"."+column_name+")"+column_allias_name);
|
||||
String column_name = columnList.get(i).getColumn_name();
|
||||
String table_allies_name = columnList.get(i).getTable_allies_name();
|
||||
String column_allias_name = columnList.get(i).getColumn_allias_name();
|
||||
String asc_desc = columnList.get(i).getAsc_desc();
|
||||
String function = columnList.get(i).getFunctions();
|
||||
if (function != null && !function.isEmpty()) {
|
||||
sb2.append(function + "(" + table_allies_name + "." + column_name + ")" + column_allias_name);
|
||||
|
||||
}else
|
||||
{
|
||||
if(i ==0)
|
||||
{
|
||||
sb2.append(column_name+" "+column_allias_name);
|
||||
}else{
|
||||
sb2.append(","+column_name+" "+column_allias_name);
|
||||
} else {
|
||||
if (i == 0) {
|
||||
sb2.append(column_name + " " + column_allias_name);
|
||||
} else {
|
||||
sb2.append("," + column_name + " " + column_allias_name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//where condition
|
||||
List<Rn_Rb_Where_Param> whereList=whereRepo.getWhereByReport(id);
|
||||
// where condition
|
||||
List<Rn_Rb_Where_Param> whereList = whereRepo.getWhereByReport(id);
|
||||
for (int i = 0; i < whereList.size(); i++) {
|
||||
String explecity=whereList.get(i).getExplecity();
|
||||
String table_column_name1=whereList.get(i).getWhere_coloumn1_tbl_alias_name();
|
||||
String column1=whereList.get(i).getWhere_coloumn();
|
||||
String condition=whereList.get(i).getWhere_condition();
|
||||
String switch_control=whereList.get(i).getSwitch_control();
|
||||
String table_column_name2=whereList.get(i).getWhere_coloumn2_tbl_alias_name();
|
||||
String column2=whereList.get(i).getWhere_coloumn2_tbl_alias_name();
|
||||
String explecity = whereList.get(i).getExplecity();
|
||||
String table_column_name1 = whereList.get(i).getWhere_coloumn1_tbl_alias_name();
|
||||
String column1 = whereList.get(i).getWhere_coloumn();
|
||||
String condition = whereList.get(i).getWhere_condition();
|
||||
String switch_control = whereList.get(i).getSwitch_control();
|
||||
String table_column_name2 = whereList.get(i).getWhere_coloumn2_tbl_alias_name();
|
||||
String column2 = whereList.get(i).getWhere_coloumn2_tbl_alias_name();
|
||||
|
||||
if(explecity!=null) {
|
||||
sb3.append(" and "+table_column_name1+"."+column1+"="+table_column_name2+"."+column2);
|
||||
}
|
||||
else {
|
||||
if (explecity != null) {
|
||||
sb3.append(" and " + table_column_name1 + "." + column1 + "=" + table_column_name2 + "." + column2);
|
||||
} else {
|
||||
sb3.append("");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
String sql6="select "+sb2+" from "+sb+" where 1=1 "+sb3+"";
|
||||
String sql6 = "select " + sb2 + " from " + sb + " where 1=1 " + sb3 + "";
|
||||
|
||||
|
||||
|
||||
//sb.append("select book.author author_1,gb_records_t.name name_2,book.title title_3 from book book,gb_records_t gb_records_t where 1=1 ");
|
||||
//String master_query=sb.toString();
|
||||
// sb.append("select book.author author_1,gb_records_t.name name_2,book.title
|
||||
// title_3 from book book,gb_records_t gb_records_t where 1=1 ");
|
||||
// String master_query=sb.toString();
|
||||
|
||||
rn_builder.setMaster_select(sql6);
|
||||
final Rn_report_builder updatedProject = rn_report_builder_repository.save(rn_builder);
|
||||
return updatedProject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// public List<String> getQueryData(String query) {
|
||||
// String sql_query = query;
|
||||
@@ -274,44 +256,42 @@ public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
// return list;
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getQueryData(String query) {
|
||||
String sql_query = query;
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
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;
|
||||
// try {
|
||||
// userName = databaseCredentialsService.getSurevaultCredentials("databaseuserName");
|
||||
// url = databaseCredentialsService.getSurevaultCredentials("databaseUrl");
|
||||
// password = databaseCredentialsService.getSurevaultCredentials("databasePassword");
|
||||
//
|
||||
// } catch (JsonProcessingException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
try (
|
||||
|
||||
// JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
Connection con = DriverManager.getConnection(url, userName, password);
|
||||
|
||||
Connection con =DriverManager.getConnection(url,userName,password);
|
||||
|
||||
//Statement stmt = con.createStatement();
|
||||
// Statement stmt = con.createStatement();
|
||||
PreparedStatement ps = con.prepareStatement(query);) {
|
||||
ResultSet rs = ps.executeQuery();
|
||||
java.sql.ResultSetMetaData rsm = rs.getMetaData();
|
||||
System.out.println("matadata::"+rsm);
|
||||
System.out.println("matadata::" + rsm);
|
||||
int rscount = rsm.getColumnCount();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> row = new HashMap<>();
|
||||
for (int i = 1; i <= rscount; i++) {
|
||||
//String data= rs.getString(i);
|
||||
//list.add(data);
|
||||
// String data= rs.getString(i);
|
||||
// list.add(data);
|
||||
String colName = rsm.getColumnName(i);
|
||||
Object colVal = rs.getObject(i);
|
||||
row.put(colName,colVal);
|
||||
row.put(colName, colVal);
|
||||
}
|
||||
list.add(row);
|
||||
|
||||
@@ -327,15 +307,14 @@ public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
public Rn_report_builder saveReportservice(Rn_report_builder report, int moduleId) {
|
||||
AppUser user = userService.getLoggedInUser();
|
||||
Long userId = user.getUserId();
|
||||
//Long accountId = user.getSys_account().getId();
|
||||
// Long accountId = user.getSys_account().getId();
|
||||
|
||||
String report_name = report.getReport_name();
|
||||
String desc = report.getDescription();
|
||||
String tags=report.getReport_tags();
|
||||
String servicename=report.getServicename();
|
||||
String tags = report.getReport_tags();
|
||||
String servicename = report.getServicename();
|
||||
|
||||
|
||||
Rn_report_builder reportBuilder=new Rn_report_builder();
|
||||
Rn_report_builder reportBuilder = new Rn_report_builder();
|
||||
reportBuilder.setReport_name(report_name);
|
||||
reportBuilder.setDescription(desc);
|
||||
reportBuilder.setReport_tags(tags);
|
||||
@@ -344,12 +323,11 @@ public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
reportBuilder.setIs_updated("N");
|
||||
reportBuilder.setServicename(servicename);
|
||||
|
||||
|
||||
return save(reportBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rn_report_builder updatereport(int reportid,Rn_report_builder reportdata) {
|
||||
public Rn_report_builder updatereport(int reportid, Rn_report_builder reportdata) {
|
||||
|
||||
Rn_report_builder oldrn_builder = rn_report_builder_repository.findById(reportid)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Constant.NOT_FOUND_EXCEPTION + " :" + reportid));
|
||||
@@ -359,23 +337,12 @@ public class Rn_report_builder_serviceIpml implements Rn_report_builder_service{
|
||||
oldrn_builder.setDescription(reportdata.getDescription());
|
||||
oldrn_builder.setServicename(reportdata.getServicename());
|
||||
|
||||
|
||||
Rn_report_builder newreport = rn_report_builder_repository.save(oldrn_builder);
|
||||
|
||||
|
||||
return newreport;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// public List<String> getQueryData(String query) {
|
||||
// List<String> queryResult = rn_report_builder_repository.getQueryData(query)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.realnet.scheduler.Entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "scheduled_jobs")
|
||||
public class JobEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id; // Auto increment
|
||||
|
||||
private String name;
|
||||
|
||||
private String cronExpression;
|
||||
|
||||
private String status; // RUNNING / PAUSED / STOPPED
|
||||
|
||||
@Column(length = 2000)
|
||||
private String description;
|
||||
private String jobType; // EMAIL / REPORT / SYNC etc.
|
||||
|
||||
private Integer lakeid;
|
||||
|
||||
public JobEntity() {
|
||||
}
|
||||
|
||||
public JobEntity(String name, String cronExpression, String status, String description) {
|
||||
this.name = name;
|
||||
this.cronExpression = cronExpression;
|
||||
this.status = status;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
// Getters & Setters
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCronExpression() {
|
||||
return cronExpression;
|
||||
}
|
||||
|
||||
public void setCronExpression(String cronExpression) {
|
||||
this.cronExpression = cronExpression;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.realnet.scheduler.Repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.scheduler.Entity.JobEntity;
|
||||
|
||||
@Repository
|
||||
public interface JobRepository extends JpaRepository<JobEntity, Long> {
|
||||
|
||||
@Query(value = "select * from scheduled_jobs where lakeid=?1", nativeQuery = true)
|
||||
|
||||
JobEntity getBylakeId(Integer lakeId);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.realnet.scheduler.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import com.realnet.scheduler.Entity.JobEntity;
|
||||
import com.realnet.scheduler.Repository.JobRepository;
|
||||
import com.realnet.scheduler.services.SmartSchedulerService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/scheduler")
|
||||
public class JobController {
|
||||
|
||||
private final SmartSchedulerService scheduler;
|
||||
private final JobRepository jobRepository;
|
||||
|
||||
public JobController(SmartSchedulerService scheduler, JobRepository jobRepository) {
|
||||
this.scheduler = scheduler;
|
||||
this.jobRepository = jobRepository;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public JobEntity createJob(@RequestBody JobEntity body) {
|
||||
|
||||
return scheduler.createAndStartJob(body);
|
||||
}
|
||||
|
||||
@PostMapping("/pause/{id}")
|
||||
public EntityResponse pauseJob(@PathVariable Long id) {
|
||||
scheduler.pauseJob(id);
|
||||
EntityResponse entityResponse = new EntityResponse("Job paused: " + id);
|
||||
return entityResponse;
|
||||
}
|
||||
|
||||
@PostMapping("/resume/{id}")
|
||||
public EntityResponse resumeJob(@PathVariable Long id) {
|
||||
scheduler.resumeJob(id);
|
||||
return new EntityResponse("Job resumed: " + id);
|
||||
}
|
||||
|
||||
@DeleteMapping("/stop/{id}")
|
||||
public EntityResponse stopJob(@PathVariable Long id) {
|
||||
scheduler.stopJob(id);
|
||||
return new EntityResponse("Job stopped: " + id);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public List<JobEntity> listJobs() {
|
||||
return jobRepository.findAll();
|
||||
}
|
||||
|
||||
@GetMapping("/lake/{lakeId}")
|
||||
public JobEntity listJobs(@PathVariable Integer lakeId) {
|
||||
return jobRepository.getBylakeId(lakeId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
package com.realnet.scheduler.services;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
//import org.springframework.scheduling.support.CronExpression;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.realnet.DataLake.Entity.Data_lake;
|
||||
import com.realnet.DataLake.Services.DataLakeActionService;
|
||||
import com.realnet.DataLake.Services.Data_lakeService;
|
||||
import com.realnet.scheduler.Entity.JobEntity;
|
||||
import com.realnet.scheduler.Repository.JobRepository;
|
||||
|
||||
@Service
|
||||
public class SmartSchedulerService {
|
||||
|
||||
private final TaskScheduler scheduler;
|
||||
private final Map<Long, ScheduledFuture<?>> runningTasks = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
public SmartSchedulerService() {
|
||||
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||
taskScheduler.setPoolSize(5);
|
||||
taskScheduler.initialize();
|
||||
this.scheduler = taskScheduler;
|
||||
}
|
||||
|
||||
// 🔹 Load jobs from DB on startup
|
||||
// @PostConstruct
|
||||
// public void init() {
|
||||
// System.out.println("🔁 Loading jobs from DB...");
|
||||
// jobRepository.findAll().forEach(job -> {
|
||||
// if ("RUNNING".equalsIgnoreCase(job.getStatus()) && job.getCronExpression() != null) {
|
||||
// startJob(job);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// @EventListener(ApplicationReadyEvent.class)
|
||||
// public void onApplicationReady() {
|
||||
// System.out.println("🚀 Application started! Loading jobs from DB...");
|
||||
// jobRepository.findAll().forEach(job -> {
|
||||
// if ("RUNNING".equalsIgnoreCase(job.getStatus()) && job.getCronExpression() != null) {
|
||||
// startJob(job);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// 🔹 Start or schedule a job
|
||||
public JobEntity createAndStartJob(JobEntity job) {
|
||||
|
||||
JobEntity existingjob = jobRepository.getBylakeId(job.getLakeid());
|
||||
if (existingjob != null) {
|
||||
job = existingjob;
|
||||
if (existingjob.getCronExpression() == null) {
|
||||
Integer lakeid = job.getLakeid();
|
||||
Data_lake data_lake = lakeService.getdetailsbyId(lakeid);
|
||||
String cron_job = data_lake.getCron_job();
|
||||
job.setCronExpression(cron_job);
|
||||
// job = jobRepository.save(job);
|
||||
}
|
||||
|
||||
} else {
|
||||
Integer lakeid = job.getLakeid();
|
||||
Data_lake data_lake = lakeService.getdetailsbyId(lakeid);
|
||||
String cron_job = data_lake.getCron_job();
|
||||
job.setCronExpression(cron_job);
|
||||
// job = jobRepository.save(job);
|
||||
}
|
||||
|
||||
// JobEntity job = new JobEntity(name, cron, "RUNNING", description);
|
||||
job.setStatus("RUNNING");
|
||||
job = jobRepository.save(job); // Auto-generated ID
|
||||
startJob(job);
|
||||
return job;
|
||||
}
|
||||
|
||||
// private void startJob(JobEntity job) {
|
||||
// ScheduledFuture<?> future = scheduler.schedule(
|
||||
//
|
||||
// () -> System.out.println(
|
||||
// "Running job: " + job.getName() + " [" + job.getId() + "] at " + java.time.LocalDateTime.now()),
|
||||
// new CronTrigger(job.getCronExpression()));
|
||||
// runningTasks.put(job.getId(), future);
|
||||
// System.out.println("✅ Job started: " + job.getName() + " | ID: " + job.getId());
|
||||
// }
|
||||
|
||||
// 🔹 Pause job
|
||||
public void pauseJob(Long id) {
|
||||
ScheduledFuture<?> future = runningTasks.get(id);
|
||||
if (future != null) {
|
||||
future.cancel(true);
|
||||
runningTasks.remove(id);
|
||||
}
|
||||
jobRepository.findById(id).ifPresent(job -> {
|
||||
job.setStatus("PAUSED");
|
||||
jobRepository.save(job);
|
||||
System.out.println("⏸️ Job paused: " + job.getName());
|
||||
});
|
||||
}
|
||||
|
||||
// 🔹 Resume job
|
||||
public void resumeJob(Long id) {
|
||||
jobRepository.findById(id).ifPresent(job -> {
|
||||
if ("PAUSED".equalsIgnoreCase(job.getStatus())) {
|
||||
startJob(job);
|
||||
job.setStatus("RUNNING");
|
||||
jobRepository.save(job);
|
||||
System.out.println("▶️ Job resumed: " + job.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 🔹 Stop job completely
|
||||
public void stopJob(Long id) {
|
||||
pauseJob(id);
|
||||
jobRepository.findById(id).ifPresent(job -> {
|
||||
job.setStatus("STOPPED");
|
||||
jobRepository.save(job);
|
||||
System.out.println("🛑 Job stopped: " + job.getName());
|
||||
});
|
||||
}
|
||||
|
||||
public void listJobs() {
|
||||
jobRepository.findAll().forEach(job -> System.out.println(
|
||||
job.getId() + " | " + job.getName() + " | " + job.getStatus() + " | " + job.getCronExpression()));
|
||||
}
|
||||
|
||||
private void startJob(JobEntity job) {
|
||||
// Step 1: Validate cron expression before scheduling
|
||||
// if (job.getCronExpression() == null || !isValidCron(job.getCronExpression())) {
|
||||
// System.err.println("❌ Invalid or missing cron expression for job: " + job.getName());
|
||||
// job.setStatus("FAILED");
|
||||
// jobRepository.save(job);
|
||||
// return;
|
||||
// }
|
||||
Runnable task;
|
||||
|
||||
switch (job.getJobType()) {
|
||||
case "DATALAKE":
|
||||
task = () -> {
|
||||
try {
|
||||
setdatalake(job);
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
break;
|
||||
case "EMAIL":
|
||||
task = () -> sendEmailJob(job);
|
||||
break;
|
||||
case "REPORT":
|
||||
task = () -> generateReport(job);
|
||||
break;
|
||||
case "SYNC":
|
||||
task = () -> {
|
||||
try {
|
||||
setdatalake(job);
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
break;
|
||||
default:
|
||||
task = () -> System.out.println("⚙️ Running generic job: " + job.getName());
|
||||
}
|
||||
|
||||
// ScheduledFuture<?> future = scheduler.schedule(task, new CronTrigger(job.getCronExpression()));
|
||||
// runningTasks.put(job.getId(), future);
|
||||
// System.out.println("✅ Job started: " + job.getName() + " | ID: " + job.getId());
|
||||
|
||||
try {
|
||||
ScheduledFuture<?> future = scheduler.schedule(task, new CronTrigger(job.getCronExpression()));
|
||||
runningTasks.put(job.getId(), future);
|
||||
System.out.println("✅ Job started: " + job.getName() + " | ID: " + job.getId());
|
||||
job.setStatus("RUNNING");
|
||||
jobRepository.save(job);
|
||||
} catch (Exception e) {
|
||||
System.err.println("🚨 Failed to schedule job: " + job.getName());
|
||||
e.printStackTrace();
|
||||
job.setStatus("FAILED");
|
||||
jobRepository.save(job);
|
||||
}
|
||||
}
|
||||
|
||||
// private boolean isValidCron(String cron) {
|
||||
// try {
|
||||
// CronExpression.parse(cron);
|
||||
// return true;
|
||||
// } catch (Exception e) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
@Autowired
|
||||
private Data_lakeService lakeService;
|
||||
|
||||
@Autowired
|
||||
private DataLakeActionService lakeActionService;
|
||||
|
||||
// Sample tasks
|
||||
private void setdatalake(JobEntity job) throws JsonProcessingException {
|
||||
|
||||
Integer lakeid = job.getLakeid();
|
||||
// Data_lake data_lake = lakeService.getdetailsbyId(lakeid);
|
||||
// String cron_job = data_lake.getCron_job();
|
||||
// job.setCronExpression(cron_job);
|
||||
// jobRepository.save(job);
|
||||
Data_lake update = lakeActionService.applyCalculation(lakeid);
|
||||
|
||||
System.out.println("📧 Start Data Lake..." + update.getName() + " [" + job.getName() + "]");
|
||||
// your email service logic here
|
||||
}
|
||||
|
||||
private void sendEmailJob(JobEntity job) {
|
||||
System.out.println("📧 Sending emails... [" + job.getName() + "]");
|
||||
// your email service logic here
|
||||
}
|
||||
|
||||
private void generateReport(JobEntity job) {
|
||||
System.out.println("📊 Generating report... [" + job.getName() + "]");
|
||||
// call report service, save file, etc.
|
||||
}
|
||||
|
||||
private void syncData(JobEntity job) {
|
||||
System.out.println("🔄 Syncing data from API... [" + job.getName() + "]");
|
||||
// hit API, update DB, etc.
|
||||
}
|
||||
|
||||
public JobEntity getByLakeId(Integer lakeId) {
|
||||
JobEntity job = jobRepository.getBylakeId(lakeId);
|
||||
return job;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -59,6 +59,7 @@ import com.realnet.users.entity.LoginUser;
|
||||
import com.realnet.users.entity.Role;
|
||||
import com.realnet.users.entity.Sys_Accounts;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.entity1.AppUserRole;
|
||||
import com.realnet.users.entity1.AppUserSessions;
|
||||
import com.realnet.users.entity1.Registration;
|
||||
import com.realnet.users.response.MessageResponse;
|
||||
@@ -156,11 +157,13 @@ public class SessionController {
|
||||
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
MDC.put("USER", loggedInUser.getUsername());
|
||||
AppUserRole usrGrp = loggedInUser.getUsrGrp();
|
||||
String groupName = usrGrp.getGroupName();
|
||||
// System.out.println("/session logged in user -> " + loggedInUser);
|
||||
|
||||
// List<String> loggedInUserRoles = new ArrayList<String>();
|
||||
StringBuilder roleString = new StringBuilder();
|
||||
roleString.append(loggedInUser.getUsrGrp().getGroupName());
|
||||
roleString.append(groupName);
|
||||
// .forEach(role -> {
|
||||
//// loggedInUserRoles.add(role.getName());
|
||||
// roleString.append(role.getName() + ", ");
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
////package com.realnet.excel.controller;
|
||||
//package com.realnet.template.controller;
|
||||
//
|
||||
//import java.io.ByteArrayInputStream;
|
||||
//import java.io.ByteArrayOutputStream;
|
||||
//import java.io.IOException;
|
||||
//
|
||||
//import org.apache.poi.ss.usermodel.Cell;
|
||||
//import org.apache.poi.ss.usermodel.Row;
|
||||
//import org.apache.poi.ss.usermodel.Sheet;
|
||||
//import org.apache.poi.ss.usermodel.Workbook;
|
||||
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.core.io.InputStreamResource;
|
||||
//import org.springframework.http.HttpHeaders;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//import org.springframework.http.MediaType;
|
||||
//import org.springframework.http.ResponseEntity;
|
||||
//import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
//import org.springframework.web.bind.annotation.GetMapping;
|
||||
//import org.springframework.web.bind.annotation.PathVariable;
|
||||
//import org.springframework.web.bind.annotation.PostMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestParam;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//import org.springframework.web.multipart.MultipartFile;
|
||||
//
|
||||
//import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
//import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
//import com.realnet.template.entity.TemplateFileUpload;
|
||||
//import com.realnet.template.repository.TemplatedataRepo;
|
||||
//import com.realnet.template.service.FileUploadService;
|
||||
//import com.realnet.users.entity1.AppUser;
|
||||
//import com.realnet.users.service1.AppUserServiceImpl;
|
||||
//
|
||||
//@RestController
|
||||
//@RequestMapping("api/template")
|
||||
//public class Controller {
|
||||
// @Autowired
|
||||
// private TemplatedataRepo temprepo;
|
||||
//
|
||||
// @Autowired
|
||||
// FileUploadService fileupload;
|
||||
// @Autowired
|
||||
// private AppUserServiceImpl userService;
|
||||
////
|
||||
//// @Autowired
|
||||
//// private FileUploadService fileUploadService;
|
||||
//
|
||||
//// @Autowired
|
||||
//// private CommFileuploadhelper fileuploadhelper;
|
||||
//
|
||||
// @GetMapping("/demo/download/{file_type}")
|
||||
// public ResponseEntity<?> demoTemplate(@PathVariable String file_type) throws IOException {
|
||||
//
|
||||
// if (file_type.equalsIgnoreCase("Customer")) {
|
||||
//
|
||||
// String filename = "Customer" + ".xlsx";
|
||||
// String[] header = { "Priority Name", "Description", "Is Active", "Effective Start Date",
|
||||
// "Effective End date" };
|
||||
// ByteArrayInputStream in = demoTemplate(header, file_type);
|
||||
// InputStreamResource file = new InputStreamResource(in);
|
||||
// return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
|
||||
// .contentType(MediaType.parseMediaType("application/vnd.ms-excel")).body(file);
|
||||
//
|
||||
// } else if (file_type.equalsIgnoreCase("impact")) {
|
||||
//
|
||||
// String filename = "Sr_impact2_t" + ".xlsx";
|
||||
// String[] header = { "Impact Name", "Description", "Is Active", "Effective Start Date",
|
||||
// "Effective End date" };
|
||||
// ByteArrayInputStream in = demoTemplate(header, file_type);
|
||||
// InputStreamResource file = new InputStreamResource(in);
|
||||
// return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
|
||||
// .contentType(MediaType.parseMediaType("application/vnd.ms-excel")).body(file);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// return new ResponseEntity<String>("Not Found", HttpStatus.BAD_REQUEST);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public static ByteArrayInputStream demoTemplate(String[] HEADERs, String file_type) throws IOException {
|
||||
// String SHEET = file_type;
|
||||
// Workbook workbook = new XSSFWorkbook();
|
||||
// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
// Sheet sheet = workbook.createSheet(SHEET);
|
||||
// Row headerRow = sheet.createRow(0);
|
||||
// for (int col = 0; col < HEADERs.length; col++) {
|
||||
// Cell cell = headerRow.createCell(col);
|
||||
// cell.setCellValue(HEADERs[col]);
|
||||
// }
|
||||
// workbook.write(out);
|
||||
// return new ByteArrayInputStream(out.toByteArray());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/getalltemplate")
|
||||
// public ResponseEntity<?> getALlTemplate() {
|
||||
// return new ResponseEntity<>(temprepo.findAll(), HttpStatus.ACCEPTED);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/gettemplatebyid/{id}")
|
||||
// public ResponseEntity<?> getTemplateById(@PathVariable Long id) {
|
||||
// return new ResponseEntity<>(fileupload.getTemplatebyid(id), HttpStatus.ACCEPTED);
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/save/{entityName}")
|
||||
// public ResponseEntity<?> post(@RequestParam(required = false) MultipartFile file, @PathVariable String entityName)
|
||||
// throws JsonMappingException, JsonProcessingException {
|
||||
//
|
||||
// TemplateFileUpload job;
|
||||
// AppUser loggedInUser = userService.getLoggedInUser();
|
||||
//
|
||||
//// job = new ObjectMapper().readValue(entityName, TemplateFileUpload.class);
|
||||
//
|
||||
// if (file != null) {
|
||||
// System.out.println(file.getOriginalFilename());
|
||||
//
|
||||
//// boolean f =
|
||||
//// fileUploadService.uploadFile(file);
|
||||
//
|
||||
// fileupload.uploadFile(file, loggedInUser.getUserId(), entityName);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// else {
|
||||
// System.out.println("erro");
|
||||
// }
|
||||
//
|
||||
//// TemplateFileUpload save = temprepo.save(job);
|
||||
//
|
||||
// return new ResponseEntity<>(HttpStatus.OK);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @DeleteMapping("/deletetemplate/{id}")
|
||||
// public ResponseEntity<String> deleteTemplateFileUploadById(@PathVariable Long id) {
|
||||
// try {
|
||||
// fileupload.deleteTemplateFileUploadById(id);
|
||||
// return ResponseEntity.ok("Template file deleted successfully");
|
||||
// } catch (Exception e) {
|
||||
// // Handle exceptions, e.g., if the entity with the given ID is not found
|
||||
// return ResponseEntity.badRequest().body("Failed to delete template file: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//// @PostMapping("/save/{filetype}")
|
||||
//// public ResponseEntity<?> uploadFile(@RequestParam MultipartFile file, @PathVariable String filetype)
|
||||
//// throws IOException, ParseException {
|
||||
//// BufferedReader br;
|
||||
//// InputStream is = file.getInputStream();
|
||||
//// br = new BufferedReader(new InputStreamReader(is));
|
||||
//// String file_name = file.getOriginalFilename();
|
||||
//// AppUser loggedInUser = userService.getLoggedInUser();
|
||||
////
|
||||
//// if (filetype.equalsIgnoreCase("priority")) {
|
||||
////
|
||||
//// if (file_name.contains("Sr_priority2_t")) {
|
||||
////
|
||||
//// String[] header = { "Priority Name", "Description", "Is Active", "Effective Start Date",
|
||||
//// "Effective End date" };
|
||||
//// ArrayList<Sr_priority2_t> prioritylist = new ArrayList<Sr_priority2_t>();
|
||||
////
|
||||
//// Workbook workbook = WorkbookFactory.create(is);
|
||||
////
|
||||
////// Create a DataFormatter to format and get each cell's value as String
|
||||
//// DataFormatter dataFormatter = new DataFormatter();
|
||||
////
|
||||
//// Sheet sheet = workbook.getSheetAt(0);
|
||||
////
|
||||
//// // Getting number of columns in the Sheet
|
||||
//// int cols = sheet.getRow(0).getLastCellNum();
|
||||
////
|
||||
//// fileupload.uploadFile(file, loggedInUser.getUserId(), filetype);
|
||||
////
|
||||
//// for (Row row : sheet) {
|
||||
////
|
||||
//// if (row.getRowNum() == 0) {
|
||||
//// for (int i = 0; i < cols; i++) {
|
||||
//// String value = dataFormatter.formatCellValue(row.getCell(i));
|
||||
////
|
||||
//// if (!header[i].equalsIgnoreCase(value)) {
|
||||
////
|
||||
//// return new ResponseEntity<>(
|
||||
//// "priority file Should have \"" + header + " \"in the header in excel file",
|
||||
//// HttpStatus.BAD_REQUEST);
|
||||
//// }
|
||||
//// }
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// if (row.getRowNum() != 0) {
|
||||
//// Date date = row.getCell(3).getDateCellValue();
|
||||
//// Date date2 = row.getCell(4).getDateCellValue();
|
||||
////
|
||||
//// Sr_priority2_t priority = new Sr_priority2_t();
|
||||
//// priority.setPriority_name(dataFormatter.formatCellValue(row.getCell(0)));
|
||||
//// priority.setDescription(dataFormatter.formatCellValue(row.getCell(1)));
|
||||
//// priority.setActive(Boolean.valueOf(dataFormatter.formatCellValue(row.getCell(2))));
|
||||
////
|
||||
//// priority.setEffective_start_date(date);
|
||||
//// priority.setEffective_end_date(date2);
|
||||
//// priorityrepo.save(priority);
|
||||
////
|
||||
//// prioritylist.add(priority);
|
||||
//// }
|
||||
////
|
||||
//// }
|
||||
////// priorityrepo.saveAll(prioritylist);
|
||||
//// workbook.close();
|
||||
////
|
||||
//////
|
||||
////
|
||||
//// return new ResponseEntity<>("File Uploaded", HttpStatus.ACCEPTED);
|
||||
//// }
|
||||
//// return new ResponseEntity<>("File name should contain Sr_priority2_t", HttpStatus.BAD_REQUEST);
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// return new ResponseEntity<>("Something Went Wrong please try again....!!!!! ", HttpStatus.BAD_REQUEST);
|
||||
////
|
||||
//// }
|
||||
////
|
||||
////// Download template data in excel Files
|
||||
////
|
||||
//// @GetMapping("/download/{file_type}")
|
||||
////
|
||||
//// public ResponseEntity<?> getFile(@PathVariable String file_type) throws IOException {
|
||||
////
|
||||
//// if (file_type.equalsIgnoreCase("priority")) {
|
||||
////
|
||||
//// String filename = "Sr_priority2_t" + ".xlsx";
|
||||
//// String[] header = { "Priority Name", "Description", "Is Active", "Effective Start Date",
|
||||
//// "Effective End date" };
|
||||
//// List<Sr_priority2_t> findAll = priorityrepo.findAll();
|
||||
//// ByteArrayInputStream in = templateByte(findAll, header);
|
||||
//// InputStreamResource file = new InputStreamResource(in);
|
||||
//// return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
|
||||
//// .contentType(MediaType.parseMediaType("application/vnd.ms-excel")).body(file);
|
||||
////
|
||||
//// } else if (file_type.equalsIgnoreCase("impact")) {
|
||||
////
|
||||
//// String filename = "Sr_impact2_t" + ".xlsx";
|
||||
//// String[] header = { "Impact Name", "Description", "Is Active", "Effective Start Date",
|
||||
//// "Effective End date" };
|
||||
//// List<Sr_impact2_t> findAll = impactrepo.findAll();
|
||||
//// ByteArrayInputStream in = templateByte3(findAll, header);
|
||||
//// InputStreamResource file = new InputStreamResource(in);
|
||||
//// return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
|
||||
//// .contentType(MediaType.parseMediaType("application/vnd.ms-excel")).body(file);
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// return new ResponseEntity<String>("Not Found", HttpStatus.BAD_REQUEST);
|
||||
////
|
||||
//// }
|
||||
//
|
||||
//}
|
||||
@@ -16,9 +16,7 @@ import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -51,12 +49,6 @@ public class ExcelController {
|
||||
FileUploadService fileupload;
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
//
|
||||
// @Autowired
|
||||
// private FileUploadService fileUploadService;
|
||||
|
||||
// @Autowired
|
||||
// private CommFileuploadhelper fileuploadhelper;
|
||||
|
||||
@GetMapping("/demo/download/{file_type}")
|
||||
public ResponseEntity<?> demoTemplate(@PathVariable String file_type) throws IOException {
|
||||
@@ -163,6 +155,56 @@ public class ExcelController {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@GetMapping("/getalltemplate")
|
||||
public ResponseEntity<?> getALlTemplate() {
|
||||
return new ResponseEntity<>(temprepo.findAll(), HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
@GetMapping("/gettemplatebyid/{id}")
|
||||
public ResponseEntity<?> getTemplateById(@PathVariable Long id) {
|
||||
return new ResponseEntity<>(fileupload.getTemplatebyid(id), HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
@PostMapping("/save/{entityName}")
|
||||
public ResponseEntity<?> post(@RequestParam(required = false) MultipartFile file, @PathVariable String entityName)
|
||||
throws JsonMappingException, JsonProcessingException {
|
||||
|
||||
TemplateFileUpload job;
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
|
||||
// job = new ObjectMapper().readValue(entityName, TemplateFileUpload.class);
|
||||
|
||||
if (file != null) {
|
||||
System.out.println(file.getOriginalFilename());
|
||||
|
||||
// boolean f =
|
||||
// fileUploadService.uploadFile(file);
|
||||
|
||||
fileupload.uploadFile(file, loggedInUser.getUserId(), entityName);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
System.out.println("erro");
|
||||
}
|
||||
|
||||
// TemplateFileUpload save = temprepo.save(job);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping("/deletetemplate/{id}")
|
||||
public ResponseEntity<String> deleteTemplateFileUploadById(@PathVariable Long id) {
|
||||
try {
|
||||
fileupload.deleteTemplateFileUploadById(id);
|
||||
return ResponseEntity.ok("Template file deleted successfully");
|
||||
} catch (Exception e) {
|
||||
// Handle exceptions, e.g., if the entity with the given ID is not found
|
||||
return ResponseEntity.badRequest().body("Failed to delete template file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// @PostMapping("/save/{filetype}")
|
||||
// public ResponseEntity<?> uploadFile(@RequestParam MultipartFile file, @PathVariable String filetype)
|
||||
// throws IOException, ParseException {
|
||||
@@ -274,54 +316,4 @@ public class ExcelController {
|
||||
//
|
||||
// }
|
||||
|
||||
@GetMapping("/getalltemplate")
|
||||
public ResponseEntity<?> getALlTemplate() {
|
||||
return new ResponseEntity<>(temprepo.findAll(), HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
@GetMapping("/gettemplatebyid/{id}")
|
||||
public ResponseEntity<?> getTemplateById(@PathVariable Long id) {
|
||||
return new ResponseEntity<>(fileupload.getTemplatebyid(id), HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
@PostMapping("/save/{entityName}/{name}")
|
||||
public ResponseEntity<?> post(@RequestParam(required = false) MultipartFile file, @PathVariable String entityName,
|
||||
@PathVariable String name) throws JsonMappingException, JsonProcessingException {
|
||||
|
||||
TemplateFileUpload job;
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
|
||||
// job = new ObjectMapper().readValue(entityName, TemplateFileUpload.class);
|
||||
|
||||
if (file != null) {
|
||||
System.out.println(file.getOriginalFilename());
|
||||
|
||||
// boolean f =
|
||||
// fileUploadService.uploadFile(file);
|
||||
|
||||
fileupload.uploadFile(file, loggedInUser.getUserId(), entityName, name);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
System.out.println("erro");
|
||||
}
|
||||
|
||||
// TemplateFileUpload save = temprepo.save(job);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping("/deletetemplate/{id}")
|
||||
public ResponseEntity<String> deleteTemplateFileUploadById(@PathVariable Long id) {
|
||||
try {
|
||||
fileupload.deleteTemplateFileUploadById(id);
|
||||
return ResponseEntity.ok("Template file deleted successfully");
|
||||
} catch (Exception e) {
|
||||
// Handle exceptions, e.g., if the entity with the given ID is not found
|
||||
return ResponseEntity.badRequest().body("Failed to delete template file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,14 +8,10 @@ import java.nio.file.StandardCopyOption;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
import com.realnet.template.entity.TemplateFileUpload;
|
||||
import com.realnet.template.repository.TemplatedataRepo;
|
||||
|
||||
@@ -28,7 +24,7 @@ public class FileUploadService {
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
public String uploadFile(MultipartFile file, Long user_id, String file_type, String name) {
|
||||
public String uploadFile(MultipartFile file, Long user_id, String entityname) {
|
||||
try {
|
||||
|
||||
String filepath = "import-data";
|
||||
@@ -75,8 +71,7 @@ public class FileUploadService {
|
||||
exceldata.setFile_name(file.getOriginalFilename());
|
||||
exceldata.setFile_changed_name(str);
|
||||
// exceldata.setFile_type(file_type);
|
||||
exceldata.setEntity_name(file_type);
|
||||
exceldata.setName(name);
|
||||
exceldata.setEntity_name(entityname);
|
||||
exceldata.setUser_id(user_id);
|
||||
repo.save(exceldata);
|
||||
|
||||
@@ -89,10 +84,6 @@ public class FileUploadService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public TemplateFileUpload getTemplatebyid(Long Id) {
|
||||
TemplateFileUpload one = repo.getOne(Id);
|
||||
return one;
|
||||
@@ -106,8 +97,6 @@ public class FileUploadService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public TemplateFileUpload getFileById(Long id) {
|
||||
// Use your JPA repository to retrieve the file by its ID
|
||||
return repo.findById(id).orElse(null);
|
||||
|
||||
@@ -210,8 +210,7 @@ public class UserController {
|
||||
|
||||
String em = user.getEmail();
|
||||
String subject = "Pass reset";
|
||||
String url = "http://" + Port_Constant.LOCAL_HOST + ":" + Port_Constant.FRONTEND_PORT_9191
|
||||
+ "/#/forgotresetpassword/" + token;
|
||||
String url = Port_Constant.FRONTEND_PORTAL_DOMAIN + "/#/forgotresetpassword/" + token;
|
||||
// String url = "http://surecns.ml:30165/#/forgotresetpassword/" + token;
|
||||
// String url = "http://localhost:9191/api" + "/resources/savePassword/" + token;
|
||||
emailService.constructEmail(em, subject, url);
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.realnet.config.EmailService;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import com.realnet.session.Service.TokenBlacklistService;
|
||||
import com.realnet.userDTO.User;
|
||||
import com.realnet.users.entity.PasswordResetRequest;
|
||||
@@ -103,6 +104,21 @@ public class AppUserController {
|
||||
return new ResponseEntity<>("User not found", HttpStatus.OK);
|
||||
}
|
||||
|
||||
// set iser active inactive
|
||||
@GetMapping("/getOneAppUser/active/{id}")
|
||||
public ResponseEntity<?> getOneAppUser(@PathVariable("id") Long id, @RequestParam Boolean active) {
|
||||
Optional<AppUser> a = appUserServiceImpl.getOneUser(id);
|
||||
|
||||
if (a.get() != null) {
|
||||
a.get().setActive(active);
|
||||
|
||||
boolean insertOrSaveUser = appUserServiceImpl.insertOrSaveUser(a.get());
|
||||
|
||||
return new ResponseEntity<>(a.get(), HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>("User not found", HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/addOneAppUser")
|
||||
public ResponseEntity<?> addOneUser(@RequestBody Registration reg) {
|
||||
if (appUserRepository.findByEmail(reg.getEmail()) != null) {
|
||||
@@ -193,12 +209,19 @@ public class AppUserController {
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
Long account_id = loggedInUser.getAccount().getAccount_id();
|
||||
|
||||
AppUser user = userService.findUserByEmail(email);
|
||||
if (user != null) {
|
||||
return ResponseEntity.badRequest().body(new MessageResponse(email + " already exist"));
|
||||
} else {
|
||||
String token = UUID.randomUUID().toString();
|
||||
AppUser appUser = new AppUser();
|
||||
|
||||
AppUser user = userService.findUserByEmail(email);
|
||||
if (user != null && user.isIsComplete()) {
|
||||
return ResponseEntity.badRequest().body(new MessageResponse(email + " already exist"));
|
||||
}
|
||||
|
||||
if (user != null) {
|
||||
appUser = user;
|
||||
|
||||
}
|
||||
String token = UUID.randomUUID().toString();
|
||||
|
||||
userService.adduserviaadmin(appUser, token, email, account_id);
|
||||
|
||||
String subject = "add user";
|
||||
@@ -210,8 +233,7 @@ public class AppUserController {
|
||||
// + "/admin/adduser/" + token;
|
||||
|
||||
emailService.sendEmail(email, subject, url);
|
||||
return new ResponseEntity<>("Email sent success", HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(new EntityResponse("Email sent success"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
@@ -267,17 +289,23 @@ public class AppUserController {
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
String fullName = loggedInUser.getFullName();
|
||||
Long account_id = loggedInUser.getAccount().getAccount_id();
|
||||
AppUser appUser = new AppUser();
|
||||
|
||||
if (email.contains(" ")) {
|
||||
// Replace whitespace with '+'
|
||||
email = email.replace(" ", "+");
|
||||
}
|
||||
|
||||
AppUser user = userService.findUserByEmail(email);
|
||||
if (user != null) {
|
||||
if (user != null && user.isIsComplete()) {
|
||||
return ResponseEntity.badRequest().body(new MessageResponse(email + " already exist"));
|
||||
} else {
|
||||
}
|
||||
|
||||
if (user != null) {
|
||||
appUser = user;
|
||||
|
||||
}
|
||||
String token = UUID.randomUUID().toString();
|
||||
AppUser appUser = new AppUser();
|
||||
userService.addguestviaadmin(appUser, token, email, account_id);
|
||||
|
||||
// String subject = "add guest";
|
||||
@@ -290,8 +318,7 @@ public class AppUserController {
|
||||
|
||||
String subject = "Guest Registration..";
|
||||
emailService.sendEmail(email, subject, url);
|
||||
return new ResponseEntity<>("Email sent success", HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(new EntityResponse("Email sent success"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
@@ -336,6 +363,4 @@ public class AppUserController {
|
||||
return ResponseEntity.ok().body(new MessageResponse("registration already done"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -14,6 +16,7 @@ import com.realnet.session.entity.AboutWork;
|
||||
import com.realnet.users.entity.Sys_Accounts;
|
||||
import com.realnet.users.repository.AboutWorkRepo;
|
||||
import com.realnet.users.repository.SysAccountRepo;
|
||||
import com.realnet.users.service1.SysAccountService;
|
||||
|
||||
@RequestMapping("/token/users/sysaccount")
|
||||
@RestController
|
||||
@@ -25,9 +28,20 @@ public class SysAccountController {
|
||||
@Autowired
|
||||
private AboutWorkRepo aboutWorkRepo;
|
||||
|
||||
@Autowired
|
||||
private SysAccountService accountService;
|
||||
|
||||
@PostMapping("/savesysaccount")
|
||||
public Sys_Accounts save(@RequestBody Sys_Accounts sys_Accounts) {
|
||||
Sys_Accounts save = sysAccountRepo.save(sys_Accounts);
|
||||
Sys_Accounts save = accountService.save(sys_Accounts);
|
||||
|
||||
System.out.println("created account data is .." + save);
|
||||
return save;
|
||||
}
|
||||
|
||||
@PutMapping("/savesysaccount/{accId}")
|
||||
public Sys_Accounts updte(@PathVariable Long accId, @RequestBody Sys_Accounts sys_Accounts) {
|
||||
Sys_Accounts save = accountService.update(accId, sys_Accounts);
|
||||
|
||||
System.out.println("created account data is .." + save);
|
||||
return save;
|
||||
|
||||
@@ -1,137 +1,121 @@
|
||||
//package com.realnet.users.controller1;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//import org.springframework.http.ResponseEntity;
|
||||
//import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
//import org.springframework.web.bind.annotation.GetMapping;
|
||||
//import org.springframework.web.bind.annotation.PathVariable;
|
||||
//import org.springframework.web.bind.annotation.PostMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestBody;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
//import com.realnet.Workspaceuser.Entity.Sec_team_members;
|
||||
//import com.realnet.Workspaceuser.Entity.Sec_teams;
|
||||
//import com.realnet.Workspaceuser.Repository.SecWorkspaceUserRepo;
|
||||
//import com.realnet.Workspaceuser.Repository.Sec_team_MemberRepository;
|
||||
//import com.realnet.Workspaceuser.Repository.Sec_teams_Repository;
|
||||
//import com.realnet.users.entity1.AppUser;
|
||||
//import com.realnet.users.repository1.AppUserRepository;
|
||||
//import com.realnet.users.response.MessageResponse;
|
||||
//import com.realnet.users.service1.AppUserServiceImpl;
|
||||
//
|
||||
//@RestController
|
||||
//@RequestMapping("/User_workSpace")
|
||||
//public class WorkSpaceController1 {
|
||||
// @Autowired
|
||||
// private AppUserServiceImpl userService;
|
||||
//
|
||||
// @Autowired
|
||||
// private AppUserRepository appUserRepository;
|
||||
// @Autowired
|
||||
// private Sec_teams_Repository sec_teams_Repository;
|
||||
//
|
||||
// @Autowired
|
||||
// private Sec_team_MemberRepository memberRepository;
|
||||
//
|
||||
// @Autowired
|
||||
// private SecWorkspaceUserRepo secWorkspaceUserRepo;
|
||||
//
|
||||
// //GET ALL USER attach from login id
|
||||
// @GetMapping("/GetAll")
|
||||
// public ResponseEntity<?> getall(){
|
||||
// AppUser loggedInUser = userService.getLoggedInUser();
|
||||
// Long account_id = loggedInUser.getAccount().getAccount_id();
|
||||
//
|
||||
// List<AppUser> li = appUserRepository.getall(account_id);
|
||||
// return new ResponseEntity<>(li,HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
// //ADD USER TO SPECIFIC TEAM
|
||||
// @PostMapping("/add_team/{id}/{userId}")
|
||||
// public ResponseEntity<?> addteam(@RequestBody Sec_team_members team_mem,
|
||||
// @PathVariable int id,@PathVariable Long userId){
|
||||
// Sec_team_members members = memberRepository.findteammember(id,userId);
|
||||
// if(members == null) {
|
||||
//
|
||||
// Sec_teams team = sec_teams_Repository.findById(id);
|
||||
// if(team != null) {
|
||||
//
|
||||
// AppUser user = appUserRepository.findById(userId).orElseThrow(null);
|
||||
//
|
||||
// team_mem.setTeam_id(team.getId());
|
||||
// team_mem.setMember_name(user.getFullName());
|
||||
// team_mem.setMember_id(user.getUserId());
|
||||
// Sec_team_members save = memberRepository.save(team_mem);
|
||||
//
|
||||
//
|
||||
// return new ResponseEntity<>(save, HttpStatus.OK);
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// return ResponseEntity.badRequest().body(new MessageResponse("team not found"));
|
||||
// }
|
||||
// else
|
||||
// return ResponseEntity.badRequest().body(new MessageResponse("member already added"));
|
||||
// }
|
||||
//
|
||||
// //REMOVE MEMBER FROM TEAM
|
||||
// @DeleteMapping("/RemoveMember/{id}/{userId}")
|
||||
// public MessageResponse removemember(@PathVariable int id,@PathVariable Long userId){
|
||||
// Sec_team_members members = memberRepository.findteammember(id,userId);
|
||||
// if(members != null) {
|
||||
// memberRepository.delete(members);
|
||||
// return new MessageResponse("deleted");
|
||||
// }else
|
||||
//
|
||||
// return new MessageResponse("member not found");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //GET ALL USER ADD BY ADMIN
|
||||
// @GetMapping("/GetAllUser")
|
||||
// public ResponseEntity<?> GetUser(){
|
||||
// AppUser loggedInUser = userService.getLoggedInUser();
|
||||
// Long account_id = loggedInUser.getAccount().getAccount_id();
|
||||
//
|
||||
// List<AppUser> li = appUserRepository.getalluser(account_id);
|
||||
// return new ResponseEntity<>(li,HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
// //GET ALL GUEST ADD BY ADMIN
|
||||
// @GetMapping("/GetAllGuest")
|
||||
// public ResponseEntity<?> Getguest(){
|
||||
// AppUser loggedInUser = userService.getLoggedInUser();
|
||||
// Long account_id = loggedInUser.getAccount().getAccount_id();
|
||||
//
|
||||
// List<AppUser> li = appUserRepository.getallguest(account_id);
|
||||
// return new ResponseEntity<>(li,HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
// //GET ALL TEAM MEMBER FROM SPECIFIC TEAM
|
||||
// @GetMapping("/GetAllMember/{team_id}")
|
||||
// public ResponseEntity<?> GetAllteamMember(@PathVariable int team_id){
|
||||
//
|
||||
//
|
||||
// List<Sec_team_members> li = memberRepository.getallteam(team_id);
|
||||
// if(li == null) {
|
||||
// return ResponseEntity.badRequest().body(new MessageResponse("team not found"));
|
||||
// }else
|
||||
// return new ResponseEntity<>(li,HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
package com.realnet.users.controller1;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.Workspaceuser.Entity.Sec_team_members;
|
||||
import com.realnet.Workspaceuser.Entity.Sec_teams;
|
||||
import com.realnet.Workspaceuser.Repository.SecWorkspaceUserRepo;
|
||||
import com.realnet.Workspaceuser.Repository.Sec_team_MemberRepository;
|
||||
import com.realnet.Workspaceuser.Repository.Sec_teams_Repository;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.repository1.AppUserRepository;
|
||||
import com.realnet.users.response.MessageResponse;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/User_workSpace")
|
||||
public class WorkSpaceController1 {
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
|
||||
@Autowired
|
||||
private AppUserRepository appUserRepository;
|
||||
@Autowired
|
||||
private Sec_teams_Repository sec_teams_Repository;
|
||||
|
||||
@Autowired
|
||||
private Sec_team_MemberRepository memberRepository;
|
||||
|
||||
@Autowired
|
||||
private SecWorkspaceUserRepo secWorkspaceUserRepo;
|
||||
|
||||
// GET ALL USER by account id attach from loggedin user
|
||||
@GetMapping("/GetAll/AccountId")
|
||||
public ResponseEntity<?> getall() {
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
Long account_id = loggedInUser.getAccount().getAccount_id();
|
||||
|
||||
List<AppUser> li = appUserRepository.getall(account_id);
|
||||
return new ResponseEntity<>(li, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// ADD USER TO SPECIFIC TEAM
|
||||
@PostMapping("/add_team/{id}/{userId}")
|
||||
public ResponseEntity<?> addteam(@RequestBody Sec_team_members team_mem, @PathVariable int id,
|
||||
@PathVariable Long userId) {
|
||||
Sec_team_members members = memberRepository.findteammember(id, userId);
|
||||
if (members == null) {
|
||||
|
||||
Sec_teams team = sec_teams_Repository.findById(id);
|
||||
if (team != null) {
|
||||
|
||||
AppUser user = appUserRepository.findById(userId).orElseThrow(null);
|
||||
|
||||
team_mem.setTeam_id(team.getId());
|
||||
team_mem.setMember_name(user.getFullName());
|
||||
team_mem.setMember_id(user.getUserId());
|
||||
Sec_team_members save = memberRepository.save(team_mem);
|
||||
|
||||
return new ResponseEntity<>(save, HttpStatus.OK);
|
||||
|
||||
} else
|
||||
return ResponseEntity.badRequest().body(new MessageResponse("team not found"));
|
||||
} else
|
||||
return ResponseEntity.badRequest().body(new MessageResponse("member already added"));
|
||||
}
|
||||
|
||||
// REMOVE MEMBER FROM TEAM
|
||||
@DeleteMapping("/RemoveMember/{id}/{userId}")
|
||||
public MessageResponse removemember(@PathVariable int id, @PathVariable Long userId) {
|
||||
Sec_team_members members = memberRepository.findteammember(id, userId);
|
||||
if (members != null) {
|
||||
memberRepository.delete(members);
|
||||
return new MessageResponse("deleted");
|
||||
} else
|
||||
|
||||
return new MessageResponse("member not found");
|
||||
}
|
||||
|
||||
// GET ALL USER ADD BY ADMIN
|
||||
@GetMapping("/GetAllUser")
|
||||
public ResponseEntity<?> GetUser() {
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
Long account_id = loggedInUser.getAccount().getAccount_id();
|
||||
|
||||
List<AppUser> li = appUserRepository.getalluser(account_id);
|
||||
return new ResponseEntity<>(li, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// GET ALL GUEST ADD BY ADMIN
|
||||
@GetMapping("/GetAllGuest")
|
||||
public ResponseEntity<?> Getguest() {
|
||||
AppUser loggedInUser = userService.getLoggedInUser();
|
||||
Long account_id = loggedInUser.getAccount().getAccount_id();
|
||||
|
||||
List<AppUser> li = appUserRepository.getallguest(account_id);
|
||||
return new ResponseEntity<>(li, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// GET ALL TEAM MEMBER FROM SPECIFIC TEAM
|
||||
@GetMapping("/GetAllMember/{team_id}")
|
||||
public ResponseEntity<?> GetAllteamMember(@PathVariable int team_id) {
|
||||
|
||||
List<Sec_team_members> li = memberRepository.getallteam(team_id);
|
||||
if (li == null) {
|
||||
return ResponseEntity.badRequest().body(new MessageResponse("team not found"));
|
||||
} else
|
||||
return new ResponseEntity<>(li, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class AppUser implements Serializable {
|
||||
private String password4;
|
||||
private Long pwdChangedCnt;
|
||||
private Date lastPwdChangedDate;
|
||||
private Blob photo;
|
||||
// private Blob photo;
|
||||
private String photoName;
|
||||
|
||||
private String provider;
|
||||
@@ -157,6 +157,8 @@ public class AppUser implements Serializable {
|
||||
@Transient
|
||||
private StringBuilder totalLogInfo;
|
||||
|
||||
// private String tshirtsize;
|
||||
|
||||
@Transient
|
||||
@JsonIgnore
|
||||
private PasswordResetToken pass;
|
||||
|
||||
@@ -20,6 +20,6 @@ public class AppUserDto {
|
||||
private String notification;
|
||||
private Long mob_no;
|
||||
private boolean active;
|
||||
|
||||
private String tshirtsize;
|
||||
|
||||
}
|
||||
|
||||
@@ -392,6 +392,9 @@ public class AppUserServiceImpl implements UserDetailsService, AppUserService {
|
||||
a.setNotification(
|
||||
appUserDto.getNotification() != null ? appUserDto.getNotification() : a.getNotification());
|
||||
|
||||
// if (appUserDto.getTshirtsize() != null) {
|
||||
// a.setTshirtsize(appUserDto.getTshirtsize());
|
||||
// }
|
||||
a.setMob_no(appUserDto.getMob_no());
|
||||
a.setActive(appUserDto.isActive());
|
||||
|
||||
@@ -527,7 +530,7 @@ public class AppUserServiceImpl implements UserDetailsService, AppUserService {
|
||||
AppUser save = appUserRepository.save(a);
|
||||
System.out.println("Password changed Successfully.. ");
|
||||
|
||||
return new ResponseEntity<>(save, HttpStatus.ACCEPTED);
|
||||
return new ResponseEntity<>("Password changed Successfully", HttpStatus.ACCEPTED);
|
||||
|
||||
}
|
||||
|
||||
@@ -644,6 +647,9 @@ public class AppUserServiceImpl implements UserDetailsService, AppUserService {
|
||||
user.setUsername(email);
|
||||
user.setEmail(email);
|
||||
user.setAccount(accounts);
|
||||
if (user.getCreatedate() == null) {
|
||||
user.setCreatedate(LocalDateTime.now());
|
||||
}
|
||||
|
||||
appUserRepository.save(user);
|
||||
|
||||
@@ -657,6 +663,9 @@ public class AppUserServiceImpl implements UserDetailsService, AppUserService {
|
||||
user.setUsername(email);
|
||||
user.setEmail(email);
|
||||
user.setAccount(accounts);
|
||||
if (user.getCreatedate() == null) {
|
||||
user.setCreatedate(LocalDateTime.now());
|
||||
}
|
||||
// user.setAccess_duration(access_duration);
|
||||
//
|
||||
// Calendar c = Calendar.getInstance();
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.itextpdf.text.pdf.PdfStructTreeController.returnType;
|
||||
import com.realnet.users.entity.Sys_Accounts;
|
||||
import com.realnet.users.repository.SysAccountRepo;
|
||||
|
||||
@@ -15,12 +16,64 @@ public class SysAccountService {
|
||||
private SysAccountRepo sysAccountRepo;
|
||||
|
||||
public Sys_Accounts save(Sys_Accounts sys) {
|
||||
|
||||
Sys_Accounts account = findByEmail(sys.getEmail());
|
||||
if (account != null) {
|
||||
|
||||
}
|
||||
|
||||
sys.setActive(true);
|
||||
Sys_Accounts accounts = sysAccountRepo.save(sys);
|
||||
|
||||
return accounts;
|
||||
|
||||
}
|
||||
|
||||
// update sysaccount
|
||||
|
||||
public Sys_Accounts update(Long accountId, Sys_Accounts request) {
|
||||
|
||||
Sys_Accounts account = sysAccountRepo.findById(accountId).get();
|
||||
// account_id generally auto-generated hai, update me change nahi karenge
|
||||
|
||||
if (request.getCompanyName() != null) {
|
||||
account.setCompanyName(request.getCompanyName());
|
||||
}
|
||||
|
||||
if (request.getWorkspace() != null) {
|
||||
account.setWorkspace(request.getWorkspace());
|
||||
}
|
||||
|
||||
if (request.getGstNumber() != null) {
|
||||
account.setGstNumber(request.getGstNumber());
|
||||
}
|
||||
|
||||
if (request.getMobile() != null) {
|
||||
account.setMobile(request.getMobile());
|
||||
}
|
||||
|
||||
if (request.getEmail() != null) {
|
||||
account.setEmail(request.getEmail());
|
||||
}
|
||||
|
||||
if (request.getPancard() != null) {
|
||||
account.setPancard(request.getPancard());
|
||||
}
|
||||
|
||||
if (request.getWorking() != null) {
|
||||
account.setWorking(request.getWorking());
|
||||
}
|
||||
|
||||
if (request.getActive() != null) {
|
||||
account.setActive(request.getActive());
|
||||
}
|
||||
|
||||
Sys_Accounts save = sysAccountRepo.save(account);
|
||||
|
||||
return save;
|
||||
|
||||
}
|
||||
|
||||
public List<Sys_Accounts> getall() {
|
||||
|
||||
List<Sys_Accounts> getall = sysAccountRepo.findAll();
|
||||
|
||||
@@ -1,15 +1,113 @@
|
||||
package com.realnet.utils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Component
|
||||
public class Port_Constant {
|
||||
|
||||
public final static String LOCAL_HOST = "43.205.154.152";
|
||||
public final static String FRONTEND_PORT_9191 = "30165";
|
||||
public static String SURE_SETU_DOMAIN = "http://34.198.218.30:30173";
|
||||
|
||||
public final static String GITEA_IP_ADDRESS = "try.gitea";
|
||||
public final static String GITEA_PORT = "io";
|
||||
public final static String SURE_VAULT_DOMAIN = "http://54.92.243.148:30150";
|
||||
public final static String SUREVAULT_DEPLOYMENT_TYPE = "32";
|
||||
public static String BACKEND_PORTAL_DOMAIN;
|
||||
public static String FRONTEND_PORTAL_DOMAIN;
|
||||
public static String SUREOPS_DOMAIN;
|
||||
public static String JOBPRO_DOMAIN;
|
||||
public static String APP_BUILD_DOMAIN;
|
||||
public static String SURE_SERVE_DOMAIN;
|
||||
public static String SURE_SETU_DOMAIN;
|
||||
public static String FARM_SCRIPT_RUNNER_DOMAIN;
|
||||
public static String DEPLOYMENT_TYPE;
|
||||
public static String FARM_IP_ADDRESS_online;
|
||||
public static String CONTROL_CENTRE_PORT;
|
||||
public static String CONTROL_CENTRE_MASTER_PORT;
|
||||
public static String CONTROL_CENTRE_MASTER_IP;
|
||||
public static String LOCALHOST;
|
||||
public static String SUREOPS_LOCALHOST;
|
||||
public static String APPBUILD_LOCALHOST;
|
||||
public static String SURE_VAULT_DOMAIN;
|
||||
public static String GITEA_DB_NAME;
|
||||
public static String GITEA_DOMAIN;
|
||||
public static String GITEA_USERNAME;
|
||||
public static String GITEA_URL;
|
||||
public static String PROTOCOL;
|
||||
public static String SONAR_QUBE_DOMAIN;
|
||||
public static String SONAR_QUBE_Username;
|
||||
|
||||
public static String SONAR_QUBE_password;
|
||||
public static String DOMAIN;
|
||||
|
||||
// SETTER
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
// Type ('dev', 'prod')
|
||||
private final String type = "dev";
|
||||
|
||||
@Value("${BACKEND_PORTAL_DOMAIN}")
|
||||
private String backendPortalDomain;
|
||||
|
||||
// @PostConstruct is used to make API calls and initialize the constants for the
|
||||
// entire application during startup.
|
||||
@PostConstruct
|
||||
public void initializeConstantsFromApi() {
|
||||
|
||||
// BACKEND_PORTAL_DOMAIN = getUrlFromApi("Backend_portal_domain");
|
||||
// String backendPortalDomain = getBackendPortalUrl();
|
||||
// System.out.println("Fetched BACKEND_PORTAL_DOMAIN: " + backendPortalDomain);
|
||||
|
||||
if (backendPortalDomain != null) {
|
||||
BACKEND_PORTAL_DOMAIN = backendPortalDomain;
|
||||
System.out.println("Fetched BACKEND_PORTAL_DOMAIN from properties file: " + backendPortalDomain);
|
||||
|
||||
FRONTEND_PORTAL_DOMAIN = getUrlFromApi(backendPortalDomain, "Frontend_portal_domain");
|
||||
System.out.println("FRONTEND_PORTAL_DOMAIN: " + FRONTEND_PORTAL_DOMAIN);
|
||||
SUREOPS_DOMAIN = getUrlFromApi(backendPortalDomain, "SUREOPS_DOMAIN");
|
||||
JOBPRO_DOMAIN = getUrlFromApi(backendPortalDomain, "JOBPRO_DOMAIN");
|
||||
APP_BUILD_DOMAIN = getUrlFromApi(backendPortalDomain, "APP_BUILD_DOMAIN");
|
||||
SURE_SERVE_DOMAIN = getUrlFromApi(backendPortalDomain, "SURE_SERVE_DOMAIN");
|
||||
SURE_SETU_DOMAIN = getUrlFromApi(backendPortalDomain, "SURE_SETU_DOMAIN");
|
||||
FARM_SCRIPT_RUNNER_DOMAIN = getUrlFromApi(backendPortalDomain, "FARM_SCRIPT_RUNNER_DOMAIN");
|
||||
DEPLOYMENT_TYPE = getUrlFromApi(backendPortalDomain, "DEPLOYMENT_TYPE");
|
||||
FARM_IP_ADDRESS_online = getUrlFromApi(backendPortalDomain, "FARM_IP_ADDRESS_online");
|
||||
CONTROL_CENTRE_PORT = getUrlFromApi(backendPortalDomain, "CONTROL_CENTRE_PORT");
|
||||
CONTROL_CENTRE_MASTER_PORT = getUrlFromApi(backendPortalDomain, "CONTROL_CENTRE_MASTER_PORT");
|
||||
CONTROL_CENTRE_MASTER_IP = getUrlFromApi(backendPortalDomain, "CONTROL_CENTRE_MASTER_IP");
|
||||
LOCALHOST = getUrlFromApi(backendPortalDomain, "Localhost");
|
||||
SUREOPS_LOCALHOST = getUrlFromApi(backendPortalDomain, "SUREOPS_LOCALHOST");
|
||||
APPBUILD_LOCALHOST = getUrlFromApi(backendPortalDomain, "APPBUILD_LOCALHOST");
|
||||
SURE_VAULT_DOMAIN = getUrlFromApi(backendPortalDomain, "SURE_VAULT_DOMAIN");
|
||||
GITEA_DOMAIN = getUrlFromApi(backendPortalDomain, "GITEA_DOMAIN");
|
||||
GITEA_USERNAME = getUrlFromApi(backendPortalDomain, "GITEA_USERNAME");
|
||||
|
||||
GITEA_URL = getUrlFromApi(backendPortalDomain, "GITEA_URL");
|
||||
|
||||
GITEA_DB_NAME = getUrlFromApi(backendPortalDomain, "GITEA_DB_NAME");
|
||||
|
||||
PROTOCOL = getUrlFromApi(backendPortalDomain, "PROTOCOL");
|
||||
SONAR_QUBE_DOMAIN = getUrlFromApi(backendPortalDomain, "SONAR_QUBE_DOMAIN");
|
||||
SONAR_QUBE_Username = getUrlFromApi(backendPortalDomain, "SONAR_QUBE_Username");
|
||||
|
||||
SONAR_QUBE_password = getUrlFromApi(backendPortalDomain, "SONAR_QUBE_password");
|
||||
DOMAIN = getUrlFromApi(backendPortalDomain, "DOMAIN");
|
||||
|
||||
} else {
|
||||
System.out.println("Error: BACKEND_PORTAL_DOMAIN could not be fetched.");
|
||||
}
|
||||
}
|
||||
|
||||
private String getUrlFromApi(String backendPortalDomain, String serviceName) {
|
||||
try {
|
||||
// Use the provided backendPortalDomain to construct the full URL
|
||||
String baseUrl = backendPortalDomain + "/token/HealthCheckup/DeploymentUrl/Deployment_url/";
|
||||
String url = baseUrl + type + "/" + serviceName;
|
||||
String Object = restTemplate.getForObject(url, String.class); // Fetch URL from API
|
||||
|
||||
System.out.println(serviceName + " : " + Object);
|
||||
return Object;
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error fetching URL for " + serviceName + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,12 @@ app.auth.tokenExpirationMsec=864000000
|
||||
app.oauth2.authorizedRedirectUris=http://localhost:8081/oauth2/redirect,myandroidapp://oauth2/redirect,myiosapp://oauth2/redirect
|
||||
|
||||
|
||||
projectPath=@project.basedir@
|
||||
angularProjectPath=@project.basedir@/webui
|
||||
# projectPath=@project.basedir@
|
||||
# angularProjectPath=@project.basedir@/webui
|
||||
|
||||
projectPath=/data
|
||||
angularProjectPath=/data/webui
|
||||
BACKEND_PORTAL_DOMAIN=http://157.66.191.31:30166
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user