-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to use web-dependency-locator, rather than web-bundler
Signed-off-by: Phillip Kruger <[email protected]>
- Loading branch information
1 parent
a607f0b
commit 7d1c744
Showing
17 changed files
with
330 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ ObjectStore | |
*.ipr | ||
*.iws | ||
.idea | ||
|
||
# VS Code | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/io/quarkus/sample/audit/AuditLogEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus.sample.audit; | ||
|
||
import jakarta.enterprise.inject.spi.CDI; | ||
import jakarta.json.bind.Jsonb; | ||
import jakarta.websocket.DecodeException; | ||
import jakarta.websocket.Decoder; | ||
import jakarta.websocket.EncodeException; | ||
import jakarta.websocket.Encoder; | ||
import jakarta.websocket.EndpointConfig; | ||
|
||
public class AuditLogEncoder implements Encoder.Text<AuditLogSocket.AuditLogEntry>, Decoder.Text<AuditLogSocket.AuditLogEntry> { | ||
|
||
private final Jsonb jsonb; | ||
|
||
public AuditLogEncoder() { | ||
this.jsonb = CDI.current().select(Jsonb.class).get(); | ||
} | ||
|
||
@Override | ||
public String encode(AuditLogSocket.AuditLogEntry object) throws EncodeException { | ||
return jsonb.toJson(object); | ||
} | ||
|
||
@Override | ||
public AuditLogSocket.AuditLogEntry decode(String s) throws DecodeException { | ||
return jsonb.fromJson(s, AuditLogSocket.AuditLogEntry.class); | ||
} | ||
|
||
@Override | ||
public boolean willDecode(String s) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void init(EndpointConfig config) { | ||
|
||
} | ||
|
||
@Override | ||
public void destroy() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.quarkus.sample.audit; | ||
|
||
import io.quarkus.logging.Log; | ||
import io.quarkus.sample.Todo; | ||
import io.quarkus.vertx.ConsumeEvent; | ||
import io.vertx.core.impl.ConcurrentHashSet; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.websocket.OnOpen; | ||
import jakarta.websocket.Session; | ||
import jakarta.websocket.server.ServerEndpoint; | ||
import java.util.Set; | ||
|
||
@ServerEndpoint(value = "/audit", encoders = AuditLogEncoder.class, decoders = AuditLogEncoder.class) | ||
@ApplicationScoped | ||
public class AuditLogSocket { | ||
|
||
Set<Session> sessions = new ConcurrentHashSet<>(); | ||
|
||
public record AuditLogEntry(AuditType type, Todo todo) { | ||
} | ||
|
||
@OnOpen | ||
public void onOpen(Session session) { | ||
sessions.add(session); | ||
} | ||
|
||
@ConsumeEvent("TODO_ADDED") | ||
public void add(Todo todo) { | ||
log(new AuditLogEntry(AuditType.TODO_ADDED, todo)); | ||
} | ||
|
||
@ConsumeEvent("TODO_CHECKED") | ||
public void check(Todo todo) { | ||
log(new AuditLogEntry(AuditType.TODO_CHECKED, todo)); | ||
} | ||
|
||
@ConsumeEvent("TODO_UNCHECKED") | ||
public void uncheck(Todo todo) { | ||
log(new AuditLogEntry(AuditType.TODO_UNCHECKED, todo)); | ||
} | ||
|
||
@ConsumeEvent("TODO_REMOVED") | ||
public void remove(Todo todo) { | ||
log(new AuditLogEntry(AuditType.TODO_REMOVED, todo)); | ||
} | ||
|
||
private void log(AuditLogEntry entry){ | ||
sessions.forEach(s -> { | ||
s.getAsyncRemote().sendObject(entry, result -> { | ||
if (result.getException() != null) { | ||
Log.error("Unable to send message: " + result.getException()); | ||
} | ||
}); | ||
}); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.quarkus.sample.audit; | ||
|
||
public enum AuditType { | ||
TODO_ADDED, TODO_CHECKED, TODO_UNCHECKED, TODO_REMOVED | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import {LitElement, html, css} from 'lit'; | ||
import '@vaadin/grid'; | ||
import { columnBodyRenderer } from '@vaadin/grid/lit.js'; | ||
|
||
class TodosAuditLog extends LitElement { | ||
|
||
static webSocket; | ||
static serverUri; | ||
|
||
static styles = css` | ||
`; | ||
|
||
static properties = { | ||
_entries: {type: Array, state: true} | ||
}; | ||
|
||
constructor() { | ||
super(); | ||
this._entries = []; | ||
if (!TodosAuditLog.logWebSocket) { | ||
if (window.location.protocol === "https:") { | ||
TodosAuditLog.serverUri = "wss:"; | ||
} else { | ||
TodosAuditLog.serverUri = "ws:"; | ||
} | ||
TodosAuditLog.serverUri += "//" + window.location.host + "/audit"; | ||
TodosAuditLog.connect(); | ||
} | ||
this._eventAuditEntry = (event) => this._receiveAuditEntry(event.detail); | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
document.addEventListener('eventAuditEntryEvent', this._eventAuditEntry, false); | ||
} | ||
|
||
disconnectedCallback() { | ||
document.removeEventListener('eventAuditEntryEvent', this._eventAuditEntry, false); | ||
super.disconnectedCallback(); | ||
} | ||
|
||
render() { | ||
return html`<vaadin-grid .items="${this._entries}"> | ||
<vaadin-grid-column header="Action" ${columnBodyRenderer(this._typeRenderer, [])}></vaadin-grid-column> | ||
<vaadin-grid-column path="todo.id"></vaadin-grid-column> | ||
<vaadin-grid-column path="todo.title"></vaadin-grid-column> | ||
<vaadin-grid-column path="todo.completed"></vaadin-grid-column> | ||
</vaadin-grid>`; | ||
} | ||
|
||
_typeRenderer(entry) { | ||
return html`${this._formatTodoType(entry.type)}`; | ||
} | ||
|
||
_formatTodoType(str) { | ||
return str.replace(/^TODO_(.*)$/, function(match, p1) { | ||
return p1.toLowerCase(); | ||
}); | ||
} | ||
|
||
_receiveAuditEntry(entry) { | ||
this._entries = [entry, ...this._entries]; | ||
} | ||
|
||
static connect() { | ||
TodosAuditLog.webSocket = new WebSocket(TodosAuditLog.serverUri); | ||
TodosAuditLog.webSocket.onmessage = function (event) { | ||
var auditentry = JSON.parse(event.data); | ||
const eventAuditEntryEvent = new CustomEvent('eventAuditEntryEvent', {detail: auditentry}); | ||
document.dispatchEvent(eventAuditEntryEvent); | ||
} | ||
TodosAuditLog.webSocket.onclose = function (event) { | ||
setTimeout(function () { | ||
TodosAuditLog.connect(); | ||
}, 100); | ||
}; | ||
} | ||
|
||
} | ||
customElements.define('todos-audit-log', TodosAuditLog); |
Oops, something went wrong.