Skip to content

Commit

Permalink
Merge branch 'devel' into dbeaver/pro#2008-jdbc-class-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
dariamarutkina authored Nov 1, 2023
2 parents 6965d85 + f98b9aa commit 4ae0748
Show file tree
Hide file tree
Showing 70 changed files with 721 additions and 249 deletions.
1 change: 1 addition & 0 deletions server/bundles/io.cloudbeaver.model/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Export-Package: io.cloudbeaver,
io.cloudbeaver.websocket,
io.cloudbeaver.model,
io.cloudbeaver.model.app,
io.cloudbeaver.model.fs,
io.cloudbeaver.model.rm,
io.cloudbeaver.model.rm.local,
io.cloudbeaver.model.rm.lock,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2023 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cloudbeaver.model.fs;

import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.fs.DBFVirtualFileSystem;

public class FSUtils {
@NotNull
public static String makeUniqueFsId(@NotNull DBFVirtualFileSystem fileSystem) {
return fileSystem.getType() + ":" + fileSystem.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
*/
package io.cloudbeaver.utils;

import io.cloudbeaver.DBWebException;
import io.cloudbeaver.WebProjectImpl;
import io.cloudbeaver.auth.NoAuthCredentialsProvider;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.model.session.WebSession;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
Expand Down Expand Up @@ -209,4 +212,12 @@ public static String getGlobalProjectId() {
return RMProjectType.GLOBAL.getPrefix() + "_" + globalConfigurationName;
}

public static WebProjectImpl getProjectById(WebSession webSession, String projectId) throws DBWebException {
WebProjectImpl project = webSession.getProjectById(projectId);
if (project == null) {
throw new DBWebException("Project '" + projectId + "' not found");
}
return project;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type NavigatorNodeInfo {

# Associated object. Return value depends on the node type - connectionId for connection node, resource path for resource node, etc.
# null - if node currently not support this property
objectId: String
objectId: String @since(version: "23.2.4")

# Supported features: item, container, leaf
# canDelete, canRename
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package io.cloudbeaver.service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.json.JSONUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;

public abstract class WebServiceServletBase extends HttpServlet {

private static final Log log = Log.getLog(WebServiceServletBase.class);
private static final Type MAP_STRING_OBJECT_TYPE = JSONUtils.MAP_TYPE_TOKEN;
private static final String REQUEST_PARAM_VARIABLES = "variables";
private static final Gson gson = new GsonBuilder()
.serializeNulls()
.setPrettyPrinting()
.create();

private final CBApplication application;

Expand Down Expand Up @@ -43,4 +54,7 @@ protected final void service(HttpServletRequest request, HttpServletResponse res

protected abstract void processServiceRequest(WebSession session, HttpServletRequest request, HttpServletResponse response) throws DBException, IOException;

protected Map<String, Object> getVariables(HttpServletRequest request) {
return gson.fromJson(request.getParameter(REQUEST_PARAM_VARIABLES), MAP_STRING_OBJECT_TYPE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.cloudbeaver.WebProjectImpl;
import io.cloudbeaver.WebServiceUtils;
import io.cloudbeaver.model.WebPropertyInfo;
import io.cloudbeaver.model.fs.FSUtils;
import io.cloudbeaver.model.rm.DBNResourceManagerProject;
import io.cloudbeaver.model.rm.DBNResourceManagerResource;
import io.cloudbeaver.model.session.WebSession;
Expand All @@ -32,6 +33,7 @@
import org.jkiss.dbeaver.model.meta.Association;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.navigator.*;
import org.jkiss.dbeaver.model.navigator.fs.DBNFileSystem;
import org.jkiss.dbeaver.model.navigator.fs.DBNPathBase;
import org.jkiss.dbeaver.model.rm.RMProject;
import org.jkiss.dbeaver.model.rm.RMProjectPermission;
Expand Down Expand Up @@ -283,6 +285,8 @@ public WebDatabaseObjectInfo getObject() {
public String getObjectId() {
if (node instanceof DBNPathBase dbnPath) {
return dbnPath.getPath().toUri().toString();
} else if (node instanceof DBNFileSystem dbnFs) {
return FSUtils.makeUniqueFsId(dbnFs.getFileSystem());
}
return null;
}
Expand Down
3 changes: 0 additions & 3 deletions server/bundles/io.cloudbeaver.service.fs/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@
class="io.cloudbeaver.service.fs.WebServiceBindingFS">
</service>
</extension>
<extension point="io.cloudbeaver.feature">
<feature id="fileSystems" label="File Systems" description="File Systems"/>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ type FSFile @since(version: "23.2.2") {
metaData: Object!
}

type FSFileSystem @since(version: "23.2.4") {
id: ID!
requiredAuth: String
}

extend type Query @since(version: "23.2.2") {
fsListFileSystems(projectId: ID!): [String!]!
fsListFileSystems(projectId: ID!): [FSFileSystem!]!

fsFileSystem(projectId: ID!, fileSystemId: ID!): FSFileSystem! @since(version: "23.2.4")

fsFile(projectId: ID!, fileURI: String!): FSFile!

Expand All @@ -21,14 +28,14 @@ extend type Mutation @since(version: "23.2.2") {

fsCreateFolder(projectId: ID!, folderURI:String!): FSFile!

fsDeleteFile(projectId: ID!, fileURI:String!): Boolean!
fsDelete(projectId: ID!, fileURI:String!): Boolean!

fsMoveFile(projectId: ID!, fromURI: String!, toURI: String!): FSFile!
fsMove(projectId: ID!, fromURI: String!, toURI: String!): FSFile!

fsWriteFileStringContent(
projectId: ID!,
fileURI:String!,
data: String!,
forceOverwrite: Boolean!
): Boolean!
): FSFile!
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.service.DBWService;
import io.cloudbeaver.service.fs.model.FSFile;
import io.cloudbeaver.service.fs.model.FSFileSystem;
import org.jkiss.code.NotNull;

import java.net.URI;
Expand All @@ -29,9 +30,17 @@
*/
public interface DBWServiceFS extends DBWService {
@NotNull
String[] getAvailableFileSystems(@NotNull WebSession webSession, @NotNull String projectId)
FSFileSystem[] getAvailableFileSystems(@NotNull WebSession webSession, @NotNull String projectId)
throws DBWebException;


@NotNull
FSFileSystem getFileSystem(
@NotNull WebSession webSession,
@NotNull String projectId,
@NotNull String fileSystemId
) throws DBWebException;

@NotNull
FSFile getFile(
@NotNull WebSession webSession,
Expand All @@ -53,7 +62,7 @@ String readFileContent(
@NotNull URI fileURI
) throws DBWebException;

boolean writeFileContent(
FSFile writeFileContent(
@NotNull WebSession webSession,
@NotNull String projectId,
@NotNull URI fileURI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@
package io.cloudbeaver.service.fs;

import io.cloudbeaver.DBWebException;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.service.DBWBindingContext;
import io.cloudbeaver.service.DBWServiceBindingServlet;
import io.cloudbeaver.service.DBWServletContext;
import io.cloudbeaver.service.WebServiceBindingBase;
import io.cloudbeaver.service.fs.impl.WebServiceFS;
import io.cloudbeaver.service.fs.model.WebFSServlet;
import org.jkiss.dbeaver.DBException;
import org.jkiss.utils.CommonUtils;

import java.net.URI;

/**
* Web service implementation
*/
public class WebServiceBindingFS extends WebServiceBindingBase<DBWServiceFS> {
public class WebServiceBindingFS extends WebServiceBindingBase<DBWServiceFS> implements DBWServiceBindingServlet<CBApplication> {

private static final String SCHEMA_FILE_NAME = "schema/service.fs.graphqls";

Expand All @@ -40,44 +45,58 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
model.getQueryType()
.dataFetcher("fsListFileSystems",
env -> getService(env).getAvailableFileSystems(getWebSession(env), env.getArgument("projectId")))
.dataFetcher("fsFileSystem",
env -> getService(env).getFileSystem(
getWebSession(env),
env.getArgument("projectId"),
env.getArgument("fileSystemId")
)
)
.dataFetcher("fsFile",
env -> getService(env).getFile(getWebSession(env),
env.getArgument("projectId"),
URI.create(env.getArgument("fileURI")))
URI.create(env.getArgument("fileURI"))
)
)
.dataFetcher("fsListFiles",
env -> getService(env).getFiles(getWebSession(env),
env.getArgument("projectId"),
URI.create(env.getArgument("folderURI")))
URI.create(env.getArgument("folderURI"))
)
)
.dataFetcher("fsReadFileContentAsString",
env -> getService(env).readFileContent(getWebSession(env),
env.getArgument("projectId"),
URI.create(env.getArgument("fileURI")))
URI.create(env.getArgument("fileURI"))
)
)
;
model.getMutationType()
.dataFetcher("fsCreateFile",
env -> getService(env).createFile(getWebSession(env),
env.getArgument("projectId"),
URI.create(env.getArgument("fileURI")))
URI.create(env.getArgument("fileURI"))
)
)
.dataFetcher("fsCreateFolder",
env -> getService(env).createFolder(getWebSession(env),
env.getArgument("projectId"),
URI.create(env.getArgument("folderURI")))
URI.create(env.getArgument("folderURI"))
)
)
.dataFetcher("fsDeleteFile",
.dataFetcher("fsDelete",
env -> getService(env).deleteFile(getWebSession(env),
env.getArgument("projectId"),
URI.create(env.getArgument("fileURI")))
URI.create(env.getArgument("fileURI"))
)
)
.dataFetcher("fsMoveFile",
.dataFetcher("fsMove",
env -> getService(env).moveFile(
getWebSession(env),
env.getArgument("projectId"),
URI.create(env.getArgument("fromURI")),
URI.create(env.getArgument("toURI")))
URI.create(env.getArgument("toURI"))
)
)
.dataFetcher("fsWriteFileStringContent",
env -> getService(env).writeFileContent(
Expand All @@ -90,4 +109,13 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
)
;
}

@Override
public void addServlets(CBApplication application, DBWServletContext servletContext) throws DBException {
servletContext.addServlet(
"fileSystems",
new WebFSServlet(application, getServiceImpl()),
application.getServicesURI() + "fs-data/*"
);
}
}
Loading

0 comments on commit 4ae0748

Please sign in to comment.