|
|
|
import { Connection, ConnectionJDBC } from '../../../crud/crud.typings';
|
|
|
|
import { connectionType, errorCode } from '@constants/env';
|
|
|
|
import { DATA_BASE_DRIVER_LINK, JDBC_ODBC_DRIVER, JDBC_ODBC_DRIVER_HELP_LINK, DEFAULT_HELP_LINK } from '@constants/constant';
|
|
|
|
import { TestStatus } from '../../../components/test_status/test_status';
|
|
|
|
import { getJdbcDatabaseType } from '../../../app.service';
|
|
|
|
import { ApiFactory } from '../../../crud/apiFactory';
|
|
|
|
const api = new ApiFactory().create();
|
|
|
|
|
|
|
|
export function testConnection(value: Connection): Promise<string[]> {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let testStatus = null;
|
|
|
|
if (!value.connectionName) {
|
|
|
|
BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null'), {
|
|
|
|
level: 'error',
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const id = BI.UUID();
|
|
|
|
const testConnection = () => {
|
|
|
|
const formValue = value;
|
|
|
|
|
|
|
|
api.testConnection(formValue).then(re => {
|
|
|
|
if (re && re.errorCode) {
|
|
|
|
if (re.errorCode === DecCst.ErrorCode.NO_IP_AUTHORIZED) {
|
|
|
|
testStatus.setFail();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 判断是否是缺少驱动,如果缺少驱动则显示下载驱动的连接
|
|
|
|
if (api.isDriverError(re.errorCode)) {
|
|
|
|
if (formValue.connectionType === connectionType.JDBC) {
|
|
|
|
const driver = (formValue.connectionData as ConnectionJDBC).driver;
|
|
|
|
// DEC-14009 1.8以上版本JDK支持ODBC连接
|
|
|
|
if (driver === JDBC_ODBC_DRIVER) {
|
|
|
|
testStatus.setFail(re.errorMsg, driver, Dec.system[DecCst.Hyperlink.DECISION_HYPERLINK_CONFIG][JDBC_ODBC_DRIVER_HELP_LINK]);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const databaseType = (formValue.connectionData as ConnectionJDBC).database;
|
|
|
|
const databaseLink = BI.get(DATA_BASE_DRIVER_LINK.find(item => item.databaseType === databaseType), 'link', DEFAULT_HELP_LINK);
|
|
|
|
const link = BI.get(getJdbcDatabaseType(databaseType, driver), 'link') || Dec.system[DecCst.Hyperlink.DECISION_HYPERLINK_CONFIG][databaseLink];
|
|
|
|
testStatus.setFail(re.errorMsg, driver, link);
|
|
|
|
} else {
|
|
|
|
testStatus.setFail(re.errorMsg);
|
|
|
|
}
|
|
|
|
} else if (re.errorCode === errorCode.DUPLICATE_NAMES) {
|
|
|
|
testStatus.setFail(BI.i18nText(re.errorMsg));
|
|
|
|
} else {
|
|
|
|
// 不缺少驱动,但连接失败,打印出当前驱动加载路径,并显示检测驱动按钮
|
|
|
|
testStatus.setFail(re.errorMsg);
|
|
|
|
api.getDriverLoadPath(formValue).then(res => {
|
|
|
|
testStatus.setExtraContainer(createDriverTestContainer(res.data));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else if (re.data) {
|
|
|
|
testStatus.setSuccess();
|
|
|
|
resolve(re.data);
|
|
|
|
setTimeout(() => {
|
|
|
|
BI.Maskers.remove(id);
|
|
|
|
}, 1000 * 2);
|
|
|
|
} else {
|
|
|
|
BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_Error'), {
|
|
|
|
level: 'error',
|
|
|
|
});
|
|
|
|
BI.Maskers.remove(id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 驱动及冲突检测内容,补充到报错弹窗里
|
|
|
|
*/
|
|
|
|
function createDriverTestContainer(path: string) {
|
|
|
|
return {
|
|
|
|
type: BI.VerticalLayout.xtype,
|
|
|
|
vgap: 5,
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
type: BI.Label.xtype,
|
|
|
|
text: BI.i18nText('Dec-Connection_Driver_Current_Load_Path', path),
|
|
|
|
textAlign: 'left',
|
|
|
|
whiteSpace: 'normal',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: BI.TextButton.xtype,
|
|
|
|
cls: 'bi-high-light',
|
|
|
|
text: BI.i18nText('Dec-Connection_Driver_Check'),
|
|
|
|
textAlign: 'left',
|
|
|
|
handler: () => {
|
|
|
|
api.checkDriverStatus({
|
|
|
|
driver: (formValue.connectionData as ConnectionJDBC).driver,
|
|
|
|
path,
|
|
|
|
}).then(res => {
|
|
|
|
const isDriverConflict = res.data;
|
|
|
|
|
|
|
|
testStatus.setExtraContainer({
|
|
|
|
type: BI.VerticalLayout.xtype,
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
type: BI.Label.xtype,
|
|
|
|
textAlign: 'left',
|
|
|
|
text: isDriverConflict
|
|
|
|
? BI.i18nText('Dec-Connection_Driver_Has_Confilt_Tip')
|
|
|
|
: BI.i18nText('Dec-Connection_Driver_No_Confilt_Tip'),
|
|
|
|
cls: isDriverConflict ? 'bi-error' : '',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
BI.Maskers.create(id, null, {
|
|
|
|
render: {
|
|
|
|
type: TestStatus.xtype,
|
|
|
|
loadingText: BI.i18nText('Dec-Dcm_Connection_Testing'),
|
|
|
|
loadingCls: 'upload-loading-icon',
|
|
|
|
successText: BI.i18nText('Dec-Dcm_Connection_Test_Success'),
|
|
|
|
successCls: 'upload-success-icon',
|
|
|
|
failText: BI.i18nText('Dec-Dcm_Connection_Test_Fail', ''),
|
|
|
|
failCls: 'upload-fail-icon',
|
|
|
|
retryText: BI.i18nText('Dec-Dcm_Connection_ReConnect'),
|
|
|
|
ref: (_ref: any) => {
|
|
|
|
testStatus = _ref;
|
|
|
|
},
|
|
|
|
listeners: [
|
|
|
|
{
|
|
|
|
eventName: TestStatus.EVENT_RELOAD,
|
|
|
|
action: () => {
|
|
|
|
testStatus.setLoading();
|
|
|
|
testConnection();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eventName: TestStatus.EVENT_CLOSE,
|
|
|
|
action: () => {
|
|
|
|
BI.Maskers.remove(id);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
BI.Maskers.show(id);
|
|
|
|
testConnection();
|
|
|
|
});
|
|
|
|
}
|