Skip to content

Commit

Permalink
CB-3839. Refactor after review, updated logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisSinelnikov committed Sep 21, 2023
1 parent 484dea9 commit d34150f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,17 @@
package io.cloudbeaver.model;

import io.cloudbeaver.utils.CBModelConstants;
import org.jkiss.dbeaver.model.websocket.event.MessageType;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
* Web server message
*/
public class WebServerMessage {


public enum MessageType {
DEBUG,
INFO,
WARNING,
ERROR
}

private final MessageType type;
private final Instant time;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
import org.jkiss.dbeaver.model.security.SMController;
import org.jkiss.dbeaver.model.security.SMObjectType;
import org.jkiss.dbeaver.model.sql.DBQuotaException;
import org.jkiss.dbeaver.model.websocket.event.WSErrorEvent;
import org.jkiss.dbeaver.model.websocket.event.MessageType;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.model.websocket.event.WSSessionLogUpdatedEvent;
import org.jkiss.dbeaver.registry.*;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.utils.ArrayUtils;
Expand Down Expand Up @@ -966,15 +967,11 @@ protected <T> T doFileReadOperation(String projectId, Path file, RMFileOperation
} catch (Exception e) {
if (credentialsProvider.getActiveUserCredentials() != null) {
WebAppUtils.getWebApplication().getEventController().addEvent(
new WSErrorEvent(
WSEventType.SESSION_LOG_MESSAGE_ADDED,
new WSSessionLogUpdatedEvent(
WSEventType.SESSION_LOG_UPDATED,
credentialsProvider.getActiveUserCredentials().getSmSessionId(),
credentialsProvider.getActiveUserCredentials().getUserId(),
e.getMessage()));
} else {
WebAppUtils.getWebApplication().getEventController().addEvent(
new WSErrorEvent(
WSEventType.SESSION_LOG_MESSAGE_ADDED,
MessageType.ERROR,
e.getMessage()));
}
log.error("Error before file reading", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.jkiss.dbeaver.model.security.SMObjectType;
import org.jkiss.dbeaver.model.security.user.SMObjectPermissions;
import org.jkiss.dbeaver.model.sql.DBQuotaException;
import org.jkiss.dbeaver.model.websocket.event.MessageType;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.model.websocket.event.WSSessionLogUpdatedEvent;
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
Expand Down Expand Up @@ -726,15 +727,20 @@ public void addSessionMessage(WebServerMessage message) {
synchronized (sessionMessages) {
sessionMessages.add(message);
}
addSessionEvent(new WSSessionLogUpdatedEvent());
addSessionEvent(new WSSessionLogUpdatedEvent(
WSEventType.SESSION_LOG_UPDATED,
this.userContext.getSmSessionId(),
this.userContext.getUserId(),
MessageType.ERROR,
message.getMessage()));
}

public void addInfoMessage(String message) {
addSessionMessage(new WebServerMessage(WebServerMessage.MessageType.INFO, message));
addSessionMessage(new WebServerMessage(MessageType.INFO, message));
}

public void addWarningMessage(String message) {
addSessionMessage(new WebServerMessage(WebServerMessage.MessageType.WARNING, message));
addSessionMessage(new WebServerMessage(MessageType.WARNING, message));
}

public List<WebServerMessage> readLog(Integer maxEntries, Boolean clearLog) {
Expand Down
2 changes: 1 addition & 1 deletion server/bundles/io.cloudbeaver.server/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<eventHandler class="io.cloudbeaver.server.events.WSUserSecretEventHandlerImpl">
<topic id="cb_user_secret"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSEventLogSendHandler">
<eventHandler class="io.cloudbeaver.server.events.WSLogEventHandler">
<topic id="cb_session_log"/>
</eventHandler>
</extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import io.cloudbeaver.model.WebServerMessage;
import io.cloudbeaver.model.session.BaseWebSession;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.websocket.event.WSErrorEvent;
import org.jkiss.dbeaver.model.websocket.event.WSSessionLogUpdatedEvent;

public class WSEventLogSendHandler extends WSDefaultEventHandler<WSErrorEvent> {
public class WSLogEventHandler extends WSDefaultEventHandler<WSSessionLogUpdatedEvent> {

protected void updateSessionData(@NotNull BaseWebSession activeUserSession, @NotNull WSErrorEvent event) {
activeUserSession.addSessionMessage(new WebServerMessage(WebServerMessage.MessageType.ERROR, event.getErrorMessage()));
protected void updateSessionData(@NotNull BaseWebSession activeUserSession, @NotNull WSSessionLogUpdatedEvent event) {
activeUserSession.addSessionMessage(new WebServerMessage(event.getMessageType(), event.getMessage()));
}

protected boolean isAcceptableInSession(@NotNull BaseWebSession activeUserSession, @NotNull WSErrorEvent event) {
protected boolean isAcceptableInSession(@NotNull BaseWebSession activeUserSession, @NotNull WSSessionLogUpdatedEvent event) {
return WSWebUtils.isSessionIdEquals(activeUserSession, event.getSessionId());
}
}

0 comments on commit d34150f

Please sign in to comment.