Skip to content

Commit f215a27

Browse files
committed
System Touch
1 parent 0aa0557 commit f215a27

6 files changed

Lines changed: 484 additions & 463 deletions

File tree

.idea/awsToolkit.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/connections/Connection.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.net.Socket;
1818
import java.util.Date;
1919

20-
public class Connection
20+
public class Connection implements AutoCloseable
2121
{
2222
protected String hash = "0xDA717018470E213F";
2323

@@ -54,4 +54,14 @@ public Connection(final BaseServer SERVER)
5454

5555
this.SERVER = SERVER;
5656
}
57+
58+
@Override
59+
public void close()
60+
{
61+
for(Connection connection : this.SERVER.CURRENT_CONNECTIONS.CURRENT_CONNECTION)
62+
{
63+
connection.close();
64+
}
65+
}
66+
5767
}

source/db/N21Store.java

Lines changed: 160 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package db;
22

33
import connections.Connection;
4+
import exceptions.ExceptionHandler;
45
import exceptions.ExceptionRecord;
56

6-
import java.sql.PreparedStatement;
7-
import java.sql.Timestamp;
7+
import java.sql.*;
8+
9+
import static java.sql.DriverManager.getConnection;
810

911
/**
1012
* Static store methods — one per N21 table.
@@ -437,8 +439,162 @@ public static void createCommunicatorTables()
437439
catch (Exception e) { fail("communicator_tables", e); }
438440
}
439441

440-
public static void storeChatMessage(final long FROM, final long TO,
441-
final String MESSAGE, final String TYPE)
442+
// ---------------------------------------------------------------------
443+
// TABLE CREATION
444+
// ---------------------------------------------------------------------
445+
446+
public static void createWhiteAuditorTables() {
447+
try (Connection c = getConnection()) {
448+
449+
((java.sql.Connection) c).createStatement().execute("""
450+
CREATE TABLE IF NOT EXISTS wat_tasks (
451+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
452+
from_national_id BIGINT NOT NULL,
453+
to_national_id BIGINT NOT NULL,
454+
type VARCHAR(32) NOT NULL,
455+
filename VARCHAR(255),
456+
size INT,
457+
payload LONGTEXT,
458+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
459+
)
460+
""");
461+
462+
} catch (Exception e) { ExceptionHandler.dispatch(e); }
463+
}
464+
465+
// ---------------------------------------------------------------------
466+
// STORE FILE
467+
// ---------------------------------------------------------------------
468+
469+
public static void storeAssignedFile(long fromId, long toId, String filename, String base64) throws Exception
470+
{
471+
try (Connection c = getConnection();
472+
PreparedStatement ps = ((java.sql.Connection) c).prepareStatement("""
473+
INSERT INTO wat_tasks (from_national_id, to_national_id, type, filename, payload)
474+
VALUES (?, ?, 'file', ?, ?)
475+
""")) {
476+
477+
ps.setLong(1, fromId);
478+
ps.setLong(2, toId);
479+
ps.setString(3, filename);
480+
ps.setString(4, base64);
481+
ps.executeUpdate();
482+
483+
} catch (Exception e) { ExceptionHandler.dispatch(e); }
484+
}
485+
486+
// ---------------------------------------------------------------------
487+
// STORE BITS
488+
// ---------------------------------------------------------------------
489+
490+
public static void storeAssignedBits(long fromId, long toId, int size, String base64) {
491+
try (Connection c = getConnection();
492+
PreparedStatement ps = ((java.sql.Connection) c).prepareStatement(
493+
"""
494+
INSERT INTO wat_tasks (from_national_id, to_national_id, type, size, payload)
495+
VALUES (?, ?, 'bits', ?, ?)
496+
"""
497+
)) {
498+
499+
ps.setLong(1, fromId);
500+
ps.setLong(2, toId);
501+
ps.setInt(3, size);
502+
ps.setString(4, base64);
503+
ps.executeUpdate();
504+
} catch (SQLException ex)
505+
{
506+
throw new RuntimeException(ex);
507+
} catch (Exception e)
508+
{
509+
throw new RuntimeException(e);
510+
}
511+
}
512+
513+
// ---------------------------------------------------------------------
514+
// STORE SIGNATORY
515+
// ---------------------------------------------------------------------
516+
517+
public static void storeAssignedSignatory(long fromId, long toId, String symbol) {
518+
try (Connection c = getConnection();
519+
PreparedStatement ps = ((java.sql.Connection) c).prepareStatement("""
520+
INSERT INTO wat_tasks (from_national_id, to_national_id, type, payload)
521+
VALUES (?, ?, 'signatory', ?)
522+
""")) {
523+
524+
ps.setLong(1, fromId);
525+
ps.setLong(2, toId);
526+
ps.setString(3, symbol);
527+
ps.executeUpdate();
528+
529+
} catch (Exception e) { ExceptionHandler.dispatch(e); }
530+
}
531+
532+
// ---------------------------------------------------------------------
533+
// LIST TASKS FOR USER
534+
// ---------------------------------------------------------------------
535+
536+
public static ResultSet loadTasksFor(long toId) {
537+
try {
538+
Connection c = getConnection();
539+
PreparedStatement ps = ((java.sql.Connection) c).prepareStatement("""
540+
SELECT id, type, from_national_id, created_at
541+
FROM wat_tasks
542+
WHERE to_national_id = ?
543+
ORDER BY created_at DESC
544+
""");
545+
ps.setLong(1, toId);
546+
return ps.executeQuery();
547+
548+
} catch (Exception e) { ExceptionHandler.dispatch(e); return null; }
549+
}
550+
551+
// ---------------------------------------------------------------------
552+
// GET SINGLE TASK
553+
// ---------------------------------------------------------------------
554+
555+
public static ResultSet loadTask(long taskId) {
556+
try {
557+
Connection c = getConnection();
558+
PreparedStatement ps = ((java.sql.Connection) c).prepareStatement("""
559+
SELECT *
560+
FROM wat_tasks
561+
WHERE id = ?
562+
""");
563+
ps.setLong(1, taskId);
564+
return ps.executeQuery();
565+
566+
} catch (Exception e) { ExceptionHandler.dispatch(e); return null; }
567+
}
568+
569+
// ---------------------------------------------------------------------
570+
// DELETE TASK
571+
// ---------------------------------------------------------------------
572+
573+
public static void deleteTask(long taskId) {
574+
try (Connection c = getConnection();
575+
PreparedStatement ps = ((java.sql.Connection) c).prepareStatement("""
576+
DELETE FROM wat_tasks WHERE id = ?
577+
""")) {
578+
579+
ps.setLong(1, taskId);
580+
ps.executeUpdate();
581+
582+
} catch (Exception e) { ExceptionHandler.dispatch(e); }
583+
}
584+
585+
586+
public static Connection getConnection() throws Exception
587+
{
588+
String url = "jdbc:mysql://localhost:3306/n21db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&characterEncoding=UTF-8";
589+
String user = "root"; // change if needed
590+
String pass = "password"; // change if needed
591+
592+
Class.forName("com.mysql.cj.jdbc.Driver");
593+
594+
return (Connection) DriverManager.getConnection(url, user, pass);
595+
}
596+
597+
public static void storeChatMessage(final long FROM, final long TO, final String MESSAGE, final String TYPE)
442598
{
443599
if (dbOk())
444600
{

source/server/nitro/NitroWebExpress.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ public static class Aspect
124124

125125
public weather.WeatherServer WEATHER_SERVER;
126126

127+
public whiteauditor.WhiteAuditorTasking WHITE_AUDITOR_TASKING;
128+
129+
127130
/** Start CONNECTION_STATUS and NitroWebExpress.SELF together. */
128131
public void start()
129132
{
@@ -136,6 +139,7 @@ public void start()
136139
if (COMMUNICATOR != null) COMMUNICATOR.start();
137140
if (BINARY_HTTP_SERVER != null) BINARY_HTTP_SERVER.start();
138141
if (WEATHER_SERVER != null) WEATHER_SERVER.start();
142+
if (WHITE_AUDITOR_TASKING != null) WHITE_AUDITOR_TASKING.start();
139143
if (NitroWebExpress.SELF != null) NitroWebExpress.SELF.start();
140144
}
141145

@@ -251,7 +255,7 @@ private void respond(final Socket CLIENT)
251255

252256
String report =
253257
"╔══════════════════════════════════════════════╗\n" +
254-
"║ " + L.apply("header") + " ║\n" +
258+
"║ " + L.apply("header") + " \n" +
255259
"╚══════════════════════════════════════════════╝\n" +
256260
L.apply("label.remote_ip") + " " + remoteIp + "\n" +
257261
L.apply("label.geo") + " " + geoLine + "\n" +
@@ -337,6 +341,9 @@ public Aspect(final WebExpress WEBEXPRESS)
337341
if(WEBEXPRESS==null) throw new SecurityException("//bodi/connect");
338342

339343
this.WEBEXPRESS = WEBEXPRESS;
344+
345+
this.WHITE_AUDITOR_TASKING = new whiteauditor.WhiteAuditorTasking(NitroWebExpress.WEBEXPRESS_COMPLIANT_HOSTNAME);
346+
340347
}
341348

342349
// ── Module loading infrastructure ─────────────────────────────────────

0 commit comments

Comments
 (0)