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.
196 lines
5.8 KiB
196 lines
5.8 KiB
import { Api } from './api'; |
|
import { Connection, TestRequest, ConnectionPoolType, SocketResult, ConnectionLicInfo, ResultType, checkDriverStatusParams } 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); |
|
} |
|
|
|
/** |
|
* 获取驱动加载路径 |
|
* @returns |
|
*/ |
|
getDriverLoadPath(data: Connection): Promise<ResultType<string>> { |
|
const form = { |
|
...data, |
|
connectionData: JSON.stringify(data.connectionData), |
|
}; |
|
|
|
return requestPost('driver/path', form); |
|
} |
|
|
|
/** |
|
* 检测驱动冲突状态 |
|
* @param data 驱动路径 |
|
*/ |
|
checkDriverStatus(data: checkDriverStatusParams): Promise<ResultType<boolean>> { |
|
return requestGet(Dec.Utils.getEncodeURL('test/driver/conflict', '', data)); |
|
} |
|
|
|
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> { |
|
// TODO: 当前emit同步回调已无法执行 |
|
this.sendEditStatusEvent(name, editStatusEvent.OPEN); |
|
|
|
if (!Dec.socket?.connected) { |
|
return Promise.resolve({ data: 'success' }); |
|
} |
|
|
|
return new Promise((resolve, rejected) => { |
|
this.addEventListener(editStatusEvent.OPEN, res => { |
|
const data = JSON.parse(res.data); |
|
|
|
if (data.errorCode) { |
|
let errorMessage = ''; |
|
switch (data.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 = data.errorMessage; |
|
break; |
|
} |
|
BI.Msg.toast(BI.i18nText(errorMessage, data.errorMessage), { |
|
level: 'error', |
|
}); |
|
rejected(data); |
|
} else { |
|
resolve(res); |
|
} |
|
}); |
|
}); |
|
} |
|
|
|
setEditedConnectionStatus(name: string): Promise<SocketResult> { |
|
return this.sendEditStatusEvent(name, editStatusEvent.CONNECTION_EDITED); |
|
} |
|
|
|
shutdownConnectionStatus(name: string): Promise<SocketResult> { |
|
return this.sendEditStatusEvent(name, editStatusEvent.CONNECTION_RELEASED); |
|
} |
|
|
|
getSocketStatus(): boolean { |
|
return !!Dec?.socket?.connected; |
|
} |
|
|
|
isDriverError(errorCode: string) { |
|
if (Dec) { |
|
return DecCst.ErrorCode.LACK_DRIVER === errorCode; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
getCipher(password: string) { |
|
return BI.Providers.getProvider('dec.provider.cipher') |
|
.getCompleteCipher(password); |
|
} |
|
|
|
getPlain(cipher: string) { |
|
return BI.Providers.getProvider('dec.provider.cipher') |
|
.getCompletePlain(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?.socket?.connected) { |
|
Dec.socket.emit(type, BI.encode(name), (re: any) => { |
|
resolve(re); |
|
}); |
|
} else { |
|
resolve({ data: 'success' }); |
|
} |
|
}); |
|
} |
|
|
|
private addEventListener(name: string, callback: Function) { |
|
if (!Dec.socket) return; |
|
|
|
if (Dec.socket.hasListeners(name)) { |
|
Dec.socket.removeListener(name); |
|
} |
|
|
|
Dec.socket.on(name, callback); |
|
} |
|
}
|
|
|