|
|
|
import { Api } from './api';
|
|
|
|
import { Connection, TestRequest, ConnectionPoolType, SocketResult, ConnectionLicInfo } from './crud.typings';
|
|
|
|
import { requestGet, requestDelete, requestPost, requestPut } from './crud.service';
|
|
|
|
import { editStatusEvent, errorCode } from '@constants/env';
|
|
|
|
|
|
|
|
export class DecisionApi implements Api {
|
|
|
|
isDec = true;
|
|
|
|
|
|
|
|
getConnectionList(): Promise<{ data?: Connection[] }> {
|
|
|
|
return requestGet('list', {});
|
|
|
|
}
|
|
|
|
|
|
|
|
getConnectionLicInfo(): Promise<{ data?: ConnectionLicInfo }> {
|
|
|
|
return requestGet('lic/info', {});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteConnection(connectionName: string) {
|
|
|
|
return requestDelete('', {
|
|
|
|
connectionName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addConnection(data: Connection) {
|
|
|
|
const form = {
|
|
|
|
...data,
|
|
|
|
connectionId: data.connectionId || data.connectionName,
|
|
|
|
connectionData: JSON.stringify(data.connectionData),
|
|
|
|
};
|
|
|
|
|
|
|
|
return requestPost('', form);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateConnection(data: Connection) {
|
|
|
|
const form = {
|
|
|
|
...data,
|
|
|
|
connectionData: JSON.stringify(data.connectionData),
|
|
|
|
};
|
|
|
|
|
|
|
|
return requestPut('', form);
|
|
|
|
}
|
|
|
|
|
|
|
|
testConnection(data: Connection): Promise<TestRequest> {
|
|
|
|
const form = {
|
|
|
|
...data,
|
|
|
|
connectionData: JSON.stringify(data.connectionData),
|
|
|
|
};
|
|
|
|
|
|
|
|
return requestPost('test', form);
|
|
|
|
}
|
|
|
|
|
|
|
|
getConnectionPool(name: string): Promise<{ data?: ConnectionPoolType }> {
|
|
|
|
return requestGet(`pool/info?connectionName=${encodeURIComponent(name)}`, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
getSimpleDriverList(): Promise<{ data: any[] }> {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
Dec.reqGet('/v10/drivers/simple/list', '', re => {
|
|
|
|
resolve(re);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getConnectionStatus(name: string): Promise<SocketResult> {
|
|
|
|
return this.sendEditStatusEvent(name, editStatusEvent.OPEN)
|
|
|
|
.then(re => {
|
|
|
|
if (re.errorCode) {
|
|
|
|
let errorMessage = '';
|
|
|
|
switch (re.errorCode) {
|
|
|
|
case errorCode.CONNECTION_DELETED:
|
|
|
|
errorMessage = 'Dec-Dcm_Connection_Deleted';
|
|
|
|
break;
|
|
|
|
case errorCode.CONNECTION_UNDER_EDIT:
|
|
|
|
errorMessage = 'Dec-Dcm_Connection_Is_Using';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errorMessage = re.errorMsg;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BI.Msg.toast(BI.i18nText(errorMessage, re.errorMsg), {
|
|
|
|
level: 'error',
|
|
|
|
});
|
|
|
|
throw re;
|
|
|
|
} else {
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
shutdownConnectionStatus(name: string): Promise<SocketResult> {
|
|
|
|
return this.sendEditStatusEvent(name, editStatusEvent.SHUTDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
getSocketStatus(): boolean {
|
|
|
|
if (Dec) {
|
|
|
|
return Dec.socket.connected;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
isDriverError(errorCode: string) {
|
|
|
|
if (Dec) {
|
|
|
|
return DecCst.ErrorCode.LACK_DRIVER === errorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCipher(password: string) {
|
|
|
|
return Dec.Utils['getTransCipherText'](password);
|
|
|
|
}
|
|
|
|
|
|
|
|
getPlain(cipher: string) {
|
|
|
|
return Dec.Utils['getPlainText'](cipher);
|
|
|
|
}
|
|
|
|
|
|
|
|
getHyperlink(name: string) {
|
|
|
|
return Dec.system[DecCst.Hyperlink.DECISION_HYPERLINK_CONFIG][name];
|
|
|
|
}
|
|
|
|
|
|
|
|
changePrincipal(value: any) {
|
|
|
|
return requestPost(`switch/principal`, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
getPrincipals(keytab: string) {
|
|
|
|
return requestGet(`/principals?keytabPath=${keytab}`, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
getTimeOut(): Promise<{ data?: any }> {
|
|
|
|
return requestGet('kdc/timeout', {});
|
|
|
|
}
|
|
|
|
|
|
|
|
putTimeOut(value: number) {
|
|
|
|
return requestPut(`kdc/timeout?timeout=${value}`, {})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取当前lic是否可以使用JNDI数据库类型
|
|
|
|
getJNDIDatabaseStatus(): Promise<{ data?: boolean }> {
|
|
|
|
return requestGet('databasetype/limit', {});
|
|
|
|
}
|
|
|
|
|
|
|
|
private sendEditStatusEvent(name: string, type: string): Promise<SocketResult> {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
if (Dec && Dec.socket.connected) {
|
|
|
|
Dec.socketEmit(type, BI.encode(name), (re: any) => {
|
|
|
|
resolve(re);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
resolve({ data: 'success' });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|