帆软决策平台数据连接界面库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1764 lines
87 KiB

import { shortcut } from '@core/core';
import { Collapse, EVENT_CHANGE } from 'src/modules/components/collapse/collapse';
import { FormItem } from '../../components/form_item/form_item';
import { Connection, ConnectionJDBC, ConnectionPoolJDBC } from 'src/modules/crud/crud.typings';
import { connectionType } from '@constants/env';
import { CONNECT_CHARSET, CONNECTION_LAYOUT, INT_MAX_VALUE, INT_MIN_VALUE, CONNECT_SSH_TYPE, CONNECT_SSL_TYPE, YES_OR_NO } from '@constants/constant';
import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo, splitUrl } from '../../../../app.service';
import { DatabaseType } from 'src/modules/app.typings';
import { TextChecker } from '../../../../components/text_checker/text_checker';
import { FileChooser } from '../../../../components/file_chooser/file_chooser';
import { ApiFactory } from 'src/modules/crud/apiFactory';
import { Editor, Label, TextAreaEditor, TextEditor, TextValueCombo, VerticalLayout, MultiSelectItem } from '@fui/core';
import { DriverSelector } from '../../components/driverselector/driverselector';
import { FileUpload } from '../../../../components/file_upload/file_upload';
import { TipsCombo } from '../../../../components/tips_combo/tips_combo';
const api = new ApiFactory().create();
const EDITOR_WIDTH = 300, EDITOR_HEIGHT = 20;
@shortcut()
export class FormJdbc extends BI.Widget {
static xtype = 'dec.dcm.maintain.form.jdbc';
props = {
formData: {} as Connection,
};
oldPassword = '';
oldSshSecret = '';
databaseType: DatabaseType;
allDatabaseTypes = getAllDatabaseTypes();
parallelLoadSet: VerticalLayout;
hdfsSet: VerticalLayout;
sshSet: VerticalLayout;
sshForm: VerticalLayout;
sslSet: VerticalLayout;
sslForm: VerticalLayout;
advancedSet: VerticalLayout;
formUser: FormItem;
formPassword: FormItem;
formPrincipal: FormItem;
formKeyPath: FormItem;
formKrb5File: FormItem;
labelTips: Label;
schemaForm: FormItem;
form = {
connectionName: null,
version: null,
driver: null,
catalog: null,
database: null,
host: null,
port: null,
user: null,
password: null,
authType: null,
principal: null,
keyPath: null,
krb5Path: null,
originalCharsetName: null,
schema: null,
url: null,
initialSize: null,
maxActive: null,
maxWait: null,
// ssh
usingSsh: null,
sshIp: null,
sshPort: null,
sshUser: null,
sshType: null,
sshPrivateKeyPathForm: null,
sshPrivateKeyPath: null,
sshSecretForm: null,
sshSecret: null,
// ssl
usingSsl: null,
caCertificate: null,
verifyCa: null,
sslClientPrivateKey: null,
sslClientCertificate: null,
// more
validationQuery: null,
testOnBorrow: null,
testOnReturn: null,
testWhileIdle: null,
timeBetweenEvictionRunsMillis: null,
numTestsPerEvictionRun: null,
minIdle: null,
minEvictableIdleTimeMillis: null,
fetchSize: null,
// 并行装载
parallelLoad: {
serverAddress: '',
isReuseTemporaryTable: 0,
filePiecesLimit: null,
fileSizeLimit: null,
},
// HDFS
hdfs: {
hdfsAddress: null,
}
};
render() {
const { connectionName, connectionData } = this.options.formData;
const {
driver,
driverSource,
user,
password,
originalCharsetName,
schema,
url,
connectionPoolAttr,
database,
authType,
principal,
keyPath,
krb5Path,
fetchSize,
// ssh
usingSsh = false,
sshIp, // sshIp默认值在表单那用||设置,因为在这可能是空字符串,解构默认值没用
sshPort = 22,
sshUser = '',
sshType = CONNECT_SSH_TYPE[0].value,
sshPrivateKeyPath = '',
sshSecret = '',
// ssl
usingSsl = false,
caCertificate = '',
verifyCa = false,
sslClientPrivateKey = '',
sslClientCertificate = '',
// 并行装载
parallelLoad,
// HDFS
hdfs,
} = connectionData as ConnectionJDBC;
this.oldPassword = password;
this.oldSshSecret = sshSecret;
!BI.isUndefined(principal) && this.initPrincipals(keyPath, principal);
const {
initialSize,
maxActive,
maxWait,
validationQuery,
testOnBorrow,
testOnReturn,
testWhileIdle,
timeBetweenEvictionRunsMillis,
numTestsPerEvictionRun,
minIdle,
minEvictableIdleTimeMillis,
} = connectionPoolAttr as ConnectionPoolJDBC;
const databaseType = getJdbcDatabaseType(database, driver);
this.databaseType = databaseType;
const { host, port, catalog, databaseName, version } = resolveUrlInfo(url, database);
this.version = !BI.isUndefined(databaseType.versions) ? (version ?? databaseType.versions[0]) : version;
const { hgap, vgap } = CONNECTION_LAYOUT;
const valueRangeConfig = {
errorText: BI.i18nText('Dec-Dcm_Connection_Value_Out_Range'),
checker: (value: string) => this.checkValueRange(value),
autoFix: true,
};
return {
type: BI.VerticalLayout.xtype,
hgap,
vgap,
items: [
// 数据连接名称
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Name'),
forms: [
{
type: TextChecker.xtype,
$value: 'connection-name',
width: EDITOR_WIDTH,
value: connectionName,
allowBlank: true,
ref: (_ref: TextChecker) => {
this.form.connectionName = _ref;
},
watermark: BI.i18nText('Dec-Dcm_Data_Connections'),
},
],
},
// 版本
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Basic_Version'),
invisible: BI.isUndefined(databaseType.versions),
forms: [
{
type: BI.TextValueCombo.xtype,
width: EDITOR_WIDTH,
value: this.version,
items: () => databaseType.versions.map(item => {
return {
text: BI.i18nText('Dec-Migration_Database_Version', item),
value: item,
}
}),
ref: (_ref: TextValueCombo) => {
this.form.version = _ref;
},
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: () => {
const version = this.form.version.getValue()[0];
this.version = version;
this.sslCollapse.setCollapse(true);
this.sslCollapse.setVisible(this.getSslSetEnabled());
!BI.isUndefined(databaseType.hasSchemas) && this.schemaForm.setVisible(databaseType.hasSchemas[version]);
this.form.driver.setDefaultDrivers(version);
},
},
],
},
],
},
// 驱动
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Driver'),
forms: [
{
type: DriverSelector.xtype,
ref: (_ref: DriverSelector) => {
this.form.driver = _ref;
},
driver,
driverSource,
connectionData,
version: this.version,
listeners: [
{
eventName: 'EVENT_CHANGE',
action: () => {
const value = this.form.driver.getValue();
const connectionData = this.options.formData.connectionData as ConnectionJDBC;
const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver);
// DEC-2020
const url = (connectionType.urls && connectionType.urls[value.driver]) || connectionType.url;
this.form.url.setValue(url);
const urlInfo = resolveUrlInfo(url, connectionData.database);
this.form.host.setValue(urlInfo.host);
this.form.database.setValue(urlInfo.databaseName);
this.form.port.setValue(urlInfo.port);
},
},
],
},
],
},
// catalog
{
type: FormItem.xtype,
name: 'catalog',
invisible: database !== 'starrocks',
forms: [
{
type: BI.TextEditor.xtype,
$value: 'database-catalog',
width: EDITOR_WIDTH,
allowBlank: true,
watermark: 'catalog',
value: catalog,
ref: (_ref: any) => {
this.form.catalog = _ref;
},
listeners: [
{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.onHostPortChange(databaseType);
},
},
],
},
],
},
// 数据库名称
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'),
forms: [
{
type: BI.TextEditor.xtype,
$value: 'database-name',
width: EDITOR_WIDTH,
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'),
value: databaseName,
ref: (_ref: any) => {
this.form.database = _ref;
},
listeners: [
{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.onHostPortChange(databaseType);
},
},
],
},
],
},
// 主机
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
forms: [
{
type: BI.TextEditor.xtype,
$value: 'database-host',
width: EDITOR_WIDTH,
allowBlank: true,
value: host,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
ref: (_ref: any) => {
this.form.host = _ref;
},
listeners: [
{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.onHostPortChange(databaseType);
},
},
],
},
],
},
// 端口
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
forms: [
{
type: TextChecker.xtype,
$value: 'database-port',
width: EDITOR_WIDTH,
allowBlank: true,
value: port,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.port = _ref;
},
listeners: [
{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.onHostPortChange(databaseType);
},
},
],
},
],
},
// 认证方式
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_AuthType'),
invisible: !databaseType.kerberos,
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'auth-type',
width: EDITOR_WIDTH,
value: authType,
ref: (_ref: TextValueCombo) => {
this.form.authType = _ref;
},
items: [
{
text: BI.i18nText('Dec-Dcm_Connection_Form_UserName_Password'),
value: '',
},
{
text: 'Kerberos',
value: 'kerberos',
},
],
listeners: [
{
eventName: BI.Combo.EVENT_CHANGE,
action: () => {
const type = this.form.authType.getValue()[0];
this.formPrincipal.setVisible(!!type);
this.formKeyPath.setVisible(!!type);
this.formKrb5File.setVisible(!!type);
this.form.krb5Path.setEnable(!type);
this.formUser.setVisible(!type);
this.formPassword.setVisible(!type);
},
},
],
},
],
},
// 用户名
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
invisible: !!authType,
ref: (_ref: FormItem) => {
this.formUser = _ref;
},
forms: [
{
type: BI.TextEditor.xtype,
$value: 'username',
width: EDITOR_WIDTH,
allowBlank: true,
value: user,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
ref: (_ref: TextEditor) => {
this.form.user = _ref;
},
},
],
},
// 密码
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
invisible: !!authType,
ref: (_ref: FormItem) => {
this.formPassword = _ref;
},
forms: [
{
type: BI.Editor.xtype,
$value: 'password',
cls: 'bi-border-bottom',
width: EDITOR_WIDTH,
height: EDITOR_HEIGHT,
allowBlank: true,
value: password,
inputType: 'password',
autocomplete: 'new-password',
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
ref: (_ref: Editor) => {
this.form.password = _ref;
},
},
],
},
// keytab密钥路径
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'),
invisible: !authType,
ref: (_ref: FormItem) => {
this.formKeyPath = _ref;
},
forms: [
{
type: FileUpload.xtype,
$value: 'key-path',
processId: "keytab",
allowBlank: true,
value: keyPath,
accept: '.keytab',
inter: '/v10/config/connection/upload/keytab?',
iconCls: "data-keytab-file",
watermark: BI.i18nText('Dec-Dcm_Connection_Form_KeyPath'),
ref: (_ref: FileUpload) => {
this.form.keyPath = _ref;
},
listeners: [
{
eventName: FileUpload.EVENT_CHECK_SUCCESS,
action: (value) => {
const principalsItems = BI.map(value.principals, function (index, item) {
return {
text: item,
value: item
}
})
this.form.principal.populate(principalsItems);
this.form.principal.setValue(principalsItems[0].value);
this.setKerberos();
this.form.krb5Path.setEnable(true);
},
}, {
eventName: FileUpload.EVENT_CLEAR_FILE,
action: () => {
this.form.krb5Path.setEnable(false);
this.form.principal.populate();
this.form.principal.setValue();
}
}
]
},
],
},
// 客户端principal
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Principal'),
invisible: !authType,
ref: (_ref: FormItem) => {
this.formPrincipal = _ref;
},
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'principal',
width: EDITOR_WIDTH,
value: principal,
ref: (_ref: TextEditor) => {
this.form.principal = _ref;
},
listeners: [
{
eventName: BI.Combo.EVENT_CHANGE,
action: () => {
this.changePrincipal();
this.setKerberos();
},
},
],
}
],
},
// krb5.conf文件
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Krb5File'),
invisible: !authType,
ref: (_ref: FormItem) => {
this.formKrb5File = _ref;
},
forms: [
{
type: FileUpload.xtype,
$value: 'krb5-file',
processId: "krb5Conf",
allowBlank: true,
value: krb5Path,
iconCls: "data-conf-file",
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Krb5File'),
ref: (_ref: FileUpload) => {
this.form.krb5Path = _ref;
},
inter: '/v10/config/connection/upload/krb5?',
accept: '.conf',
listeners: [
{
eventName: FileUpload.EVENT_CHECK_SUCCESS,
action: () => {
this.setKerberos();
},
}
]
}
]
},
// 编码
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'),
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'original-charset-name',
width: EDITOR_WIDTH,
value: originalCharsetName ? originalCharsetName : '',
items: CONNECT_CHARSET,
ref: (_ref: TextValueCombo) => {
this.form.originalCharsetName = _ref;
},
},
],
},
// 模式
{
type: FormItem.xtype,
invisible: BI.isUndefined(databaseType.hasSchemas) ? !databaseType.hasSchema : !databaseType.hasSchemas[this.version],
name: BI.i18nText('Dec-Dcm_Connection_Form_Pattern'),
forms: [
{
type: BI.VerticalLayout.xtype,
height: 55,
items: [
{
type: BI.FloatLeftLayout.xtype,
items: [
{
type: BI.TextButton.xtype,
cls: 'bi-high-light',
text: BI.i18nText('Dec-Dcm_Connection_Click_Connect_Database'),
handler: () => {
this.fireEvent('EVENT_TEST_CONNECTION');
},
},
{
type: BI.Label.xtype,
cls: 'bi-tips',
lgap: 3,
text: BI.i18nText('Dec-Dcm_Connection_Read_Mode_List'),
},
],
},
{
type: BI.TextValueCombo.xtype,
_tgap: 15,
$value: 'schema',
width: EDITOR_WIDTH,
disabled: true,
value: schema,
items: schema ? [{ text: schema, value: schema }] : [],
ref: (_ref: TextValueCombo) => {
this.form.schema = _ref;
},
},
],
},
],
ref: (_ref: FormItem) => {
this.schemaForm = _ref;
},
},
// 并行装载设置
{
type: Collapse.xtype,
invisible: BI.isNull(parallelLoad),
name: BI.i18nText('Dec-Dcm_Connection_Setting', BI.i18nText('Dec-Dcm_Connection_Parallel_Load')),
el: {
type: TipsCombo.xtype,
_lgap: 6,
el: {
type: BI.CenterAdaptLayout.xtype,
innerHgap: 15,
innerVgap: 10,
items: [
{
type: BI.Label.xtype,
text: BI.i18nText('Dec-Dcm_Connection_Setting_Tips', BI.i18nText('Dec-Dcm_Connection_Parallel_Load')),
},
/**
* FIXME: 帮助链接待提供
*/
{
type: BI.A.xtype,
href: '',
el: {
type: BI.Label.xtype,
text: BI.i18nText('Dec-BI_Help_Paper'),
}
}
]
}
},
listeners: [
{
eventName: EVENT_CHANGE,
action: (isCollapse: boolean) => {
this.parallelLoadSet.setVisible(!isCollapse);
}
}
]
},
{
type: BI.VerticalLayout.xtype,
invisible: true,
ref: (_ref: VerticalLayout) => {
this.parallelLoadSet = _ref;
},
items: [
{
// 服务器地址-节点1
type: FormItem.xtype,
name: `${BI.i18nText('Dec-Dcm_Connection_Server_Address')}-${BI.i18nText('Dec-Memory_Detection_Server_Cluster_Node', '1')}`,
_bgap: vgap,
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'server-cluster-node',
width: EDITOR_WIDTH,
value: parallelLoad?.serverAddress ?? '',
items: parallelLoad?.serverAddressItems || [],
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: (value: string) => {
this.form.parallelLoad.serverAddress = value;
}
}
]
},
],
},
{
// 复用临时表
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Reuse_Temporary_Table'),
_bgap: vgap,
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'reuse-temporary-table',
width: EDITOR_WIDTH,
value: parallelLoad?.reuseTemporaryTable ?? 0,
items: YES_OR_NO,
watermark: BI.i18nText('Dec-Dcm_Connection_Reuse_Temporary_Table'),
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: (value: number) => {
this.form.parallelLoad.isReuseTemporaryTable = value;
}
}
]
},
],
},
{
// 临时文件条数限制
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Temporary_File_Pieces_Limit'),
_bgap: vgap,
forms: [
{
type: BI.Editor.xtype,
$value: 'temporary-file-pieces-limit',
cls: 'bi-border-bottom',
width: EDITOR_WIDTH,
height: EDITOR_HEIGHT,
allowBlank: true,
value: parallelLoad?.filePiecesLimit ?? '',
watermark: BI.i18nText('Dec-Dcm_Connection_Temporary_File_Pieces_Limit'),
ref: (_ref: Editor) => {
this.form.parallelLoad.filePiecesLimit = _ref;
},
},
],
},
{
// 临时文件大小限制(MB)
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Temporary_File_Size_Limit'),
forms: [
{
type: BI.Editor.xtype,
$value: 'temporary-file-size-limit',
cls: 'bi-border-bottom',
width: EDITOR_WIDTH,
height: EDITOR_HEIGHT,
allowBlank: true,
value: parallelLoad?.fileSizeLimit ?? '',
watermark: BI.i18nText('Dec-Dcm_Connection_Temporary_File_Size_Limit'),
ref: (_ref: Editor) => {
this.form.parallelLoad.fileSizeLimit = _ref;
},
},
],
},
]
},
// HDFS设置
{
type: Collapse.xtype,
invisible: BI.isNull(hdfs),
name: BI.i18nText('Dec-Dcm_Connection_Setting', 'HDFS'),
el: {
type: TipsCombo.xtype,
_lgap: 6,
el: {
type: BI.CenterAdaptLayout.xtype,
innerHgap: 15,
innerVgap: 10,
items: [
{
type: BI.Label.xtype,
text: BI.i18nText('Dec-Dcm_Connection_Setting_Tips', 'HDFS'),
},
{
type: BI.A.xtype,
href: '',
el: {
type: BI.Label.xtype,
text: BI.i18nText('Dec-BI_Help_Paper'),
}
}
]
}
},
listeners: [
{
eventName: EVENT_CHANGE,
action: (isCollapse: boolean) => {
this.hdfsSet.setVisible(!isCollapse);
}
}
]
},
{
type: BI.VerticalLayout.xtype,
invisible: true,
ref: (_ref: VerticalLayout) => {
this.hdfsSet = _ref;
},
items: [
{
// HDFS地址
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Address', 'HDFS'),
forms: [
{
type: BI.Editor.xtype,
$value: 'hdfs-connection-address',
cls: 'bi-border-bottom',
width: EDITOR_WIDTH,
height: EDITOR_HEIGHT,
allowBlank: true,
value: hdfs?.hdfsAddress ?? '',
watermark: BI.i18nText('Dec-Dcm_Connection_Address', 'HDFS'),
ref: (_ref: Editor) => {
this.form.hdfs.hdfsAddress = _ref;
},
},
],
}
]
},
// 分隔线
{
type: BI.Layout.xtype,
cls: 'bi-border-top',
bgap: 8,
},
// 数据连接URL
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'),
forms: [
{
type: BI.TextEditor.xtype,
$value: 'database-url',
width: EDITOR_WIDTH,
allowBlank: true,
value: url,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_URL'),
ref: (_ref: TextEditor) => {
this.form.url = _ref;
},
listeners: [
{
eventName: 'EVENT_CHANGE',
action: () => {
const urlInfo = resolveUrlInfo(this.form.url.getValue(), database);
this.form.host.setValue(urlInfo.host);
this.form.catalog.setValue(urlInfo.catalog);
this.form.database.setValue(urlInfo.databaseName);
this.form.port.setValue(urlInfo.port);
},
},
],
},
],
},
// 最大活动连接数
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
forms: [
{
type: TextChecker.xtype,
$value: 'max-active',
width: EDITOR_WIDTH,
allowBlank: false,
value: maxActive,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Active'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.maxActive = _ref;
},
},
],
},
// 获取连接前检验
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Borrow'),
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'check',
width: EDITOR_WIDTH,
allowBlank: true,
value: testOnBorrow,
items: this.getBooleanItem(),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Borrow'),
ref: (_ref: TextValueCombo) => {
this.form.testOnBorrow = _ref;
},
},
],
},
// 校验语句
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'),
forms: [
{
type: BI.TextAreaEditor.xtype,
$value: 'validation-query',
cls: 'bi-border',
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query_Watermark'),
value: api.getPlain(validationQuery || ''),
width: EDITOR_WIDTH,
height: 100,
ref: (_ref: TextAreaEditor) => {
this.form.validationQuery = _ref;
},
},
],
},
// 最大等待时间
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
forms: [
{
type: TextChecker.xtype,
$value: 'max-wait',
width: EDITOR_WIDTH,
allowBlank: false,
value: maxWait,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Max_Wait'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.maxWait = _ref;
},
},
{
type: BI.Label.xtype,
lgap: 5,
height: CONNECTION_LAYOUT.labelHeight,
text: BI.i18nText('Dec-Dcm_Millisecond'),
},
],
},
// SSH设置
{
type: Collapse.xtype,
width: 100,
name: BI.i18nText('Dec-Dcm_Connection_Setting', 'SSH'),
listeners: [
{
eventName: EVENT_CHANGE,
action: (isCollapse: boolean) => {
this.sshSet.setVisible(!isCollapse);
},
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
ref: (_ref: VerticalLayout) => {
this.sshSet = _ref;
},
bgap: vgap,
invisible: true,
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Tunnel', 'SSH'),
forms: [
{
type: BI.MultiSelectItem.xtype,
ref: (_ref: MultiSelectItem) => {
this.form.usingSsh = _ref;
},
logic: { dynamic: true },
text: BI.i18nText('Dec-Basic_Use') + BI.i18nText('Dec-Dcm_Connection_Tunnel', 'SSH'),
selected: usingSsh,
listeners: [
{
eventName: BI.MultiSelectItem.EVENT_CHANGE,
action: () => {
const value = this.form.usingSsh.isSelected();
this.sshForm.setVisible(value);
},
},
],
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
ref: (_ref: VerticalLayout) => {
this.sshForm = _ref;
},
bgap: vgap,
invisible: !usingSsh,
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
forms: [
{
type: TextChecker.xtype,
ref: (_ref: TextChecker) => {
this.form.sshIp = _ref;
},
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
value: sshIp,
listeners: [
{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.form.sshSecret.setValue("");
}
}
]
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
forms: [
{
type: TextChecker.xtype,
ref: (_ref: TextChecker) => {
this.form.sshPort = _ref;
},
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
allowBlank: false,
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
value: String(sshPort || 22),
listeners: [
{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.form.sshSecret.setValue("");
}
}
]
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
forms: [
{
type: TextChecker.xtype,
ref: (_ref: TextChecker) => {
this.form.sshUser = _ref;
},
watermark: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
value: sshUser,
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_VerifyType'),
forms: [
{
type: BI.TextValueCombo.xtype,
ref: (_ref: TextValueCombo) => {
this.form.sshType = _ref;
},
width: EDITOR_WIDTH,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_VerifyType'),
items: CONNECT_SSH_TYPE,
value: sshType,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: () => {
const sshType = this.form.sshType.getValue()[0];
this.onSshTypeChange(sshType);
},
},
],
},
],
},
{
type: FormItem.xtype,
ref: (_ref: FormItem) => {
this.form.sshPrivateKeyPathForm = _ref;
},
name: BI.i18nText('Dec-Dcm_Connection_Form_PrivateKey'),
forms: [
{
type: FileChooser.xtype,
ref: (_ref: TextChecker) => {
this.form.sshPrivateKeyPath = _ref;
},
root: 'certificates',
watermark: BI.i18nText('Dec-Dcm_Connection_Form_PrivateKey'),
value: sshPrivateKeyPath,
},
],
},
{
type: FormItem.xtype,
ref: (ref: FormItem) => {
this.form.sshSecretForm = ref;
},
name: BI.i18nText(''),
forms: [
{
type: TextChecker.xtype,
ref: (_ref: TextChecker) => {
this.form.sshSecret = _ref;
},
watermark: BI.i18nText(''),
inputType: 'password',
autocomplete: 'new-password',
value: sshSecret,
},
],
},
],
},
},
],
},
},
// SSL设置
{
type: Collapse.xtype,
width: 100,
name: BI.i18nText('Dec-Dcm_Connection_Setting', 'SSL'),
invisible: !this.getSslSetEnabled(),
ref: (_ref: Collapse) => {
this.sslCollapse = _ref;
},
listeners: [
{
eventName: EVENT_CHANGE,
action: (isCollapse: boolean) => {
this.sslSet.setVisible(!isCollapse);
},
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
ref: (_ref: VerticalLayout) => {
this.sslSet = _ref;
},
bgap: vgap,
invisible: true,
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Tunnel', 'SSL'),
forms: [
{
type: BI.MultiSelectItem.xtype,
ref: (_ref: MultiSelectItem) => {
this.form.usingSsl = _ref;
},
logic: { dynamic: true },
text: BI.i18nText('Dec-Basic_Use') + BI.i18nText('Dec-Dcm_Connection_Tunnel', 'SSL'),
selected: usingSsl,
listeners: [
{
eventName: BI.MultiSelectItem.EVENT_CHANGE,
action: () => {
const value = this.form.usingSsl.isSelected();
this.sslForm.setVisible(value);
},
},
],
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
ref: (_ref: VerticalLayout) => {
this.sslForm = _ref;
},
bgap: vgap,
invisible: !usingSsl,
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_CA_Certificate'),
forms: [
{
type: FileChooser.xtype,
ref: (_ref: FileChooser) => {
this.form.caCertificate = _ref;
},
root: 'certificates',
watermark: BI.i18nText('Dec-Dcm_Connection_Form_CA_Certificate'),
value: caCertificate,
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Verify_CA_Certificate'),
forms: [
{
type: BI.TextValueCombo.xtype,
ref: (_ref: TextValueCombo) => {
this.form.verifyCa = _ref;
},
width: EDITOR_WIDTH,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Verify_CA_Certificate'),
items: this.getBooleanItem(),
value: verifyCa,
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Client') + BI.i18nText('Dec-Dcm_Connection_Form_SecretKey'),
forms: [
{
type: FileChooser.xtype,
ref: (_ref: FileChooser) => {
this.form.sslClientPrivateKey = _ref;
},
root: 'certificates',
watermark: BI.i18nText('Dec-Dcm_Connection_Client') + BI.i18nText('Dec-Dcm_Connection_Form_SecretKey'),
value: sslClientPrivateKey,
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Client') + BI.i18nText('Dec-Dcm_Connection_Form_Certificate'),
forms: [
{
type: FileChooser.xtype,
ref: (_ref: FileChooser) => {
this.form.sslClientCertificate = _ref;
},
root: 'certificates',
watermark: BI.i18nText('Dec-Dcm_Connection_Client') + BI.i18nText('Dec-Dcm_Connection_Form_Certificate'),
value: sslClientCertificate,
},
],
},
],
},
},
],
},
},
// 高级设置
{
type: Collapse.xtype,
width: 100,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_More_Setting'),
listeners: [
{
eventName: EVENT_CHANGE,
action: (isCollapse: boolean) => {
this.advancedSet.setVisible(!isCollapse);
},
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
vgap: vgap,
top: -15,
invisible: true,
ref: (_ref: VerticalLayout) => {
this.advancedSet = _ref;
},
items: [
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
forms: [
{
type: TextChecker.xtype,
$value: 'initial-size',
width: EDITOR_WIDTH,
allowBlank: false,
value: initialSize,
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
ref: (_ref: TextChecker) => {
this.form.initialSize = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'),
forms: [
{
type: TextChecker.xtype,
$value: 'min-idle',
width: EDITOR_WIDTH,
allowBlank: false,
value: minIdle,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Idle'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.minIdle = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'),
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'test-on-return',
width: EDITOR_WIDTH,
allowBlank: true,
value: testOnReturn,
items: this.getBooleanItem(),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_On_Return'),
ref: (_ref: TextValueCombo) => {
this.form.testOnReturn = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'),
forms: [
{
type: BI.TextValueCombo.xtype,
$value: 'test-while-idle',
width: EDITOR_WIDTH,
allowBlank: true,
value: testWhileIdle,
items: this.getBooleanItem(),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_While_Idle'),
ref: (_ref: TextValueCombo) => {
this.form.testWhileIdle = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
forms: [
{
type: TextChecker.xtype,
$value: 'test-between-evicition-millis',
width: EDITOR_WIDTH,
allowBlank: false,
value: timeBetweenEvictionRunsMillis,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Test_Between_Eviction_Millis'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Number'),
checker: (value: string) => this.checkNumber(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.timeBetweenEvictionRunsMillis = _ref;
},
},
{
type: BI.Label.xtype,
lgap: 5,
height: CONNECTION_LAYOUT.labelHeight,
text: BI.i18nText('Dec-Dcm_Millisecond'),
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
forms: [
{
type: TextChecker.xtype,
$value: 'test-pereviction-run-num',
width: EDITOR_WIDTH,
allowBlank: false,
value: numTestsPerEvictionRun,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Tests_PerEviction_Run_Num'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.numTestsPerEvictionRun = _ref;
},
},
],
},
{
type: FormItem.xtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
forms: [
{
type: TextChecker.xtype,
$value: 'min-evictable-idle-time-millis',
width: EDITOR_WIDTH,
allowBlank: false,
value: minEvictableIdleTimeMillis,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Min_Evictable_Idle_Time_Millis'),
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Integer'),
checker: (value: string) => this.checkInteger(value),
autoFix: true,
},
valueRangeConfig,
],
ref: (_ref: TextChecker) => {
this.form.minEvictableIdleTimeMillis = _ref;
},
},
{
type: BI.Label.xtype,
lgap: 5,
height: CONNECTION_LAYOUT.labelHeight,
text: BI.i18nText('BI-Basic_Seconds'),
},
],
},
{
el: {
type: BI.VerticalLayout.xtype,
cls: 'bi-border-top',
invisible: fetchSize < 0 && fetchSize !== -2,
items: [
{
el: {
type: FormItem.xtype,
name: 'Fetchsize',
forms: [
{
type: TextChecker.xtype,
$value: 'fetch-size',
width: EDITOR_WIDTH,
allowBlank: true,
value: fetchSize === -2 ? '' : fetchSize,
watermark: 'Fetchsize',
validationChecker: [
{
errorText: BI.i18nText('Dec-Dcm_Connection_Check_Fetch_Size_Range'),
checker: (value: string) =>
BI.isInteger(value) && BI.parseInt(value) >= 0 && BI.parseInt(value) <= 1000000,
autoFix: true,
},
],
ref: (_ref: TextChecker) => {
this.form.fetchSize = _ref;
},
},
],
},
vgap: 15,
},
],
},
},
],
},
},
],
};
}
public mounted() {
const sshType = this.form.sshType.getValue()[0];
this.onSshTypeChange(sshType);
this.setKerberos();
}
public setError(value: string) {
this.form.connectionName.setError(value);
}
private checkInteger(value: string) {
return /^[\d]+$/.test(value);
}
private checkNumber(value: string) {
return /^[(\-|\+)?\d]+$/.test(value);
}
private checkValueRange(value: string) {
return parseInt(value, 0) <= INT_MAX_VALUE && parseInt(value, 0) >= INT_MIN_VALUE;
}
private getDrivers() {
const connectionData = this.options.formData.connectionData as ConnectionJDBC;
const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver);
const drivers = connectionType.drivers
? connectionType.drivers.map((item) => {
return {
text: item,
value: item,
};
})
: [
{
text: connectionType.driver,
value: connectionType.driver,
},
];
if (!drivers.some((item) => item.text === connectionData.driver)) {
return [
{
text: connectionData.driver,
value: connectionData.driver,
},
...drivers,
];
}
return drivers;
}
private getBooleanItem() {
return [
{
text: BI.i18nText('Dec-Dcm_Yes'),
value: true,
},
{
text: BI.i18nText('Dec-Dcm_No'),
value: false,
},
];
}
private onHostPortChange(databaseType) {
const { urls, url } = databaseType;
const driver = this.form.driver.getValue();
const selectUrl = BI.get(urls, driver.driver) || url;
const host = this.form.host.getValue();
const port = this.form.port.getValue();
const catalog = this.form.catalog.getValue();
const database = this.form.database.getValue();
this.form.url.setValue(splitUrl(host, port, catalog, database, selectUrl));
}
private onSshTypeChange(sshType) {
const { privateKeyPathFormVisible, secretFormName } = CONNECT_SSH_TYPE.find((SSH_TYPE) => sshType === SSH_TYPE.value);
this.form.sshPrivateKeyPathForm.setVisible(privateKeyPathFormVisible);
this.form.sshSecretForm.setName(secretFormName);
this.form.sshSecret.setWatermark(secretFormName);
}
private getSslSetEnabled(): boolean {
const { databaseType } = this.databaseType;
return databaseType === 'mysql' || this.version === 'mysql';
}
public setSchemas(schemas: string[]) {
this.form.schema.setEnable(true);
if (schemas.length > 0) {
const value = this.form.schema.getValue()[0];
this.form.schema.populate(
schemas.map((item) => {
return {
text: item,
value: item,
};
})
);
this.form.schema.setValue(value && schemas.some((item) => item === value) ? value : schemas[0]);
}
}
public setKerberos() {
const KerberosParams = BI.extend({}, {
keytabPath: this.form.keyPath.getValue(),
krb5ConfPath: this.form.krb5Path.getValue(),
principal: this.form.principal.getValue()[0]
});
this.form.krb5Path.setFileInfo(KerberosParams);
this.form.keyPath.setFileInfo(KerberosParams);
}
public initPrincipals(keyPath, principal) {
let self = this;
api.getPrincipals(keyPath).then(res => {
const principalsItems = BI.map(res.data, function (index, item) {
return {
text: item,
value: item
}
});
self.form.principal.populate(principalsItems);
self.form.principal.setValue(principal);
})
}
public changePrincipal() {
let self = this;
const KerberosParams = BI.extend({}, {
keytabPath: this.form.keyPath.getValue(),
krb5ConfPath: this.form.krb5Path.getValue(),
principal: this.form.principal.getValue()[0]
});
api.changePrincipal(KerberosParams).then(res => {
self.form.keyPath.setValue(res.data.keytabPath);
self.form.krb5Path.setValue(res.data.krb5ConfPath);
});
}
public validation(): boolean {
const driver = this.form.driver.validation();
const sshSet = !this.form.usingSsh.isSelected() || BI.isNotEmptyString(this.form.sshPort.getValue());
return driver && sshSet;
}
public getSubmitValue(): Connection {
const connectionData = this.options.formData.connectionData as ConnectionJDBC;
const connectionPoolAttr = connectionData.connectionPoolAttr;
const originalCharsetName = this.form.originalCharsetName.getValue()[0] || '';
// TODO 获取表单数据这里待优化
const { parallelLoad, hdfs } = this.form;
return {
connectionType: connectionType.JDBC,
connectionId: this.form.connectionName.getValue(),
connectionName: this.form.connectionName.getValue(),
connectionData: <ConnectionJDBC>BI.extend({}, connectionData, {
database: connectionData.database,
connectionName: this.form.connectionName.getValue(),
...this.form.driver.getValue(),
url: this.form.url.getValue(),
user: this.form.user.getValue(),
password: this.oldPassword === this.form.password.getValue() ? this.oldPassword : api.getCipher(this.form.password.getValue()),
queryType: '',
newCharsetName: originalCharsetName ? 'gbk' : '', // 后台要求,originalCharsetName不为空时,newCharsetName为gbk
originalCharsetName,
schema: this.form.schema.getValue()[0],
host: this.form.host.getValue(),
authType: this.form.authType.getValue()[0] || '',
creator: Dec ? Dec.personal.username : '',
principal: this.form.principal.getValue()[0],
keyPath: this.form.keyPath.getValue(),
krb5Path: this.form.krb5Path.getValue(),
fetchSize: BI.isEmptyString(this.form.fetchSize.getValue()) ? -2 : BI.parseInt(this.form.fetchSize.getValue()),
// ssh
usingSsh: this.form.usingSsh.isSelected(),
// redirectPort: 0,
// redirectIp: '',
// sshKeepAlive: 10000,
// sshTimeOut: 10000,
sshIp: this.form.sshIp.getValue(),
sshPort: Number(this.form.sshPort.getValue()),
sshUser: this.form.sshUser.getValue(),
sshType: this.form.sshType.getValue()[0],
sshPrivateKeyPath: this.form.sshPrivateKeyPath.getValue(),
sshSecret: this.oldSshSecret === this.form.sshSecret.getValue() ? this.oldSshSecret : api.getCipher(this.form.sshSecret.getValue()),
// ssl
usingSsl: this.getSslSetEnabled() && this.form.usingSsl.isSelected(),
caCertificate: this.form.caCertificate.getValue(),
verifyCa: this.form.verifyCa.getValue()[0],
sslType: CONNECT_SSL_TYPE[0].value,
sslClientPrivateKey: this.form.sslClientPrivateKey.getValue(),
sslClientCertificate: this.form.sslClientCertificate.getValue(),
// 连接池
connectionPoolAttr: {
initialSize: this.form.initialSize.getValue(),
maxActive: this.form.maxActive.getValue(),
minIdle: this.form.minIdle.getValue(),
maxWait: this.form.maxWait.getValue(),
validationQuery: api.getCipher(this.form.validationQuery.getValue()),
testOnBorrow: BI.size(this.form.testOnBorrow.getValue()) > 0 ? this.form.testOnBorrow.getValue()[0] : connectionPoolAttr.testOnBorrow,
testOnReturn: BI.size(this.form.testOnReturn.getValue()) > 0 ? this.form.testOnReturn.getValue()[0] : connectionPoolAttr.testOnReturn,
testWhileIdle: BI.size(this.form.testWhileIdle.getValue()) > 0 ? this.form.testWhileIdle.getValue()[0] : connectionPoolAttr.testWhileIdle,
timeBetweenEvictionRunsMillis: this.form.timeBetweenEvictionRunsMillis.getValue(),
numTestsPerEvictionRun: this.form.numTestsPerEvictionRun.getValue(),
minEvictableIdleTimeMillis: this.form.minEvictableIdleTimeMillis.getValue(),
},
// 并行装载
parallelLoad: {
serverAddress: parallelLoad.serverAddress,
isReuseTemporaryTable: parallelLoad.isReuseTemporaryTable,
filePiecesLimit: parallelLoad.filePiecesLimit.getValue(),
fileSizeLimit: parallelLoad.fileSizeLimit.getValue(),
},
hdfs: {
hdfsAddress: hdfs.hdfsAddress.getValue(),
}
// HDFS
}),
};
}
}