UNPKG

@sap_oss/wdio-qmate-service

Version:

[![REUSE status](https://api.reuse.software/badge/github.com/SAP/wdio-qmate-service)](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[![Node.js CI](https://github.com/SAP/wdio-qmate-service/actions/workflows/node.js.yml/badge.svg)](http

179 lines 8.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserSettings = void 0; const verboseLogger_1 = require("../../helper/verboseLogger"); /** * @class userSettings * @memberof util */ class UserSettings { vlf = new verboseLogger_1.VerboseLoggerFactory("util", "userSettings"); _srvInstance = null; async initS4UserSettingService(user, password) { if (!this._srvInstance) { const vl = this.vlf.initLog(await this.initS4UserSettingService); const params = browser.config.params; if (params?.systemUrl) { try { this._srvInstance = await service.odata.init(`${params.systemUrl}/sap/opu/odata/UI2/INTEROP`, user, password); } catch (error) { if (error instanceof Error) { throw new Error(`Failed to initialize S4 User Setting Service: ${error.message}.`); } else { throw new Error("Failed to initialize S4 User Setting Service."); } } } else { throw new Error("System URL is missing in the config file."); } } } async setLanguageFromUserSettings(user, password) { const vl = this.vlf.initLog(this.setLanguageFromUserSettings); await this.initS4UserSettingService(user, password); process.env.USER_SETTINGS_LANG_KEY = await this._getLanguageResponse(this._srvInstance); util.console.info(`Language Key: ${process.env.USER_SETTINGS_LANG_KEY} was set.`); } async setDateFormatFromUserSettings(user, password) { const vl = this.vlf.initLog(this.setDateFormatFromUserSettings); await this.initS4UserSettingService(user, password); process.env.USER_SETTINGS_DATE_FORMAT = await this._getDateFormatsResponse(this._srvInstance); //removes: the whitespace characters 0-* and the brackets including the content of the brackets. util.console.info(`Date Format: ${process.env.USER_SETTINGS_DATE_FORMAT} was set.`); } async setTimeFormatFromUserSettings(user, password) { const vl = this.vlf.initLog(this.setTimeFormatFromUserSettings); await this.initS4UserSettingService(user, password); process.env.USER_SETTINGS_TIME_FORMAT = await this._getTimeFormatResponse(this._srvInstance); util.console.info(`Time Format: ${process.env.USER_SETTINGS_TIME_FORMAT} was set.`); } async setTimeZoneFromUserSettings(user, password) { const vl = this.vlf.initLog(this.setTimeZoneFromUserSettings); await this.initS4UserSettingService(user, password); const res = await service.odata.get(this._srvInstance, "UserProfileProperties", { id: "TIME_ZONE", shellType: "FLP" }); process.env.USER_SETTINGS_TIME_ZONE = await this._getTimeZoneResponse(this._srvInstance); util.console.info(`Time Zone: ${process.env.USER_SETTINGS_TIME_ZONE} was set.`); } async setNumberFormatFromUserSettings(user, password) { const vl = this.vlf.initLog(this.setNumberFormatFromUserSettings); await this.initS4UserSettingService(user, password); process.env.USER_SETTINGS_NUMBER_FORMAT = await this._getNumberFormatResponse(this._srvInstance); util.console.info(`Number Format: ${process.env.USER_SETTINGS_NUMBER_FORMAT} was set.`); } async setS4UserSettings(user, password) { const vl = this.vlf.initLog(this.setS4UserSettings); try { await this.initS4UserSettingService(user, password); await this.setDateFormatFromUserSettings(user, password); await this.setLanguageFromUserSettings(user, password); await this.setNumberFormatFromUserSettings(user, password); await this.setTimeFormatFromUserSettings(user, password); await this.setTimeZoneFromUserSettings(user, password); } catch (error) { vl.log(`Function: 'setUserSettingsForS4' failed: Unable to set the UserSettings: ${error}`); } } async getLanguageFromUserSettings(user, password) { const vl = this.vlf.initLog(this.getLanguageFromUserSettings); await this.initS4UserSettingService(user, password); return await this._getLanguageResponse(this._srvInstance); } async getDateFormatFromUserSettings(user, password) { const vl = this.vlf.initLog(this.getDateFormatFromUserSettings); await this.initS4UserSettingService(user, password); return await this._getDateFormatsResponse(this._srvInstance); } async getTimeFormatFromUserSettings(user, password) { const vl = this.vlf.initLog(this.getTimeFormatFromUserSettings); await this.initS4UserSettingService(user, password); return await this._getTimeFormatResponse(this._srvInstance); } async getTimeZoneFromUserSettings(user, password) { const vl = this.vlf.initLog(this.getTimeZoneFromUserSettings); await this.initS4UserSettingService(user, password); return await this._getTimeZoneResponse(this._srvInstance); } async getNumberFormatFromUserSettings(user, password) { const vl = this.vlf.initLog(this.getNumberFormatFromUserSettings); return await this._getNumberFormatResponse(this._srvInstance); } async _getTimeZoneResponse(srvInstance) { try { const res = await service.odata.get(srvInstance, "UserProfileProperties", { id: "TIME_ZONE", shellType: "FLP" }); return res.value.replace("/", ", "); } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get Time Zone from User Settings: ${error.message}.`); } else { throw new Error("Failed to get Time Zone from User Settings."); } } } async _getTimeFormatResponse(srvInstance) { try { const res = await service.odata.get(srvInstance, "UserProfileProperties", { id: "TIME_FORMAT", shellType: "FLP" }); const resUserData = await service.odata.get(this._srvInstance, "UserProfilePropertyValues", { id: "TIME_FORMAT", shellType: "FLP", value: res.value }); return resUserData.description.replace(/\s*\(.*?\)$/, ""); } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get Time Format from User Settings: ${error.message}.`); } else { throw new Error("Failed to get Time Format from User Settings."); } } } async _getDateFormatsResponse(srvInstance) { try { const res = await service.odata.get(srvInstance, "UserProfileProperties", { id: "DATE_FORMAT", shellType: "FLP" }); const resUserData = await service.odata.get(this._srvInstance, "UserProfilePropertyValues", { id: "DATE_FORMAT", shellType: "FLP", value: res.value }); return resUserData.description.replace(/\s*\(.*?\)$/, ""); } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get Date Format from User Settings: ${error.message}.`); } else { throw new Error("Failed to get Date Format from User Settings."); } } } async _getLanguageResponse(srvInstance) { try { const res = await service.odata.get(srvInstance, "UserProfileProperties", { id: "LANGUAGE", shellType: "FLP" }); return res.value; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get Language from User Settings: ${error.message}.`); } else { throw new Error("Failed to get Language from User Settings."); } } } async _getNumberFormatResponse(srvInstance) { try { const res = await service.odata.get(srvInstance, "UserProfileProperties", { id: "NUMBER_FORMAT", shellType: "FLP" }); const resUserData = await service.odata.get(srvInstance, "UserProfilePropertyValues", { id: "NUMBER_FORMAT", shellType: "FLP", value: res.value }); return resUserData.description.replace(/\s*\(.*?\)$/, ""); } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get Number Format from User Settings: ${error.message}.`); } else { throw new Error("Failed to get Number Format from User Settings."); } } } } exports.UserSettings = UserSettings; exports.default = new UserSettings(); //# sourceMappingURL=userSettings.js.map