Skip to content

Commit

Permalink
CB-5623 use same method
Browse files Browse the repository at this point in the history
  • Loading branch information
yagudin10 committed Oct 28, 2024
1 parent a415693 commit 4c269c7
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ public DBNModel getNavigatorModel() {
return navigatorModel;
}

public DBNModel getNavigatorModelOrThrow() throws DBWebException {

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)
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 @@ -336,11 +336,7 @@ public static String getConnectionContainerInfo(DBPDataSourceContainer container
}

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)
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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 = getNavigatorModel(session);
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 = 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");
}
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -381,9 +380,8 @@ protected List<? extends DBSObject> 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);
}
Expand All @@ -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");
}
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 = getNavigatorModel(session).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,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);
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -951,10 +951,7 @@ private void checkDataEditAllowed(DBSEntity dataContainer) throws DBWebException

@NotNull

Check warning on line 952 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:952: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 {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,7 @@ public String generateEntityQuery(@NotNull WebSession session, @NotNull String g
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.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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 4c269c7

Please sign in to comment.