-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo.java
More file actions
224 lines (192 loc) · 11.7 KB
/
Copy pathDemo.java
File metadata and controls
224 lines (192 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package fastaimatcher.demo;
import fastaimatcher.*;
import fastansi.FastANSI;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
/**
* Live FastANSI SOX & Compliance Audit Engine Demo.
* Demonstrates high-throughput verification of enterprise interface import batches.
*/
public class Demo {
private static final String C_GREEN = FastANSI.fg(74, 222, 128);
private static final String C_RED = FastANSI.fg(248, 113, 113);
private static final String C_BORDER = FastANSI.fg(90, 100, 115);
private static final String C_GRAY = FastANSI.fg(140, 150, 165);
private static final String C_DIM = FastANSI.fg(160, 170, 185);
private static final String C_WHITE = FastANSI.FG_BRIGHT_WHITE;
private static final String C_BOLD_WHITE = FastANSI.BOLD + FastANSI.FG_BRIGHT_WHITE;
private static final String RESET = FastANSI.RESET;
public static void main(String[] args) throws Exception {
try {
System.setOut(new java.io.PrintStream(System.out, true, StandardCharsets.UTF_8));
System.setErr(new java.io.PrintStream(System.err, true, StandardCharsets.UTF_8));
} catch (Exception ignored) {}
printHeroHeader();
// 1. SOX & ITGC Compliance Control Catalogue
List<Rule> rules = List.of(
new Rule("SOX-404-SOD", Rule.Category.APPROVAL,
"Four-Eyes & Segregation of Duties: Batch upload and approval must be distinct human actors",
List.of(), Double.NaN),
new Rule("ITGC-SYS-AUTHP", Rule.Category.MANDATORY,
"System/Automated approval restricted: Automated bypass requires explicit human sign-off",
List.of("example.com"), Double.NaN),
new Rule("FIN-REJ-TOLERANCE", Rule.Category.NUMERIC_LIMIT,
"Rejected transaction tolerance limit: Maximum 0 rejected rows allowed per billing period batch",
List.of(), 0.0)
);
FastAIMatcher matcher = new FastAIMatcher(rules);
System.out.printf(" %sLoaded %s%d%s active SOX/ITGC compliance controls into verification pipeline:%s\n",
C_GRAY, C_BOLD_WHITE, rules.size(), C_GRAY, RESET);
for (int i = 0; i < rules.size(); i++) {
Rule r = rules.get(i);
boolean isLast = (i == rules.size() - 1);
String branch = isLast ? "└──" : "├──";
String subBranch = isLast ? " " : "│ ";
String idTag = "[" + r.id() + "]";
String text = r.ruleText();
int maxLineLen = 70;
if (text.length() <= maxLineLen) {
System.out.printf(" %s " + C_WHITE + "%-20s " + C_GRAY + "%-14s " + C_DIM + "%s" + RESET + "\n",
C_BORDER + branch + RESET, idTag, r.category().name(), text);
} else {
int splitIdx = text.lastIndexOf(' ', maxLineLen);
if (splitIdx == -1) splitIdx = maxLineLen;
String line1 = text.substring(0, splitIdx);
String line2 = text.substring(splitIdx).trim();
System.out.printf(" %s " + C_WHITE + "%-20s " + C_GRAY + "%-14s " + C_DIM + "%s" + RESET + "\n",
C_BORDER + branch + RESET, idTag, r.category().name(), line1);
System.out.printf(" %s %-20s %-14s " + C_DIM + "%s" + RESET + "\n",
C_BORDER + subBranch + RESET, "", "", line2);
}
}
System.out.println();
// 2. Locate and stream Enterprise Import CSV records
Path csvPath = Paths.get("..", "..", "docs", "list-import-20260731084257.csv");
if (!Files.exists(csvPath)) {
csvPath = Paths.get("docs", "list-import-20260731084257.csv");
}
List<TargetDocument> documents = new ArrayList<>();
if (Files.exists(csvPath)) {
try (BufferedReader reader = Files.newBufferedReader(csvPath, StandardCharsets.UTF_8)) {
String header = reader.readLine();
String line;
int count = 0;
while ((line = reader.readLine()) != null && count < 8) {
String[] cols = line.split(",", -1);
if (cols.length >= 19) {
String approvedBy = cols[1];
String id = cols[6];
String name = cols[7];
String rejectedStr = cols[14];
String status = cols[15];
String uploadedBy = cols[18];
List<String> approvers = approvedBy.contains("system.approval") ? List.of() : List.of(approvedBy);
Map<String, String> meta = Map.of(
"budget", rejectedStr, // bound to rejected rows for threshold check
"rejected", rejectedStr,
"uploadedBy", uploadedBy,
"status", status
);
String text = String.format("Batch %s (%s) uploaded by %s approved by %s status %s",
id, name, uploadedBy, approvedBy, status);
documents.add(new TargetDocument(id, name, text, meta, approvers));
count++;
}
}
}
}
// Fallback synthetic documents if CSV is not reachable
if (documents.isEmpty()) {
documents.add(new TargetDocument("100001", "IMPORT_STAGE_PARTNER_20260701",
"Enterprise Directs Batch interface.batch@example.com approved by erika.musterfrau@example.com",
Map.of("budget", "0"), List.of("erika.musterfrau@example.com")));
documents.add(new TargetDocument("100002", "IMPORT_STAGE_COMMISSION_20260702",
"Enterprise Directs Batch interface.batch@example.com approved by system.approval@example.com",
Map.of("budget", "0"), List.of()));
documents.add(new TargetDocument("100006", "IMPORT_STAGE_TARIFF_20260706",
"Enterprise Directs Batch interface.batch@example.com approved by otto.normalverbraucher@example.com",
Map.of("budget", "2"), List.of("otto.normalverbraucher@example.com")));
}
// 3. Telemetry Stream Header
printTableHead();
int totalEvaluated = 0;
int violationsFound = 0;
List<MatchFinding> allFindings = new ArrayList<>();
for (int i = 0; i < documents.size(); i++) {
TargetDocument doc = documents.get(i);
List<MatchFinding> findings = matcher.match(doc);
allFindings.addAll(findings);
totalEvaluated++;
for (MatchFinding f : findings) {
if (f.isViolated()) {
violationsFound++;
}
printFindingRow(doc.docId(), doc.title(), f);
}
if (i < documents.size() - 1) {
printTableDivider();
}
}
printTableFoot();
// 4. Binary Serialization (.matchbin) Audit Trail
byte[] encoded = MatcherCodec.encode(allFindings);
List<MatchFinding> decoded = MatcherCodec.decode(encoded);
System.out.printf("\n %s📊 AUDIT SUMMARY%s\n", C_BOLD_WHITE, RESET);
System.out.printf(" %sBatches Scanned :%s %s%d%s\n", C_GRAY, RESET, C_WHITE, totalEvaluated, RESET);
System.out.printf(" %sTotal Controls :%s %s%d%s\n", C_GRAY, RESET, C_WHITE, allFindings.size(), RESET);
System.out.printf(" %sNon-Compliant :%s %s%d%s\n", C_GRAY, RESET, violationsFound > 0 ? C_RED : C_GREEN, violationsFound, RESET);
System.out.printf(" %sAudit Bin Size :%s %s%d bytes%s (round-trip verified: %s%d findings%s)\n\n",
C_GRAY, RESET, C_WHITE, encoded.length, RESET, C_GREEN, decoded.size(), RESET);
System.out.printf(" %s✔ FastAIMatcher Telemetry Audit Pipeline Finished Successfully.%s\n", C_GREEN, RESET);
}
private static void printHeroHeader() {
System.out.println();
System.out.println(" " + C_BOLD_WHITE + "⚡ FastAIMatcher" + C_GRAY + " — High-Throughput SOX & Enterprise Audit Telemetry Engine" + RESET);
System.out.println();
}
private static void printTableHead() {
System.out.println(C_BORDER + "┌────────┬──────────────────────────────────────┬───────────────────┬───────────┬───────┬──────────────────────────────┐" + RESET);
System.out.printf(C_BORDER + "│ " + C_BOLD_WHITE + "%-6s " + C_BORDER + "│ " + C_BOLD_WHITE + "%-36s " + C_BORDER + "│ " + C_BOLD_WHITE + "%-17s " + C_BORDER + "│ " + C_BOLD_WHITE + "%-9s " + C_BORDER + "│ " + C_BOLD_WHITE + "%-5s " + C_BORDER + "│ " + C_BOLD_WHITE + "%-28s " + C_BORDER + "│\n" + RESET,
"BATCH", "STREAM / CONTEXT", "CONTROL RULE", "STATUS", "SCORE", "AUDIT EXPLANATION");
System.out.println(C_BORDER + "├────────┼──────────────────────────────────────┼───────────────────┼───────────┼───────┼──────────────────────────────┤" + RESET);
}
private static void printFindingRow(String batchId, String name, MatchFinding f) {
String shortName = name.length() > 36 ? name.substring(0, 33) + "..." : name;
String statusBadge;
switch (f.status()) {
case COMPLIANT:
statusBadge = C_GREEN + "COMPLIANT" + RESET;
break;
case VIOLATION:
statusBadge = C_RED + "VIOLATION" + RESET;
break;
case MISSING_EVIDENCE:
statusBadge = C_DIM + "MISS_EVID" + RESET;
break;
default:
statusBadge = C_DIM + "WARNING " + RESET;
break;
}
String rawExpl = f.explanation();
String shortExpl = rawExpl.length() > 28 ? rawExpl.substring(0, 25) + "..." : rawExpl;
System.out.printf(C_BORDER + "│ " + C_DIM + "%-6s " + C_BORDER + "│ " + C_WHITE + "%-36s " + C_BORDER + "│ " + C_DIM + "%-17s " + C_BORDER + "│ %s " + C_BORDER + "│ " + C_WHITE + "%1.2f " + C_BORDER + "│ " + (f.isViolated() ? C_RED : C_DIM) + "%-28s " + C_BORDER + "│\n" + RESET,
batchId,
shortName,
f.ruleId(),
statusBadge,
f.confidenceScore(),
shortExpl);
}
private static void printTableDivider() {
System.out.println(C_BORDER + "│ │ │ │ │ │ │" + RESET);
}
private static void printTableFoot() {
System.out.println(C_BORDER + "└────────┴──────────────────────────────────────┴───────────────────┴───────────┴───────┴──────────────────────────────┘" + RESET);
}
}