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-5762 add simple tests for data transfer api #2962

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
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 @@ -102,6 +102,7 @@ protected static DBWBindingContext getBindingContext(DataFetchingEnvironment env
return GraphQLEndpoint.getBindingContext(env);
}

@NotNull
protected static WebSession getWebSession(DataFetchingEnvironment env) throws DBWebException {
return CBPlatform.getInstance().getSessionManager().getWebSession(
getServletRequest(env), getServletResponse(env));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
import com.google.gson.GsonBuilder;
import io.cloudbeaver.model.app.WebApplication;
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 jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.json.JSONUtils;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,21 @@ public class WebSQLContextInfo implements WebSessionProvider {

private static final Log log = Log.getLog(WebSQLContextInfo.class);

@NotNull
private final transient WebSQLProcessor processor;
@NotNull
private final String id;
private final String projectId;
private final Map<String, WebSQLResultsInfo> resultInfoMap = new HashMap<>();

private final AtomicInteger resultId = new AtomicInteger();

public WebSQLContextInfo(
WebSQLProcessor processor, String id, String catalogName, String schemaName, String projectId
@NotNull WebSQLProcessor processor,
@NotNull String id,
String catalogName,
String schemaName,
String projectId
) throws DBCException {
this.processor = processor;
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private WebDataFormat getDataFormat(DataFetchingEnvironment env) {
}

@NotNull
public static WebSQLConfiguration getSQLConfiguration(WebSession webSession) {
private static WebSQLConfiguration getSQLConfiguration(WebSession webSession) {
return webSession.getAttribute("sqlConfiguration", cfg -> new WebSQLConfiguration(), WebSQLConfiguration::dispose);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Bundle-Release-Date: 20241021
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Export-Package: io.cloudbeaver.service.data.transfer.impl
Require-Bundle: io.cloudbeaver.server,
org.jkiss.dbeaver.data.transfer,
org.jkiss.dbeaver.data.transfer;visibility:=reexport,
org.jkiss.dbeaver.registry
Automatic-Module-Name: io.cloudbeaver.service.data.transfer
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.cloudbeaver.service.sql.WebSQLProcessor;
import io.cloudbeaver.service.sql.WebSQLResultsInfo;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;

import java.nio.file.Path;
import java.util.List;
Expand All @@ -37,33 +38,40 @@
*/
public interface DBWServiceDataTransfer extends DBWService {

@NotNull

Check warning on line 41 in server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java#L41

Missing a Javadoc comment.
@WebAction
List<WebDataTransferStreamProcessor> getAvailableStreamProcessors(WebSession session) throws DBWebException;
List<WebDataTransferStreamProcessor> getAvailableStreamProcessors(@NotNull WebSession session) throws DBWebException;

@NotNull

Check warning on line 45 in server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java#L45

Missing a Javadoc comment.
@WebAction
List<WebDataTransferStreamProcessor> getAvailableImportStreamProcessors(WebSession session) throws DBWebException;
List<WebDataTransferStreamProcessor> getAvailableImportStreamProcessors(@NotNull WebSession session) throws DBWebException;

@NotNull

Check warning on line 49 in server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java#L49

Missing a Javadoc comment.
@WebAction
WebAsyncTaskInfo dataTransferExportDataFromContainer(
WebSQLProcessor sqlProcessor,
String containerNodePath,
WebDataTransferParameters parameters) throws DBWebException;
@NotNull WebSQLProcessor sqlProcessor,
@NotNull String containerNodePath,
@NotNull WebDataTransferParameters parameters) throws DBWebException;

@NotNull

Check warning on line 56 in server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java#L56

Missing a Javadoc comment.
@WebAction
WebAsyncTaskInfo asyncImportDataContainer(
@NotNull String processorId,
@NotNull Path path,
@NotNull WebSQLResultsInfo webSQLResultsInfo,
@NotNull WebSession webSession) throws DBWebException;

@NotNull

Check warning on line 64 in server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java#L64

Missing a Javadoc comment.
@WebAction
WebAsyncTaskInfo dataTransferExportDataFromResults(
WebSQLContextInfo sqlContextInfo,
String resultsId,
WebDataTransferParameters parameters) throws DBWebException;
@NotNull WebSQLContextInfo sqlContextInfo,
@NotNull String resultsId,
@NotNull WebDataTransferParameters parameters) throws DBWebException;

@Nullable

Check warning on line 71 in server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java#L71

Missing a Javadoc comment.
@WebAction
Boolean dataTransferRemoveDataFile(WebSession session, String dataFileId) throws DBWebException;
Boolean dataTransferRemoveDataFile(@NotNull WebSession session, @NotNull String dataFileId) throws DBWebException;

@NotNull

Check warning on line 75 in server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/DBWServiceDataTransfer.java#L75

Missing a Javadoc comment.
WebDataTransferDefaultExportSettings defaultExportSettings();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
import io.cloudbeaver.service.DBWServiceBindingServlet;
import io.cloudbeaver.service.DBWServletContext;
import io.cloudbeaver.service.WebServiceBindingBase;
import io.cloudbeaver.service.data.transfer.impl.WebDataTransferImportServlet;
import io.cloudbeaver.service.data.transfer.impl.WebDataTransferParameters;
import io.cloudbeaver.service.data.transfer.impl.WebDataTransferServlet;
import io.cloudbeaver.service.data.transfer.impl.WebServiceDataTransfer;
import io.cloudbeaver.service.data.transfer.impl.WebDataTransferImportServlet;
import io.cloudbeaver.service.sql.WebServiceBindingSQL;
import org.jkiss.dbeaver.DBException;

/**
* Web service implementation
*/
public class WebServiceBindingDataTransfer extends WebServiceBindingBase<DBWServiceDataTransfer> implements DBWServiceBindingServlet<CBApplication> {
public class WebServiceBindingDataTransfer extends WebServiceBindingBase<DBWServiceDataTransfer>
implements DBWServiceBindingServlet<CBApplication<?>> {

public WebServiceBindingDataTransfer() {
super(DBWServiceDataTransfer.class, new WebServiceDataTransfer(), "schema/service.data.transfer.graphqls");
Expand Down Expand Up @@ -65,7 +66,7 @@ public void bindWiring(DBWBindingContext model) {
}

@Override
public void addServlets(CBApplication application, DBWServletContext servletContext) throws DBException {
public void addServlets(CBApplication<?> application, DBWServletContext servletContext) throws DBException {
if (!application.isMultiuser()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import jakarta.servlet.annotation.MultipartConfig;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.json.JSONUtils;

Expand All @@ -50,21 +51,19 @@
public class WebDataTransferImportServlet extends WebServiceServletBase {

private static final Log log = Log.getLog(WebDataTransferImportServlet.class);
public static final String ECLIPSE_JETTY_MULTIPART_CONFIG = "org.eclipse.jetty.multipartConfig";
private static final String ECLIPSE_JETTY_MULTIPART_CONFIG = "org.eclipse.jetty.multipartConfig";
private final DBWServiceDataTransfer dbwServiceDataTransfer;

DBWServiceDataTransfer dbwServiceDataTransfer;


public WebDataTransferImportServlet(CBApplication application, DBWServiceDataTransfer dbwServiceDataTransfer) {
public WebDataTransferImportServlet(@NotNull CBApplication<?> application, @NotNull DBWServiceDataTransfer dbwServiceDataTransfer) {
super(application);
this.dbwServiceDataTransfer = dbwServiceDataTransfer;
}

@Override
protected void processServiceRequest(
WebSession session,
HttpServletRequest request,
HttpServletResponse response
WebSession session,
HttpServletRequest request,
HttpServletResponse response
) throws IOException, DBWebException {
if (!session.isAuthorizedInSecurityManager()) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Import for users only");
Expand Down Expand Up @@ -108,7 +107,7 @@ protected void processServiceRequest(
}

WebAsyncTaskInfo asyncImportDataContainer =
dbwServiceDataTransfer.asyncImportDataContainer(processorId, filePath, webSQLResultsInfo, session);
dbwServiceDataTransfer.asyncImportDataContainer(processorId, filePath, webSQLResultsInfo, session);
response.setContentType(CBConstants.APPLICATION_JSON);
Map<String, Object> parameters = new LinkedHashMap<>();
parameters.put("id", asyncImportDataContainer.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
*/
package io.cloudbeaver.service.data.transfer.impl;

import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.data.json.JSONUtils;

import java.util.Map;

public class WebDataTransferOutputSettings {
private final boolean insertBom;
@Nullable
private final String encoding;
@Nullable
private final String timestampPattern;
private final boolean compress;
@Nullable
private final String fileName;

public WebDataTransferOutputSettings(Map<String, Object> outputSettings) {
Expand All @@ -35,7 +39,13 @@ public WebDataTransferOutputSettings(Map<String, Object> outputSettings) {
this.fileName = JSONUtils.getString(outputSettings, "fileName");
}

public WebDataTransferOutputSettings(boolean insertBom, String encoding, String timestampPattern, boolean compress, String fileName) {
public WebDataTransferOutputSettings(
boolean insertBom,
@Nullable String encoding,
@Nullable String timestampPattern,
boolean compress,
@Nullable String fileName
) {
this.insertBom = insertBom;
this.encoding = encoding;
this.timestampPattern = timestampPattern;
Expand All @@ -47,10 +57,12 @@ public boolean isInsertBom() {
return insertBom;
}

@Nullable
public String getEncoding() {
return encoding;
}

@Nullable
public String getTimestampPattern() {
return timestampPattern;
}
Expand All @@ -59,6 +71,7 @@ public boolean isCompress() {
return compress;
}

@Nullable
public String getFileName() {
return fileName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,53 @@
package io.cloudbeaver.service.data.transfer.impl;

import io.cloudbeaver.service.sql.WebSQLDataFilter;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.data.json.JSONUtils;

import java.util.Map;

public class WebDataTransferParameters {

private String processorId;
private Map<String, Object> dbProducerSettings;
private Map<String, Object> processorProperties;
private WebSQLDataFilter filter;
private WebDataTransferOutputSettings outputSettings;

public WebDataTransferParameters() {
}
@NotNull
private final String processorId;
@NotNull
private final Map<String, Object> dbProducerSettings;
@NotNull
private final Map<String, Object> processorProperties;
@NotNull
private final WebSQLDataFilter filter;
@NotNull
private final WebDataTransferOutputSettings outputSettings;

public WebDataTransferParameters(Map<String, Object> params) {
this.processorId = JSONUtils.getString(params, "processorId");
this.processorId = JSONUtils.getString(params, "processorId", "");
this.dbProducerSettings = JSONUtils.getObject(params, "settings");
this.processorProperties = JSONUtils.getObject(params, "processorProperties");
this.filter = new WebSQLDataFilter(JSONUtils.getObject(params, "filter"));
this.outputSettings = new WebDataTransferOutputSettings(JSONUtils.getObject(params, "outputSettings"));
}

@NotNull
public String getProcessorId() {
return processorId;
}

public void setProcessorId(String processorId) {
this.processorId = processorId;
}

@NotNull
public Map<String, Object> getDbProducerSettings() {
return dbProducerSettings;
}

public void setDbProducerSettings(Map<String, Object> dbProducerSettings) {
this.dbProducerSettings = dbProducerSettings;
}

@NotNull
public Map<String, Object> getProcessorProperties() {
return processorProperties;
}

public void setProcessorProperties(Map<String, Object> processorProperties) {
this.processorProperties = processorProperties;
}

@NotNull
public WebSQLDataFilter getFilter() {
return filter;
}

public void setFilter(WebSQLDataFilter filter) {
this.filter = filter;
}

@NotNull
public WebDataTransferOutputSettings getOutputSettings() {
return outputSettings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.cloudbeaver.service.data.transfer.DBWServiceDataTransfer;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor;
Expand All @@ -34,15 +35,15 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;

public class WebDataTransferServlet extends WebServiceServletBase {

private static final Log log = Log.getLog(WebDataTransferServlet.class);

@NotNull
private final DBWServiceDataTransfer dtManager;

public WebDataTransferServlet(CBApplication application, DBWServiceDataTransfer dtManager) {
public WebDataTransferServlet(@NotNull CBApplication<?> application, @NotNull DBWServiceDataTransfer dtManager) {
super(application);
this.dtManager = dtManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package io.cloudbeaver.service.data.transfer.impl;

import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -26,7 +29,8 @@
public WebDataTransferSessionConfig() {
}

public WebDataTransferTaskConfig getTask(String dataFileId) {
@Nullable

Check warning on line 32 in server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/impl/WebDataTransferSessionConfig.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.data.transfer/src/io/cloudbeaver/service/data/transfer/impl/WebDataTransferSessionConfig.java#L32

Missing a Javadoc comment.
public WebDataTransferTaskConfig getTask(@NotNull String dataFileId) {
return tasks.get(dataFileId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

public class WebDataTransferStreamProcessor {

@NotNull
private final WebSession session;
@NotNull
private final DataTransferProcessorDescriptor processor;

public WebDataTransferStreamProcessor(WebSession session, DataTransferProcessorDescriptor processor) {
public WebDataTransferStreamProcessor(@NotNull WebSession session, @NotNull DataTransferProcessorDescriptor processor) {
this.session = session;
this.processor = processor;
}
Expand Down
Loading