From 4c269c7bd3f171c9a121cf56ab2db2f9b95fdf90 Mon Sep 17 00:00:00 2001 From: Ainur Date: Mon, 28 Oct 2024 09:18:18 +0100 Subject: [PATCH] CB-5623 use same method --- .../src/io/cloudbeaver/model/fs/FSUtils.java | 5 +--- .../cloudbeaver/model/session/WebSession.java | 6 ++++ .../src/io/cloudbeaver/WebServiceUtils.java | 6 +--- .../service/core/impl/WebServiceCore.java | 5 +--- .../navigator/impl/WebServiceNavigator.java | 29 +++++++------------ .../service/sql/WebSQLProcessor.java | 5 +--- .../service/sql/impl/WebServiceSQL.java | 5 +--- .../service/fs/impl/WebServiceFS.java | 13 ++------- .../metadata/WebServiceBindingMetadata.java | 7 +---- 9 files changed, 24 insertions(+), 57 deletions(-) diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/fs/FSUtils.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/fs/FSUtils.java index 3567866c10..ca64c38f36 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/fs/FSUtils.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/fs/FSUtils.java @@ -48,10 +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(); - if (navigatorModel == null) { - throw new DBWebException("Navigator model is not found in session"); - } + 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"); diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java index 58e0d14144..c857b8f9b7 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java @@ -404,6 +404,12 @@ public DBNModel getNavigatorModel() { return navigatorModel; } + 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 */ diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/WebServiceUtils.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/WebServiceUtils.java index 1d531ad6e8..2d44b8ccde 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/WebServiceUtils.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/WebServiceUtils.java @@ -336,11 +336,7 @@ public static String getConnectionContainerInfo(DBPDataSourceContainer container } public static void updateConfigAndRefreshDatabases(WebSession session, String projectId) throws DBWebException { - DBNModel navigatorModel = session.getNavigatorModel(); - if (navigatorModel == null) { - throw new DBWebException("Navigator model is not found in session"); - } - DBNProject projectNode = navigatorModel.getRoot().getProjectNode(session.getProjectById(projectId)); + DBNProject projectNode = session.getNavigatorModelOrThrow().getRoot().getProjectNode(session.getProjectById(projectId)); DBNModel.updateConfigAndRefreshDatabases(projectNode.getDatabases()); } diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/impl/WebServiceCore.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/impl/WebServiceCore.java index f6f5fe1f16..bb9617728e 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/impl/WebServiceCore.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/impl/WebServiceCore.java @@ -639,10 +639,7 @@ public WebConnectionInfo copyConnectionFromNode( @NotNull WebConnectionConfig config ) throws DBWebException { try { - DBNModel navigatorModel = webSession.getNavigatorModel(); - if (navigatorModel == null) { - throw new DBWebException("Navigator model is not found in session"); - } + DBNModel navigatorModel = webSession.getNavigatorModelOrThrow(); WebSessionProjectImpl project = getProjectById(webSession, projectId); DBPDataSourceRegistry dataSourceRegistry = project.getDataSourceRegistry(); diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/navigator/impl/WebServiceNavigator.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/navigator/impl/WebServiceNavigator.java index d42bdefee1..cce3fd8430 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/navigator/impl/WebServiceNavigator.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/navigator/impl/WebServiceNavigator.java @@ -83,7 +83,7 @@ public List getNavigatorNodeChildren( DBNNode[] nodeChildren; boolean isRootPath = CommonUtils.isEmpty(parentPath) || "/".equals(parentPath) || ROOT_DATABASES.equals(parentPath); - DBNModel navigatorModel = getNavigatorModel(session); + DBNModel navigatorModel = session.getNavigatorModelOrThrow(); Set applicableDrivers = WebServiceUtils.getApplicableDriversIds(); if (isRootPath) { DBNRoot rootNode = navigatorModel.getRoot(); @@ -155,8 +155,7 @@ public List getNavigatorNodeParents( try { DBRProgressMonitor monitor = session.getProgressMonitor(); - DBNModel navigatorModel = getNavigatorModel(session); - DBNNode node = navigatorModel.getNodeByPath(monitor, nodePath); + DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath); if (node == null) { throw new DBWebException("Node '" + nodePath + "' not found"); } @@ -198,7 +197,7 @@ public WebNavigatorNodeInfo getNavigatorNodeInfo( try { DBRProgressMonitor monitor = session.getProgressMonitor(); - DBNNode node = getNavigatorModel(session).getNodeByPath(monitor, nodePath); + DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath); if (node == null) { throw new DBWebException("Navigator node '" + nodePath + "' not found"); } @@ -217,7 +216,7 @@ public boolean setNavigatorNodeFilter( try { DBRProgressMonitor monitor = webSession.getProgressMonitor(); - DBNNode node = getNavigatorModel(webSession).getNodeByPath(monitor, nodePath); + DBNNode node = webSession.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath); if (node == null) { throw new DBWebException("Navigator node '" + nodePath + "' not found"); } @@ -256,7 +255,7 @@ public boolean refreshNavigatorNode( try { DBRProgressMonitor monitor = session.getProgressMonitor(); - DBNNode node = getNavigatorModel(session).getNodeByPath(monitor, nodePath); + DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath); if (node == null) { throw new DBWebException("Navigator node '" + nodePath + "' not found"); } @@ -381,9 +380,8 @@ protected List getCatalogs(DBRProgressMonitor monitor, DBSO @Nullable protected WebNavigatorNodeInfo getNodeFromObject(WebSession session, DBSObject object) throws DBWebException { - DBNModel navigatorModel = getNavigatorModel(session); 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); } @@ -397,7 +395,7 @@ public String renameNode( try { DBRProgressMonitor monitor = session.getProgressMonitor(); - DBNNode node = getNavigatorModel(session).getNodeByPath(monitor, nodePath); + DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath); if (node == null) { throw new DBWebException("Navigator node '" + nodePath + "' not found"); } @@ -502,8 +500,9 @@ public int deleteNodes( String projectId = null; boolean containsFolderNodes = false; Map nodes = new LinkedHashMap<>(); + DBNModel model = session.getNavigatorModelOrThrow(); for (String path : nodePaths) { - DBNNode node = getNavigatorModel(session).getNodeByPath(monitor, path); + DBNNode node = model.getNodeByPath(monitor, path); if (node == null) { throw new DBWebException("Navigator node '" + path + "' not found"); } @@ -598,7 +597,7 @@ public boolean moveNodesToFolder( try { DBRProgressMonitor monitor = session.getProgressMonitor(); DBNNode folderNode; - DBNModel navigatorModel = getNavigatorModel(session); + DBNModel navigatorModel = session.getNavigatorModelOrThrow(); folderNode = navigatorModel.getNodeByPath(monitor, folderNodePath); for (String path : nodePaths) { DBNNode node = navigatorModel.getNodeByPath(monitor, path); @@ -695,12 +694,4 @@ public DBCExecutionContext getCommandExecutionContext(DBSObject object) { } return executionContext; } - - private DBNModel getNavigatorModel(@NotNull WebSession webSession) throws DBWebException { - DBNModel model = webSession.getNavigatorModel(); - if (model == null) { - throw new DBWebException("Navigator model is not found in session"); - } - return model; - } } diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java index 626cc78338..96d9fdd960 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java @@ -951,10 +951,7 @@ private void checkDataEditAllowed(DBSEntity dataContainer) throws DBWebException @NotNull public T getDataContainerByNodePath(DBRProgressMonitor monitor, @NotNull String containerPath, Class type) throws DBException { - DBNModel navigatorModel = webSession.getNavigatorModel(); - if (navigatorModel == null) { - throw new DBWebException("Navigator model is not found in session"); - } + DBNModel navigatorModel = webSession.getNavigatorModelOrThrow(); DBNNode node = navigatorModel.getNodeByPath(monitor, containerPath); if (node == null) { throw new DBWebException("Container node '" + containerPath + "' not found"); diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java index 578bff9aaa..36ff2f17d7 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java @@ -242,10 +242,7 @@ public String generateEntityQuery(@NotNull WebSession session, @NotNull String g private List getObjectListFromNodeIds(@NotNull WebSession session, @NotNull List nodePathList) throws DBWebException { try { List objectList = new ArrayList<>(nodePathList.size()); - DBNModel navigatorModel = session.getNavigatorModel(); - if (navigatorModel == null) { - throw new DBException("Navigator model is not found in session"); - } + DBNModel navigatorModel = session.getNavigatorModelOrThrow(); for (String nodePath : nodePathList) { DBNNode node = navigatorModel.getNodeByPath(session.getProgressMonitor(), nodePath); if (node == null) { diff --git a/server/bundles/io.cloudbeaver.service.fs/src/io/cloudbeaver/service/fs/impl/WebServiceFS.java b/server/bundles/io.cloudbeaver.service.fs/src/io/cloudbeaver/service/fs/impl/WebServiceFS.java index 552e0cbe70..187184c780 100644 --- a/server/bundles/io.cloudbeaver.service.fs/src/io/cloudbeaver/service/fs/impl/WebServiceFS.java +++ b/server/bundles/io.cloudbeaver.service.fs/src/io/cloudbeaver/service/fs/impl/WebServiceFS.java @@ -25,7 +25,6 @@ import org.jkiss.code.NotNull; import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.model.app.DBPProject; -import org.jkiss.dbeaver.model.navigator.DBNModel; import org.jkiss.dbeaver.model.navigator.DBNProject; import org.jkiss.dbeaver.model.navigator.fs.DBNFileSystem; import org.jkiss.dbeaver.model.navigator.fs.DBNFileSystems; @@ -52,11 +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)); } - DBNModel navigatorModel = webSession.getNavigatorModel(); - if (navigatorModel == null) { - throw new DBException("Navigator model is not found in session"); - } - DBNProject projectNode = navigatorModel.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)); } @@ -83,11 +78,7 @@ public FSFileSystem getFileSystem( @NotNull String nodePath ) throws DBWebException { try { - DBNModel navigatorModel = webSession.getNavigatorModel(); - if (navigatorModel == null) { - throw new DBException("Navigator model is not found in session"); - } - var node = navigatorModel.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)); } diff --git a/server/bundles/io.cloudbeaver.service.metadata/src/io/cloudbeaver/service/metadata/WebServiceBindingMetadata.java b/server/bundles/io.cloudbeaver.service.metadata/src/io/cloudbeaver/service/metadata/WebServiceBindingMetadata.java index 771f93f129..d135f77666 100644 --- a/server/bundles/io.cloudbeaver.service.metadata/src/io/cloudbeaver/service/metadata/WebServiceBindingMetadata.java +++ b/server/bundles/io.cloudbeaver.service.metadata/src/io/cloudbeaver/service/metadata/WebServiceBindingMetadata.java @@ -23,7 +23,6 @@ import io.cloudbeaver.service.WebServiceBindingBase; import io.cloudbeaver.service.metadata.impl.WebServiceMetadata; import org.jkiss.dbeaver.DBException; -import org.jkiss.dbeaver.model.navigator.DBNModel; import org.jkiss.dbeaver.model.navigator.DBNNode; /** @@ -56,10 +55,6 @@ private DBNNode getNodeFromPath(DataFetchingEnvironment env) throws DBException if (nodePath == null) { throw new DBException("Node path is null"); } - DBNModel navigatorModel = webSession.getNavigatorModel(); - if (navigatorModel == null) { - throw new DBException("Navigator model is not found in session"); - } - return navigatorModel.getNodeByPath(webSession.getProgressMonitor(), nodePath); + return webSession.getNavigatorModelOrThrow().getNodeByPath(webSession.getProgressMonitor(), nodePath); } }