mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-3516 add compress flag to the export settings (#1792)
* CB-3516 add compress flag to the export settings * CB-3516 add compression checkbox * CB-3516 zip export result download fix * CB-3516 fix zip name --------- Co-authored-by: naumov <iamemptyhuh@gmail.com>
This commit is contained in:
co-authored by
naumov
parent
a571eeef8e
commit
0c981a67f4
+2
@@ -18,12 +18,14 @@ input DataTransferOutputSettingsInput {
|
||||
insertBom: Boolean
|
||||
encoding: String
|
||||
timestampPattern: String
|
||||
compress: Boolean
|
||||
}
|
||||
|
||||
type DataTransferOutputSettings {
|
||||
insertBom: Boolean!
|
||||
encoding: String!
|
||||
timestampPattern: String!
|
||||
compress: Boolean!
|
||||
}
|
||||
|
||||
type DataTransferDefaultExportSettings {
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@ public class WebDataTransferDefaultExportSettings {
|
||||
this.outputSettings = new WebDataTransferOutputSettings(
|
||||
false,
|
||||
defConsumerSettings.getOutputEncoding(),
|
||||
defConsumerSettings.getOutputTimestampPattern()
|
||||
defConsumerSettings.getOutputTimestampPattern(),
|
||||
defConsumerSettings.isCompressResults()
|
||||
);
|
||||
this.supportedEncodings = Charset.availableCharsets().keySet();
|
||||
}
|
||||
|
||||
+8
-1
@@ -24,17 +24,20 @@ public class WebDataTransferOutputSettings {
|
||||
private final boolean insertBom;
|
||||
private final String encoding;
|
||||
private final String timestampPattern;
|
||||
private final boolean compress;
|
||||
|
||||
public WebDataTransferOutputSettings(Map<String, Object> outputSettings) {
|
||||
this.insertBom = JSONUtils.getBoolean(outputSettings, "insertBom", false);
|
||||
this.encoding = JSONUtils.getString(outputSettings, "encoding");
|
||||
this.timestampPattern = JSONUtils.getString(outputSettings, "timestampPattern");
|
||||
this.compress = JSONUtils.getBoolean(outputSettings, "compress", false);
|
||||
}
|
||||
|
||||
public WebDataTransferOutputSettings(boolean insertBom, String encoding, String timestampPattern) {
|
||||
public WebDataTransferOutputSettings(boolean insertBom, String encoding, String timestampPattern, boolean compress) {
|
||||
this.insertBom = insertBom;
|
||||
this.encoding = encoding;
|
||||
this.timestampPattern = timestampPattern;
|
||||
this.compress = compress;
|
||||
}
|
||||
|
||||
public boolean isInsertBom() {
|
||||
@@ -48,4 +51,8 @@ public class WebDataTransferOutputSettings {
|
||||
public String getTimestampPattern() {
|
||||
return timestampPattern;
|
||||
}
|
||||
|
||||
public boolean isCompress() {
|
||||
return compress;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ public class WebDataTransferServlet extends WebServiceServletBase {
|
||||
} else {
|
||||
fileName = taskInfo.getDataFileId();
|
||||
}
|
||||
|
||||
fileName = WebDataTransferUtils.normalizeFileName(fileName, taskInfo.getParameters().getOutputSettings());
|
||||
Path dataFile = taskInfo.getDataFile();
|
||||
session.addInfoMessage("Download data ...");
|
||||
response.setHeader("Content-Type", processor.getContentType());
|
||||
|
||||
+8
@@ -17,6 +17,7 @@
|
||||
package io.cloudbeaver.service.data.transfer.impl;
|
||||
|
||||
import io.cloudbeaver.model.session.WebSession;
|
||||
import org.jkiss.code.NotNull;
|
||||
import org.jkiss.dbeaver.Log;
|
||||
import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor;
|
||||
import org.jkiss.dbeaver.tools.transfer.registry.DataTransferProcessorDescriptor;
|
||||
@@ -33,6 +34,13 @@ class WebDataTransferUtils {
|
||||
return CommonUtils.isEmpty(ext) ? "data" : ext;
|
||||
}
|
||||
|
||||
public static String normalizeFileName(
|
||||
@NotNull String fileName,
|
||||
@NotNull WebDataTransferOutputSettings outputSettings
|
||||
) {
|
||||
return outputSettings.isCompress() ? fileName + ".zip" : fileName;
|
||||
}
|
||||
|
||||
public static WebDataTransferSessionConfig getSessionDataTransferConfig(WebSession session) {
|
||||
return session.getAttribute("dataTransfer", x -> new WebDataTransferSessionConfig(), WebDataTransferSessionConfig::deleteExportFiles);
|
||||
}
|
||||
|
||||
+7
-2
@@ -173,12 +173,16 @@ public class WebServiceDataTransfer implements DBWServiceDataTransfer {
|
||||
}
|
||||
throw new DBException("Error exporting data", e);
|
||||
}
|
||||
WebDataTransferTaskConfig taskConfig = new WebDataTransferTaskConfig(exportFile, parameters);
|
||||
Path finallyExportFile = parameters.getOutputSettings().isCompress()
|
||||
? exportFile.resolveSibling(WebDataTransferUtils.normalizeFileName(
|
||||
exportFile.getFileName().toString(), parameters.getOutputSettings()))
|
||||
: exportFile;
|
||||
WebDataTransferTaskConfig taskConfig = new WebDataTransferTaskConfig(finallyExportFile, parameters);
|
||||
String exportFileName = CommonUtils.escapeFileName(CommonUtils.truncateString(dataContainer.getName(), 32));
|
||||
taskConfig.setExportFileName(exportFileName);
|
||||
WebDataTransferUtils.getSessionDataTransferConfig(sqlProcessor.getWebSession()).addTask(taskConfig);
|
||||
|
||||
result = exportFile.getFileName().toString();
|
||||
result = finallyExportFile.getFileName().toString();
|
||||
} catch (Throwable e) {
|
||||
throw new InvocationTargetException(e);
|
||||
} finally {
|
||||
@@ -223,6 +227,7 @@ public class WebServiceDataTransfer implements DBWServiceDataTransfer {
|
||||
|
||||
WebDataTransferOutputSettings outputSettings = parameters.getOutputSettings();
|
||||
settings.setOutputEncodingBOM(outputSettings.isInsertBom());
|
||||
settings.setCompressResults(outputSettings.isCompress());
|
||||
if (!CommonUtils.isEmpty(outputSettings.getEncoding())) {
|
||||
settings.setOutputEncoding(outputSettings.getEncoding());
|
||||
}
|
||||
|
||||
+8
-7
@@ -1,10 +1,11 @@
|
||||
query getDataTransferDefaultParameters {
|
||||
settings: dataTransferDefaultExportSettings {
|
||||
outputSettings {
|
||||
insertBom
|
||||
encoding
|
||||
timestampPattern
|
||||
}
|
||||
supportedEncodings
|
||||
settings: dataTransferDefaultExportSettings {
|
||||
outputSettings {
|
||||
insertBom
|
||||
encoding
|
||||
timestampPattern
|
||||
compress
|
||||
}
|
||||
supportedEncodings
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,12 +346,14 @@ export interface DataTransferDefaultExportSettings {
|
||||
}
|
||||
|
||||
export interface DataTransferOutputSettings {
|
||||
compress: Scalars['Boolean'];
|
||||
encoding: Scalars['String'];
|
||||
insertBom: Scalars['Boolean'];
|
||||
timestampPattern: Scalars['String'];
|
||||
}
|
||||
|
||||
export interface DataTransferOutputSettingsInput {
|
||||
compress?: InputMaybe<Scalars['Boolean']>;
|
||||
encoding?: InputMaybe<Scalars['String']>;
|
||||
insertBom?: InputMaybe<Scalars['Boolean']>;
|
||||
timestampPattern?: InputMaybe<Scalars['String']>;
|
||||
@@ -2412,7 +2414,7 @@ export type ExportDataFromResultsQuery = { taskInfo: { id: string, name?: string
|
||||
export type GetDataTransferDefaultParametersQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type GetDataTransferDefaultParametersQuery = { settings: { supportedEncodings: Array<string>, outputSettings: { insertBom: boolean, encoding: string, timestampPattern: string } } };
|
||||
export type GetDataTransferDefaultParametersQuery = { settings: { supportedEncodings: Array<string>, outputSettings: { insertBom: boolean, encoding: string, timestampPattern: string, compress: boolean } } };
|
||||
|
||||
export type GetDataTransferProcessorsQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
@@ -3974,6 +3976,7 @@ export const GetDataTransferDefaultParametersDocument = `
|
||||
insertBom
|
||||
encoding
|
||||
timestampPattern
|
||||
compress
|
||||
}
|
||||
supportedEncodings
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import styled, { css } from 'reshadow';
|
||||
|
||||
import { BASE_CONTAINERS_STYLES, Combobox, Container, FieldCheckbox, Loader, useResource } from '@cloudbeaver/core-blocks';
|
||||
import { BASE_CONTAINERS_STYLES, Combobox, Container, FieldCheckbox, Loader, useResource, useTranslate } from '@cloudbeaver/core-blocks';
|
||||
import type { DataTransferOutputSettings } from '@cloudbeaver/core-sdk';
|
||||
|
||||
import { DefaultExportOutputSettingsResource } from './DefaultExportOutputSettingsResource';
|
||||
@@ -24,6 +24,8 @@ interface Props {
|
||||
}
|
||||
|
||||
export const OutputOptionsForm = observer(function OutputOptionsForm(props: Props) {
|
||||
const translate = useTranslate();
|
||||
|
||||
const resource = useResource(OutputOptionsForm, DefaultExportOutputSettingsResource, undefined);
|
||||
|
||||
return (
|
||||
@@ -44,9 +46,14 @@ export const OutputOptionsForm = observer(function OutputOptionsForm(props: Prop
|
||||
<Combobox name="encoding" state={props.outputSettings} items={data.supportedEncodings} tiny searchable>
|
||||
Encoding
|
||||
</Combobox>
|
||||
<FieldCheckbox name="insertBom" state={props.outputSettings} small>
|
||||
Insert BOM
|
||||
</FieldCheckbox>
|
||||
<Container vertical gap>
|
||||
<FieldCheckbox name="insertBom" state={props.outputSettings} small>
|
||||
Insert BOM
|
||||
</FieldCheckbox>
|
||||
<FieldCheckbox name="compress" state={props.outputSettings} small>
|
||||
{translate('data_transfer_output_settings_compress')}
|
||||
</FieldCheckbox>
|
||||
</Container>
|
||||
</Container>
|
||||
</Container>,
|
||||
);
|
||||
|
||||
@@ -13,5 +13,7 @@ export default [
|
||||
['data_transfer_exporting_table', 'Table:'],
|
||||
['data_transfer_exporting_sql', 'SQL:'],
|
||||
['data_transfer_format_settings', 'Format'],
|
||||
|
||||
['data_transfer_output_settings', 'Output'],
|
||||
['data_transfer_output_settings_compress', 'Compression'],
|
||||
];
|
||||
|
||||
@@ -11,4 +11,6 @@ export default [
|
||||
['data_transfer_notification_delete', 'Elimina'],
|
||||
['data_transfer_exporting_table', 'Tabella:'],
|
||||
['data_transfer_exporting_sql', 'SQL:'],
|
||||
|
||||
['data_transfer_output_settings_compress', 'Compression'],
|
||||
];
|
||||
|
||||
@@ -12,4 +12,6 @@ export default [
|
||||
['data_transfer_notification_delete', 'Удалить'],
|
||||
['data_transfer_exporting_table', 'Таблица:'],
|
||||
['data_transfer_exporting_sql', 'SQL:'],
|
||||
|
||||
['data_transfer_output_settings_compress', 'Сжатие'],
|
||||
];
|
||||
|
||||
@@ -12,4 +12,6 @@ export default [
|
||||
['data_transfer_notification_delete', '删除'],
|
||||
['data_transfer_exporting_table', '表:'],
|
||||
['data_transfer_exporting_sql', 'SQL:'],
|
||||
|
||||
['data_transfer_output_settings_compress', 'Compression'],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user