This commit is contained in:
2026-06-17 06:31:11 +02:00
parent 79ddb307c1
commit 1f4a1667c3
27 changed files with 2251 additions and 32 deletions

View File

@@ -0,0 +1,724 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>State Machine Explorer - click.kamil.multi.core.OrderStateMachineConfig</title>
<!-- Popper and Tippy for tooltips -->
<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>
<link rel="stylesheet" href="https://unpkg.com/tippy.js@6/animations/scale.css"/>
<!-- SVG Pan & Zoom -->
<script src="https://cdn.jsdelivr.net/npm/svg-pan-zoom@3.6.1/dist/svg-pan-zoom.min.js"></script>
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;900&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--sidebar-bg: #ffffff;
--main-bg: #f8fafc;
--accent: #ef4444;
--primary: #3b82f6;
--text: #0f172a;
--text-muted: #64748b;
--border: #e2e8f0;
}
body {
margin: 0;
display: flex;
height: 100vh;
font-family: 'Inter', -apple-system, sans-serif;
background: var(--main-bg);
color: var(--text);
overflow: hidden;
}
#sidebar {
width: 480px;
min-width: 350px;
max-width: 900px;
background: var(--sidebar-bg);
border-right: 2px solid var(--border);
display: flex;
flex-direction: column;
box-shadow: 10px 0 15px rgba(0,0,0,0.02);
z-index: 10;
overflow-x: hidden;
resize: horizontal;
position: relative;
transition: width 0.3s ease, min-width 0.3s ease, padding 0.3s ease;
}
#sidebar.collapsed {
width: 0 !important;
min-width: 0 !important;
border-right: none;
padding: 0;
overflow: hidden;
resize: none;
}
#toggle-sidebar {
position: absolute;
top: 20px;
left: 20px;
z-index: 50;
background: #fff;
border: 1px solid var(--border);
border-radius: 8px;
padding: 8px;
cursor: pointer;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
}
#toggle-sidebar:hover {
background: #f8fafc;
border-color: var(--primary);
}
#toggle-sidebar svg {
width: 20px;
height: 20px;
fill: none;
stroke: var(--text-muted);
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
#sidebar::after {
content: '⋮';
position: absolute;
right: 2px; top: 50%;
transform: translateY(-50%);
color: var(--border);
font-size: 1.2rem;
pointer-events: none;
}
.sidebar-header {
padding: 30px 30px 10px;
}
header h1 { font-weight: 900; font-size: 1.6rem; color: var(--text); margin: 0 0 5px 0; letter-spacing: -0.5px; }
header p { font-family: 'JetBrains Mono', monospace; font-size: 0.7rem; color: var(--text-muted); margin: 0 0 15px 0; opacity: 0.7; }
.tabs {
display: flex;
padding: 0 30px;
border-bottom: 1px solid var(--border);
gap: 20px;
}
.tab {
padding: 10px 0;
font-size: 0.85rem;
font-weight: 600;
color: var(--text-muted);
cursor: pointer;
position: relative;
transition: color 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); }
.tab.active::after {
content: '';
position: absolute;
bottom: -1px; left: 0; right: 0;
height: 2px;
background: var(--primary);
}
.tab-content {
flex-grow: 1;
padding: 25px 30px;
overflow-y: auto;
display: none;
}
.tab-content.active { display: block; }
.ep-card, .flow-card {
padding: 18px;
background: #fff;
border: 1px solid var(--border);
border-radius: 14px;
margin-bottom: 15px;
cursor: pointer;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
position: relative;
word-break: break-all;
overflow-wrap: anywhere;
}
.ep-card:hover, .flow-card:hover {
border-color: var(--primary);
transform: translateX(5px);
box-shadow: 0 15px 30px -10px rgba(59, 130, 246, 0.15);
}
.ep-type {
font-size: 0.6rem;
font-weight: 900;
padding: 3px 8px;
border-radius: 6px;
display: inline-block;
margin-bottom: 10px;
text-transform: uppercase;
letter-spacing: 0.8px;
}
.type-rest { background: #eff6ff; color: #1d4ed8; }
.type-custom { background: #fef2f2; color: #b91c1c; }
.type-jms { background: #f5f3ff; color: #7c3aed; }
.type-sqs { background: #fff7ed; color: #ea580c; }
.type-sns { background: #fff1f2; color: #e11d48; }
.type-kafka { background: #fefce8; color: #854d0e; }
.type-rabbit { background: #f0fdf4; color: #166534; }
.ep-name, .flow-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 6px; color: var(--text); }
.ep-fqn, .flow-desc { font-family: 'Inter', sans-serif; font-size: 0.75rem; color: var(--text-muted); opacity: 0.9; line-height: 1.4; }
#main { flex-grow: 1; position: relative; background: var(--main-bg); overflow: hidden; }
#svg-container {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
display: flex;
align-items: center;
justify-content: center;
}
svg {
width: 100%;
height: 100%;
display: block;
}
/* SVG Interactivity Styles */
svg a { text-decoration: none !important; }
.active-path {
stroke: var(--accent) !important;
stroke-width: 2.5px !important;
filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.3));
transition: all 0.3s;
}
.active-path text, a.active-path text {
fill: #000 !important;
font-weight: 900 !important;
paint-order: stroke;
stroke: #fff;
stroke-width: 3.5px;
}
.dimmed {
opacity: 0.2 !important;
filter: grayscale(1);
transition: opacity 0.4s ease;
pointer-events: none;
}
/* Tippy Styling */
.tippy-box[data-theme~='modern'] {
background-color: #fff;
color: var(--text);
box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
border: 1px solid var(--border);
border-radius: 16px;
padding: 0;
max-width: 550px !important;
}
.tooltip-content {
padding: 20px;
max-width: 500px;
word-break: break-word;
overflow-wrap: anywhere;
}
.payload-box {
background: #0f172a;
color: #e2e8f0;
border-radius: 8px;
padding: 12px;
font-family: 'JetBrains Mono', monospace;
font-size: 0.75rem;
line-height: 1.5;
margin-top: 10px;
}
.payload-param {
margin-bottom: 4px;
}
.payload-param:last-child { margin-bottom: 0; }
</style>
</head>
<body>
<div id="sidebar">
<div class="sidebar-header">
<header>
<h1>Explorer</h1>
<p>click.kamil.multi.core.OrderStateMachineConfig</p>
</header>
</div>
<div class="tabs">
<div class="tab active" data-tab="explorer">Explorer</div>
<div class="tab" data-tab="flows">Business Flows</div>
</div>
<div id="tab-explorer" class="tab-content active">
<div id="ep-list"></div>
</div>
<div id="tab-flows" class="tab-content">
<div id="flow-list"></div>
</div>
</div>
<div id="main">
<button id="toggle-sidebar" aria-label="Toggle Sidebar" title="Toggle Sidebar">
<svg viewBox="0 0 24 24"><path d="M4 6h16M4 12h16M4 18h16"></path></svg>
</button>
<div id="svg-container">
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 168 405" width="100%" zoomAndPan="magnify"><defs/><g><ellipse cx="45.2604" cy="25.2083" fill="#222222" rx="11.4583" ry="11.4583" style="stroke:#222222;stroke-width:1.1458333333333333;"/><rect fill="#FFFFFF" height="45.8333" rx="14.3229" ry="14.3229" style="stroke:#94A3B8;stroke-width:1.1458333333333333;" width="57.2917" x="16.6146" y="83.6458"/><text fill="#000000" font-family="Inter" font-size="10.3125" font-weight="bold" lengthAdjust="spacing" textLength="22.9167" x="33.8021" y="110.4599">NEW</text><rect fill="#FFFFFF" height="45.8333" rx="14.3229" ry="14.3229" style="stroke:#94A3B8;stroke-width:1.1458333333333333;" width="76.7708" x="6.875" y="184.4792"/><text fill="#000000" font-family="Inter" font-size="10.3125" font-weight="bold" lengthAdjust="spacing" textLength="65.3125" x="12.6042" y="211.2932">PROCESSING</text><rect fill="#FFFFFF" height="45.8333" rx="14.3229" ry="14.3229" style="stroke:#94A3B8;stroke-width:1.1458333333333333;" width="74.4792" x="8.0208" y="285.3125"/><text fill="#000000" font-family="Inter" font-size="10.3125" font-weight="bold" lengthAdjust="spacing" textLength="63.0208" x="13.75" y="312.1266">COMPLETED</text><ellipse cx="45.2604" cy="386.1458" fill="none" rx="12.6042" ry="12.6042" style="stroke:#222222;stroke-width:1.1458333333333333;"/><ellipse cx="45.2604" cy="386.1458" fill="#222222" rx="6.875" ry="6.875" style="stroke:#222222;stroke-width:1.1458333333333333;"/><polygon fill="#CBD5E1" points="45.2604,83.3979,49.8438,73.0854,45.2604,77.6688,40.6771,73.0854,45.2604,83.3979" style="stroke:#CBD5E1;stroke-width:1.1458333333333333;"/><path d="M45.2604,41.323 C45.2604,52.7366 45.2604,62.8874 45.2604,76.5229 " fill="none" style="stroke:#CBD5E1;stroke-width:1.1458333333333333;"/><polygon fill="#1E90FF" points="45.2604,184.4415,49.8438,174.129,45.2604,178.7124,40.6771,174.129,45.2604,184.4415" style="stroke:#1E90FF;stroke-width:1.1458333333333333;"/><path d="M45.2604,129.5779 C45.2604,145.908 45.2604,161.2512 45.2604,177.5665 " fill="none" style="stroke:#1E90FF;stroke-width:2.2916666666666665;"/><a href="#link_SUBMIT" target="_self" title="#link_SUBMIT" xlink:actuate="onRequest" xlink:href="#link_SUBMIT" xlink:show="new" xlink:title="#link_SUBMIT" xlink:type="simple"><text fill="#0000FF" font-family="JetBrains Mono" font-size="9.1667" lengthAdjust="spacing" text-decoration="underline" textLength="113.4375" x="46.4063" y="160.1123">SUBMIT / processAction()</text></a><polygon fill="#1E90FF" points="45.2604,285.2749,49.8438,274.9624,45.2604,279.5457,40.6771,274.9624,45.2604,285.2749" style="stroke:#1E90FF;stroke-width:1.1458333333333333;"/><path d="M45.2604,230.4113 C45.2604,246.7413 45.2604,262.0846 45.2604,278.3999 " fill="none" style="stroke:#1E90FF;stroke-width:2.2916666666666665;"/><a href="#link_FINISH" target="_self" title="#link_FINISH" xlink:actuate="onRequest" xlink:href="#link_FINISH" xlink:show="new" xlink:title="#link_FINISH" xlink:type="simple"><text fill="#0000FF" font-family="JetBrains Mono" font-size="9.1667" lengthAdjust="spacing" text-decoration="underline" textLength="27.5" x="46.4063" y="260.9456">FINISH</text></a><polygon fill="#CBD5E1" points="45.2604,373.4202,49.8438,363.1077,45.2604,367.6911,40.6771,363.1077,45.2604,373.4202" style="stroke:#CBD5E1;stroke-width:1.1458333333333333;"/><path d="M45.2604,331.1691 C45.2604,344.8226 45.2604,355.0691 45.2604,366.5452 " fill="none" style="stroke:#CBD5E1;stroke-width:1.1458333333333333;"/><!--SRC=[RP5TJy8m58Rl-okEuKQDHEP78iQG20wT4IGEumKXvh0UHyFMBcqLqVZVFNEey-DctNbE-xxlQJSAYscEaE7AF7fmENdKA1pnFnLeqHiBscWISoK9A2_y2YIvnAh2AwChx3nPCdvLa70BfSjpEKFq1Ay2e8l98hNcKSkUoLXlELUUIcwi95knHli0zsT7NtGyLyb2atCGCEiRxOUO4qIQhTOWLYy4xS_2hpA2cSaaWvlAosgoiDTYC48fbKvPwwsUS8xIB4l-W9chPp-rrYo_J2_9ToqgxM1WjFblsqUKez-TzMJ9J1vIyBjP7_2x9Gi5GT2gXtnAhvHUZD6c_2ZtZh878IRRKsWsEp0CxuGG_8Ncf164xLQ_lrFUmPHxevlhNXZ7qV0SJaxecUzDOzRfbCLzVDiTH6CkZc4oQMIilqQmNdQXi2RXTAT9-SoRMzEfg0d-TUjT3qPNuJWy-slMZuPHVF73h49GBImjle-NO_5uxm00]--></g></svg>
</div>
</div>
<script id="metadata-json" type="application/json">
{
"name" : "click.kamil.multi.core.OrderStateMachineConfig",
"states" : [ {
"rawName" : "COMPLETED",
"fullIdentifier" : "COMPLETED"
}, {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
}, {
"rawName" : "\"COMPLETED\"",
"fullIdentifier" : "COMPLETED"
}, {
"rawName" : "NEW",
"fullIdentifier" : "NEW"
}, {
"rawName" : "\"NEW\"",
"fullIdentifier" : "NEW"
} ],
"transitions" : [ {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"NEW\"",
"fullIdentifier" : "NEW"
} ],
"targetStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"event" : "SUBMIT",
"guard" : null,
"actions" : [ {
"expression" : "processAction()",
"isLambda" : false,
"internalLogic" : "@Override default void execute(StateContext<String,String> context){\n System.out.println(\"Processing order: \" + context.getMessageHeader(\"orderId\"));\n}\n",
"lineNumber" : 31
} ],
"order" : null
}, {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"targetStates" : [ {
"rawName" : "\"COMPLETED\"",
"fullIdentifier" : "COMPLETED"
} ],
"event" : "FINISH",
"guard" : null,
"actions" : [ ],
"order" : null
} ],
"startStates" : [ "NEW" ],
"endStates" : [ "COMPLETED" ],
"renderChoicesAsDiamonds" : true,
"flows" : [ ],
"metadata" : {
"triggers" : [ {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
} ],
"entryPoints" : [ {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
}, {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.api.OrderApi",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
} ],
"callChains" : [ {
"entryPoint" : {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
},
"methodChain" : [ "click.kamil.multi.core.OrderController.submitOrder" ],
"triggerPoint" : {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
}
} ],
"properties" : {
"default" : { }
}
}
}
</script>
<script>
const metadata = JSON.parse(document.getElementById('metadata-json').textContent);
let panZoomInstance;
document.addEventListener('DOMContentLoaded', () => {
const svg = document.querySelector('#svg-container svg');
panZoomInstance = svgPanZoom(svg, { zoomEnabled: true, controlIconsEnabled: true, fit: true, center: true });
document.getElementById('toggle-sidebar').addEventListener('click', () => {
const sidebar = document.getElementById('sidebar');
sidebar.classList.toggle('collapsed');
// Re-center SVG pan-zoom after transition
setTimeout(() => {
if (panZoomInstance) {
panZoomInstance.resize();
panZoomInstance.center();
}
}, 300);
});
setupTabs();
populateSidebar();
populateFlows();
attachInteractivity();
});
function setupTabs() {
const flows = metadata.flows || [];
if (flows.length === 0) {
document.querySelector('.tabs').style.display = 'none';
document.querySelector('.tab-content[data-tab="flows"]')?.remove();
return;
}
document.querySelectorAll('.tab').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('.tab, .tab-content').forEach(el => el.classList.remove('active'));
tab.classList.add('active');
document.getElementById('tab-' + tab.dataset.tab).classList.add('active');
});
});
}
function populateSidebar() {
const list = document.getElementById('ep-list');
const entryPoints = metadata.metadata.entryPoints || [];
const machineEvents = new Set(metadata.transitions.map(t => t.event).filter(Boolean));
entryPoints.forEach(ep => {
// Quality Filter: Hide if it doesn't trigger a machine event
const chains = (metadata.metadata.callChains || []).filter(c =>
c.entryPoint.className === ep.className &&
c.entryPoint.methodName === ep.methodName &&
machineEvents.has(c.triggerPoint.event)
);
if (chains.length === 0) return;
const card = document.createElement('div');
card.className = 'ep-card';
card.innerHTML = `
<div class="ep-type type-${ep.type.toLowerCase()}">${ep.type}</div>
<div class="ep-name">${ep.name}</div>
<div class="ep-fqn">${ep.className}.${ep.methodName}</div>
`;
card.onmouseenter = () => highlightEntryPoint(ep);
card.onmouseleave = clearHighlights;
list.appendChild(card);
});
}
function populateFlows() {
const list = document.getElementById('flow-list');
const flows = metadata.flows || [];
if (flows.length === 0) {
list.innerHTML = '<p style="color:var(--text-muted); font-size:0.8rem; font-style:italic;">No business flows defined.</p>';
return;
}
flows.forEach(flow => {
const card = document.createElement('div');
card.className = 'flow-card';
card.innerHTML = `
<div class="flow-name">${flow.name}</div>
<div class="flow-desc">${flow.description}</div>
`;
card.onmouseenter = () => highlightFlow(flow);
card.onmouseleave = clearHighlights;
list.appendChild(card);
});
}
function highlightEntryPoint(ep) {
clearHighlights();
const machineEvents = new Set(metadata.transitions.map(t => t.event).filter(Boolean));
const chains = metadata.metadata.callChains || [];
const relevantEvents = chains
.filter(c => c.entryPoint.className === ep.className && c.entryPoint.methodName === ep.methodName && machineEvents.has(c.triggerPoint.event))
.map(c => c.triggerPoint.event);
if (relevantEvents.length === 0) return;
highlightEvents(relevantEvents);
}
function highlightFlow(flow) {
clearHighlights();
if (!flow.steps || flow.steps.length === 0) return;
highlightEvents(flow.steps);
}
function highlightEvents(steps) {
const svg = document.querySelector('#svg-container svg');
// Dim everything first
svg.querySelectorAll('path, rect, circle, ellipse, text, polygon').forEach(el => {
el.classList.add('dimmed');
});
steps.forEach(step => {
let linkId = "";
if (step.includes("->")) {
// Named Choice Branch: "SRC->TGT"
const parts = step.split("->");
linkId = "#link_anon_" + normalize(parts[0]) + "_" + normalize(parts[1]);
} else {
// Standard Event
linkId = "#link_" + normalize(step);
}
svg.querySelectorAll('a').forEach(link => {
const href = link.getAttribute('xlink:href') || link.getAttribute('href');
if (href === linkId) {
highlightLinkGroup(link);
}
});
});
// Un-dim all state nodes for context
svg.querySelectorAll('rect, circle, ellipse, polygon').forEach(el => {
const isChoice = el.tagName === 'polygon' && el.points?.numberOfItems === 4;
if (isChoice || ['rect', 'circle', 'ellipse'].includes(el.tagName)) {
el.classList.remove('dimmed');
let next = el.nextElementSibling;
while(next && next.tagName === 'text') {
next.classList.remove('dimmed');
next = next.nextElementSibling;
}
}
});
}
function highlightLinkGroup(link) {
link.classList.add('active-path');
link.querySelectorAll('*').forEach(child => child.classList.remove('dimmed'));
// Find path and polygon immediately before the <a> tag (interleaved)
let prev = link.previousElementSibling;
let foundPath = false;
let foundPolygon = false;
while (prev) {
if (prev.tagName === 'path' && !foundPath) {
prev.classList.remove('dimmed');
prev.classList.add('active-path');
foundPath = true;
} else if (prev.tagName === 'polygon' && !foundPolygon && prev.points?.numberOfItems !== 4) {
prev.classList.remove('dimmed');
prev.classList.add('active-path');
foundPolygon = true;
} else if (['rect', 'circle', 'ellipse'].includes(prev.tagName) ||
(prev.tagName === 'polygon' && prev.points?.numberOfItems === 4)) {
// Hit a state node, stop traversal
break;
}
if (foundPath && foundPolygon) break;
prev = prev.previousElementSibling;
}
}
function clearHighlights() {
document.querySelectorAll('.dimmed, .active-path').forEach(el => {
el.classList.remove('dimmed', 'active-path');
});
}
function attachInteractivity() {
const svg = document.querySelector('#svg-container svg');
const transitions = metadata.transitions || [];
svg.querySelectorAll('a').forEach(link => {
const href = link.getAttribute('xlink:href') || link.getAttribute('href');
if (!href || !href.startsWith('#link_')) return;
const linkId = href.replace('#link_', '');
const isAnon = linkId.startsWith('anon_');
let metaTrans = null;
if (isAnon) {
metaTrans = transitions.find(t =>
!t.event &&
"anon_" + normalize(t.sourceStates[0].fullIdentifier) + "_" + normalize(t.targetStates[0].fullIdentifier) === linkId
);
} else {
metaTrans = transitions.find(t => normalize(t.event) === linkId);
}
if (metaTrans || isAnon) {
link.style.cursor = 'pointer';
const setupTippy = (el) => {
tippy(el, {
content: createTooltip(isAnon ? "Internal logic" : linkId, metaTrans),
allowHTML: true,
theme: 'modern',
interactive: true,
appendTo: document.body,
placement: 'right',
offset: [0, 20]
});
};
setupTippy(link);
let path = link.previousElementSibling;
while(path && path.tagName !== 'path') path = path.previousElementSibling;
if (path) {
path.style.cursor = 'pointer';
setupTippy(path);
}
}
});
}
function normalize(s) {
if (!s) return "";
return s.replace(/[^a-zA-Z0-9]/g, '_');
}
function createTooltip(name, trans) {
const chains = (metadata.metadata.callChains || []).filter(c => normalize(c.triggerPoint.event) === name);
let html = `<div class="tooltip-content">
<div style="font-weight:900; font-size:1.1rem; margin-bottom:12px; border-bottom:1px solid #eee; padding-bottom:8px; line-height:1.3;">
${name === 'Internal logic' ? name : 'Event: <span style="color:var(--accent)">' + name + '</span>'}
</div>`;
if (trans && trans.guard) {
const lineInfo = trans.guard.lineNumber ? ` <span style="color:#94a3b8; font-weight:400; font-size:0.6rem;">(Line: ${trans.guard.lineNumber})</span>` : '';
html += `<div style="font-size:0.7rem; font-weight:800; color:#94a3b8; text-transform:uppercase; margin-bottom:4px">Guard${lineInfo}</div>
<div style="background:#f1f5f9; padding:6px; border-radius:4px; font-family:monospace; font-size:0.8rem; margin-bottom:12px; border:1px solid #e2e8f0;">${trans.guard.expression}</div>`;
if (trans.guard.internalLogic) {
html += `<div style="font-size:0.65rem; font-weight:800; color:#cbd5e1; text-transform:uppercase; margin-bottom:4px">Internal Logic</div>
<pre style="background:#1e293b; color:#f8fafc; padding:8px; border-radius:4px; font-family:'JetBrains Mono', monospace; font-size:0.7rem; overflow-x:auto; margin-bottom:12px;"><code>${trans.guard.internalLogic.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</code></pre>`;
}
}
if (trans && trans.actions && trans.actions.length > 0) {
html += `<div style="font-size:0.7rem; font-weight:800; color:#94a3b8; text-transform:uppercase; margin-bottom:4px">Actions</div>`;
trans.actions.forEach(action => {
const lineInfo = action.lineNumber ? ` <span style="color:#94a3b8; font-weight:400; font-size:0.6rem;">(Line: ${action.lineNumber})</span>` : '';
html += `<div style="font-size:0.7rem; font-weight:800; color:#94a3b8; text-transform:uppercase; margin-bottom:4px">Action${lineInfo}</div>
<div style="background:#f1f5f9; padding:6px; border-radius:4px; font-family:monospace; font-size:0.8rem; margin-bottom:12px; border:1px solid #e2e8f0;">${action.expression}</div>`;
if (action.internalLogic) {
html += `<div style="font-size:0.65rem; font-weight:800; color:#cbd5e1; text-transform:uppercase; margin-bottom:4px">Internal Logic</div>
<pre style="background:#1e293b; color:#f8fafc; padding:8px; border-radius:4px; font-family:'JetBrains Mono', monospace; font-size:0.7rem; overflow-x:auto; margin-bottom:12px;"><code>${action.internalLogic.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</code></pre>`;
}
});
}
if (chains && chains.length > 0) {
html += `<div style="font-size:0.7rem; font-weight:800; color:#94a3b8; text-transform:uppercase; margin-bottom:10px; border-top:1px solid #eee; padding-top:10px">Triggered by</div>`;
chains.forEach(c => {
html += `<div style="margin-bottom:20px">
<div style="font-weight:700; font-size:0.85rem; color:var(--text);">${c.entryPoint.name}</div>
${renderParameters(c.entryPoint.parameters)}
<div style="margin-left:10px; border-left:2px solid #e2e8f0; padding-left:12px; margin-top:10px">
${c.methodChain.map((m, i) => `<div style="font-size:0.7rem; color:#475569; margin-top:4px; font-family:'JetBrains Mono', monospace;"><b>${i+1}</b> ${m}</div>`).join('')}
</div>
</div>`;
});
}
html += `</div>`;
return html;
}
function renderParameters(params) {
if (!params || params.length === 0) return "";
let html = `<div style="font-size:0.65rem; font-weight:700; color:#94a3b8; margin-top:8px; margin-bottom:4px; text-transform:uppercase;">Input Data</div>`;
html += `<div class="payload-box">`;
params.forEach(p => {
const annotation = (p.annotations || []).find(a => a.endsWith("RequestBody") || a.endsWith("PathVariable") || a.endsWith("RequestParam"));
const cleanAnn = annotation ? "@" + annotation.substring(annotation.lastIndexOf('.') + 1) : "";
html += `<div class="payload-param">
<span style="color:#f43f5e; font-size:0.65rem; font-weight:bold;">${cleanAnn}</span>
<span style="color:#38bdf8;">${p.type}</span>
<span style="color:#a3e635;">${p.name}</span>
</div>`;
});
html += `</div>`;
return html;
}
</script>
</body>
</html>

View File

@@ -0,0 +1,108 @@
{
"metadata" : {
"triggers" : [ {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
} ],
"entryPoints" : [ {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
}, {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.api.OrderApi",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
} ],
"callChains" : [ {
"entryPoint" : {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
},
"methodChain" : [ "click.kamil.multi.core.OrderController.submitOrder" ],
"triggerPoint" : {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
}
} ],
"properties" : {
"default" : { }
}
},
"name" : "click.kamil.multi.core.OrderStateMachineConfig",
"renderChoicesAsDiamonds" : true,
"startStates" : [ "NEW" ],
"transitions" : [ {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"NEW\"",
"fullIdentifier" : "NEW"
} ],
"targetStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"event" : "SUBMIT",
"guard" : null,
"actions" : [ {
"expression" : "processAction()",
"isLambda" : false,
"internalLogic" : "@Override default void execute(StateContext<String,String> context){\n System.out.println(\"Processing order: \" + context.getMessageHeader(\"orderId\"));\n}\n",
"lineNumber" : 31
} ],
"order" : null
}, {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"targetStates" : [ {
"rawName" : "\"COMPLETED\"",
"fullIdentifier" : "COMPLETED"
} ],
"event" : "FINISH",
"guard" : null,
"actions" : [ ],
"order" : null
} ],
"endStates" : [ "COMPLETED" ]
}

View File

@@ -0,0 +1,32 @@
@startuml
!pragma layout smetana
set separator none
hide empty description
hide stereotype
skinparam state {
BackgroundColor white
BorderColor #94a3b8
BorderThickness 1
FontName Inter
FontSize 9
FontStyle bold
RoundCorner 20
Padding 1
}
skinparam shadowing false
skinparam ArrowFontName JetBrains Mono
skinparam ArrowFontSize 8
skinparam ArrowColor #cbd5e1
skinparam ArrowThickness 1
skinparam dpi 110
skinparam svgLinkTarget _self
[*] --> NEW
NEW -[#1E90FF,bold]-> PROCESSING <<external>> <<e_SUBMIT>> : SUBMIT / processAction()
PROCESSING -[#1E90FF,bold]-> COMPLETED <<external>> <<e_FINISH>> : FINISH
COMPLETED --> [*]
@enduml

View File

@@ -17,3 +17,5 @@ include ':state_machines:extended_analysis_sample'
include ':state_machines:inheritance_sample' include ':state_machines:inheritance_sample'
include ':state_machines:ultimate_ecosystem_sm' include ':state_machines:ultimate_ecosystem_sm'
include ':state_machines:enterprise_order_system' include ':state_machines:enterprise_order_system'
include ':state_machines:multi_module_sample:api-module'
include ':state_machines:multi_module_sample:core-module'

View File

@@ -10,8 +10,10 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
@Slf4j @Slf4j
public class PropertyResolver { public class PropertyResolver {
@@ -42,32 +44,33 @@ public class PropertyResolver {
return allProperties; return allProperties;
} }
public Map<String, Map<String, String>> resolveAllProperties(Path rootDir) { public Map<String, Map<String, String>> resolveAllProperties(Set<Path> rootDirs) {
Map<String, Map<String, String>> profiles = new HashMap<>(); Map<String, Map<String, String>> profiles = new HashMap<>();
// 1. Load default profile for (Path rootDir : rootDirs) {
Map<String, String> defaultProps = new HashMap<>(); // 1. Load default profile
loadMatching(rootDir, "application.properties", defaultProps); Map<String, String> defaultProps = profiles.computeIfAbsent("default", k -> new HashMap<>());
loadMatching(rootDir, "application.yml", defaultProps); loadMatching(rootDir, "application.properties", defaultProps);
loadMatching(rootDir, "application.yaml", defaultProps); loadMatching(rootDir, "application.yml", defaultProps);
profiles.put("default", defaultProps); loadMatching(rootDir, "application.yaml", defaultProps);
// 2. Discover and load all other profiles // 2. Discover and load all other profiles
try (Stream<Path> paths = Files.walk(rootDir)) { try (Stream<Path> paths = Files.walk(rootDir)) {
paths.filter(Files::isRegularFile) paths.filter(Files::isRegularFile)
.filter(p -> { .filter(p -> {
String name = p.getFileName().toString(); String name = p.getFileName().toString();
return name.startsWith("application-") && return name.startsWith("application-") &&
(name.endsWith(".properties") || name.endsWith(".yml") || name.endsWith(".yaml")); (name.endsWith(".properties") || name.endsWith(".yml") || name.endsWith(".yaml"));
}) })
.forEach(p -> { .forEach(p -> {
String name = p.getFileName().toString(); String name = p.getFileName().toString();
String profile = name.substring("application-".length(), name.lastIndexOf('.')); String profile = name.substring("application-".length(), name.lastIndexOf('.'));
Map<String, String> loaded = p.toString().endsWith(".properties") ? loadProperties(p) : loadYaml(p); Map<String, String> loaded = p.toString().endsWith(".properties") ? loadProperties(p) : loadYaml(p);
profiles.computeIfAbsent(profile, k -> new HashMap<>()).putAll(loaded); profiles.computeIfAbsent(profile, k -> new HashMap<>()).putAll(loaded);
}); });
} catch (IOException e) { } catch (IOException e) {
log.error("Failed to scan for profiles in {}", rootDir, e); log.error("Failed to scan for profiles in {}", rootDir, e);
}
} }
return profiles; return profiles;

View File

@@ -0,0 +1,140 @@
package click.kamil.springstatemachineexporter.analysis.resolver;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Slf4j
public class SiblingDependencyResolver {
private static final Pattern GRADLE_PROJECT_DEP = Pattern.compile("project\\(['\"]:(.*?)['\"]\\)");
private static final Pattern MAVEN_DEPENDENCY = Pattern.compile("<dependency>\\s*<groupId>(.*?)</groupId>\\s*<artifactId>(.*?)</artifactId>\\s*<version>(.*?)</version>", Pattern.DOTALL);
public Set<Path> resolveSiblings(Path projectDir) {
Set<Path> siblings = new HashSet<>();
try {
siblings.addAll(resolveGradleSiblings(projectDir));
siblings.addAll(resolveMavenSiblings(projectDir));
} catch (Exception e) {
log.warn("Error resolving sibling dependencies for {}", projectDir, e);
}
return siblings;
}
private Set<Path> resolveGradleSiblings(Path projectDir) throws IOException {
Set<Path> siblings = new HashSet<>();
Path buildGradle = projectDir.resolve("build.gradle");
if (!Files.exists(buildGradle)) {
buildGradle = projectDir.resolve("build.gradle.kts");
}
if (Files.exists(buildGradle)) {
log.info("Found build.gradle at {}", buildGradle);
String content = Files.readString(buildGradle);
Matcher matcher = GRADLE_PROJECT_DEP.matcher(content);
Set<String> gradlePaths = new HashSet<>();
while (matcher.find()) {
gradlePaths.add(matcher.group(1));
}
log.info("Found project dependencies: {}", gradlePaths);
if (!gradlePaths.isEmpty()) {
Path rootDir = findGradleRoot(projectDir);
log.info("Resolved Gradle root to: {}", rootDir);
if (rootDir != null) {
for (String gradlePath : gradlePaths) {
String relativePath = gradlePath.replace(':', '/');
Path resolvedSibling = rootDir.resolve(relativePath).normalize();
if (Files.exists(resolvedSibling)) {
log.info("Discovered local Gradle sibling dependency: {}", resolvedSibling);
siblings.add(resolvedSibling);
}
}
}
}
}
return siblings;
}
private Path findGradleRoot(Path start) {
Path current = start.toAbsolutePath();
Path lastSettingsDir = null;
while (current != null) {
if (Files.exists(current.resolve("settings.gradle")) || Files.exists(current.resolve("settings.gradle.kts"))) {
lastSettingsDir = current;
}
if (Files.exists(current.resolve(".git"))) {
return lastSettingsDir != null ? lastSettingsDir : current;
}
current = current.getParent();
}
return lastSettingsDir;
}
private Set<Path> resolveMavenSiblings(Path projectDir) throws IOException {
Set<Path> siblings = new HashSet<>();
Path pom = projectDir.resolve("pom.xml");
if (Files.exists(pom)) {
String content = Files.readString(pom);
Matcher matcher = MAVEN_DEPENDENCY.matcher(content);
Set<String> targetArtifacts = new HashSet<>();
while (matcher.find()) {
targetArtifacts.add(matcher.group(2)); // Just tracking artifactId for simplicity
}
if (!targetArtifacts.isEmpty()) {
Path rootDir = findMavenRoot(projectDir);
if (rootDir != null) {
// Find all pom.xml files in the workspace (excluding node_modules, build, etc.)
try (Stream<Path> paths = Files.walk(rootDir)) {
paths.filter(p -> p.getFileName().toString().equals("pom.xml")
&& !p.toString().contains("/target/")
&& !p.toString().contains("/node_modules/"))
.forEach(p -> {
try {
String pContent = Files.readString(p);
Matcher artMatcher = Pattern.compile("<artifactId>(.*?)</artifactId>").matcher(pContent);
if (artMatcher.find()) {
String artifactId = artMatcher.group(1);
if (targetArtifacts.contains(artifactId)) {
Path siblingDir = p.getParent();
// Don't add ourselves
if (!siblingDir.equals(projectDir)) {
log.info("Discovered local Maven sibling dependency: {}", siblingDir);
siblings.add(siblingDir);
}
}
}
} catch (IOException e) {
// ignore
}
});
}
}
}
}
return siblings;
}
private Path findMavenRoot(Path start) {
Path current = start.toAbsolutePath();
Path lastPomDir = null;
while (current != null) {
if (Files.exists(current.resolve("pom.xml"))) {
lastPomDir = current;
}
if (Files.exists(current.resolve(".git"))) {
return lastPomDir != null ? lastPomDir : current;
}
current = current.getParent();
}
return lastPomDir;
}
}

View File

@@ -36,7 +36,7 @@ public class SpringMvcDetector {
for (Object modifier : node.modifiers()) { for (Object modifier : node.modifiers()) {
if (modifier instanceof Annotation annotation) { if (modifier instanceof Annotation annotation) {
String name = annotation.getTypeName().getFullyQualifiedName(); String name = annotation.getTypeName().getFullyQualifiedName();
if (name.endsWith("RestController") || name.endsWith("Controller") || name.endsWith("Path")) { if (name.endsWith("RestController") || name.endsWith("Controller") || name.endsWith("Path") || name.endsWith("RequestMapping")) {
return true; return true;
} }
} }

View File

@@ -29,7 +29,9 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class AstTransitionParser { public class AstTransitionParser {
private static final ConstantResolver constantResolver = new ConstantResolver(); private static final ConstantResolver constantResolver = new ConstantResolver();
@@ -258,6 +260,21 @@ public class AstTransitionParser {
if (expr instanceof MethodInvocation mi) { if (expr instanceof MethodInvocation mi) {
IMethodBinding binding = mi.resolveMethodBinding(); IMethodBinding binding = mi.resolveMethodBinding();
if (binding != null) { if (binding != null) {
// Try to resolve deeper logic from the return type (e.g., a Bean returning an Action interface)
ITypeBinding returnType = binding.getReturnType();
if (returnType != null) {
String returnFqn = returnType.getTypeDeclaration().getQualifiedName();
TypeDeclaration returnTd = context.getTypeDeclaration(returnFqn);
if (returnTd != null) {
for (MethodDeclaration rmd : returnTd.getMethods()) {
String name = rmd.getName().getIdentifier();
if (name.equals("execute") || name.equals("evaluate")) {
return rmd.toString();
}
}
}
}
// Try same file // Try same file
ASTNode declNode = cu.findDeclaringNode(binding.getKey()); ASTNode declNode = cu.findDeclaringNode(binding.getKey());
if (declNode instanceof MethodDeclaration md) { if (declNode instanceof MethodDeclaration md) {
@@ -267,7 +284,7 @@ public class AstTransitionParser {
// Try other files via CodebaseContext // Try other files via CodebaseContext
ITypeBinding declaringClass = binding.getDeclaringClass(); ITypeBinding declaringClass = binding.getDeclaringClass();
if (declaringClass != null) { if (declaringClass != null) {
String fqn = declaringClass.getQualifiedName(); String fqn = declaringClass.getTypeDeclaration().getQualifiedName();
TypeDeclaration td = context.getTypeDeclaration(fqn); TypeDeclaration td = context.getTypeDeclaration(fqn);
if (td != null) { if (td != null) {
for (MethodDeclaration md : td.getMethods()) { for (MethodDeclaration md : td.getMethods()) {
@@ -287,7 +304,7 @@ public class AstTransitionParser {
if (binding != null) { if (binding != null) {
ITypeBinding declaringClass = binding.getDeclaringClass(); ITypeBinding declaringClass = binding.getDeclaringClass();
if (declaringClass != null) { if (declaringClass != null) {
String fqn = declaringClass.getQualifiedName(); String fqn = declaringClass.getTypeDeclaration().getQualifiedName();
TypeDeclaration td = context.getTypeDeclaration(fqn); TypeDeclaration td = context.getTypeDeclaration(fqn);
if (td != null) { if (td != null) {
for (MethodDeclaration md : td.getMethods()) { for (MethodDeclaration md : td.getMethods()) {

View File

@@ -69,20 +69,20 @@ public class CodebaseContext {
} }
public void scan(Path rootDir) throws IOException { public void scan(Path rootDir) throws IOException {
scan(rootDir, Collections.emptySet()); scan(Set.of(rootDir), Collections.emptySet());
} }
private final List<CompilationUnit> allCus = new ArrayList<>(); private final List<CompilationUnit> allCus = new ArrayList<>();
private final Map<String, List<String>> interfaceToImpls = new HashMap<>(); private final Map<String, List<String>> interfaceToImpls = new HashMap<>();
public void scan(Path rootDir, Set<String> customIgnorePatterns) throws IOException { public void scan(Set<Path> rootDirs, Set<String> customIgnorePatterns) throws IOException {
this.allProperties = propertyResolver.resolveAllProperties(rootDir); this.allProperties = propertyResolver.resolveAllProperties(rootDirs);
Set<String> activeIgnore = new HashSet<>(ignorePatterns); Set<String> activeIgnore = new HashSet<>(ignorePatterns);
activeIgnore.addAll(customIgnorePatterns); activeIgnore.addAll(customIgnorePatterns);
List<Path> javaFiles = FileUtils.findFilesWithExtension(Set.of(rootDir), ".java", activeIgnore); List<Path> javaFiles = FileUtils.findFilesWithExtension(rootDirs, ".java", activeIgnore);
for (Path javaFile : javaFiles) { for (Path javaFile : javaFiles) {
String source = Files.readString(javaFile); String source = Files.readString(javaFile);
CompilationUnit cu = parse(source, javaFile.getFileName().toString()); CompilationUnit cu = parse(source, javaFile.getFileName().toString());

View File

@@ -26,6 +26,7 @@ import java.io.PrintWriter;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Slf4j @Slf4j
public class ExportService { public class ExportService {
@@ -61,7 +62,16 @@ public class ExportService {
public void runExporter(Path inputDir, Path outputDir, List<String> selectedFormats, boolean renderChoicesAsDiamonds, List<String> activeProfiles, Path flowsOverride, String machineFilter) throws IOException { public void runExporter(Path inputDir, Path outputDir, List<String> selectedFormats, boolean renderChoicesAsDiamonds, List<String> activeProfiles, Path flowsOverride, String machineFilter) throws IOException {
CodebaseContext context = new CodebaseContext(); CodebaseContext context = new CodebaseContext();
context.setActiveProfiles(activeProfiles); context.setActiveProfiles(activeProfiles);
context.setSourcepath(List.of(inputDir.toString()));
click.kamil.springstatemachineexporter.analysis.resolver.SiblingDependencyResolver siblingResolver = new click.kamil.springstatemachineexporter.analysis.resolver.SiblingDependencyResolver();
Set<Path> allPaths = new HashSet<>();
allPaths.add(inputDir);
allPaths.addAll(siblingResolver.resolveSiblings(inputDir));
context.setSourcepath(allPaths.stream()
.map(p -> p.resolve("src/main/java").toString())
.filter(p -> Files.exists(Path.of(p)))
.collect(Collectors.toList()));
context.setResolveBindings(true); context.setResolveBindings(true);
Path hintsFile = inputDir.resolve("hints.json"); Path hintsFile = inputDir.resolve("hints.json");
@@ -90,7 +100,7 @@ public class ExportService {
} }
} }
context.scan(inputDir); context.scan(allPaths, Collections.emptySet());
CodebaseIntelligenceProvider intelligence = new JdtIntelligenceProvider(context, inputDir); CodebaseIntelligenceProvider intelligence = new JdtIntelligenceProvider(context, inputDir);
exportAll(context, intelligence, outputDir, selectedFormats, renderChoicesAsDiamonds, flows, machineFilter, activeProfiles != null ? activeProfiles : Collections.emptyList()); exportAll(context, intelligence, outputDir, selectedFormats, renderChoicesAsDiamonds, flows, machineFilter, activeProfiles != null ? activeProfiles : Collections.emptyList());

View File

@@ -125,6 +125,12 @@ public class RegressionTest {
root.resolve("state_machines/enterprise_order_system"), root.resolve("state_machines/enterprise_order_system"),
Path.of("src/test/resources/golden/EnterpriseStateMachineConfig"), Path.of("src/test/resources/golden/EnterpriseStateMachineConfig"),
"EnterpriseStateMachineConfig" "EnterpriseStateMachineConfig"
),
new TestScenario(
"Multi-Module Sample",
root.resolve("state_machines/multi_module_sample/core-module"),
Path.of("src/test/resources/golden/OrderStateMachineConfig"),
"OrderStateMachineConfig"
) )
); );
} }

View File

@@ -44,6 +44,30 @@
"lineNumber" : 17 "lineNumber" : 17
} ], } ],
"entryPoints" : [ { "entryPoints" : [ {
"type" : "REST",
"name" : "POST /api/enterprise/orders/place",
"className" : "click.kamil.examples.enterprise.api.OrderApi",
"methodName" : "placeOrder",
"metadata" : {
"path" : "/api/enterprise/orders/place",
"verb" : "POST"
},
"parameters" : [ ]
}, {
"type" : "REST",
"name" : "POST /api/enterprise/orders/{id}/cancel",
"className" : "click.kamil.examples.enterprise.api.OrderApi",
"methodName" : "cancelOrder",
"metadata" : {
"path" : "/api/enterprise/orders/{id}/cancel",
"verb" : "POST"
},
"parameters" : [ {
"name" : "id",
"type" : "String",
"annotations" : [ "PathVariable" ]
} ]
}, {
"type" : "REST", "type" : "REST",
"name" : "POST /api/enterprise/orders/place", "name" : "POST /api/enterprise/orders/place",
"className" : "click.kamil.examples.enterprise.api.OrderController", "className" : "click.kamil.examples.enterprise.api.OrderController",

View File

@@ -9,6 +9,16 @@
"lineNumber" : 15 "lineNumber" : 15
} ], } ],
"entryPoints" : [ { "entryPoints" : [ {
"type" : "REST",
"name" : "POST /api/v2/orders/submit",
"className" : "click.kamil.examples.statemachine.inheritance.api.OrderApi",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/api/v2/orders/submit",
"verb" : "POST"
},
"parameters" : [ ]
}, {
"type" : "REST", "type" : "REST",
"name" : "POST /api/v2/orders/submit", "name" : "POST /api/v2/orders/submit",
"className" : "click.kamil.examples.statemachine.inheritance.api.OrderControllerImpl", "className" : "click.kamil.examples.statemachine.inheritance.api.OrderControllerImpl",

View File

@@ -0,0 +1,12 @@
digraph statemachine {
rankdir=LR;
node [shape=rounded, style=filled, fillcolor=white, fontname="Arial"];
edge [fontname="Arial", fontsize=10];
_start [shape=circle, label="", fillcolor=black, width=0.1];
_start -> NEW;
COMPLETED [fillcolor=lightgray];
NEW -> PROCESSING [label="SUBMIT / processAction()", style="solid", color="black"];
PROCESSING -> COMPLETED [label="FINISH", style="solid", color="black"];
}

View File

@@ -0,0 +1,108 @@
{
"metadata" : {
"triggers" : [ {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
} ],
"entryPoints" : [ {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
}, {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.api.OrderApi",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
} ],
"callChains" : [ {
"entryPoint" : {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
},
"methodChain" : [ "click.kamil.multi.core.OrderController.submitOrder" ],
"triggerPoint" : {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
}
} ],
"properties" : {
"default" : { }
}
},
"name" : "click.kamil.multi.core.OrderStateMachineConfig",
"renderChoicesAsDiamonds" : true,
"startStates" : [ "NEW" ],
"transitions" : [ {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"NEW\"",
"fullIdentifier" : "NEW"
} ],
"targetStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"event" : "SUBMIT",
"guard" : null,
"actions" : [ {
"expression" : "processAction()",
"isLambda" : false,
"internalLogic" : "@Override default void execute(StateContext<String,String> context){\n System.out.println(\"Processing order: \" + context.getMessageHeader(\"orderId\"));\n}\n",
"lineNumber" : 31
} ],
"order" : null
}, {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"targetStates" : [ {
"rawName" : "\"COMPLETED\"",
"fullIdentifier" : "COMPLETED"
} ],
"event" : "FINISH",
"guard" : null,
"actions" : [ ],
"order" : null
} ],
"endStates" : [ "COMPLETED" ]
}

View File

@@ -0,0 +1,32 @@
@startuml
!pragma layout smetana
set separator none
hide empty description
hide stereotype
skinparam state {
BackgroundColor white
BorderColor #94a3b8
BorderThickness 1
FontName Inter
FontSize 9
FontStyle bold
RoundCorner 20
Padding 1
}
skinparam shadowing false
skinparam ArrowFontName JetBrains Mono
skinparam ArrowFontSize 8
skinparam ArrowColor #cbd5e1
skinparam ArrowThickness 1
skinparam dpi 110
skinparam svgLinkTarget _self
[*] --> NEW
NEW -[#1E90FF,bold]-> PROCESSING <<external>> <<e_SUBMIT>> : SUBMIT / processAction()
PROCESSING -[#1E90FF,bold]-> COMPLETED <<external>> <<e_FINISH>> : FINISH
COMPLETED --> [*]
@enduml

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="NEW">
<state id="NEW">
<transition target="PROCESSING" event="SUBMIT"/>
</state>
<state id="PROCESSING">
<transition target="COMPLETED" event="FINISH"/>
</state>
<state id="COMPLETED">
</state>
</scxml>

View File

@@ -0,0 +1,724 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>State Machine Explorer - click.kamil.multi.core.OrderStateMachineConfig</title>
<!-- Popper and Tippy for tooltips -->
<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>
<link rel="stylesheet" href="https://unpkg.com/tippy.js@6/animations/scale.css"/>
<!-- SVG Pan & Zoom -->
<script src="https://cdn.jsdelivr.net/npm/svg-pan-zoom@3.6.1/dist/svg-pan-zoom.min.js"></script>
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;900&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--sidebar-bg: #ffffff;
--main-bg: #f8fafc;
--accent: #ef4444;
--primary: #3b82f6;
--text: #0f172a;
--text-muted: #64748b;
--border: #e2e8f0;
}
body {
margin: 0;
display: flex;
height: 100vh;
font-family: 'Inter', -apple-system, sans-serif;
background: var(--main-bg);
color: var(--text);
overflow: hidden;
}
#sidebar {
width: 480px;
min-width: 350px;
max-width: 900px;
background: var(--sidebar-bg);
border-right: 2px solid var(--border);
display: flex;
flex-direction: column;
box-shadow: 10px 0 15px rgba(0,0,0,0.02);
z-index: 10;
overflow-x: hidden;
resize: horizontal;
position: relative;
transition: width 0.3s ease, min-width 0.3s ease, padding 0.3s ease;
}
#sidebar.collapsed {
width: 0 !important;
min-width: 0 !important;
border-right: none;
padding: 0;
overflow: hidden;
resize: none;
}
#toggle-sidebar {
position: absolute;
top: 20px;
left: 20px;
z-index: 50;
background: #fff;
border: 1px solid var(--border);
border-radius: 8px;
padding: 8px;
cursor: pointer;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
}
#toggle-sidebar:hover {
background: #f8fafc;
border-color: var(--primary);
}
#toggle-sidebar svg {
width: 20px;
height: 20px;
fill: none;
stroke: var(--text-muted);
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
#sidebar::after {
content: '⋮';
position: absolute;
right: 2px; top: 50%;
transform: translateY(-50%);
color: var(--border);
font-size: 1.2rem;
pointer-events: none;
}
.sidebar-header {
padding: 30px 30px 10px;
}
header h1 { font-weight: 900; font-size: 1.6rem; color: var(--text); margin: 0 0 5px 0; letter-spacing: -0.5px; }
header p { font-family: 'JetBrains Mono', monospace; font-size: 0.7rem; color: var(--text-muted); margin: 0 0 15px 0; opacity: 0.7; }
.tabs {
display: flex;
padding: 0 30px;
border-bottom: 1px solid var(--border);
gap: 20px;
}
.tab {
padding: 10px 0;
font-size: 0.85rem;
font-weight: 600;
color: var(--text-muted);
cursor: pointer;
position: relative;
transition: color 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); }
.tab.active::after {
content: '';
position: absolute;
bottom: -1px; left: 0; right: 0;
height: 2px;
background: var(--primary);
}
.tab-content {
flex-grow: 1;
padding: 25px 30px;
overflow-y: auto;
display: none;
}
.tab-content.active { display: block; }
.ep-card, .flow-card {
padding: 18px;
background: #fff;
border: 1px solid var(--border);
border-radius: 14px;
margin-bottom: 15px;
cursor: pointer;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
position: relative;
word-break: break-all;
overflow-wrap: anywhere;
}
.ep-card:hover, .flow-card:hover {
border-color: var(--primary);
transform: translateX(5px);
box-shadow: 0 15px 30px -10px rgba(59, 130, 246, 0.15);
}
.ep-type {
font-size: 0.6rem;
font-weight: 900;
padding: 3px 8px;
border-radius: 6px;
display: inline-block;
margin-bottom: 10px;
text-transform: uppercase;
letter-spacing: 0.8px;
}
.type-rest { background: #eff6ff; color: #1d4ed8; }
.type-custom { background: #fef2f2; color: #b91c1c; }
.type-jms { background: #f5f3ff; color: #7c3aed; }
.type-sqs { background: #fff7ed; color: #ea580c; }
.type-sns { background: #fff1f2; color: #e11d48; }
.type-kafka { background: #fefce8; color: #854d0e; }
.type-rabbit { background: #f0fdf4; color: #166534; }
.ep-name, .flow-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 6px; color: var(--text); }
.ep-fqn, .flow-desc { font-family: 'Inter', sans-serif; font-size: 0.75rem; color: var(--text-muted); opacity: 0.9; line-height: 1.4; }
#main { flex-grow: 1; position: relative; background: var(--main-bg); overflow: hidden; }
#svg-container {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
display: flex;
align-items: center;
justify-content: center;
}
svg {
width: 100%;
height: 100%;
display: block;
}
/* SVG Interactivity Styles */
svg a { text-decoration: none !important; }
.active-path {
stroke: var(--accent) !important;
stroke-width: 2.5px !important;
filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.3));
transition: all 0.3s;
}
.active-path text, a.active-path text {
fill: #000 !important;
font-weight: 900 !important;
paint-order: stroke;
stroke: #fff;
stroke-width: 3.5px;
}
.dimmed {
opacity: 0.2 !important;
filter: grayscale(1);
transition: opacity 0.4s ease;
pointer-events: none;
}
/* Tippy Styling */
.tippy-box[data-theme~='modern'] {
background-color: #fff;
color: var(--text);
box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
border: 1px solid var(--border);
border-radius: 16px;
padding: 0;
max-width: 550px !important;
}
.tooltip-content {
padding: 20px;
max-width: 500px;
word-break: break-word;
overflow-wrap: anywhere;
}
.payload-box {
background: #0f172a;
color: #e2e8f0;
border-radius: 8px;
padding: 12px;
font-family: 'JetBrains Mono', monospace;
font-size: 0.75rem;
line-height: 1.5;
margin-top: 10px;
}
.payload-param {
margin-bottom: 4px;
}
.payload-param:last-child { margin-bottom: 0; }
</style>
</head>
<body>
<div id="sidebar">
<div class="sidebar-header">
<header>
<h1>Explorer</h1>
<p>click.kamil.multi.core.OrderStateMachineConfig</p>
</header>
</div>
<div class="tabs">
<div class="tab active" data-tab="explorer">Explorer</div>
<div class="tab" data-tab="flows">Business Flows</div>
</div>
<div id="tab-explorer" class="tab-content active">
<div id="ep-list"></div>
</div>
<div id="tab-flows" class="tab-content">
<div id="flow-list"></div>
</div>
</div>
<div id="main">
<button id="toggle-sidebar" aria-label="Toggle Sidebar" title="Toggle Sidebar">
<svg viewBox="0 0 24 24"><path d="M4 6h16M4 12h16M4 18h16"></path></svg>
</button>
<div id="svg-container">
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 168 405" width="100%" zoomAndPan="magnify"><defs/><g><ellipse cx="45.2604" cy="25.2083" fill="#222222" rx="11.4583" ry="11.4583" style="stroke:#222222;stroke-width:1.1458333333333333;"/><rect fill="#FFFFFF" height="45.8333" rx="14.3229" ry="14.3229" style="stroke:#94A3B8;stroke-width:1.1458333333333333;" width="57.2917" x="16.6146" y="83.6458"/><text fill="#000000" font-family="Inter" font-size="10.3125" font-weight="bold" lengthAdjust="spacing" textLength="22.9167" x="33.8021" y="110.4599">NEW</text><rect fill="#FFFFFF" height="45.8333" rx="14.3229" ry="14.3229" style="stroke:#94A3B8;stroke-width:1.1458333333333333;" width="76.7708" x="6.875" y="184.4792"/><text fill="#000000" font-family="Inter" font-size="10.3125" font-weight="bold" lengthAdjust="spacing" textLength="65.3125" x="12.6042" y="211.2932">PROCESSING</text><rect fill="#FFFFFF" height="45.8333" rx="14.3229" ry="14.3229" style="stroke:#94A3B8;stroke-width:1.1458333333333333;" width="74.4792" x="8.0208" y="285.3125"/><text fill="#000000" font-family="Inter" font-size="10.3125" font-weight="bold" lengthAdjust="spacing" textLength="63.0208" x="13.75" y="312.1266">COMPLETED</text><ellipse cx="45.2604" cy="386.1458" fill="none" rx="12.6042" ry="12.6042" style="stroke:#222222;stroke-width:1.1458333333333333;"/><ellipse cx="45.2604" cy="386.1458" fill="#222222" rx="6.875" ry="6.875" style="stroke:#222222;stroke-width:1.1458333333333333;"/><polygon fill="#CBD5E1" points="45.2604,83.3979,49.8438,73.0854,45.2604,77.6688,40.6771,73.0854,45.2604,83.3979" style="stroke:#CBD5E1;stroke-width:1.1458333333333333;"/><path d="M45.2604,41.323 C45.2604,52.7366 45.2604,62.8874 45.2604,76.5229 " fill="none" style="stroke:#CBD5E1;stroke-width:1.1458333333333333;"/><polygon fill="#1E90FF" points="45.2604,184.4415,49.8438,174.129,45.2604,178.7124,40.6771,174.129,45.2604,184.4415" style="stroke:#1E90FF;stroke-width:1.1458333333333333;"/><path d="M45.2604,129.5779 C45.2604,145.908 45.2604,161.2512 45.2604,177.5665 " fill="none" style="stroke:#1E90FF;stroke-width:2.2916666666666665;"/><a href="#link_SUBMIT" target="_self" title="#link_SUBMIT" xlink:actuate="onRequest" xlink:href="#link_SUBMIT" xlink:show="new" xlink:title="#link_SUBMIT" xlink:type="simple"><text fill="#0000FF" font-family="JetBrains Mono" font-size="9.1667" lengthAdjust="spacing" text-decoration="underline" textLength="113.4375" x="46.4063" y="160.1123">SUBMIT / processAction()</text></a><polygon fill="#1E90FF" points="45.2604,285.2749,49.8438,274.9624,45.2604,279.5457,40.6771,274.9624,45.2604,285.2749" style="stroke:#1E90FF;stroke-width:1.1458333333333333;"/><path d="M45.2604,230.4113 C45.2604,246.7413 45.2604,262.0846 45.2604,278.3999 " fill="none" style="stroke:#1E90FF;stroke-width:2.2916666666666665;"/><a href="#link_FINISH" target="_self" title="#link_FINISH" xlink:actuate="onRequest" xlink:href="#link_FINISH" xlink:show="new" xlink:title="#link_FINISH" xlink:type="simple"><text fill="#0000FF" font-family="JetBrains Mono" font-size="9.1667" lengthAdjust="spacing" text-decoration="underline" textLength="27.5" x="46.4063" y="260.9456">FINISH</text></a><polygon fill="#CBD5E1" points="45.2604,373.4202,49.8438,363.1077,45.2604,367.6911,40.6771,363.1077,45.2604,373.4202" style="stroke:#CBD5E1;stroke-width:1.1458333333333333;"/><path d="M45.2604,331.1691 C45.2604,344.8226 45.2604,355.0691 45.2604,366.5452 " fill="none" style="stroke:#CBD5E1;stroke-width:1.1458333333333333;"/><!--SRC=[RP5TJy8m58Rl-okEuKQDHEP78iQG20wT4IGEumKXvh0UHyFMBcqLqVZVFNEey-DctNbE-xxlQJSAYscEaE7AF7fmENdKA1pnFnLeqHiBscWISoK9A2_y2YIvnAh2AwChx3nPCdvLa70BfSjpEKFq1Ay2e8l98hNcKSkUoLXlELUUIcwi95knHli0zsT7NtGyLyb2atCGCEiRxOUO4qIQhTOWLYy4xS_2hpA2cSaaWvlAosgoiDTYC48fbKvPwwsUS8xIB4l-W9chPp-rrYo_J2_9ToqgxM1WjFblsqUKez-TzMJ9J1vIyBjP7_2x9Gi5GT2gXtnAhvHUZD6c_2ZtZh878IRRKsWsEp0CxuGG_8Ncf164xLQ_lrFUmPHxevlhNXZ7qV0SJaxecUzDOzRfbCLzVDiTH6CkZc4oQMIilqQmNdQXi2RXTAT9-SoRMzEfg0d-TUjT3qPNuJWy-slMZuPHVF73h49GBImjle-NO_5uxm00]--></g></svg>
</div>
</div>
<script id="metadata-json" type="application/json">
{
"name" : "click.kamil.multi.core.OrderStateMachineConfig",
"states" : [ {
"rawName" : "COMPLETED",
"fullIdentifier" : "COMPLETED"
}, {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
}, {
"rawName" : "\"COMPLETED\"",
"fullIdentifier" : "COMPLETED"
}, {
"rawName" : "NEW",
"fullIdentifier" : "NEW"
}, {
"rawName" : "\"NEW\"",
"fullIdentifier" : "NEW"
} ],
"transitions" : [ {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"NEW\"",
"fullIdentifier" : "NEW"
} ],
"targetStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"event" : "SUBMIT",
"guard" : null,
"actions" : [ {
"expression" : "processAction()",
"isLambda" : false,
"internalLogic" : "@Override default void execute(StateContext<String,String> context){\n System.out.println(\"Processing order: \" + context.getMessageHeader(\"orderId\"));\n}\n",
"lineNumber" : 31
} ],
"order" : null
}, {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"targetStates" : [ {
"rawName" : "\"COMPLETED\"",
"fullIdentifier" : "COMPLETED"
} ],
"event" : "FINISH",
"guard" : null,
"actions" : [ ],
"order" : null
} ],
"startStates" : [ "NEW" ],
"endStates" : [ "COMPLETED" ],
"renderChoicesAsDiamonds" : true,
"flows" : [ ],
"metadata" : {
"triggers" : [ {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
} ],
"entryPoints" : [ {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
}, {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.api.OrderApi",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
} ],
"callChains" : [ {
"entryPoint" : {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
},
"methodChain" : [ "click.kamil.multi.core.OrderController.submitOrder" ],
"triggerPoint" : {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
}
} ],
"properties" : {
"default" : { }
}
}
}
</script>
<script>
const metadata = JSON.parse(document.getElementById('metadata-json').textContent);
let panZoomInstance;
document.addEventListener('DOMContentLoaded', () => {
const svg = document.querySelector('#svg-container svg');
panZoomInstance = svgPanZoom(svg, { zoomEnabled: true, controlIconsEnabled: true, fit: true, center: true });
document.getElementById('toggle-sidebar').addEventListener('click', () => {
const sidebar = document.getElementById('sidebar');
sidebar.classList.toggle('collapsed');
// Re-center SVG pan-zoom after transition
setTimeout(() => {
if (panZoomInstance) {
panZoomInstance.resize();
panZoomInstance.center();
}
}, 300);
});
setupTabs();
populateSidebar();
populateFlows();
attachInteractivity();
});
function setupTabs() {
const flows = metadata.flows || [];
if (flows.length === 0) {
document.querySelector('.tabs').style.display = 'none';
document.querySelector('.tab-content[data-tab="flows"]')?.remove();
return;
}
document.querySelectorAll('.tab').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('.tab, .tab-content').forEach(el => el.classList.remove('active'));
tab.classList.add('active');
document.getElementById('tab-' + tab.dataset.tab).classList.add('active');
});
});
}
function populateSidebar() {
const list = document.getElementById('ep-list');
const entryPoints = metadata.metadata.entryPoints || [];
const machineEvents = new Set(metadata.transitions.map(t => t.event).filter(Boolean));
entryPoints.forEach(ep => {
// Quality Filter: Hide if it doesn't trigger a machine event
const chains = (metadata.metadata.callChains || []).filter(c =>
c.entryPoint.className === ep.className &&
c.entryPoint.methodName === ep.methodName &&
machineEvents.has(c.triggerPoint.event)
);
if (chains.length === 0) return;
const card = document.createElement('div');
card.className = 'ep-card';
card.innerHTML = `
<div class="ep-type type-${ep.type.toLowerCase()}">${ep.type}</div>
<div class="ep-name">${ep.name}</div>
<div class="ep-fqn">${ep.className}.${ep.methodName}</div>
`;
card.onmouseenter = () => highlightEntryPoint(ep);
card.onmouseleave = clearHighlights;
list.appendChild(card);
});
}
function populateFlows() {
const list = document.getElementById('flow-list');
const flows = metadata.flows || [];
if (flows.length === 0) {
list.innerHTML = '<p style="color:var(--text-muted); font-size:0.8rem; font-style:italic;">No business flows defined.</p>';
return;
}
flows.forEach(flow => {
const card = document.createElement('div');
card.className = 'flow-card';
card.innerHTML = `
<div class="flow-name">${flow.name}</div>
<div class="flow-desc">${flow.description}</div>
`;
card.onmouseenter = () => highlightFlow(flow);
card.onmouseleave = clearHighlights;
list.appendChild(card);
});
}
function highlightEntryPoint(ep) {
clearHighlights();
const machineEvents = new Set(metadata.transitions.map(t => t.event).filter(Boolean));
const chains = metadata.metadata.callChains || [];
const relevantEvents = chains
.filter(c => c.entryPoint.className === ep.className && c.entryPoint.methodName === ep.methodName && machineEvents.has(c.triggerPoint.event))
.map(c => c.triggerPoint.event);
if (relevantEvents.length === 0) return;
highlightEvents(relevantEvents);
}
function highlightFlow(flow) {
clearHighlights();
if (!flow.steps || flow.steps.length === 0) return;
highlightEvents(flow.steps);
}
function highlightEvents(steps) {
const svg = document.querySelector('#svg-container svg');
// Dim everything first
svg.querySelectorAll('path, rect, circle, ellipse, text, polygon').forEach(el => {
el.classList.add('dimmed');
});
steps.forEach(step => {
let linkId = "";
if (step.includes("->")) {
// Named Choice Branch: "SRC->TGT"
const parts = step.split("->");
linkId = "#link_anon_" + normalize(parts[0]) + "_" + normalize(parts[1]);
} else {
// Standard Event
linkId = "#link_" + normalize(step);
}
svg.querySelectorAll('a').forEach(link => {
const href = link.getAttribute('xlink:href') || link.getAttribute('href');
if (href === linkId) {
highlightLinkGroup(link);
}
});
});
// Un-dim all state nodes for context
svg.querySelectorAll('rect, circle, ellipse, polygon').forEach(el => {
const isChoice = el.tagName === 'polygon' && el.points?.numberOfItems === 4;
if (isChoice || ['rect', 'circle', 'ellipse'].includes(el.tagName)) {
el.classList.remove('dimmed');
let next = el.nextElementSibling;
while(next && next.tagName === 'text') {
next.classList.remove('dimmed');
next = next.nextElementSibling;
}
}
});
}
function highlightLinkGroup(link) {
link.classList.add('active-path');
link.querySelectorAll('*').forEach(child => child.classList.remove('dimmed'));
// Find path and polygon immediately before the <a> tag (interleaved)
let prev = link.previousElementSibling;
let foundPath = false;
let foundPolygon = false;
while (prev) {
if (prev.tagName === 'path' && !foundPath) {
prev.classList.remove('dimmed');
prev.classList.add('active-path');
foundPath = true;
} else if (prev.tagName === 'polygon' && !foundPolygon && prev.points?.numberOfItems !== 4) {
prev.classList.remove('dimmed');
prev.classList.add('active-path');
foundPolygon = true;
} else if (['rect', 'circle', 'ellipse'].includes(prev.tagName) ||
(prev.tagName === 'polygon' && prev.points?.numberOfItems === 4)) {
// Hit a state node, stop traversal
break;
}
if (foundPath && foundPolygon) break;
prev = prev.previousElementSibling;
}
}
function clearHighlights() {
document.querySelectorAll('.dimmed, .active-path').forEach(el => {
el.classList.remove('dimmed', 'active-path');
});
}
function attachInteractivity() {
const svg = document.querySelector('#svg-container svg');
const transitions = metadata.transitions || [];
svg.querySelectorAll('a').forEach(link => {
const href = link.getAttribute('xlink:href') || link.getAttribute('href');
if (!href || !href.startsWith('#link_')) return;
const linkId = href.replace('#link_', '');
const isAnon = linkId.startsWith('anon_');
let metaTrans = null;
if (isAnon) {
metaTrans = transitions.find(t =>
!t.event &&
"anon_" + normalize(t.sourceStates[0].fullIdentifier) + "_" + normalize(t.targetStates[0].fullIdentifier) === linkId
);
} else {
metaTrans = transitions.find(t => normalize(t.event) === linkId);
}
if (metaTrans || isAnon) {
link.style.cursor = 'pointer';
const setupTippy = (el) => {
tippy(el, {
content: createTooltip(isAnon ? "Internal logic" : linkId, metaTrans),
allowHTML: true,
theme: 'modern',
interactive: true,
appendTo: document.body,
placement: 'right',
offset: [0, 20]
});
};
setupTippy(link);
let path = link.previousElementSibling;
while(path && path.tagName !== 'path') path = path.previousElementSibling;
if (path) {
path.style.cursor = 'pointer';
setupTippy(path);
}
}
});
}
function normalize(s) {
if (!s) return "";
return s.replace(/[^a-zA-Z0-9]/g, '_');
}
function createTooltip(name, trans) {
const chains = (metadata.metadata.callChains || []).filter(c => normalize(c.triggerPoint.event) === name);
let html = `<div class="tooltip-content">
<div style="font-weight:900; font-size:1.1rem; margin-bottom:12px; border-bottom:1px solid #eee; padding-bottom:8px; line-height:1.3;">
${name === 'Internal logic' ? name : 'Event: <span style="color:var(--accent)">' + name + '</span>'}
</div>`;
if (trans && trans.guard) {
const lineInfo = trans.guard.lineNumber ? ` <span style="color:#94a3b8; font-weight:400; font-size:0.6rem;">(Line: ${trans.guard.lineNumber})</span>` : '';
html += `<div style="font-size:0.7rem; font-weight:800; color:#94a3b8; text-transform:uppercase; margin-bottom:4px">Guard${lineInfo}</div>
<div style="background:#f1f5f9; padding:6px; border-radius:4px; font-family:monospace; font-size:0.8rem; margin-bottom:12px; border:1px solid #e2e8f0;">${trans.guard.expression}</div>`;
if (trans.guard.internalLogic) {
html += `<div style="font-size:0.65rem; font-weight:800; color:#cbd5e1; text-transform:uppercase; margin-bottom:4px">Internal Logic</div>
<pre style="background:#1e293b; color:#f8fafc; padding:8px; border-radius:4px; font-family:'JetBrains Mono', monospace; font-size:0.7rem; overflow-x:auto; margin-bottom:12px;"><code>${trans.guard.internalLogic.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</code></pre>`;
}
}
if (trans && trans.actions && trans.actions.length > 0) {
html += `<div style="font-size:0.7rem; font-weight:800; color:#94a3b8; text-transform:uppercase; margin-bottom:4px">Actions</div>`;
trans.actions.forEach(action => {
const lineInfo = action.lineNumber ? ` <span style="color:#94a3b8; font-weight:400; font-size:0.6rem;">(Line: ${action.lineNumber})</span>` : '';
html += `<div style="font-size:0.7rem; font-weight:800; color:#94a3b8; text-transform:uppercase; margin-bottom:4px">Action${lineInfo}</div>
<div style="background:#f1f5f9; padding:6px; border-radius:4px; font-family:monospace; font-size:0.8rem; margin-bottom:12px; border:1px solid #e2e8f0;">${action.expression}</div>`;
if (action.internalLogic) {
html += `<div style="font-size:0.65rem; font-weight:800; color:#cbd5e1; text-transform:uppercase; margin-bottom:4px">Internal Logic</div>
<pre style="background:#1e293b; color:#f8fafc; padding:8px; border-radius:4px; font-family:'JetBrains Mono', monospace; font-size:0.7rem; overflow-x:auto; margin-bottom:12px;"><code>${action.internalLogic.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</code></pre>`;
}
});
}
if (chains && chains.length > 0) {
html += `<div style="font-size:0.7rem; font-weight:800; color:#94a3b8; text-transform:uppercase; margin-bottom:10px; border-top:1px solid #eee; padding-top:10px">Triggered by</div>`;
chains.forEach(c => {
html += `<div style="margin-bottom:20px">
<div style="font-weight:700; font-size:0.85rem; color:var(--text);">${c.entryPoint.name}</div>
${renderParameters(c.entryPoint.parameters)}
<div style="margin-left:10px; border-left:2px solid #e2e8f0; padding-left:12px; margin-top:10px">
${c.methodChain.map((m, i) => `<div style="font-size:0.7rem; color:#475569; margin-top:4px; font-family:'JetBrains Mono', monospace;"><b>${i+1}</b> ${m}</div>`).join('')}
</div>
</div>`;
});
}
html += `</div>`;
return html;
}
function renderParameters(params) {
if (!params || params.length === 0) return "";
let html = `<div style="font-size:0.65rem; font-weight:700; color:#94a3b8; margin-top:8px; margin-bottom:4px; text-transform:uppercase;">Input Data</div>`;
html += `<div class="payload-box">`;
params.forEach(p => {
const annotation = (p.annotations || []).find(a => a.endsWith("RequestBody") || a.endsWith("PathVariable") || a.endsWith("RequestParam"));
const cleanAnn = annotation ? "@" + annotation.substring(annotation.lastIndexOf('.') + 1) : "";
html += `<div class="payload-param">
<span style="color:#f43f5e; font-size:0.65rem; font-weight:bold;">${cleanAnn}</span>
<span style="color:#38bdf8;">${p.type}</span>
<span style="color:#a3e635;">${p.name}</span>
</div>`;
});
html += `</div>`;
return html;
}
</script>
</body>
</html>

View File

@@ -0,0 +1,108 @@
{
"metadata" : {
"triggers" : [ {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
} ],
"entryPoints" : [ {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
}, {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.api.OrderApi",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
} ],
"callChains" : [ {
"entryPoint" : {
"type" : "REST",
"name" : "POST /orders/submit",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"metadata" : {
"path" : "/orders/submit",
"verb" : "POST"
},
"parameters" : [ {
"name" : "orderId",
"type" : "String",
"annotations" : [ "RequestBody" ]
} ]
},
"methodChain" : [ "click.kamil.multi.core.OrderController.submitOrder" ],
"triggerPoint" : {
"event" : "SUBMIT",
"className" : "click.kamil.multi.core.OrderController",
"methodName" : "submitOrder",
"sourceModule" : null,
"stateMachineId" : null,
"lineNumber" : 18
}
} ],
"properties" : {
"default" : { }
}
},
"name" : "click.kamil.multi.core.OrderStateMachineConfig",
"renderChoicesAsDiamonds" : true,
"startStates" : [ "NEW" ],
"transitions" : [ {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"NEW\"",
"fullIdentifier" : "NEW"
} ],
"targetStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"event" : "SUBMIT",
"guard" : null,
"actions" : [ {
"expression" : "processAction()",
"isLambda" : false,
"internalLogic" : "@Override default void execute(StateContext<String,String> context){\n System.out.println(\"Processing order: \" + context.getMessageHeader(\"orderId\"));\n}\n",
"lineNumber" : 31
} ],
"order" : null
}, {
"type" : "EXTERNAL",
"sourceStates" : [ {
"rawName" : "\"PROCESSING\"",
"fullIdentifier" : "PROCESSING"
} ],
"targetStates" : [ {
"rawName" : "\"COMPLETED\"",
"fullIdentifier" : "COMPLETED"
} ],
"event" : "FINISH",
"guard" : null,
"actions" : [ ],
"order" : null
} ],
"endStates" : [ "COMPLETED" ]
}

View File

@@ -0,0 +1,32 @@
@startuml
!pragma layout smetana
set separator none
hide empty description
hide stereotype
skinparam state {
BackgroundColor white
BorderColor #94a3b8
BorderThickness 1
FontName Inter
FontSize 9
FontStyle bold
RoundCorner 20
Padding 1
}
skinparam shadowing false
skinparam ArrowFontName JetBrains Mono
skinparam ArrowFontSize 8
skinparam ArrowColor #cbd5e1
skinparam ArrowThickness 1
skinparam dpi 110
skinparam svgLinkTarget _self
[*] --> NEW
NEW -[#1E90FF,bold]-> PROCESSING <<external>> <<e_SUBMIT>> : SUBMIT / processAction()
PROCESSING -[#1E90FF,bold]-> COMPLETED <<external>> <<e_FINISH>> : FINISH
COMPLETED --> [*]
@enduml

View File

@@ -0,0 +1,12 @@
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web:3.2.0'
implementation 'org.springframework.statemachine:spring-statemachine-core:3.2.0'
}

View File

@@ -0,0 +1,12 @@
package click.kamil.multi.api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("/orders")
public interface OrderApi {
@PostMapping("/submit")
void submitOrder(@RequestBody String orderId);
}

View File

@@ -0,0 +1,12 @@
package click.kamil.multi.api;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.action.Action;
public interface ProcessAction extends Action<String, String> {
@Override
default void execute(StateContext<String, String> context) {
System.out.println("Processing order: " + context.getMessageHeader("orderId"));
}
}

View File

@@ -0,0 +1,13 @@
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation project(':state_machines:multi_module_sample:api-module')
implementation 'org.springframework.boot:spring-boot-starter-web:3.2.0'
implementation 'org.springframework.statemachine:spring-statemachine-core:3.2.0'
}

View File

@@ -0,0 +1,20 @@
package click.kamil.multi.core;
import click.kamil.multi.api.OrderApi;
import lombok.RequiredArgsConstructor;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.StateMachineFactory;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
public class OrderController implements OrderApi {
private final StateMachineFactory<String, String> factory;
@Override
public void submitOrder(String orderId) {
StateMachine<String, String> sm = factory.getStateMachine(orderId);
sm.sendEvent("SUBMIT");
}
}

View File

@@ -0,0 +1,43 @@
package click.kamil.multi.core;
import click.kamil.multi.api.ProcessAction;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.config.EnableStateMachineFactory;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
@Configuration
@EnableStateMachineFactory
public class OrderStateMachineConfig extends StateMachineConfigurerAdapter<String, String> {
@Override
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
states
.withStates()
.initial("NEW")
.state("PROCESSING")
.end("COMPLETED");
}
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
transitions
.withExternal()
.source("NEW")
.target("PROCESSING")
.event("SUBMIT")
.action(processAction())
.and()
.withExternal()
.source("PROCESSING")
.target("COMPLETED")
.event("FINISH");
}
@Bean
public ProcessAction processAction() {
return new ProcessAction() {};
}
}

View File

@@ -0,0 +1,3 @@
rootProject.name = 'multi-module-sample'
include 'api-module'
include 'core-module'