Renaming + Add timeout to check the connection
MODIFY
src/integration/asset/AssetFactory.ts
src/integration/asset/AssetFactory.ts
-import { AssetConnectionType, AssetSetting } from '../../types/Setting';
-
-import AssetIntegration from './AssetIntegration';
-import AssetSchneiderIntegration from './schneider/AssetSchneiderIntegration';
-import Logging from '../../utils/Logging';
import SettingStorage from '../../storage/mongodb/SettingStorage';
+import TenantStorage from '../../storage/mongodb/TenantStorage';
+import { AssetConnectionType, AssetSetting } from '../../types/Setting';
import Tenant from '../../types/Tenant';
import TenantComponents from '../../types/TenantComponents';
-import TenantStorage from '../../storage/mongodb/TenantStorage';
+import Logging from '../../utils/Logging';
import Utils from '../../utils/Utils';
+import AssetIntegration from './AssetIntegration';
+import SchneiderAssetIntegration from './schneider/SchneiderAssetIntegration';
+
const MODULE_NAME = 'AssetFactory';
@@ -23,10 +23,10 @@ export default class AssetFactory {
// Find connection
const foundConnection = settings.asset.connections.find((connection) => connection.id === connectionID);
if (foundConnection) {
- let assetIntegrationImpl = null;
+ let assetIntegrationImpl: AssetIntegration<AssetSetting> = null;
switch (foundConnection.type) {
case AssetConnectionType.SCHNEIDER:
- assetIntegrationImpl = new AssetSchneiderIntegration(tenantID, settings.asset, foundConnection);
+ assetIntegrationImpl = new SchneiderAssetIntegration(tenantID, settings.asset, foundConnection);
break;
}
return assetIntegrationImpl;

RENAME
src/integration/asset/schneider/AssetSchneiderIntegration.ts
src/integration/asset/schneider/SchneiderAssetIntegration.ts
@@ -5,11 +5,12 @@ import { AssetConnectionSetting, AssetSetting } from '../../../types/Setting';
import Constants from '../../../utils/Constants';
import Cypher from '../../../utils/Cypher';
import AssetIntegration from '../AssetIntegration';
+import Utils from '../../../utils/Utils';
-const MODULE_NAME = 'AssetSchneiderIntegration';
+const MODULE_NAME = 'SchneiderAssetIntegration';
-export default class AssetSchneiderIntegration extends AssetIntegration<AssetSetting> {
+export default class SchneiderAssetIntegration extends AssetIntegration<AssetSetting> {
public constructor(tenantID: string, settings: AssetSetting, connection: AssetConnectionSetting) {
super(tenantID, settings, connection);
}
@@ -23,10 +24,12 @@ export default class AssetSchneiderIntegration extends AssetIntegration<AssetSet
params.append('username', this.connection.connection.user);
params.append('password', Cypher.decrypt(this.connection.connection.password));
// Send credentials to get the token
- await axios.post(`${this.connection.url}/GetToken`, params,
- {
+ await Utils.promiseWithTimeout(5000,
+ axios.post(`${this.connection.url}/GetToken`, params, {
headers: this.buildFormHeaders()
- });
+ }),
+ `Time out error (5s) when trying to test the connection URL '${this.connection.url}/GetToken'`
+ );
}
private isAssetConnectionInitialized(): void {
@@ -40,9 +43,9 @@ export default class AssetSchneiderIntegration extends AssetIntegration<AssetSet
}
}
- private buildFormHeaders(): object {
+ private buildFormHeaders(): any {
return {
'Content-Type': 'application/x-www-form-urlencoded'
- }
+ };
}
}

Renaming + Add timeout to check the connection