Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-5623 fix npe #3030

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static Path getPathFromNode(@NotNull WebSession webSession, @NotNull Stri
public static DBNPathBase getNodeByPath(@NotNull WebSession webSession, @NotNull String nodePath) throws DBException {
DBRProgressMonitor monitor = webSession.getProgressMonitor();

DBNModel navigatorModel = webSession.getNavigatorModel();
DBNModel navigatorModel = webSession.getNavigatorModelOrThrow();
DBNNode node = navigatorModel.getNodeByPath(monitor, nodePath);
if (!(node instanceof DBNPathBase dbnPath)) {
throw new DBWebException("Node '" + nodePath + "' is not found in File Systems");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,18 @@
this.locale = locale != null ? locale : Locale.getDefault().getLanguage();
}

@Nullable
public DBNModel getNavigatorModel() {
return navigatorModel;
}

@NotNull

Check warning on line 407 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java:407:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)

Check warning on line 407 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java#L407

Missing a Javadoc comment.
public DBNModel getNavigatorModelOrThrow() throws DBWebException {
if (navigatorModel != null) {
return navigatorModel;
}
throw new DBWebException("Navigator model is not found in session");
}
/**
* Returns and clears progress messages
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@
return container.getName() + " [" + container.getId() + "]";
}

public static void updateConfigAndRefreshDatabases(WebSession session, String projectId) {
DBNProject projectNode = session.getNavigatorModel().getRoot().getProjectNode(session.getProjectById(projectId));
public static void updateConfigAndRefreshDatabases(WebSession session, String projectId) throws DBWebException {

Check warning on line 338 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/WebServiceUtils.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/WebServiceUtils.java:338:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)

Check warning on line 338 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/WebServiceUtils.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/WebServiceUtils.java#L338

Missing a Javadoc comment.
DBNProject projectNode = session.getNavigatorModelOrThrow().getRoot().getProjectNode(session.getProjectById(projectId));
DBNModel.updateConfigAndRefreshDatabases(projectNode.getDatabases());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.cloudbeaver.model.session.WebSession;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDatasourceFolderEvent;
import org.jkiss.utils.CommonUtils;

Expand All @@ -32,15 +33,19 @@ public class WSFolderUpdatedEventHandlerImpl extends WSAbstractProjectEventHandl

@Override
protected void updateSessionData(@NotNull BaseWebSession activeUserSession, @NotNull WSDatasourceFolderEvent event) {
if (activeUserSession instanceof WebSession) {
var webSession = (WebSession) activeUserSession;
if (activeUserSession instanceof WebSession webSession) {
var project = webSession.getProjectById(event.getProjectId());
if (project == null) {
log.debug("Project " + event.getProjectId() + " is not found in session " + webSession.getSessionId());
return;
}
project.getDataSourceRegistry().refreshConfig();
webSession.getNavigatorModel().getRoot().getProjectNode(project).getDatabases().refreshChildren();
DBNModel navigatorModel = webSession.getNavigatorModel();
if (navigatorModel == null) {
log.debug("Navigator model is not found in session " + webSession.getSessionId());
return;
}
navigatorModel.getRoot().getProjectNode(project).getDatabases().refreshChildren();
}
activeUserSession.addSessionEvent(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public WebConnectionInfo copyConnectionFromNode(
@NotNull WebConnectionConfig config
) throws DBWebException {
try {
DBNModel navigatorModel = webSession.getNavigatorModel();
DBNModel navigatorModel = webSession.getNavigatorModelOrThrow();
WebSessionProjectImpl project = getProjectById(webSession, projectId);
DBPDataSourceRegistry dataSourceRegistry = project.getDataSourceRegistry();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public List<WebNavigatorNodeInfo> getNavigatorNodeChildren(

DBNNode[] nodeChildren;
boolean isRootPath = CommonUtils.isEmpty(parentPath) || "/".equals(parentPath) || ROOT_DATABASES.equals(parentPath);
DBNModel navigatorModel = session.getNavigatorModel();
DBNModel navigatorModel = session.getNavigatorModelOrThrow();
Set<String> applicableDrivers = WebServiceUtils.getApplicableDriversIds();
if (isRootPath) {
DBNRoot rootNode = navigatorModel.getRoot();
Expand Down Expand Up @@ -155,8 +155,7 @@ public List<WebNavigatorNodeInfo> getNavigatorNodeParents(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();

DBNModel navigatorModel = session.getNavigatorModel();
DBNNode node = navigatorModel.getNodeByPath(monitor, nodePath);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Node '" + nodePath + "' not found");
}
Expand Down Expand Up @@ -198,7 +197,7 @@ public WebNavigatorNodeInfo getNavigatorNodeInfo(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();

DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, nodePath);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Navigator node '" + nodePath + "' not found");
}
Expand All @@ -217,7 +216,7 @@ public boolean setNavigatorNodeFilter(
try {
DBRProgressMonitor monitor = webSession.getProgressMonitor();

DBNNode node = webSession.getNavigatorModel().getNodeByPath(monitor, nodePath);
DBNNode node = webSession.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Navigator node '" + nodePath + "' not found");
}
Expand Down Expand Up @@ -256,7 +255,7 @@ public boolean refreshNavigatorNode(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();

DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, nodePath);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Navigator node '" + nodePath + "' not found");
}
Expand Down Expand Up @@ -380,10 +379,9 @@ protected List<? extends DBSObject> getCatalogs(DBRProgressMonitor monitor, DBSO
}

@Nullable
protected WebNavigatorNodeInfo getNodeFromObject(WebSession session, DBSObject object){
DBNModel navigatorModel = session.getNavigatorModel();
protected WebNavigatorNodeInfo getNodeFromObject(WebSession session, DBSObject object) throws DBWebException {
DBRProgressMonitor monitor = session.getProgressMonitor();
DBNNode node = navigatorModel.getNodeByObject(monitor, object, false);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByObject(monitor, object, false);

return node == null ? null : new WebNavigatorNodeInfo(session, node);
}
Expand All @@ -397,7 +395,7 @@ public String renameNode(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();

DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, nodePath);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Navigator node '" + nodePath + "' not found");
}
Expand Down Expand Up @@ -502,8 +500,9 @@ public int deleteNodes(
String projectId = null;
boolean containsFolderNodes = false;
Map<DBNNode, DBEObjectMaker> nodes = new LinkedHashMap<>();
DBNModel model = session.getNavigatorModelOrThrow();
for (String path : nodePaths) {
DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, path);
DBNNode node = model.getNodeByPath(monitor, path);
if (node == null) {
throw new DBWebException("Navigator node '" + path + "' not found");
}
Expand Down Expand Up @@ -598,9 +597,10 @@ public boolean moveNodesToFolder(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();
DBNNode folderNode;
folderNode = session.getNavigatorModel().getNodeByPath(monitor, folderNodePath);
DBNModel navigatorModel = session.getNavigatorModelOrThrow();
folderNode = navigatorModel.getNodeByPath(monitor, folderNodePath);
for (String path : nodePaths) {
DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, path);
DBNNode node = navigatorModel.getNodeByPath(monitor, path);
if (node == null) {
throw new DBWebException("Navigator node '" + path + "' not found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,9 +948,9 @@
}
}

@NotNull

Check warning on line 951 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java:951:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
public <T> T getDataContainerByNodePath(DBRProgressMonitor monitor, @NotNull String containerPath, Class<T> type) throws DBException {
DBNNode node = webSession.getNavigatorModel().getNodeByPath(monitor, containerPath);
DBNNode node = webSession.getNavigatorModelOrThrow().getNodeByPath(monitor, containerPath);
if (node == null) {
throw new DBWebException("Container node '" + containerPath + "' not found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.jkiss.dbeaver.model.exec.trace.DBCTraceDynamic;
import org.jkiss.dbeaver.model.exec.trace.DBCTraceProperty;
import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.*;
Expand Down Expand Up @@ -238,11 +239,12 @@
}

@NotNull
private List<DBSObject> getObjectListFromNodeIds(@NotNull WebSession session, @NotNull List<String> nodePathList) throws DBWebException {

Check warning on line 242 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Line is longer than 140 characters (found 141). Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java:242:0: warning: Line is longer than 140 characters (found 141). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
try {
List<DBSObject> objectList = new ArrayList<>(nodePathList.size());
DBNModel navigatorModel = session.getNavigatorModelOrThrow();
for (String nodePath : nodePathList) {
DBNNode node = session.getNavigatorModel().getNodeByPath(session.getProgressMonitor(), nodePath);
DBNNode node = navigatorModel.getNodeByPath(session.getProgressMonitor(), nodePath);
if (node == null) {
throw new DBException("Node '" + nodePath + "' not found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public FSFileSystem[] getAvailableFileSystems(@NotNull WebSession webSession, @N
if (project == null) {
throw new DBException(MessageFormat.format("Project ''{0}'' is not found in session", projectId));
}
DBNProject projectNode = webSession.getNavigatorModel().getRoot().getProjectNode(project);
DBNProject projectNode = webSession.getNavigatorModelOrThrow().getRoot().getProjectNode(project);
if (projectNode == null) {
throw new DBException(MessageFormat.format("Project ''{0}'' is not found in navigator model", projectId));
}
Expand All @@ -78,7 +78,7 @@ public FSFileSystem getFileSystem(
@NotNull String nodePath
) throws DBWebException {
try {
var node = webSession.getNavigatorModel().getNodeByPath(webSession.getProgressMonitor(), nodePath);
var node = webSession.getNavigatorModelOrThrow().getNodeByPath(webSession.getProgressMonitor(), nodePath);
if (!(node instanceof DBNFileSystem fs)) {
throw new DBException(MessageFormat.format("Node ''{0}'' is not File System", nodePath));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
private DBNNode getNodeFromPath(DataFetchingEnvironment env) throws DBException {
WebSession webSession = getWebSession(env);
String nodePath = env.getArgument("nodeId");
return webSession.getNavigatorModel().getNodeByPath(webSession.getProgressMonitor(), nodePath);
if (nodePath == null) {
throw new DBException("Node path is null");
}
return webSession.getNavigatorModelOrThrow().getNodeByPath(webSession.getProgressMonitor(), nodePath);
}
}